On my Arch Linux system (Linux Kernel 3.14.2) bind mounts do not respect the read only option
# mkdir test
# mount --bind -o ro test/ /mnt
# touch /mnt/foo
creates the file /mnt/foo
. The relevant entry in /proc/mounts
is
/dev/sda2 /mnt ext4 rw,noatime,data=ordered 0 0
The mount options do not match my requested options, but do match both the read/write behaviour of the bind mount and the options used to originally mount /dev/sda2
on /
/dev/sda2 / ext4 rw,noatime,data=ordered 0 0
If, however, I remount the mount then it respects the read only option
# mount --bind -o remount,ro test/ /mnt
# touch /mnt/bar
touch: cannot touch ‘/mnt/bar’: Read-only file system
and the relevant entry in /proc/mounts/
/dev/sda2 /mnt ext4 ro,relatime,data=ordered 0 0
looks like what I might expect (although in truth I would expect to see the full path of the test
directory). The entry in /proc/mounts/
for the orignal mount of /dev/sda2/
on /
is also unchanged and remains read/write
/dev/sda2 / ext4 rw,noatime,data=ordered 0 0
This behaviour and the work around have been known since at least 2008 and are documented in the man page of mount
Note that the filesystem mount options will remain the same as those on the original mount point, and cannot be changed by passing the -o option along with --bind/--rbind. The mount options can be changed by a separate remount command
Not all distributions behave the same. Arch seems to silently fail to respect the options while Debian generates a warning when the bind mount does not get mount read-only
mount: warning: /mnt seems to be mounted read-write.
There are reports that this behaviour was "fixed" in Debian Lenny and Squeeze although it does not appear to be a universal fix nor does it still work in Debian Wheezy. What is the difficultly associated with making bind mount respect the read only option on the initial mount?
mount -t bind
and a helper script at bugs.launchpad.net/ubuntu/+source/mountall/+bug/519380/etc/mtab
. After the initial mount the entry says the mount is rw and after the remount it says ro, so it is reporting the state of the mount correctly. It is just the mount command that fails.mount --bind -o ro
, they both spit out a messagemount: warning: «mountpoint» seems to be mounted read-write.
So it seems Debian dropped or lost the patch at some point... Remount works, though.