Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 412781 - localmount doesn't support ro /etc
Summary: localmount doesn't support ro /etc
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal major
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2012-04-20 14:10 UTC by Jaco Kroon
Modified: 2012-05-02 06:09 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
localmount-ro-etc.patch (localmount-ro-etc.patch,646 bytes, patch)
2012-04-20 14:13 UTC, Jaco Kroon
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaco Kroon 2012-04-20 14:10:15 UTC
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
Comment 1 Jaco Kroon 2012-04-20 14:13:05 UTC
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).
Comment 2 SpanKY gentoo-dev 2012-04-29 01:42:22 UTC
if /etc/mtab is a symlink to /proc/mounts, why do you need `mount -n` ?
Comment 3 Jaco Kroon 2012-05-01 18:17:01 UTC
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.
Comment 4 SpanKY gentoo-dev 2012-05-01 18:31:05 UTC
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.
Comment 5 Jaco Kroon 2012-05-01 18:37:11 UTC
As root then:

blackpearl ~ # echo foo > /proc/mounts 
-su: echo: write error: Invalid argument
blackpearl ~ #
Comment 6 SpanKY gentoo-dev 2012-05-01 20:18:43 UTC
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.
Comment 7 Jaco Kroon 2012-05-02 06:09:53 UTC
Wasn't aware of that. Apologies for the noise.