Bug 450646 - /sbin/mount.nfs fails with read-only /etc
/sbin/mount.nfs fails with read-only /etc
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: nfs-utils (Show other bugs)
All Linux
low Severity medium
: rc
: ---
Assigned To: Steve Dickson
Depends On:
Blocks: 457524
  Show dependency treegraph
Reported: 2008-06-10 01:57 EDT by Istvan Marko
Modified: 2010-10-22 21:48 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-09-02 06:03:19 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Patch against mount.c which resolves the problem. (347 bytes, patch)
2008-10-08 04:51 EDT, Ondrej Valousek
no flags Details | Diff
Patch for RO /etc/mtab (611 bytes, patch)
2008-11-07 13:39 EST, Shane Bradley
no flags Details | Diff

  None (edit)
Description Istvan Marko 2008-06-10 01:57:03 EDT
Description of problem:

/sbin/mount.nfs from nfs-utils-1.0.9-33 as shipped with RHEL 5.2
doesn't work with a read-only /etc (which you would find on nfsroot
or stateless installations).

It's the following patch that broke things:

Patch25: nfs-utils-1.0.10-mount-mtablock.patch
# 227985: /sbin/mount.nfs mtab lock

Before that patch the mtab mangling code ignored the failed
lock. That's obviously not the right behavior either but it allowed
for a working nfsroot/stateless installation.

The proper fix is to make mount.nfs check if /etc/mtab a symlink to
/proc/mounts (as it typically is on systems with a r/o /etc) and don't
try to lock or modify it if it is. /bin/mount already does this,
mount.nfs should match that behavior. Ditto for umount.nfs and

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Bring up a system that has the filesystem containing /etc mounted read-only.
2. Try to mount an NFS volume:
   # mount filer:/path /mnt

Actual results:
can't create lock file /etc/mtab~19675: Read-only file system (use -n flag to override)

Expected results:
a mounted filesystem

Additional info:
Comment 1 Ondrej Valousek 2008-08-02 04:47:32 EDT
I can reproduce this as well. The problem is at line 541 of utils/mount/mount.c:
        if (!nomtab) {
                add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
                         flags, extra_opts, 0, 0);
It should probably read somehing like
        if (!nomtab && mtab_is_writable()) {
                add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
                         flags, extra_opts, 0, 0);
Comment 2 Ondrej Valousek 2008-10-08 04:51:10 EDT
Created attachment 319735 [details]
Patch against mount.c which resolves the problem.

Please find the attached patch which resolves my problem.
I have verified it and it works OK.
Can this go into the mainstream?
Comment 3 Bryn M. Reeves 2008-10-22 07:54:31 EDT
The patch doesn't seem unreasonable to me, although I wonder if it's better to place the call to mtab_is_writable() inside add_mtab(), as this would be more in keeping with what is currently done for update_mtab() in support/nfs/fstab.c:

update_mtab (const char *dir, nfs_mntent_t *instead) {
        mntFILE *mfp, *mftmp;
        const char *fnam = MOUNTED;
        struct mntentchn mtabhead;      /* dummy */
        struct mntentchn *mc, *mc0, *absent = NULL;

        if (mtab_does_not_exist() || !mtab_is_writable())

I.e. make the check on the mtab file inside the routine that updates it, rather than in each caller of that function.
Comment 4 Ondrej Valousek 2008-10-22 09:03:49 EDT
Well yes, you are right. But if you want to do it this way I would do it cleanly in 2 steps:
1. remove the condition "if(!nomtab)" from mount.c so that add_mtab is called every time (even when -n option is passed)
2. add this:
        if (nomtab || !mtab_is_writable())
  in the add_mtab function.

This way it would look more like the update_mtab_entry() from mount.c in the util-linux package which is providing the /bin/mount command.

But essentially you are right - your solution would do as well.
Comment 5 Bryn M. Reeves 2008-10-22 09:10:10 EDT
Agreed - I think this would be the best approach. It keeps things consistent with other parts of the code & seems more logical/clean to me.
Comment 6 Shane Bradley 2008-11-07 13:39:40 EST
Created attachment 322880 [details]
Patch for RO /etc/mtab
Comment 9 Steve Dickson 2009-04-29 13:31:46 EDT
Fixed in nfs-utils-1.0.9-42.el5
Comment 11 Chris Ward 2009-07-03 14:03:34 EDT
~~ Attention - RHEL 5.4 Beta Released! ~~

RHEL 5.4 Beta has been released! There should be a fix present in the Beta release that addresses this particular request. Please test and report back results here, at your earliest convenience. RHEL 5.4 General Availability release is just around the corner!

If you encounter any issues while testing Beta, please describe the issues you have encountered and set the bug into NEED_INFO. If you encounter new issues, please clone this bug to open a new issue and request it be reviewed for inclusion in RHEL 5.4 or a later update, if it is not of urgent severity.

Please do not flip the bug status to VERIFIED. Only post your verification results, and if available, update Verified field with the appropriate value.

Questions can be posted to this bug or your customer or partner representative.
Comment 12 Ondrej Valousek 2009-07-08 05:09:46 EDT
I can confirm that nfs-utils-1.0.9-42 package shipped in RHEL 5.4 Beta fixes this issue (tested with both nfs and nfs4).
Comment 15 errata-xmlrpc 2009-09-02 06:03:19 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.


Note You need to log in before you can comment on or make changes to this bug.