2014-01-03

Slitaz -- core64 / initrd.cpio


initrd - initrd.cpio

1.
 http://hg.slitaz.org/wok-undigest/file/0468b8dbcb0f/linux/receipt
 50 cp /usr/share/boot/initrd initrd.cpio

http://hg.slitaz.org/wok/file/2ecc1cd5a9a4/busybox-boot/receipt
 116 ( cd $fs/usr/share/boot ; find bin dev init | cpio -o -H newc > initrd )


2.
root@slitaz:/tmp/rootfs# ls -l
total 12
drwxr-xr-x    2 root     root          4096 Jan  2 23:03 bin
drwxr-xr-x    2 root     root          4096 Jan  2 23:03 dev
-rwxr-xr-x    1 root     root          1992 Dec  8 00:19 init


3.
root@slitaz:/tmp/rootfs# ls -l bin dev
bin:
total 2112
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 busybox
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 cp
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 ln
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 mkdir
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 mknod
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 mount
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 sed
-rwsr-xr-x    8 root     root        267428 Dec  8 00:09 sh

dev:
total 0
crw-rw----    1 root     root        5,   1 Dec  8 00:19 console
crwxrwx--x    1 root     root        1,   3 Dec  8 00:19 null
crw-rw----    1 root     root        5,   0 Dec  8 00:19 tty
crw-rw----    1 root     root        4,   1 Dec  8 00:19 tty1
root@slitaz:/tmp/rootfs#


4.
root@slitaz:/tmp/rootfs# cat init
#!/bin/sh

export PATH=/bin
export HOME=/
export TERM=vt100

if [ -n "$1" ]; then
    [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
    [ -n "$subnet" ] && NETMASK="netmask $subnet"
    ifconfig $interface ${ip:-0.0.0.0} $BROADCAST $NETMASK
    while route del default gw 0.0.0.0 dev $interface ; do : ; done
    for i in $router ; do route add default gw $i dev $interface; done
    [ -n "$domain" ] && echo search $domain > /etc/resolv.conf
    for i in $dns ; do echo nameserver $i; done >> /etc/resolv.conf
    exit 0
fi

mkdir /tmp /mnt /proc /etc
mount -t proc none /proc
while read name major minor ; do
    for i in '' 1 2 3 4 5 6 7 8 9 ; do
        mknod -m 644 /dev/$name$i b $major $(($i + $minor))
    done
done <<EOM
loop    7    0
hda    3    0
hdb    3    64
hdc    22    0
hdd    22    64
sda    8    0
sdb    8    16
sdc    8    32
sdd    8    48
EOM

arg()
{
root="$(sed "s/^/ /;s/$/ /;/ $1=/!d;s/.* $1=\([^ ]*\).*/\1/" </proc/cmdline)"
busybox [ -n "$root" ]
}

arg init
init=${root:-/sbin/init}
[ -n "$(sed 's/$/ /;s/^/ /;/ ro /!d' /proc/cmdline)" ] && ro="-o ro"
[ -n "$(sed 's/$/ /;s/^/ /;/ rw /!d' /proc/cmdline)" ] && ro="-o rw"
arg root && root="$(echo $root | sed 's|/|\\/|g')" &&
    mount $ro $(busybox blkid | sed "s/\"//g;/$root/!d;s/:.*//;q") /mnt
arg loopfs && busybox losetup /dev/loop /mnt/$root && mount /dev/loop /mnt
arg subroot && cp /bin/busybox /mnt/$root/dev/shm &&
    chroot="$root/dev/shm/busybox chroot $root"
busybox [ -x /mnt/$root$init ] && exec busybox switch_root mnt $chroot $init

for i in $(busybox --list) ; do ln /bin/busybox /bin/$i 2> /dev/null ; done

[ -d /proc/bus/usb ] && mount -t usbfs usbfs /proc/bus/usb
while read type dir ; do
    grep -qs $type /proc/filesystems || continue
    mkdir $dir
    mount -t $type none $dir
done <<EOM
sysfs        /sys
devtmpfs    /dev
devpts        /dev/pts
EOM

TTY=$(tty 2>/dev/null)
TTY=${TTY:-/dev/tty1}

[ -x /bin/udhcpc ] && udhcpc -b -s /init
while true; do
    busybox | sed '/Current/,$!d'
    if [ -x /bin/setsid ]; then
        setsid sh -c "exec sh <$TTY >$TTY 2>&1"
    else
        sh <$TTY >$TTY 2>&1
    fi
done