@@ -76,10 +76,15 @@ What is rootfs?
7676---------------
7777
7878Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is
79- always present in 2.6 systems. You can't unmount rootfs for approximately the
80- same reason you can't kill the init process; rather than having special code
81- to check for and handle an empty list, it's smaller and simpler for the kernel
82- to just make sure certain lists can't become empty.
79+ always present in 2.6 systems. Traditionally, you can't unmount rootfs for
80+ approximately the same reason you can't kill the init process; rather than
81+ having special code to check for and handle an empty list, it's smaller and
82+ simpler for the kernel to just make sure certain lists can't become empty.
83+
84+ However, if the kernel is booted with "nullfs_rootfs", an immutable empty
85+ filesystem called nullfs is used as the true root, with the mutable rootfs
86+ (tmpfs/ramfs) mounted on top of it. This allows pivot_root() and unmounting
87+ of the initramfs to work normally.
8388
8489Most systems just mount another filesystem over rootfs and ignore it. The
8590amount of space an empty instance of ramfs takes up is tiny.
@@ -121,17 +126,26 @@ All this differs from the old initrd in several ways:
121126 program. See the switch_root utility, below.)
122127
123128 - When switching another root device, initrd would pivot_root and then
124- umount the ramdisk. But initramfs is rootfs: you can neither pivot_root
125- rootfs, nor unmount it. Instead delete everything out of rootfs to
126- free up the space (find -xdev / -exec rm '{}' ';'), overmount rootfs
127- with the new root (cd /newmount; mount --move . /; chroot .), attach
128- stdin/stdout/stderr to the new /dev/console, and exec the new init.
129+ umount the ramdisk. Traditionally, initramfs is rootfs: you can neither
130+ pivot_root rootfs, nor unmount it. Instead delete everything out of
131+ rootfs to free up the space (find -xdev / -exec rm '{}' ';'), overmount
132+ rootfs with the new root (cd /newmount; mount --move . /; chroot .),
133+ attach stdin/stdout/stderr to the new /dev/console, and exec the new init.
129134
130135 Since this is a remarkably persnickety process (and involves deleting
131136 commands before you can run them), the klibc package introduced a helper
132137 program (utils/run_init.c) to do all this for you. Most other packages
133138 (such as busybox) have named this command "switch_root".
134139
140+ However, if the kernel is booted with "nullfs_rootfs", pivot_root() works
141+ normally from the initramfs. Userspace can simply do::
142+
143+ chdir(new_root);
144+ pivot_root(".", ".");
145+ umount2(".", MNT_DETACH);
146+
147+ This is the preferred method when nullfs_rootfs is enabled.
148+
135149Populating initramfs:
136150---------------------
137151
0 commit comments