More custom initramfs switch_root woes (bad '/sbin/init')

Matthew Franz mdfranz at gmail.com
Wed Apr 18 04:09:46 UTC 2007


I've seen earlier thread this month (and a lot of the comments/wiki
pages) over on the Gento site and read most everything (well, except
Kernel/Busybox source)

switch_root: bad init '/sbin/init'
[   18.571462] Kernel panic - not syncing: Attempted to kill init!
[   18.584241]

Busybox 1.4.2 (glibc -- built on Ubuntu Dapper)
Kernel 2.6.20.2

* I assume it is possible for the real root to be a ramfs  (if there
are other ways to get job control and multiple terminals I'm fine with
that too) I would love for the /init to behave like linuxrc and just
behave like linitrd. There is no *real* root (meaning some physical
device or cloop or whatever)

* The fact that my initramfs /init is being executed by bash (I have
my reason) shouldn't be an issue?!

* The initramfs should be fine (created with code ripped from
mkinitramfs from Ubuntu) but I can post that somewhere

I'm left scratching my head here and am hoping another few sets of
eye's might spot a goof-up...

Thanks..

- mdf

qemu -m 384 -nographic -kernel bzImage -initrd initramfs -append
'console=ttyS0' /dev/zero

or

qemu -m 384 -kernel bzImage -initrd initramfs /dev/zero (thought the
append might be hosing something)


starting qemu...
(qemu) [    0.000000] Linux version 2.6.20.2 (root at gx620) (gcc version
4.0.3 (Ubuntu 4.0.3-1ubuntu5)) #1 SMP PREEMPT Sat Apr 7 07:56:09 CDT
2007
[    0.000000] BIOS-provided physical RAM map:

snip

[    3.250196] checking if image is initramfs... it is
[   12.523136] Freeing initrd memory: 5025k freed
[   15.206515] RAMDISK driver initialized: 16 RAM disks of 65536K size
1024 blocksize

snip

[   15.553368] Time: tsc clocksource has been installed.
[   15.600797] Freeing unused kernel memory: 312k freed
Starting init!
Creating new root directory
Creating mount points...
-/tmp
-/var/lock
-/proc
-/sys
-/dev
Creating /proc & /sys
Copying directories...
-/etc
-/sbin
-/bin
Creating devices...
drwxr-xr-x    2 0        0               0 Apr 18 03:52 .
drwxr-xr-x   10 0        0               0 Apr 18 03:52 ..
crw-r--r--    1 0        0          5,   1 Apr 18 03:52 console
crw-r--r--    1 0        0          1,   3 Apr 18 03:52 null
Entering final root
switch_root: bad init '/sbin/init'
[   18.571462] Kernel panic - not syncing: Attempted to kill init!
[   18.584241]


And here is my init:

#!/bin/bash
/bin/busybox  echo "Starting init!"
/bin/busybox  mount -t proc none /proc
/bin/busybox --install

echo "Creating new root directory"
mkdir /newroot
mount -t ramfs none /newroot

echo "Creating mount points..."
for d in /tmp /var/lock /proc /sys /dev
do
    echo -${d}
    mkdir -p /newroot/${d}
done

echo "Creating /proc & /sys"
mount -t proc none /newroot/proc
mount -t sysfs none /newroot/sys

echo "Copying directories..."
for d in /etc /sbin /bin
do
    echo -${d}
    cp -a $d /newroot
done

echo "Creating devices..."
mknod /newroot/dev/console c 5 1
mknod /newroot/dev/null c 1 3
ls -al /newroot/dev/

cp -a /dev/tty[0-9] /newroot/dev/
cp -a /dev/ttyS[0-9] /newroot/dev/
cp -a /dev/hd* /newroot/dev/
cp -a /dev/sd* /newroot/dev/
cp -a /dev/ram* /newroot/dev/

echo "Entering final root"
exec switch_root -c /dev/console /newroot /sbin/init





-- 
Matthew Franz
http://www.threatmind.net/



More information about the busybox mailing list