[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: Why doesn't switch_root work within my initramfs?
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2011-10-23 15:32:42
Message-ID: 201110231732.42451.vda.linux () googlemail ! com
[Download RAW message or body]

On Sunday 23 October 2011 16:21, Parmenides wrote:
> Hi,
> 
>     I have built a initramfs. The /etc/inittab is:
> 
> ::sysinit:/etc/init.d/rcS
> tty1::askfirst:/bin/sh
> tty2::askfirst:/bin/sh
> tty3::askfirst:/bin/sh
> tty4::askfirst:/bin/sh
> tty5::askfirst:/bin/sh
> tty6::askfirst:/bin/sh
> ::restart:/sbin/init
> ::ctrlaltdel:/sbin/reboot
> ::shutdown:/bin/umount -a -r
> 
> The /etc/init.d/rcS is:
> 
> #!/bin/sh
> mount -t proc proc /proc
> mount -t sysfs sysfs /sys
> mdev -s
> mount /dev/hda1 /mnt
> exec switch_root /mnt /sbin/init
> 
> When the kernel booting, I got these message on the screen:
> 
> BusyBox v1.19.2 (2011-10-22 16:15:41 CST) multi-call binary.
> 
> Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGS]
> 
> Free initramfs and switch to another root fs:
> chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,
> execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.
> 
> Options:
>         -c DEV  Reopen stdio to DEV after switch
> 
> I have check the conditions of switch_root as follows:
> 1. 'ls /mnt' to ensure that the /dev/hda1 is mounted successfully.
> 2. In rcS, the switch_root command is called by exec. So, the
> switch_root command runs in the process with PID = 1.

No, switch_root's PID in your example is not 1.
sysinit script is run as a *child* of init.

If you plan to use switch_root, you don't want to use an init
which uses inittab.
Instead, arrange for a shell script to be run as init process,
and make last command of this shellscript to be "exec switch_root ...".

-- 
vda
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic