You are not logged in.
I'm trying to figure out how to mount a directory (bind) as read-only in /etc/fstab.
Some background:
With the following entry in fstab:
/tmp/testmount /tmp/testmount_ro none bind,ro 0 0
I get the following error when trying to mount:
$ mount /tmp/testmount_ro
mount: warning: /tmp/testmount_ro seems to be mounted read-write.
$ touch /tmp/testmount_ro/test
$ ls /tmp/testmount_ro
test
$ rm /tmp/testmount_ro/test
$ umount /tmp/testmount_ro/
Testing from the command line, I get the same error:
$ mount /tmp/testmount /tmp/testmount_ro -o bind,ro
mount: warning: /tmp/testmount_ro seems to be mounted read-write.
$ touch /tmp/testmount_ro/test
$ ls /tmp/testmount_ro
test
$ rm /tmp/testmount_ro/test
but I don't get the error if I remount it as read-only:
$ mount /tmp/testmount /tmp/testmount_ro -o remount,ro
$ touch /tmp/testmount_ro/test
touch: cannot touch `/tmp/testmount_ro/test': Read-only file system
but it turns out it's actually doing the read-only remount on the partition above (/tmp)
$ touch /tmp/test
touch: cannot touch `/tmp/test': Read-only file system
Does anyone know how to get this working in fstab (or otherwise)? Should I be using a different method for providing a read-only version of a directory?
Last edited by emphire (2011-02-24 00:49:26)
Offline
From the mount manpage, it doesn't seem like you can do it:
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, for example:mount --bind olddir newdir
mount -o remount,ro newdirNote that behavior of the remount operation depends on the /etc/mtab file. The first command stores the 'bind'
flag to the /etc/mtab file and the second command reads the flag from the file. If you have a system without the
/etc/mtab file or if you explicitly define source and target for the remount command (then mount(8) does not read
/etc/mtab), then you have to use bind flag (or option) for the remount command too. For example:mount --bind olddir newdir
mount -o remount,ro,bind olddir newdir
You might have to hack-solve it by adding the remount command to rc.local
Last edited by fukawi2 (2011-02-23 23:02:32)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
You might have to hack-solve it by adding the remount command to rc.local
I was hoping to do it from /etc/fstab, but an rc.local hack it is! Thanks!
Offline