Switch_root / pivot_root help needed

Patrick Zwahlen zwahlen at partenaire.ch
Fri Mar 17 09:42:54 UTC 2006


Hi there,

I am new to this mailinglist, and would need some help on solving a
switch_root problem. I couldn't find examples in the list, but I might
have looked too fast... :-)

I am working on a project that will ultimately run on a Soekris box, but
I am doing my current tests using qemu.

Anyway, here is what I am doing:

- I boot a 2.6.15.6 kernel (i586)
- kernel uncompresses an initramfs (cpio archive passed from the
bootloader)
- /init is an ash script
- I mount /proc /sys
- I mount /dev as tmpfs (this is what RedHat are doing in their initrd,
not sure why...)
- I populate /dev using udevstart
- I mount my hard drive, which contains my new root filesystems
(currently ext2 files)
	mount /dev/hda2 /mnt/hda2
- I loopback mount my rootfs 
	mkdir /mnt/newroot
	losetup /dev/loop0 /mnt/hda2/rootfs.ext2
	mount /dev/loop0 /mnt/newroot
- I mount /proc in my new root
- And finally:
	cd /mnt/newroot
	switch_root -c /dev/ttyS0 . /sbin/init
	switch_root: not rootfs

The code generating the error is in switch_root.c
=================================================
	if (stat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/",
&stfs) ||
		(stfs.f_type != RAMFS_MAGIC && stfs.f_type !=
TMPFS_MAGIC) ||
		getpid() != 1)
	{
		bb_error_msg_and_die("not rootfs");
	}
=================================================
However, I don't understand which test is failing. My /init does exist,
but it is a symbolic link to /etc/rc.sysinit (my actual ash script). My
"/" is not listed when I do a "mount", but it is definitely the kernel's
rootfs. And finally, I am pretty sure I am PID 1. I am clearly wrong
somewhere here :-)

I have also done a test with pivot_root:
	cd /mnt/newroot
	pivot_root . Initrd
	pivot_root: pivot_root: Invalid argument

At this point, I am stuck ! Are there special kernel requirements ? Does
busybox's switch_root/pivot_root depends on other applets ?

Thanks a lot for your help and support. - Patrick -




More information about the busybox mailing list