[BusyBox] Busybox init.
Hiroshi Ito
ito at mlb.co.jp
Sat Nov 6 11:54:09 UTC 2004
Hello,
> Eg:
> initrd's linuxrc last lines...
>
> cd /root
> pivot_root . initrd
> exec chroot . /sbin/init <dev/console >dev/console 2>&1
This is your fault.
this means,
process of chroot will have pid 1.
and init will have another.
my /sbin/init also shell script.
I put my /sbin/init end of this mail.
It is on real root filesystem, not in initrd.
My root filesystem is on /dev/mtdbock/1(on flash) with cramfs
( read only )
You will need explanation to understand my script.
1.if linux command line argument has argument like "usbroot=0/part2"
mount usbdisk and boot from there,
( I have most of redhat 9 is on usbdisk. )
2.if there is /initrd/init, execute it.
( this for debugging purpos.
I can easyly download ramdisk with tftp(I use u-boot),so
when I want to change a /sbin/init, I check it with
initrd before rewrite flash.)
3.create root filesystem with tmpfs, and chroot to there,
then execute init.
all tmpfs's directory are symlink to cramfs.
but where I needs to write, create a real directory, but
contents are symlink to cramfs.
( command mkwritable, you see is my program.
which do like,
for file in $*; do
rm $file; mkdir $file; ln -s /rom/$file/* $file"
done
but mkwritable does more, about keep owner, permission, device
and not only for directory, but files...
I program it with C. )
4. /etc/init.d/conf restore
It restore's users setting.
it might restores /etc/inittab, so I'm doing before starting init.
with my case, busybox init works well.
here is my /sbin/init
/rom/root # cat /sbin/init
#!/bin/sh
if [ -n "$mlddebug" ]; then
echo run sh begining of /sbin/init
/bin/sh
fi
[ -x /initrd/init ] && exec /initrd/init $*;
PATH=/bin:/sbin:/etc:/usr/bin:/usr/sbin
export PATH
if [ -n "$usbroot" ]; then
disk=${usbroot%/*}
mount -n -t devfs none /dev
mount -n -t proc none /proc
for i in usbcore ehci-hcd usb-storage usb-ohci; do
insmod $i
usleep 500000;
done
timeout=5
[ -n "$usbtimeout" ] && timeout=$usbtimeout;
while let $(( $timeout > 0 )); do
echo -n $timeout;
sleep 1;
if [ -d /dev/discs/disc$disk ]; then
echo found USB disk;
break;
fi
timeout=$(($timeout - 1));
done
if let $(( $timeout > 0 )) && mount -n -o ro /dev/discs/disc$usbroot /ram; then
if [ -d /initrd/root ]; then
umount /initrd
freeramdisk /dev/root.old
fi
umount /dev
umount /proc
pivot_root /ram /ram/initrd
cd /
exec /sbin/init $*
else
echo Can not mount USB disk:$usbroot;
umount /dev
umount /proc
fi
fi
mount -n -t tmpfs none /ram
cd /
for i in *; do ln -sf /rom/$i /ram; done
mkdir /ram/rom
pivot_root /ram /ram/rom
cd /
mkwritable /proc /tmp /mnt/* /var /var/run
rm -f /dev
mkdir /dev
mount -n -t devfs none /dev
mount -n -t proc none /proc
if [ -d /rom/initrd/root ]; then
umount /rom/initrd
freeramdisk /dev/root.old
fi
/etc/init.d/conf restore
#umount /proc
if [ -n "$mlddebug" ]; then
echo run sh befoe init
sh
fi
exec /bin/busybox init $*
/rom/root #
--------
Hiroshi Ito
Media Lab. Inc.,
URL http://www.mlb.co.jp ( Sorry, Japanese only. )
TEL +81-3-5294-7255 FAX +81-3-5294-7256
More information about the busybox
mailing list