Why '-c DEV' option for switch_root?

Laurent Bercot ska-dietlibc at skarnet.org
Fri Dec 6 10:28:26 UTC 2013


> I don't know if I understand it right.
> Does it mean that as long as we don't do some strange redirections of standard IO in our initramfs, we don't need to add this option when switching root? So in most cases we don't need to reopen the stdio, right?

  Unless your real root's /dev/console is the same file as your
initramfs's /dev/console, you probably do.

  When your system boots, process 1 (and all its offspring, if there's
no redirection) has fds 0, 1 and 2 pointing to your initramfs's
/dev/console. That device will remain open as long as you don't close
those fds. switch_root needs to reopen 0, 1 and 2 to your new /dev/console
to be able to really clean up your initramfs.

(The best solution is to stop using initramfs and boot directly on your
real root filesystem, using a tmpfs to perform early operations that need
writable space, and using pivot_root if you really need to change root
filesystems. initramfs is a trap.)

-- 
  Laurent



More information about the busybox mailing list