switch_root guide?

Rob Landley rob at landley.net
Fri Oct 20 22:55:35 UTC 2006


On Friday 20 October 2006 5:06 pm, Chris Steel wrote:
> Hi,
> 
> Has anyone written an idiot's guide to using
> switch_root?

mkdir newfs
mount /dev/blah newfs
exec switch_root newfs /sbin/init

Don't forget the exec.

> Looking at the source code it looks like busybox
> required /init to be file rather than a link to
> /sbin/init,

http://busybox.net/downloads/patches/svn-14577.patch

> so in my initramfs I've replace my /init 
> symbolic link with a file which mounts proc and sys,
> starts mdev, waits until a usb key appears in the dev
> directory, mounts it, and switch roots to it.
> 
> You'll note that at no time have I called busybox
> /sbin/init. However at boot I always see the 'init
> running' message,

A message from the kernel, perhaps?

> and as soon as the usb key is 
> detected, a shell appears, based on my initramfs, and
> never switch_roots to  the new rootfs.

What's your rdinit set to?

> It seems that I can't put any printfs in the
> switch_root code to work out what's going on as I
> haven't got a console running at the point (I assume).

You should have a console.  Can't spawn a process without stdin and stdout 
pointing to something.  (Ok, they could be closed, but the kernel initializes 
them based on the console= kernel command line argument.)

> Any hints on how I can get switch_root to work?

I don't know what's wrong with your setup.

Rob
-- 
"Perfection is reached, not when there is no longer anything to add, but
when there is no longer anything to take away." - Antoine de Saint-Exupery



More information about the busybox mailing list