2 * Copyright (c) 2010 Marcel Moolenaar
3 * Copyright (c) 1999-2004 Poul-Henning Kamp
4 * Copyright (c) 1999 Michael Smith
5 * Copyright (c) 1989, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "opt_rootdevname.h"
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <sys/param.h>
46 #include <sys/fcntl.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/mdioctl.h>
51 #include <sys/mount.h>
52 #include <sys/mutex.h>
53 #include <sys/namei.h>
56 #include <sys/filedesc.h>
57 #include <sys/reboot.h>
60 #include <sys/syscallsubr.h>
61 #include <sys/sysproto.h>
63 #include <sys/sysctl.h>
64 #include <sys/sysent.h>
65 #include <sys/systm.h>
66 #include <sys/vnode.h>
68 #include <geom/geom.h>
71 * The root filesystem is detailed in the kernel environment variable
72 * vfs.root.mountfrom, which is expected to be in the general format
74 * <vfsname>:[<path>][ <vfsname>:[<path>] ...]
75 * vfsname := the name of a VFS known to the kernel and capable
76 * of being mounted as root
77 * path := disk device name or other data used by the filesystem
78 * to locate its physical store
80 * If the environment variable vfs.root.mountfrom is a space separated list,
81 * each list element is tried in turn and the root filesystem will be mounted
82 * from the first one that succeeds.
84 * The environment variable vfs.root.mountfrom.options is a comma delimited
85 * set of string mount options. These mount options must be parseable
86 * by nmount() in the kernel.
89 static int parse_mount(char **);
90 static struct mntarg *parse_mountroot_options(struct mntarg *, const char *);
91 static int sysctl_vfs_root_mount_hold(SYSCTL_HANDLER_ARGS);
92 static void vfs_mountroot_wait(void);
93 static int vfs_mountroot_wait_if_neccessary(const char *fs, const char *dev);
96 * The vnode of the system's root (/ in the filesystem, without chroot
99 struct vnode *rootvnode;
102 * Mount of the system's /dev.
104 struct mount *rootdevmp;
106 char *rootdevnames[2] = {NULL, NULL};
108 struct mtx root_holds_mtx;
109 MTX_SYSINIT(root_holds, &root_holds_mtx, "root_holds", MTX_DEF);
111 struct root_hold_token {
113 LIST_ENTRY(root_hold_token) list;
116 static LIST_HEAD(, root_hold_token) root_holds =
117 LIST_HEAD_INITIALIZER(root_holds);
126 static enum action root_mount_onfail = A_CONTINUE;
128 static int root_mount_mddev;
129 static int root_mount_complete;
131 /* By default wait up to 3 seconds for devices to appear. */
132 static int root_mount_timeout = 3;
133 TUNABLE_INT("vfs.mountroot.timeout", &root_mount_timeout);
135 static int root_mount_always_wait = 0;
136 SYSCTL_INT(_vfs, OID_AUTO, root_mount_always_wait, CTLFLAG_RDTUN,
137 &root_mount_always_wait, 0,
138 "Wait for root mount holds even if the root device already exists");
140 SYSCTL_PROC(_vfs, OID_AUTO, root_mount_hold,
141 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
142 NULL, 0, sysctl_vfs_root_mount_hold, "A",
143 "List of root mount hold tokens");
146 sysctl_vfs_root_mount_hold(SYSCTL_HANDLER_ARGS)
149 struct root_hold_token *h;
152 sbuf_new(&sb, NULL, 256, SBUF_AUTOEXTEND | SBUF_INCLUDENUL);
154 mtx_lock(&root_holds_mtx);
155 LIST_FOREACH(h, &root_holds, list) {
156 if (h != LIST_FIRST(&root_holds))
158 sbuf_printf(&sb, "%s", h->who);
160 mtx_unlock(&root_holds_mtx);
162 error = sbuf_finish(&sb);
164 error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb));
169 struct root_hold_token *
170 root_mount_hold(const char *identifier)
172 struct root_hold_token *h;
174 h = malloc(sizeof *h, M_DEVBUF, M_ZERO | M_WAITOK);
176 mtx_lock(&root_holds_mtx);
177 LIST_INSERT_HEAD(&root_holds, h, list);
178 mtx_unlock(&root_holds_mtx);
183 root_mount_rel(struct root_hold_token *h)
189 mtx_lock(&root_holds_mtx);
190 LIST_REMOVE(h, list);
192 mtx_unlock(&root_holds_mtx);
200 /* No mutex is acquired here because int stores are atomic. */
201 return (root_mount_complete);
209 if (VFS_ROOT(TAILQ_FIRST(&mountlist), LK_EXCLUSIVE, &rootvnode))
210 panic("Cannot find root vnode");
212 VOP_UNLOCK(rootvnode, 0);
214 p = curthread->td_proc;
215 FILEDESC_XLOCK(p->p_fd);
217 if (p->p_fd->fd_cdir != NULL)
218 vrele(p->p_fd->fd_cdir);
219 p->p_fd->fd_cdir = rootvnode;
222 if (p->p_fd->fd_rdir != NULL)
223 vrele(p->p_fd->fd_rdir);
224 p->p_fd->fd_rdir = rootvnode;
227 FILEDESC_XUNLOCK(p->p_fd);
231 vfs_mountroot_devfs(struct thread *td, struct mount **mpp)
233 struct vfsoptlist *opts;
234 struct vfsconf *vfsp;
240 if (rootdevmp != NULL) {
242 * Already have /dev; this happens during rerooting.
244 error = vfs_busy(rootdevmp, 0);
249 vfsp = vfs_byname("devfs");
250 KASSERT(vfsp != NULL, ("Could not find devfs by name"));
254 mp = vfs_mount_alloc(NULLVP, vfsp, "/dev", td->td_ucred);
256 error = VFS_MOUNT(mp);
257 KASSERT(error == 0, ("VFS_MOUNT(devfs) failed %d", error));
261 opts = malloc(sizeof(struct vfsoptlist), M_MOUNT, M_WAITOK);
265 mtx_lock(&mountlist_mtx);
266 TAILQ_INSERT_HEAD(&mountlist, mp, mnt_list);
267 mtx_unlock(&mountlist_mtx);
275 error = kern_symlinkat(td, "/", AT_FDCWD, "dev", UIO_SYSSPACE);
277 printf("kern_symlink /dev -> / returns %d\n", error);
283 vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs)
286 struct mount *mporoot, *mpnroot;
287 struct vnode *vp, *vporoot, *vpdevfs;
291 mpnroot = TAILQ_NEXT(mpdevfs, mnt_list);
293 /* Shuffle the mountlist. */
294 mtx_lock(&mountlist_mtx);
295 mporoot = TAILQ_FIRST(&mountlist);
296 TAILQ_REMOVE(&mountlist, mpdevfs, mnt_list);
297 if (mporoot != mpdevfs) {
298 TAILQ_REMOVE(&mountlist, mpnroot, mnt_list);
299 TAILQ_INSERT_HEAD(&mountlist, mpnroot, mnt_list);
301 TAILQ_INSERT_TAIL(&mountlist, mpdevfs, mnt_list);
302 mtx_unlock(&mountlist_mtx);
304 cache_purgevfs(mporoot, true);
305 if (mporoot != mpdevfs)
306 cache_purgevfs(mpdevfs, true);
308 VFS_ROOT(mporoot, LK_EXCLUSIVE, &vporoot);
311 vporoot->v_iflag &= ~VI_MOUNT;
313 vporoot->v_mountedhere = NULL;
314 mporoot->mnt_flag &= ~MNT_ROOTFS;
315 mporoot->mnt_vnodecovered = NULL;
318 /* Set up the new rootvnode, and purge the cache */
319 mpnroot->mnt_vnodecovered = NULL;
321 cache_purgevfs(rootvnode->v_mount, true);
323 if (mporoot != mpdevfs) {
324 /* Remount old root under /.mount or /mnt */
326 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
330 NDFREE(&nd, NDF_ONLY_PNBUF);
332 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
338 error = (vp->v_type == VDIR) ? 0 : ENOTDIR;
340 error = vinvalbuf(vp, V_SAVE, 0, 0);
343 mporoot->mnt_vnodecovered = vp;
344 vp->v_mountedhere = mporoot;
345 strlcpy(mporoot->mnt_stat.f_mntonname,
351 NDFREE(&nd, NDF_ONLY_PNBUF);
354 printf("mountroot: unable to remount previous root "
355 "under /.mount or /mnt (error %d)\n", error);
358 /* Remount devfs under /dev */
359 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "/dev", td);
363 error = (vp->v_type == VDIR) ? 0 : ENOTDIR;
365 error = vinvalbuf(vp, V_SAVE, 0, 0);
367 vpdevfs = mpdevfs->mnt_vnodecovered;
368 if (vpdevfs != NULL) {
369 cache_purge(vpdevfs);
370 vpdevfs->v_mountedhere = NULL;
373 mpdevfs->mnt_vnodecovered = vp;
374 vp->v_mountedhere = mpdevfs;
380 printf("mountroot: unable to remount devfs under /dev "
381 "(error %d)\n", error);
382 NDFREE(&nd, NDF_ONLY_PNBUF);
384 if (mporoot == mpdevfs) {
386 /* Unlink the no longer needed /dev/dev -> / symlink */
387 error = kern_unlinkat(td, AT_FDCWD, "/dev/dev",
390 printf("mountroot: unable to unlink /dev/dev "
391 "(error %d)\n", error);
396 * Configuration parser.
399 /* Parser character classes. */
400 #define CC_WHITESPACE -1
401 #define CC_NONWHITESPACE -2
408 parse_peek(char **conf)
415 parse_poke(char **conf, int c)
422 parse_advance(char **conf)
429 parse_skipto(char **conf, int mc)
434 c = parse_peek(conf);
439 match = (c == ' ' || c == '\t' || c == '\n') ? 1 : 0;
441 case CC_NONWHITESPACE:
444 match = (c != ' ' && c != '\t') ? 1 : 0;
447 match = (c == mc) ? 1 : 0;
458 parse_token(char **conf, char **tok)
465 error = parse_skipto(conf, CC_NONWHITESPACE);
469 error = parse_skipto(conf, CC_WHITESPACE);
471 *tok = malloc(len + 1, M_TEMP, M_WAITOK | M_ZERO);
477 parse_dir_ask_printenv(const char *var)
481 val = kern_getenv(var);
483 printf(" %s=%s\n", var, val);
489 parse_dir_ask(char **conf)
495 vfs_mountroot_wait();
497 printf("\nLoader variables:\n");
498 parse_dir_ask_printenv("vfs.root.mountfrom");
499 parse_dir_ask_printenv("vfs.root.mountfrom.options");
501 printf("\nManual root filesystem specification:\n");
502 printf(" <fstype>:<device> [options]\n");
503 printf(" Mount <device> using filesystem <fstype>\n");
504 printf(" and with the specified (optional) option list.\n");
506 printf(" eg. ufs:/dev/da0s1a\n");
507 printf(" zfs:tank\n");
508 printf(" cd9660:/dev/cd0 ro\n");
509 printf(" (which is equivalent to: ");
510 printf("mount -t cd9660 -o ro /dev/cd0 /)\n");
512 printf(" ? List valid disk boot devices\n");
513 printf(" . Yield 1 second (for background tasks)\n");
514 printf(" <empty line> Abort manual input\n");
518 printf("\nmountroot> ");
519 cngets(name, sizeof(name), GETS_ECHO);
522 if (name[0] == '?' && name[1] == '\0') {
523 printf("\nList of GEOM managed disk devices:\n ");
527 if (name[0] == '.' && name[1] == '\0') {
532 error = parse_mount(&mnt);
534 printf("Invalid file system specification.\n");
535 } while (error != 0);
541 parse_dir_md(char **conf)
545 struct md_ioctl *mdio;
551 error = parse_token(conf, &tok);
556 mdio = malloc(sizeof(*mdio) + len + 1, M_TEMP, M_WAITOK | M_ZERO);
557 path = (void *)(mdio + 1);
558 bcopy(tok, path, len);
561 /* Get file status. */
562 error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &sb, NULL);
566 /* Open /dev/mdctl so that we can attach/detach. */
567 error = kern_openat(td, AT_FDCWD, "/dev/" MDCTL_NAME, UIO_SYSSPACE,
572 fd = td->td_retval[0];
573 mdio->md_version = MDIOVERSION;
574 mdio->md_type = MD_VNODE;
576 if (root_mount_mddev != -1) {
577 mdio->md_unit = root_mount_mddev;
579 error = kern_ioctl(td, fd, MDIOCDETACH, (void *)mdio);
581 /* Ignore errors. We don't care. */
582 root_mount_mddev = -1;
585 mdio->md_file = (void *)(mdio + 1);
586 mdio->md_options = MD_AUTOUNIT | MD_READONLY;
587 mdio->md_mediasize = sb.st_size;
590 error = kern_ioctl(td, fd, MDIOCATTACH, (void *)mdio);
595 if (mdio->md_unit > 9) {
596 printf("rootmount: too many md units\n");
597 mdio->md_file = NULL;
598 mdio->md_options = 0;
599 mdio->md_mediasize = 0;
601 error = kern_ioctl(td, fd, MDIOCDETACH, (void *)mdio);
603 /* Ignore errors. We don't care. */
608 root_mount_mddev = mdio->md_unit;
609 printf(MD_NAME "%u attached to %s\n", root_mount_mddev, mdio->md_file);
611 error = kern_close(td, fd);
619 parse_dir_onfail(char **conf)
624 error = parse_token(conf, &action);
628 if (!strcmp(action, "continue"))
629 root_mount_onfail = A_CONTINUE;
630 else if (!strcmp(action, "panic"))
631 root_mount_onfail = A_PANIC;
632 else if (!strcmp(action, "reboot"))
633 root_mount_onfail = A_REBOOT;
634 else if (!strcmp(action, "retry"))
635 root_mount_onfail = A_RETRY;
637 printf("rootmount: %s: unknown action\n", action);
641 free(action, M_TEMP);
646 parse_dir_timeout(char **conf)
652 error = parse_token(conf, &tok);
656 secs = strtol(tok, &endtok, 0);
657 error = (secs < 0 || *endtok != '\0') ? EINVAL : 0;
659 root_mount_timeout = secs;
665 parse_directive(char **conf)
670 error = parse_token(conf, &dir);
674 if (strcmp(dir, ".ask") == 0)
675 error = parse_dir_ask(conf);
676 else if (strcmp(dir, ".md") == 0)
677 error = parse_dir_md(conf);
678 else if (strcmp(dir, ".onfail") == 0)
679 error = parse_dir_onfail(conf);
680 else if (strcmp(dir, ".timeout") == 0)
681 error = parse_dir_timeout(conf);
683 printf("mountroot: invalid directive `%s'\n", dir);
684 /* Ignore the rest of the line. */
685 (void)parse_skipto(conf, '\n');
693 parse_mount_dev_present(const char *dev)
698 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, dev, curthread);
702 NDFREE(&nd, NDF_ONLY_PNBUF);
703 return (error != 0) ? 0 : 1;
708 parse_mount(char **conf)
712 char *dev, *fs, *opts, *tok;
713 int delay, error, timeout;
715 error = parse_token(conf, &tok);
719 error = parse_skipto(&tok, ':');
724 parse_poke(&tok, '\0');
728 if (root_mount_mddev != -1) {
729 /* Handle substitution for the md unit number. */
730 tok = strstr(dev, "md#");
732 tok[2] = '0' + root_mount_mddev;
736 error = parse_token(conf, &tok);
737 opts = (error == 0) ? tok : NULL;
739 printf("Trying to mount root from %s:%s [%s]...\n", fs, dev,
740 (opts != NULL) ? opts : "");
742 errmsg = malloc(ERRMSGL, M_TEMP, M_WAITOK | M_ZERO);
744 if (vfs_byname(fs) == NULL) {
745 strlcpy(errmsg, "unknown file system", ERRMSGL);
750 error = vfs_mountroot_wait_if_neccessary(fs, dev);
755 timeout = root_mount_timeout * hz;
759 ma = mount_arg(ma, "fstype", fs, -1);
760 ma = mount_arg(ma, "fspath", "/", -1);
761 ma = mount_arg(ma, "from", dev, -1);
762 ma = mount_arg(ma, "errmsg", errmsg, ERRMSGL);
763 ma = mount_arg(ma, "ro", NULL, 0);
764 ma = parse_mountroot_options(ma, opts);
766 error = kernel_mount(ma, MNT_ROOTFS);
767 if (error == 0 || timeout <= 0)
770 if (root_mount_timeout * hz == timeout ||
771 (bootverbose && timeout % hz == 0)) {
772 printf("Mounting from %s:%s failed with error %d; "
773 "retrying for %d more second%s\n", fs, dev, error,
774 timeout / hz, (timeout / hz > 1) ? "s" : "");
776 pause("rmretry", delay);
781 printf("Mounting from %s:%s failed with error %d",
783 if (errmsg[0] != '\0')
784 printf(": %s", errmsg);
788 free(errmsg, M_TEMP);
791 /* kernel_mount can return -1 on error. */
792 return ((error < 0) ? EDOOFUS : error);
797 vfs_mountroot_parse(struct sbuf *sb, struct mount *mpdevfs)
803 root_mount_mddev = -1;
806 conf = sbuf_data(sb);
807 mp = TAILQ_NEXT(mpdevfs, mnt_list);
808 error = (mp == NULL) ? 0 : EDOOFUS;
809 root_mount_onfail = A_CONTINUE;
811 error = parse_skipto(&conf, CC_NONWHITESPACE);
812 if (error == PE_EOL) {
813 parse_advance(&conf);
818 switch (parse_peek(&conf)) {
820 error = parse_skipto(&conf, '\n');
823 error = parse_directive(&conf);
826 error = parse_mount(&conf);
828 printf("mountroot: invalid file system "
836 /* Ignore any trailing garbage on the line. */
837 if (parse_peek(&conf) != '\n') {
838 printf("mountroot: advancing to next directive...\n");
839 (void)parse_skipto(&conf, '\n');
841 mp = TAILQ_NEXT(mpdevfs, mnt_list);
847 * We failed to mount (a new) root.
849 switch (root_mount_onfail) {
853 panic("mountroot: unable to (re-)mount root.");
858 kern_reboot(RB_NOSYNC);
866 vfs_mountroot_conf0(struct sbuf *sb)
868 char *s, *tok, *mnt, *opt;
871 sbuf_printf(sb, ".onfail panic\n");
872 sbuf_printf(sb, ".timeout %d\n", root_mount_timeout);
873 if (boothowto & RB_ASKNAME)
874 sbuf_printf(sb, ".ask\n");
876 if (boothowto & RB_DFLTROOT)
877 sbuf_printf(sb, "%s\n", ROOTDEVNAME);
879 if (boothowto & RB_CDROM) {
880 sbuf_printf(sb, "cd9660:/dev/cd0 ro\n");
881 sbuf_printf(sb, ".timeout 0\n");
882 sbuf_printf(sb, "cd9660:/dev/cd1 ro\n");
883 sbuf_printf(sb, ".timeout %d\n", root_mount_timeout);
885 s = kern_getenv("vfs.root.mountfrom");
887 opt = kern_getenv("vfs.root.mountfrom.options");
889 error = parse_token(&tok, &mnt);
891 sbuf_printf(sb, "%s %s\n", mnt,
892 (opt != NULL) ? opt : "");
894 error = parse_token(&tok, &mnt);
900 if (rootdevnames[0] != NULL)
901 sbuf_printf(sb, "%s\n", rootdevnames[0]);
902 if (rootdevnames[1] != NULL)
903 sbuf_printf(sb, "%s\n", rootdevnames[1]);
905 if (!(boothowto & RB_DFLTROOT))
906 sbuf_printf(sb, "%s\n", ROOTDEVNAME);
908 if (!(boothowto & RB_ASKNAME))
909 sbuf_printf(sb, ".ask\n");
913 vfs_mountroot_readconf(struct thread *td, struct sbuf *sb)
915 static char buf[128];
919 int error, flags, len;
921 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/.mount.conf", td);
923 error = vn_open(&nd, &flags, 0, NULL);
927 NDFREE(&nd, NDF_ONLY_PNBUF);
929 len = sizeof(buf) - 1;
931 error = vn_rdwr(UIO_READ, nd.ni_vp, buf, len, ofs,
932 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred,
938 buf[len - resid] = 0;
939 sbuf_printf(sb, "%s", buf);
943 VOP_UNLOCK(nd.ni_vp, 0);
944 vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
949 vfs_mountroot_wait(void)
951 struct root_hold_token *h;
952 struct timeval lastfail;
960 mtx_lock(&root_holds_mtx);
961 if (LIST_EMPTY(&root_holds)) {
962 mtx_unlock(&root_holds_mtx);
965 if (ppsratecheck(&lastfail, &curfail, 1)) {
966 printf("Root mount waiting for:");
967 LIST_FOREACH(h, &root_holds, list)
968 printf(" %s", h->who);
971 msleep(&root_holds, &root_holds_mtx, PZERO | PDROP, "roothold",
977 vfs_mountroot_wait_if_neccessary(const char *fs, const char *dev)
982 * In case of ZFS and NFS we don't have a way to wait for
983 * specific device. Also do the wait if the user forced that
984 * behaviour by setting vfs.root_mount_always_wait=1.
986 if (strcmp(fs, "zfs") == 0 || strstr(fs, "nfs") != NULL ||
987 dev[0] == '\0' || root_mount_always_wait != 0) {
988 vfs_mountroot_wait();
993 * Otherwise, no point in waiting if the device is already there.
994 * Note that we must wait for GEOM to finish reconfiguring itself,
995 * eg for geom_part(4) to finish tasting.
1000 if (parse_mount_dev_present(dev))
1004 * No luck. Let's wait. This code looks weird, but it's that way
1005 * to behave exactly as it used to work before.
1007 vfs_mountroot_wait();
1008 printf("mountroot: waiting for device %s...\n", dev);
1010 timeout = root_mount_timeout * hz;
1012 pause("rmdev", delay);
1014 } while (timeout > 0 && !parse_mount_dev_present(dev));
1033 sb = sbuf_new_auto();
1034 vfs_mountroot_conf0(sb);
1037 error = vfs_mountroot_devfs(td, &mp);
1039 error = vfs_mountroot_parse(sb, mp);
1041 vfs_mountroot_shuffle(td, mp);
1043 error = vfs_mountroot_readconf(td, sb);
1051 * Iterate over all currently mounted file systems and use
1052 * the time stamp found to check and/or initialize the RTC.
1053 * Call inittodr() only once and pass it the largest of the
1054 * timestamps we encounter.
1057 mtx_lock(&mountlist_mtx);
1058 mp = TAILQ_FIRST(&mountlist);
1059 while (mp != NULL) {
1060 if (mp->mnt_time > timebase)
1061 timebase = mp->mnt_time;
1062 mp = TAILQ_NEXT(mp, mnt_list);
1064 mtx_unlock(&mountlist_mtx);
1067 /* Keep prison0's root in sync with the global rootvnode. */
1068 mtx_lock(&prison0.pr_mtx);
1069 prison0.pr_root = rootvnode;
1070 vref(prison0.pr_root);
1071 mtx_unlock(&prison0.pr_mtx);
1073 mtx_lock(&root_holds_mtx);
1074 atomic_store_rel_int(&root_mount_complete, 1);
1075 wakeup(&root_mount_complete);
1076 mtx_unlock(&root_holds_mtx);
1078 EVENTHANDLER_INVOKE(mountroot);
1081 static struct mntarg *
1082 parse_mountroot_options(struct mntarg *ma, const char *options)
1085 char *name, *name_arg;
1086 char *val, *val_arg;
1089 if (options == NULL || options[0] == '\0')
1092 p = opts = strdup(options, M_MOUNT);
1097 while((name = strsep(&p, ",")) != NULL) {
1098 if (name[0] == '\0')
1101 val = strchr(name, '=');
1106 if( strcmp(name, "rw") == 0 ||
1107 strcmp(name, "noro") == 0) {
1109 * The first time we mount the root file system,
1110 * we need to mount 'ro', so We need to ignore
1111 * 'rw' and 'noro' mount options.
1115 name_arg = strdup(name, M_MOUNT);
1118 val_arg = strdup(val, M_MOUNT);
1120 ma = mount_arg(ma, name_arg, val_arg,
1121 (val_arg != NULL ? -1 : 0));
1123 free(opts, M_MOUNT);