Day Six - Lunching /sbin/init - Stage 1 (0.4)
the work bench is :
[root@Server isolinux]# mkdir dev
[root@Server isolinux]# mknod -m 600 dev/console c 5 1
[root@Server isolinux]# mkdir sbin
[root@Server isolinux]# vi sbin/init.c
void main()
{
printf("\n\n init : Hello World !!! \n");
for(;;);
}
[root@Server isolinux]# cc -static sbin/init.c -o sbin/init
and this is script stage-1.0.4 :
# cleanup ##########
rm -rf livecd.iso
# initrd.gz ##########
dd if=/dev/zero of=initrd bs=1M count=1
mke2fs -F -m0 -b 1024 initrd
tune2fs -c 0 -i 0 initrd
mkdir initrdDIR
mount -t ext2 -o loop initrd initrdDIR
rm -rf initrdDIR/lost+found/
# /proc
mkdir initrdDIR/proc
# /cdrom
mkdir initrdDIR/cdrom
# /ramdisk
mkdir initrdDIR/ramdisk
# /dev
mkdir initrdDIR/dev
mknod -m 600 initrdDIR/dev/console c 5 1
mknod -m 600 initrdDIR/dev/null c 1 3
mknod -m 600 initrdDIR/dev/ram0 b 1 0
mknod -m 600 initrdDIR/dev/loop0 b 7 0
mknod -m 660 initrdDIR/dev/hda b 3 0
mknod -m 660 initrdDIR/dev/hdb b 3 64
mknod -m 660 initrdDIR/dev/hdc b 22 0
mknod -m 660 initrdDIR/dev/hdd b 22 64
# busybox
cp -r /root/bootcd/src/busybox-1.00/_install/* initrdDIR/
rm -rf initrdDIR/linuxrc
# linuxrc
echo '#!/bin/sh' > initrdDIR/linuxrc
echo 'echo Mounting /proc filesystem' >> initrdDIR/linuxrc
echo 'mount -t proc /proc /proc' >> initrdDIR/linuxrc
echo 'echo Mounting CDROM' >> initrdDIR/linuxrc
echo '(/bin/mount -t iso9660 /dev/hda /cdrom && /usr/bin/test -f /cdrom/isolinux/isolinux.bin) ||' >> initrdDIR/linuxrc
echo '(/bin/mount -t iso9660 /dev/hdb /cdrom && /usr/bin/test -f /cdrom/isolinux/isolinux.bin) ||' >> initrdDIR/linuxrc
echo '(/bin/mount -t iso9660 /dev/hdc /cdrom && /usr/bin/test -f /cdrom/isolinux/isolinux.bin) ||' >> initrdDIR/linuxrc
echo '(/bin/mount -t iso9660 /dev/hdd /cdrom && /usr/bin/test -f /cdrom/isolinux/isolinux.bin) ||' >> initrdDIR/linuxrc
echo '(/bin/echo Ooops, no CD found. Halting. && /sbin/halt)' >> initrdDIR/linuxrc
echo 'echo Mounting RAMDISK - 16M' >> initrdDIR/linuxrc
echo '/bin/mount -t tmpfs -o size=16M tmpfs /ramdisk' >> initrdDIR/linuxrc
echo 'echo Creating new root on RAMDISK' >> initrdDIR/linuxrc
echo '/bin/mkdir /ramdisk/proc' >> initrdDIR/linuxrc
echo '/bin/mkdir /ramdisk/initrd' >> initrdDIR/linuxrc
echo '/bin/cp -r /cdrom/dev /ramdisk' >> initrdDIR/linuxrc
echo '/bin/cp -r /cdrom/sbin /ramdisk' >> initrdDIR/linuxrc
# Debuging purposes
#echo 'echo Lunching demo shell' >> initrdDIR/linuxrc
#echo '/bin/sh' >> initrdDIR/linuxrc
echo 'echo Changing root' >> initrdDIR/linuxrc
echo '/bin/echo "0x100" > /proc/sys/kernel/real-root-dev' >> initrdDIR/linuxrc
echo '/sbin/pivot_root /ramdisk /ramdisk/initrd' >> initrdDIR/linuxrc
echo '/initrd/bin/umount /initrd/proc' >> initrdDIR/linuxrc
chmod 755 initrdDIR/linuxrc
umount initrdDIR
rm -rf initrdDIR
gzip -9 initrd
# isolinux ##########
mkdir isolinux
mv initrd.gz isolinux
cp /root/bootcd/src/syslinux-3.11/isolinux.bin isolinux/
cp /root/bootcd/src/linux-2.4.32/arch/i386/boot/bzImage isolinux/vmlinuz
# isolinux.cfg
echo "default hw" > isolinux/isolinux.cfg
echo "label hw" >> isolinux/isolinux.cfg
echo "kernel vmlinuz" >> isolinux/isolinux.cfg
echo "append initrd=initrd.gz" >> isolinux/isolinux.cfg
# boot.cat
find . -type f -exec md5sum {} \; > isolinux/boot.cat
# make ISO9660 ##########
mkisofs -pad -l -r -J -v -V "IraNUX" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -o livecd.iso .
# cleanup ##########
rm -rf isolinux