Sunday, April 30, 2006

Day Six - Lunching /sbin/init - Stage 1 (0.4)

This is it ..... I am lunching /sbin/init for the first time in my life ;-)

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

Saturday, April 29, 2006

Day Five - Loopback device compile-in

A little change in kernel config for Loopback device compile-in :

module : "block-major-7"
config : block devices -> loopback device support

Thursday, April 27, 2006

Day Four - Mounting CDROM - stage 1 (0.3)

At last, with a little change in my kernel configuration, I can mount CDROM , here is my stage-1.0.3 script :

# cleanup ##########

rm -rf *.iso
rm -rf isolinux

# initrd.gz ##########

dd if=/dev/zero of=initrd bs=1M count=1
mke2fs -F -m0 -b 1024 initrd
mkdir initrdDIR
mount -t ext2 -o loop initrd initrdDIR
rm -rf initrdDIR/lost+found/

# /proc
mkdir initrdDIR/proc

# /cdrom
mkdir initrdDIR/cdrom

# /dev
mkdir initrdDIR/dev
mknod -m 600 initrdDIR/dev/console c 5 1
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 " Hello World !! 0.3" ' >> initrdDIR/linuxrc
echo 'echo Mounting /proc filesystem' >> initrdDIR/linuxrc
echo 'mount -t proc /proc /proc' >> 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 Launching a demo shell' >> initrdDIR/linuxrc
echo '/bin/sh' >> initrdDIR/linuxrc
echo 'umount /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 "HELLOWORLD" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -o helloworld.iso .


This is my kernel 2.4.32 config file change :

1- compile in "ide-cd " :
ATA/IDE/MFM/RLL support -> IDE,ATA and ATAPI block devices -> Include IDE/ATAPI CDROM support
2- conpile in "nls_iso8859_1" :
File system -> Native language support -> NLS ISO 8859-1

Wednesday, April 26, 2006

Day Three - First shell prompt - new linuxrc

I change linuxrc and my first shell prompt appears , here is my new linuxrc :

#!/bin/sh
echo " Hello World !! 0.3"
echo "Mounting /proc filesystem"
mount -t proc /proc /proc
echo "Launching a demo shell"
/bin/sh
umount /proc


and I add this line to my script before # /dev :

mkdir initrdDIR/proc

Day two - Scripting "Hello World" - stage 1(0.2)

I am trying to change linuxrc to a shell script , here is my new stage-1.0.2 script :

# cleanup ##########

rm -rf *.iso
rm -rf isolinux

# initrd.gz ##########

dd if=/dev/zero of=initrd bs=1M count=1
mke2fs -F -m0 -b 1024 initrd
mkdir initrdDIR
mount -t ext2 -o loop initrd initrdDIR
rm -rf initrdDIR/lost+found/

# /dev
mkdir initrdDIR/dev
mknod initrdDIR/dev/console c 5 1

# busybox
cp -r /root/bootcd/src/busybox-1.00/_install/* initrdDIR/
rm -rf initrdDIR/linuxrc

# linuxrc
echo '#!/bin/sh' > initrdDIR/linuxrc
echo 'echo " Hello World !! 0.2" ' >> initrdDIR/linuxrc
echo 'while true; do test' >> initrdDIR/linuxrc
echo 'done' >> initrdDIR/linuxrc
chmod 755 initrdDIR/linuxrc

umount initrdDIR
rm -rf initrdDIR
gzip -9 initrd

# isolinux ##########

mkdir isolinux
mv initrd.gz isolinux
cp /usr/src/syslinux-3.11/isolinux.bin isolinux/
cp /boot/vmlinuz-2.4.32 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 "HELLOWORLD" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -o helloworld.iso .

Tuesday, April 25, 2006

Day two - Scripting "Hello World !!" - Stage 1 (0.1)

I make my own script for building "Hello World!" ISO , and here it is, stage-1.0.1 script :


# cleanup ##########

rm -rf *.iso
rm -rf isolinux

# initrd.gz ##########

dd if=/dev/zero of=initrd bs=600k count=1
mke2fs -F -m0 -b 1024 initrd
mkdir initrdDIR
mount -t ext2 -o loop initrd initrdDIR
rm -rf initrdDIR/lost+found/

# /dev
mkdir initrdDIR/dev
mknod initrdDIR/dev/console c 5 1

# linuxrc
echo "#include " > linuxrc.c
echo "void main(){printf(\"\n\nHello World! \\n\");for(;;);}" >> linuxrc.c
cc -static linuxrc.c -o initrdDIR/linuxrc
rm -rf linuxrc.c

umount initrdDIR
rm -rf initrdDIR
gzip -9 initrd

# isolinux ##########

mkdir isolinux
mv initrd.gz isolinux
cp /usr/src/syslinux-3.11/isolinux.bin isolinux/
cp /boot/vmlinuz-2.4.32 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 "HELLOWORLD" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -o helloworld.iso .

Day two - Lunching "Hello World !!" - Stage 1

According to Esteve's article , I do somthing like this, and it works :

[root@Server mylivecd]# ls
[root@Server mylivecd]# dd if=/dev/zero of=initrd bs=4096k count=1
1+0 records in
1+0 records out
[root@Server mylivecd]# losetup /dev/loop0 initrd
[root@Server mylivecd]# mke2fs -m 0 /dev/loop0
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1024 inodes, 4096 blocks
0 blocks (0.00%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@Server mylivecd]# tune2fs -c 0 -i 0 /dev/loop0
tune2fs 1.27 (8-Mar-2002)
Setting maximal mount count to -1
Setting interval between check 0 seconds
[root@Server mylivecd]# mkdir initrdDIR
[root@Server mylivecd]# mount /dev/loop0 initrdDIR/
[root@Server mylivecd]# cd initrdDIR/
[root@Server initrdDIR]# ls
lost+found
[root@Server initrdDIR]# mkdir dev
[root@Server initrdDIR]# cd dev
[root@Server dev]# mknod -m 600 console c 5 1
[root@Server dev]# cd ..
[root@Server initrdDIR]# vi linuxrc.c

/* Print "Hello World!" and loops forever. */

#include <stdio.h>

void main()
{
printf("\n\nHello World!\n");
for(;;);
}


[root@Server initrdDIR]# cc -static linuxrc.c -o linuxrc
linuxrc.c: In function `main':
linuxrc.c:6: warning: return type of `main' is not `int'
[root@Server initrdDIR]# ls
dev linuxrc linuxrc.c lost+found
[root@Server initrdDIR]# cd ..
[root@Server mylivecd]# umount initrdDIR
[root@Server mylivecd]# losetup -d /dev/loop0
[root@Server mylivecd]# mkdir isolinux
[root@Server mylivecd]# cd isolinux
[root@Server isolinux]# cp /boot/vmlinuz-2.4.32 vmlinuz
[root@Server isolinux]# cp /usr/src/syslinux-3.11/isolinux.bin .
[root@Server isolinux]# cp ../initrd .
[root@Server isolinux]# gzip initrd
[root@Server isolinux]# vi isolinux.cfg

default hw
label hw
kernel vmlinuz
append initrd=initrd.gz

[root@Server isolinux]# cd ..
[root@Server mylivecd]# find . -type f -exec md5sum {} \; > isolinux/boot.cat
[root@Server mylivecd]# mkisofs -pad -l -r -J -v -V "HELLOWORLD" -b isolinux/isolinux.bin > -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 > -boot-info-table -hide-rr-moved -o helloworld.iso .
mkisofs 1.14 (i686-pc-linux-gnu)
Scanning .
Scanning ./initrdDIR
Scanning ./isolinux
Excluded by match: ./isolinux/boot.cat

Size of boot image is 4 sectors -> No emulation
Total translation table size: 2048
Total rockridge attributes bytes: 1084
Total directory bytes: 4096
Path table size(bytes): 44
Max brk space used 6000
2672 extents written (5 Mb)
[root@Server mylivecd]# ls
helloworld.iso initrd initrdDIR isolinux
[root@Server mylivecd]#

Thursday, April 20, 2006

Day One - LiveCD "Hello World" !!! - Road map

This is my start point, I found This doc , and Adventre is begin :

HOWTO build your own Live-CD from scratch

Thanks to Esteve Llobera

ToDo :
I have to read These too ...

From Power Up To Bash Prompt

The Linux Bootdisk HOWTO

How To Build a Minimal Linux System from Source Code


Road map :

Stage 1 - Building a livecd that contain complete linux distribution
Stage 2 - Building a script for Installing linux from livecd to hard disk
Stage 3 - Building a configuration script