When building PXE based boot environments it's often desirable to have read-only / systems. Now when localmount executes /etc by implication will also be read-only, and localmount will fail. A simple check (as in /etc/init.d/root) is possible to check if /etc is r/o and pass -n to mount in those cases. Personally my root PXE environments has /etc/mtab symlinked to /proc/mounts, but there may be better solutions for this. Reproducible: Always
Created attachment 309621 [details, diff] localmount-ro-etc.patch Very simple "fix" for the situation. Potentially one can re-check rw status after mount and create /etc/mtab from /proc/mounts after mounting the local filesystems ... I dunno ... shouldn't be hard to do: if [ -n "${etcreadonly}" && echo 2>/dev/null >/etc/.test.$$ ]; then rm -rf /etc/mtab /etc/.test.$$ cp /proc/mounts /etc/mtab fi as example might do the trick (after applying attached patch).
if /etc/mtab is a symlink to /proc/mounts, why do you need `mount -n` ?
jkroon@blackpearl ~ $ ls -la /proc/mounts lrwxrwxrwx 1 root root 11 May 1 20:15 /proc/mounts -> self/mounts jkroon@blackpearl ~ $ ls -la /proc/self/mounts -r--r--r-- 1 jkroon jkroon 0 May 1 20:15 /proc/self/mounts So mount trying to open /etc/mtab would result in access denied and a mount failure.
when you're root, permissions/ownership don't generally apply $ sudo su - # echo asdf > foo # chown 1234:1234 foo # chmod 000 foo # cat foo asdf further, as you pointed out, /proc/self/mounts has the permission of the app that's being executed. `mount` is run as root, thus /proc/self/mounts would be owned by root, not by you. /proc/self/ is a symlink of the active process, so running `ls` as non-root is merely showing that your `ls` is being run as you.
As root then: blackpearl ~ # echo foo > /proc/mounts -su: echo: write error: Invalid argument blackpearl ~ #
that isn't a permission issue. /proc/mounts is not a writable file. but `mount` already has logic for when /etc/mtab points to /proc/mounts because of that.
Wasn't aware of that. Apologies for the noise.