WARNING: switch_root removes recursively all files and directories on the current root filesystem.
-- man switch_root
from util-linux
, version 2.32-2.fc28.x86_64
Why?
WARNING: switch_root removes recursively all files and directories on the current root filesystem.
-- man switch_root
from util-linux
, version 2.32-2.fc28.x86_64
Why?
The exact behaviour of switch_root
is explained here:
https://github.com/torvalds/linux/blob/v4.17/Documentation/filesystems/ramfs-rootfs-initramfs.txt
When switching another root device, initrd would pivot_root and then umount the ramdisk. But initramfs is rootfs: you can neither pivot_root rootfs, nor unmount it. Instead delete everything out of rootfs to free up the space (
find -xdev / -exec rm '{}' ';'
) ...
And the reason Linux doesn't support unmounting the initial rootfs:
Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is always present in 2.6 systems. You can't unmount rootfs for approximately the same reason you can't kill the init process; rather than having special code to check for and handle an empty list, it's smaller and simpler for the kernel to just make sure certain lists can't become empty.