Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 19972  / 3 Years ago, sun, may 16, 2021, 1:00:04

I need to remount one directory (/src) as readonly in another location (/dst). This can be done like this:



$ sudo mount --bind /src /dst
$ sudo mount -o remount,ro /dst


However, I would like to use /etc/fstab to have the mount taking place at boot time and have seen different suggested solutions to this problem, e.g.



/src  /dst    none  bind            0 0
/src /dst none remount,bind,ro 0 0


which unfortunately leaves the directory mounted read/write on my system and this



/src  /dst    none  bind            0 0
/dst /dst none remount,bind,ro 0 0


which will issue an error when trying to mount /dst:



mount: /dst not mounted already, or bad option


The above solutions supposedly works on different distros, but unfortunately not on Ubuntu 10.04.4 LTS (kernel 2.6.32-41-server).



Any ideas how to accomplish this apart from placing the mount commands into /etc/rc.local?


More From » mount

 Answers
4

On older kernels, mount --bind cannot create a read-only view of a read-write filesystem. The kernel stores the read-write status of the filesystem in a single place which is not duplicated by the bind mount. Newer kernels allow this but still require a separate mount step: first bind, then make read-only. There is a kernel patch to change that, and some distributions (such as Debian) have applied it, but Ubuntu hasn't (at least not as of 12.04).



One solution is to create the read-only view from a boot script instead from /etc/fstab, as Oli explains.



Otherwise, you can use bindfs instead. This is a FUSE filesystem. Going through FUSE is slightly slower as it introduces an additional layer of indirection. You also lose support for extended file metadata such as ACLs. On the flip side, the read-only view will have a recognizable filesystem type, making it easy to exclude from filesystem traversals (such as locate and backups).



The fstab entry looks like this:



bindfs#/src  /dst  fuse perms=a=rX

[#38528] Tuesday, May 18, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
umplegitimat

Total Points: 137
Total Questions: 126
Total Answers: 118

Location: Saint Pierre and Miquelon
Member since Sat, Aug 21, 2021
3 Years ago
umplegitimat questions
;