Indeed:
- Fedora Linux 28 – this uses the
dracut
initramfs. - Boot into an initramfs shell, by adding
rd.break
as an option on the kernel command line. cd /sysroot
usr/bin/pivot_root . mnt
-> pivot_root
fails with "Invalid argument", corresponding to an errno
value of EINVAL
.
There is no explanation for this in man 2 pivot_root
:
EINVAL
put_old is not underneath new_root.
Why does it fail? And as the next commenter replied, "Then how would Linux exit early user space?"
Best Answer
Unlike the
initrd
, Linux does not allow to unmount theinitramfs
. Apparently this helped keep the kernel code simple.Instead of
pivot_root
, you can use theswitch_root
command. It implements the following procedure. Notice thatswitch_root
deletes all the files on the old root, to free the initramfs memory, so you need to be careful where you run this command.Note the shell commands suggested are only rough equivalents to the C code. The commands won't really work unless they are all built in to your shell, because the first command deletes all the programs and other files from the initramfs :-).
https://github.com/torvalds/linux/blob/v4.17/Documentation/filesystems/ramfs-rootfs-initramfs.txt