3

I use mount --bind to "overlay" a file from one ext4,rw filesystem onto another file in ext4,ro filesystem. For example, /etc/hosts is on a read-only / partition, but I have another partition where /rw/etc/hosts is writable. So when I do

# mount --bind /rw/etc/hosts /etc/hosts

any writes to /etc/hosts will go to /rw/etc/hosts


This worked fine in CentOS 6.3.
# mount -o ro /dev/sdc1 /ro
# mount -o rw /dev/sdc2 /rw
# mount --bind rw/test ro/test
# echo 1 > rw/test
# cat ro/test
1
# echo 2 > ro/test                    # [1]
# cat rw/test
2

But I cannot get it to work in CentOS 6.4 I repeat the steps from above, but I get an error when trying to write to ro/test:

# echo 2 > ro/test                    # [1]
-bash: ro/test: Read-only file system

SELinux is disabled. Any ideas what could cause this to stop working?

CentOS 6.3 kernel: 2.6.32-279.22.1.el6.x86_64
CentOS 6.4 kernel: 2.6.32-358.el6.x86_64 and 2.6.32-358.2.1.el6.x86_64

Ivan
  • 31
  • CentOS 6.3 and CentOS 6.4 have had a variety of different kernel versions. Can you be more specific about the versions of the kernels that do and do not work for you? –  Apr 12 '13 at 02:43
  • @KenStailey Updated the question with the kernel versions. – Ivan Apr 12 '13 at 18:11
  • Probably a bug of some kind, but what happens if you specifically mount -o remount,rw your test? – mikeserv Mar 23 '14 at 20:47

2 Answers2

1

Any ideas what could cause this to stop working?

Probably a bug that was introduced into the kernel along with support for fsfreeze. I opened BZ #951311 to track this.

  • I don't have access to the bug you filed, but I will file one myself. It could be related/duplicate. – Ivan Apr 12 '13 at 18:13
-2
# mount --bind rw/test ro/test
# echo 1 > rw/test

You can only mount directories.

You cannot use echo to write into a directory.

You probably want

# mount --bind rw ro
  • 2
    You can mount --bind files. Please see: http://unix.stackexchange.com/questions/44373/single-bind-mounted-file-gets-out-of-sync-in-linux – Ivan Apr 12 '13 at 01:04
  • 1
    Heh, the man page for mount(8) needs some updating. The man page for mount(2) gets it right but mount(8) says newdir and olddir not newnode, etc. –  Apr 12 '13 at 01:10