Follow-up to 4febd28: bring back /dev, /proc, and /sys

We need /proc for rs_remount_root() and conf_parse_cmdline(), /dev for
early multi-console support, and /sys for the cgroups support.  All of
these may be in the system /etc/fstab, which fs_mount() later remounts.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-02-07 12:53:35 +01:00
1 parent 0c85f8adfe
commit 18359ef448
1 file changed
+31 -12
+31 -12
View File
@@ -160,8 +160,7 @@ static void fs_remount_root(int fsckerr)
break; break;
} }
/* If / is not listed in fstab, or listed as 'ro', leave it /* If / is not listed in fstab, or listed as 'ro', leave it alone */
* alone. */
if (!fs || !strcmp(fs->fs_type, "ro")) if (!fs || !strcmp(fs->fs_type, "ro"))
goto out; goto out;
@@ -185,16 +184,10 @@ static void fs_remount_root(int fsckerr)
} }
#endif /* SYSROOT */ #endif /* SYSROOT */
static void fs_init(void) static void fs_mount(void)
{ {
if (!rescue) { if (!rescue)
/*
* /etc/fstab may mount over this later, we need /proc
* to be able to remount / as read-write --Jocke
*/
mount("none", "/proc", "proc", 0, NULL);
fs_remount_root(fsck_all()); fs_remount_root(fsck_all());
}
_d("Root FS up, calling hooks ..."); _d("Root FS up, calling hooks ...");
plugin_run_hooks(HOOK_ROOTFS_UP); plugin_run_hooks(HOOK_ROOTFS_UP);
@@ -209,6 +202,27 @@ static void fs_init(void)
umask(0022); umask(0022);
} }
/*
* We need /proc for rs_remount_root() and conf_parse_cmdline(), /dev
* for early multi-console, and /sys for the cgroups support. Any
* occurrence of these file systems in /etc/fstab will replace these
* mounts later in fs_mount()
*/
static void fs_init(void)
{
struct {
char *spec, *file, *type;
} fs[] = {
{ "proc", "/proc", "proc" },
{ "devtmpfs", "/dev", "devtmpfs" },
{ "sysfs", "/sys", "sysfs" },
};
size_t i;
for (i = 0; i < NELEMS(fs); i++)
mount(fs[i].spec, fs[i].file, fs[i].type, 0, NULL);
}
/* /*
* If everything goes south we can use this to give the operator an * If everything goes south we can use this to give the operator an
* emergency shell to debug the problem -- Finit should not crash! * emergency shell to debug the problem -- Finit should not crash!
@@ -362,7 +376,12 @@ int main(int argc, char *argv[])
return client(argc, argv); return client(argc, argv);
/* /*
* Parse kernel command line (debug, rescue, splash, etc.) * Need /dev, /proc, and /sys for console=, remount and cgroups
*/
fs_init();
/*
* Parse /proc/cmdline (debug, rescue, splash, console=, etc.)
* Also calls log_init() to set correct log level * Also calls log_init() to set correct log level
*/ */
conf_parse_cmdline(argc, argv); conf_parse_cmdline(argc, argv);
@@ -412,7 +431,7 @@ int main(int argc, char *argv[])
/* Check and mount filesystems. */ /* Check and mount filesystems. */
fs_init(); fs_mount();
/* /*
* Initialize .conf system and load static /etc/finit.conf. * Initialize .conf system and load static /etc/finit.conf.