[BusyBox] Busybox init.

Hans-Werner Hilse hilse at web.de
Tue Nov 9 14:06:43 UTC 2004


Hello,

On Tue, 9 Nov 2004 12:56:34 +0100
"Rory Vieira" <rory.vieira at coolview.nl> wrote:

> We want a initrd running busybox to run another rootfs also running
> busybox.
> We want to have the initrd execute the rootfs' busybox as 'init' using
> chroot (and probably pivot_root before that) WITHOUT having to use SysVinit (which
> isn't bad though)

I'm doing it this way:

I have a shell script /sbin/init in my initrd.
It does this:
----
#!/bin/sh
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
mkdir /ram
mount -t tmpfs tmpfs /ram -o size=10M
cp -a `ls -1 | grep -v ram | grep -v proc | grep -v lost+found` /ram/
cd /ram
mkdir proc mnt sys
mv sbin/init sbin/init.old
mv sbin/minit sbin/init
pivot_root . mnt
exec /usr/sbin/chroot . /sbin/init <dev/console >dev/console 2>&1
----
I'm actually using "minit", not busybox's init. So you would replace that line which moves my sbin/minit to sbin/init to a line like
'ln -s ../bin/busybox sbin/init'
Take care that your symlink is valid in chroot.

My script simply copies everything from ramdisk to tmpfs /ram. You could also extract your tmpfs from a tar.gz or similar, if you need a real small initrd. The statement may be only ash-compatible.

The important part: Now your init system runs as PID 1, which does! matter, otherwise unmounting the old root (in chroot under /mnt) won't work and freeramdisk won't work, too.

I'm actually using this for a not-really-diskless P166 which is my router to a city-WLAN. Because the sound of the HD is annoying, i'm just loading an initrd and then switch the HD off. works quite well.
I really love minit, the boot concept is simple and it's easy to add logging to every self written script.

HTH,

Hans-Werner Hilse



More information about the busybox mailing list