Re: pivot_root depreciated?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 30.01.2014 15:15, schrieb Phillip Susi:
> On 1/30/2014 3:16 AM, Karel Zak wrote:
>> everyone switched to our switch_root :-)
> 
> Except apparently for the systemd folks, which for some odd reason
> like the idea of keeping around the initrd for the life of the system
> so init can "return" to it ( yuck! ).

That is false. In order to keep the initramfs around, you have to copy
it to a tmpfs, since you can't pivot rootfs. In order to free the memory
occupied by the original initramfs, you still need to run switch_root or
an equivalent.

In particular, if systemd is used in the initramfs, it will do an
equivalent to util-linux's switch_root, but it will use an internal
reimplementation to be able to pass some internal state from the
initrd's systemd to the system's systemd (which would be lost if systemd
would exec an external binary other than systemd).

At least mkinitcpio now generates a fresh "initrd" to return to during
system shutdown instead of keeping around the actual initrd.

>> Anyway, I don't see any info about pivot_root syscall deprecation
>> in Linux kernel source tree.
> 
> Me neither, but then why switch_root?  I thought the whole reason it
> came about was because Linus et al considered pivot_root() to have
> been a terrible idea.

No idea what Linus said or didn't say about it, but here are the facts:

Initrd is a bad idea. It's a ramdisk of fixed size with an actual file
system on it. Instead, we now use initramfs, which is simply an archive
which is extracted directly into rootfs. And as I said above, you can't
pivot rootfs.

So, the old method was:
1) Mount "initrd" on /.
2) Do stuff, mount root on /realroot.
3) Pivot /realroot to / and / to /initrd
4) Exec /sbin/init
5) Unmount /initrd.

The new method is:
1) Extract "initramfs" into rootfs.
2) Do stuff, mount root on /realroot.
3) Delete all contents of / using unlink/rmdir
4) chdir("/realroot"); mount --move /realroot ., chroot(".");
5) Exec /sbin/init.

Step 3)-5) is what switch_root does. Somewhere in those steps, you also
move all API file system mount into /realroot, and maybe some details
which I forgot.

This doesn't mean that pivot_root should be deprecated, it just means
that you cannot use it for switchting from initramfs to the system.

Detailed explanations:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt

http://git.busybox.net/busybox/tree/util-linux/switch_root.c#n132

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux