Skip to contentSkip to conversation

overlayfs: mounting overlayfs on top of overlayfs

DISCUSSION Jordi Pujol 2 participants 7 messages Jun 3, 2011 – Jun 10, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello,

The attached script (test05.sh) makes a read-only overlayfs mount on top of another readonly overlayfs mount, repeating this in a loop,

when all the read-only filesystems are mounted, then it mounts another overlayfs that uses the last read-only rootdir as lowerdir and a read-write filesystem in upperdir,

this method gives persistence to mount and unmount, overlayfs will save the fs changes in the read-write upperdir.

But it gives a problem when we try to edit the files that are only on the most upper read-only dir, ( that files are not included in lower read-only dirs ).

# sed -i -e s|a|a|g /tmp/tmp.b/tmp.k/etc/apache2/conf.d/continuoustrade.conf
sed: couldn't open temporary file 
/tmp/tmp.b/tmp.k/etc/apache2/conf.d/sedthJcp8: Read-only file system

when we "touch" the file, therefore can be edited.

# touch /tmp/tmp.b/tmp.k/etc/apache2/conf.d/continuoustrade.conf
(OK)
# sed -i -e s|a|a|g /tmp/tmp.b/tmp.k/etc/apache2/conf.d/continuoustrade.conf
(OK)

the same happens using KDE editors like kate or kwrite.

P.D: is included another testing script (test04.sh) that mounts all levels in read/write mode, it works, but this method is worse because uses multiple directories to save the changed files and when modifying the files are copied several times across the directories.

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com

+ set -x
+ set -e
+ mktemp -d -p /tmp
+ WORK_DIR=/tmp/tmp.bYP9FObwD6
+ unset uf lf
+ read uf
+ [ -e /lnet/image/LneTPers64/00filesystem.squashfs ]
+ [ -d /lnet/image/LneTPers64/00filesystem.squashfs ]
+ basename /lnet/image/LneTPers64/00filesystem.squashfs
+ u=/tmp/tmp.bYP9FObwD6/00filesystem.squashfs
+ mkdir -p /tmp/tmp.bYP9FObwD6/00filesystem.squashfs
+ mount -o loop /lnet/image/LneTPers64/00filesystem.squashfs /tmp/tmp.bYP9FObwD6/00filesystem.squashfs
+ [ -n ]
+ lf=/tmp/tmp.bYP9FObwD6/00filesystem.squashfs
+ read uf
+ [ -e /lnet/image/LneTPers64/12firmwarert.squashfs ]
+ [ -d /lnet/image/LneTPers64/12firmwarert.squashfs ]
+ basename /lnet/image/LneTPers64/12firmwarert.squashfs
+ u=/tmp/tmp.bYP9FObwD6/12firmwarert.squashfs
+ mkdir -p /tmp/tmp.bYP9FObwD6/12firmwarert.squashfs
+ mount -o loop /lnet/image/LneTPers64/12firmwarert.squashfs /tmp/tmp.bYP9FObwD6/12firmwarert.squashfs
+ [ -n /tmp/tmp.bYP9FObwD6/00filesystem.squashfs ]
+ [ -d /tmp/tmp.bYP9FObwD6/00filesystem.squashfs ]
+ l=/tmp/tmp.bYP9FObwD6/00filesystem.squashfs
+ mktemp -d -p /tmp/tmp.bYP9FObwD6
+ r=/tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH
+ mount -t overlayfs -o ro,lowerdir=/tmp/tmp.bYP9FObwD6/00filesystem.squashfs,upperdir=/tmp/tmp.bYP9FObwD6/12firmwarert.squashfs overlayfs /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH
+ lf=/tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH
+ read uf
+ [ -e /lnet/image/LneTPers64/90pcjordi.squashfs ]
+ [ -d /lnet/image/LneTPers64/90pcjordi.squashfs ]
+ basename /lnet/image/LneTPers64/90pcjordi.squashfs
+ u=/tmp/tmp.bYP9FObwD6/90pcjordi.squashfs
+ mkdir -p /tmp/tmp.bYP9FObwD6/90pcjordi.squashfs
+ mount -o loop /lnet/image/LneTPers64/90pcjordi.squashfs /tmp/tmp.bYP9FObwD6/90pcjordi.squashfs
+ [ -n /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH ]
+ [ -d /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH ]
+ l=/tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH
+ mktemp -d -p /tmp/tmp.bYP9FObwD6
+ r=/tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF
+ mount -t overlayfs -o ro,lowerdir=/tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH,upperdir=/tmp/tmp.bYP9FObwD6/90pcjordi.squashfs overlayfs /tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF
+ lf=/tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF
+ read uf
+ [ -d /tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF ]
+ mktemp -d -p /tmp/tmp.bYP9FObwD6
+ ROOT_DIR=/tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b
+ mktemp -d -p /tmp/tmp.bYP9FObwD6
+ COW_DIR=/tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW
+ mount -t overlayfs -o rw,lowerdir=/tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF,upperdir=/tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW overlayfs /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b
+ echo rootdir: /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b
rootdir: /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b
+ echo COW: /tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW
COW: /tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW
+ find /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2 -type f
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/continuoustrade.conf
sed: couldn't open temporary file /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/sedthJcp8: Read-only file system
+ :
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/jplive.conf
sed: couldn't open temporary file /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/sed7QBon8: Read-only file system
+ :
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/libretto.conf
sed: couldn't open temporary file /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/sedpu5gN8: Read-only file system
+ :
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/librettoweb.conf
sed: couldn't open temporary file /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/sed73phL8: Read-only file system
+ :
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/ports.conf
sed: couldn't open temporary file /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/sedvNIHA8: Read-only file system
+ :
+ find /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2 -type f
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/continuoustrade.conf
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/jplive.conf
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/libretto.conf
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/librettoweb.conf
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/ports.conf
+ find /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2 -type f

+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/continuoustrade.conf
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/jplive.conf
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/libretto.conf
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/conf.d/librettoweb.conf
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/apache2/ports.conf
+ find /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default -type f
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/acpid
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/alsa
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/bluetooth
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/bootlogd
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cacerts
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cgconfig
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cgred
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/console-setup
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cron
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cups
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/dbus
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/devpts
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/halt
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ifupdown
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/irqbalance
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/jobadmind
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/kdm.d/10_desktop-base
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/kexec
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/keyboard
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-firewall
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-service-defaults
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-upnpclient
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/locale
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/nss
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ntpdate
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/openvpn
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rcS
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rsync
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rsyslog
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/samba
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/saned
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ssh
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/tmpfs
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/useradd
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/vnc-lnet
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/xinetd

+ find /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default -type f
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/acpid
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/alsa
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/bluetooth
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/bootlogd
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cacerts
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cgconfig
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cgred
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/console-setup
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cron
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cups
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/dbus
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/devpts
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/halt
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ifupdown
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/irqbalance
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/jobadmind
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/kdm.d/10_desktop-base
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/kexec
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/keyboard
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-firewall
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-service-defaults
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-upnpclient
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/locale
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/nss
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ntpdate
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/openvpn
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rcS
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rsync
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rsyslog
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/samba
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/saned
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ssh
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/tmpfs
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/useradd
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/vnc-lnet
+ touch /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/xinetd
+ find /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default -type f

+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/acpid
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/alsa
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/bluetooth
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/bootlogd
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cacerts
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cgconfig
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cgred
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/console-setup
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cron
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/cups
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/dbus
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/devpts
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/halt
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ifupdown
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/irqbalance
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/jobadmind
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/kdm.d/10_desktop-base
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/kexec
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/keyboard
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-firewall
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-service-defaults
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/lnet-upnpclient
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/locale
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/nss
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ntpdate
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/openvpn
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rcS
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rsync
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/rsyslog
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/samba
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/saned
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/ssh
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/tmpfs
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/useradd
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/vnc-lnet
+ sed -i -e s|a|a|g /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b/etc/default/xinetd

+ mount
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
rootfs on / type rootfs (rw)
tmpfs on /run type tmpfs (rw,nosuid,relatime,size=410976k,mode=755)
tmpfs on /lnet type tmpfs (rw,relatime,size=2054872k)
/dev/sda1 on /lnet/image type ext3 (ro,noatime,errors=continue,barrier=0,data=writeback,commit=0)
/dev/loop0 on /lnet/00filesystem.squashfs type squashfs (ro,noatime)
/dev/sda2 on /lnet/cowroot type ext4 (rw,relatime,user_xattr,acl,barrier=1,data=ordered,commit=0)
/lnet/cowroot/LneTPersCOW on /lnet/cow type none (rw,bind,commit=0)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,relatime,size=2054872k)
tmpfs on /var/log type tmpfs (rw,nosuid,relatime,size=2054872k,mode=755)
tmpfs on /var/tmp type tmpfs (rw,nosuid,nodev,relatime,size=2054872k)
cgroup on /sys/fs/cgroup type cgroup (rw,relatime,memory,cpu)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,relatime,size=2054872k)
/lnet/cowroot/LneThome on /home type none (rw,bind,commit=0)
/home/JPLive/cacheapt-amd64 on /var/cache/apt type none (rw,bind,commit=0)
/home/JPLive/libapt-amd64 on /var/lib/apt type none (rw,bind,commit=0)
/home/JPLive/var-spool on /var/spool type none (rw,bind,commit=0)
/dev/loop4 on /tmp/tmp.bYP9FObwD6/00filesystem.squashfs type squashfs (ro)
/dev/loop5 on /tmp/tmp.bYP9FObwD6/12firmwarert.squashfs type squashfs (ro)
/home/JPLive/git/linux-2.6/overlayfs/overlayfs on /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH type overlayfs (ro,lowerdir=/tmp/tmp.bYP9FObwD6/00filesystem.squashfs,upperdir=/tmp/tmp.bYP9FObwD6/12firmwarert.squashfs) /dev/loop6 on /tmp/tmp.bYP9FObwD6/90pcjordi.squashfs type squashfs (ro)
/home/JPLive/git/linux-2.6/overlayfs/overlayfs on /tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF type overlayfs (ro,lowerdir=/tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH,upperdir=/tmp/tmp.bYP9FObwD6/90pcjordi.squashfs) /home/JPLive/git/linux-2.6/overlayfs/overlayfs on /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b type overlayfs (rw,lowerdir=/tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF,upperdir=/tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW)
+ umount /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b
+ find /tmp/tmp.bYP9FObwD6 -mindepth 1 -maxdepth 1 -type d
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW ]
+ mountpoint /tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW
/tmp/tmp.bYP9FObwD6/tmp.Cb0t6fshqW is not a mountpoint
+ :
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b ]
+ mountpoint /tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b
/tmp/tmp.bYP9FObwD6/tmp.k41C1t8H8b is not a mountpoint
+ :
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF ]
+ mountpoint /tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF
/tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF is a mountpoint
+ umount /tmp/tmp.bYP9FObwD6/tmp.zX0iRoUfKF
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/90pcjordi.squashfs ]
+ mountpoint /tmp/tmp.bYP9FObwD6/90pcjordi.squashfs
/tmp/tmp.bYP9FObwD6/90pcjordi.squashfs is a mountpoint
+ umount /tmp/tmp.bYP9FObwD6/90pcjordi.squashfs
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH ]
+ mountpoint /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH
/tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH is a mountpoint
+ umount /tmp/tmp.bYP9FObwD6/tmp.n7ZqjtjpxH
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/12firmwarert.squashfs ]
+ mountpoint /tmp/tmp.bYP9FObwD6/12firmwarert.squashfs
/tmp/tmp.bYP9FObwD6/12firmwarert.squashfs is a mountpoint
+ umount /tmp/tmp.bYP9FObwD6/12firmwarert.squashfs
+ read f
+ [ -d /tmp/tmp.bYP9FObwD6/00filesystem.squashfs ]
+ mountpoint /tmp/tmp.bYP9FObwD6/00filesystem.squashfs
/tmp/tmp.bYP9FObwD6/00filesystem.squashfs is a mountpoint
+ umount /tmp/tmp.bYP9FObwD6/00filesystem.squashfs
+ read f
+ :

#1 lore raw

Hello,

Here is attached an automated script that creates his own test data and reproduces the problem,

I have observed that the problem does not appear when we use as lower dir a read/write directory and not an squashfs compressed file.

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com

#2 lore raw

Hello,

The attached patch solves the problem,

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com

overlayfs v10:
- Test for readonly using the vfsmount superblock from the main filesystem.
- Ignore WRITE request for the real filesystems.

fs/overlayfs/inode.c +5 -0
@@ -54,6 +54,9 @@ int ovl_permission(struct inode *inode,
 	bool is_upper;
 	int err;
 
+	if (mask & MAY_WRITE && IS_RDONLY(inode))
+		return -EROFS;
+
 	if (S_ISDIR(inode->i_mode)) {
 		oe = inode->i_private;
 	} else if (flags & IPERM_FLAG_RCU) {
@@ -102,6 +105,8 @@ int ovl_permission(struct inode *inode,
 		err = -EACCES;
 		if (IS_IMMUTABLE(realinode))
 			goto out_dput;
+
+		mask &= ~MAY_WRITE;
 	}
 
 	if (realinode->i_op->permission)
maintainer
#3 lore raw
Quoted 32 lines · Jordi Pujol

Hello,

The attached patch solves the problem,

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com

overlayfs v10:
- Test for readonly using the vfsmount superblock from the main filesystem.
- Ignore WRITE request for the real filesystems.

fs/overlayfs/inode.c +3 -0
@@ -54,6 +54,9 @@ int ovl_permission(struct inode *inode,
 	bool is_upper;
 	int err;
 
+	if (mask & MAY_WRITE && IS_RDONLY(inode))
+		return -EROFS;
+
 	if (S_ISDIR(inode->i_mode)) {
 		oe = inode->i_private;
 	} else if (flags & IPERM_FLAG_RCU) {

fs/overlayfs/inode.c int ovl_permission(struct inode *inode, · line 109

Quoted 5 lines
fs/overlayfs/inode.c +2 -0
@@ -102,6 +105,8 @@ int ovl_permission(struct inode *inode,
 		err = -EACCES;
 		if (IS_IMMUTABLE(realinode))
 			goto out_dput;
+
+		mask &= ~MAY_WRITE;

Well, this is not correct. We *do* want to check for write permission. The above would simply ignore the access control.

What are the permission bits on the file in question?

Thanks,
Miklos

#4 lore raw

A Dimarts, 7 de juny de 2011 10:08:48, Miklos Szeredi va escriure:

Quoted 1 line

Well, this is not correct. We *do* want to check for write permission.

Well, another of my patches that solve the problem making a workaround,

Quoted 1 line

The above would simply ignore the access control.

only in some case.

Quoted 1 line

What are the permission bits on the file in question?

the problem is that sed can't create the temporary file in the same directory, normally sed will create it using umask permissions, 0022 in my system,

try the automated test contained in my previous message, it creates a log file that shows the errors.

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com

maintainer
#5 lore raw
Quoted 7 lines · Jordi Pujol

A Dimarts, 7 de juny de 2011 10:08:48, Miklos Szeredi va escriure:

Quoted 1 line

Well, this is not correct. We *do* want to check for write permission.

Well, another of my patches that solve the problem making a workaround,

Quoted 1 line

The above would simply ignore the access control.

only in some case.

Quoted 8 lines
Quoted 1 line

What are the permission bits on the file in question?

the problem is that sed can't create the temporary file in the same directory, normally sed will create it using umask permissions, 0022 in my system,

try the automated test contained in my previous message, it creates a log file that shows the errors.

Thanks for the script, it helped.

The attached patch should fix it. It's not a generic solution and other filesystems may still not function correctly as a read-only lower layer (e.g. I can see that btrfs has some sort of "r/o volume flag").

That can be fixed by checking file mode and acl instead of calling ->permission() on the lower inode. Will add that as a FIXME item.

Thanks,
Miklos

commit 0896db57a7e8ab075278c8d46a2620a3f32d866f

Author: Miklos Szeredi <[email protected]>
Date:   Wed Jun 8 16:53:50 2011 +0200

ovl: fix overlayfs over overlayfs

Overlayfs expects ->permission() to not check for readonliness (which is normally checked by the VFS) and so not return with -EROFS. This is not true of some filesystems, notably overlayfs itself.

The following patch should fix this by making sure that if the upper layer is read-only (such as squashfs) then it will mark overlayfs read-only too and by making ovl_permission() only return EROFS in the excpetional case where the upper filesystem became r/o after the overlay was constructed.

fs/overlayfs/inode.c +10 -1
index 289006e..ce39fab 100644
@@ -90,9 +90,18 @@ int ovl_permission(struct inode *inode, int mask, unsigned int flags)
 		/*
 		 * Writes will always be redirected to upper layer, so
 		 * ignore lower layer being read-only.
+		 *
+		 * If the overlay itself is read-only then proceed
+		 * with the permission check, don't return EROFS.
+		 * This will only happen if this is the lower layer of
+		 * another overlayfs.
+		 *
+		 * If upper fs becomes read-only after the overlay was
+		 * constructed return EROFS to prevent modification of
+		 * upper layer.
 		 */
 		err = -EROFS;
-		if (is_upper && IS_RDONLY(realinode) &&
+		if (is_upper && !IS_RDONLY(inode) && IS_RDONLY(realinode) &&
 		    (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
 			goto out_dput;
 
fs/overlayfs/super.c +4 -0
index 7109b45..c741b17 100644
@@ -548,6 +548,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 		goto out_put_upper_mnt;
 	}
 
+	/* If the upper fs is r/o, we mark overlayfs r/o too */
+	if (ufs->upper_mnt->mnt_sb->s_flags & MS_RDONLY)
+		sb->s_flags |= MS_RDONLY;
+
 	if (!(sb->s_flags & MS_RDONLY)) {
 		err = mnt_want_write(ufs->upper_mnt);
 		if (err)
#6 lore raw

Hello,

Here are my comments about this patch:

I think "append" should also be prohibited in a read-only fs.

if (mask & (MAY_WRITE | MAY_APPEND))

About the readonly modification on the main filisystem mount, before this modification overlayfs already emited a warning message when mounting using a read only upperdir. Following is an old log:

+ COW_DIR=/tmp/TEST-sz5/COW-Mec
+ mount -t tmpfs -o ro tmpfs /tmp/TEST-sz5/COW-Mec
+ mount -t overlayfs -o rw,lowerdir=/tmp/TEST-sz5/ROOT-RO- kei,upperdir=/tmp/TEST-sz5/COW-Mec overlayfs /tmp/TEST-sz5/ROOT-S1M
mount: block device overlayfs is write-protected, mounting read-only (warning, return code 0)

+ mount -o remount,rw /tmp/TEST-sz5/ROOT-S1M
mount: cannot remount block device overlayfs read-write, is write-protected (error, rc 32)

+ mount -l
overlayfs on /tmp/TEST-sz5/ROOT-S1M type overlayfs (ro,

but now, after appliying the last patch, the behaviour is very confused:
- there is no warning message when mounting overlayfs rw on a ro upperdir
- /proc/mounts shows overlayfs as a rw fs while really it is ro

+ mount -l
...
tmpfs on /tmp/TEST-Eo7/COW-uYW type tmpfs (ro)
overlayfs on /tmp/TEST-Eo7/ROOT-dAb type overlayfs (rw,lowerdir=/tmp/TEST- Eo7/ROOT-RO-TfK,upperdir=/tmp/TEST-Eo7/ROOT-RO-TfK,upperdir=/tmp/TEST-Eo7/COW- uYW)
+ mount -o remount,rw /tmp/TEST-Eo7/ROOT-dAb
mount: cannot remount block device overlayfs read-write, is write-protected

Sincerely, the previous behaviour was better,

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com