Switch_root / pivot_root help needed
Rob Landley
rob at landley.net
Fri Mar 17 20:10:21 UTC 2006
On Friday 17 March 2006 4:42 am, Patrick Zwahlen wrote:
> 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.
svn 14007 applied a fix to switch_root after 1.1.0 came out. 1.1.1 comes out
monday, might want to grab a current snapshot and test to see if stuff works
for you...
> 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...)
Mostly to provide an empty directory so you don't have to worry about deleting
stuff from last time.
> - I populate /dev using udevstart
Might want to look at mdev, but it's your system.
> - 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
You can mount --move the existing /proc and /sys mounts, by the way...
> - 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.
You can break 'em up a bit and stick printf() calls between them.
> My /init does exist,
> but it is a symbolic link to /etc/rc.sysinit (my actual ash script).
Looks like the S_ISREG() is hitting you then. Yeah, a symlink is legitimate,
I should tweak that...
> My
> "/" is not listed when I do a "mount",
cat /proc/mounts
> 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
pivot_root won't work with rootfs. You can't relocate/umount rootfs.
> At this point, I am stuck ! Are there special kernel requirements ? Does
> busybox's switch_root/pivot_root depends on other applets ?
No, I'm guessing it's the S_ISREG() test. I suppose we don't really _need_
that...
> Thanks a lot for your help and support. - Patrick -
Rob
--
Never bet against the cheap plastic solution.
More information about the busybox
mailing list