From 4989de6accd3e3e1ffcdafbcae3a1f79fa9c987a Mon Sep 17 00:00:00 2001 From: Erik van der Kouwe Date: Tue, 3 Aug 2010 13:57:58 +0000 Subject: [PATCH] Don't write to /etc/mtab in newroot, may be an issue on read-only filesystems --- commands/mount/mount.c | 9 ++++++--- commands/newroot/newroot.sh | 2 +- man/man1/mount.1 | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/commands/mount/mount.c b/commands/mount/mount.c index 305cb78a9..e459e4f2d 100644 --- a/commands/mount/mount.c +++ b/commands/mount/mount.c @@ -26,12 +26,13 @@ int main(argc, argv) int argc; char *argv[]; { - int i, n, v = 0, mountflags; + int i, n, v = 0, mountflags, write_mtab; char **ap, *vs, *opt, *err, *type, *args, *device; char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10]; if (argc == 1) list(); /* just list /etc/mtab */ mountflags = 0; + write_mtab = 1; type = NULL; args = NULL; ap = argv+1; @@ -43,7 +44,8 @@ char *argv[]; case 't': if (++i == argc) usage(); type = argv[i]; break; - case 'i': mountflags |= MS_REUSE; break; + case 'i': mountflags |= MS_REUSE; break; + case 'n': write_mtab = 0; break; case 'o': if (++i == argc) usage(); args = argv[i]; break; @@ -82,8 +84,9 @@ char *argv[]; /* The mount has completed successfully. Tell the user. */ printf("%s is read-%s mounted on %s\n", argv[1], mountflags & MS_RDONLY ? "only" : "write", argv[2]); - + /* Update /etc/mtab. */ + if (!write_mtab) return 0; n = load_mtab("mount"); if (n < 0) exit(1); /* something is wrong. */ diff --git a/commands/newroot/newroot.sh b/commands/newroot/newroot.sh index 0689fc323..530330ae5 100644 --- a/commands/newroot/newroot.sh +++ b/commands/newroot/newroot.sh @@ -1,5 +1,5 @@ #!/bin/sh # Actually, newroot is just like mounting on the root -exec mount "$*" / +exec mount -n "$*" / diff --git a/man/man1/mount.1 b/man/man1/mount.1 index dc1f8bc76..08cf475b2 100644 --- a/man/man1/mount.1 +++ b/man/man1/mount.1 @@ -17,6 +17,7 @@ mount \- mount a file system .SH OPTIONS .FL "\-r" "File system is mounted read-only" .FL "\-t" "File system type" +.FL "\-n" "Don't update mtab" .FL "\-o" "Options passed to FS server" .SH EXAMPLES .EX "mount /dev/fd1 /user" "Mount diskette 1 on \fI/user\fP" -- 2.44.0