LiveCD Howto (CentOS 4) - Step by step - 01/12/2006 - Ver 1.1 (This howto is for CentOS 4.4 i386. The version numbers may be different) Overview This howto illustrate the way to "compile" your own LiveCD from any Linux disto out there. Some commands maybe different between distos, But generally - it gives a good start point. The flow of the LiveCD startup is 1. Booting from CD (or pxe for that matter) using the isolinux. The Linux kernel and initrd load into memory. 2. initrd does the magic: load relevant kenrel modules, mount the CD or NFS mount, mount cramfs (read-only), mount tmpfs (read-write), join the two using unionfs, chroot into the real system by running the scripts instead of /bin/init. 3. The real system loads by running /etc/rc.d/rc.sysinit, /etc/rc.d/rc 3 and finally /bin/login -f root 4. The bash has configuration to run once some process (X, xterm, icewm, firefox) 5. After the real system cease to exist (by killing the "login", the initrd takes over again and kill everything, umount everything, eject the CD and reboot. The command for the real system should be "kill -15-1" (most of the time runs from php script) Step by step 1. 2. 3. Install CentOS minimal installation. Download unionfs (http://www.am-utils.org/project-unionfs.html). You will need gcc & kernel-devel packages in order to complete unionfs # yum install gcc # yum install kernel-devel 4. Untar unionfs source # tar -zxf unionfs-1.1.5.tar.gz # cd unionfs-1.1.5 Some kernel sources has to be modified: # vi /lib/modules/2.6.9-42.0.3.el/build/include/linux/gfp.h look for gfp_t and *delete* this line ( typedef unsigned int gfp_t; ) # vi /lib/modules/2.6.9-42.0.3.el/build/include/linux/slab.h look for kzalloc and *delete* this line ( extern void *kzalloc(size_t, int; ) # make (ignore compile errors, you only need the unionfs.ko & unionctl which are ready after the make.) 5. Remove the kernel sources as we touched them and they are no longer current! # rpm e kernel-devel-2.6.9-42.0.3.el 6. Copy the unionfs & unionctl to the right place # mkdir /lib/modules/2.6.9-42.0.3.el/kernel/fs/unionfs # cp unionfs.ko /lib/modules/2.6.9-42.0.3.el/kernel/fs/unionfs/ # cp unionctl /usr/bin/ 7. Creating busybox. busybox is binary application which can be compiles staticly and include lots of gui applications in in, such as ls, mount, insmod etc. for that matter, we will compile busybox from source, this way we can select which applications we want and which we don't Attached you could file.config file from the busybox (v. 1.2.2) which include what I thought needed. The result is 750Kbyte busybox one file (no lib needed) This compilation has be on quite full installation and not on our minimal system. Once this busybox compiled - we can use in on our system without no additional libs. # wget http://www.busybox.net/downloads/busybox-1.2.2.tar.gz # tar -zxvf busybox-1.2.2.tar.gz # cd busybox-1.2.2 # make menuconfig or use my.config file # make # cp busybox /path/to/initrd/bin 8. Creating the initrd
# dd if=/dev/zero of=initrd bs=1m count=8 # mke2fs initrd # mkdir /mnt/loop # mount -o loop initrd /mnt/loop # cd /mnt/loop # mkdir etc dev lib bin proc new cdrom static dynamic union # touch etc/mtab # cd /mnt/loop/bin/ # cp /bin/bash. # cp /sbin/killall5. # cp /bin/sleep. 9. Now we have to bring all the shared library from the binaries we copied # cd /mnt/loop/lib/ # ldd../bin/* bash: libtermcap.so.2 => /lib/libtermcap.so.2 (0x007e9000) libdl.so.2 => /lib/libdl.so.2 (0x006e0000) busybox: not a dynamic executable killall5: sleep: libm.so.6 => /lib/tls/libm.so.6 (0x006bb000) librt.so.1 => /lib/tls/librt.so.1 (0x00d2f000) libpthread.so.0 => /lib/tls/libpthread.so.0 (0x007e9000) # cp /lib/libc.so.6. # cp /lib/ld-linux.so.2. # cp /lib/libtermcap.so.2. # cp /lib/libdl.so.2. -rwxr-xr-x 1 root root 110K Dec 1 09:47 ld-linux.so.2* -rwxr-xr-x 1 root root 1.5M Dec 1 09:47 libc.so.6* -rwxr-xr-x 1 root root 17K Dec 1 09:48 libdl.so.2* -rwxr-xr-x 1 root root 12K Dec 1 09:48 libtermcap.so.2* drwxr-xr-x 3 root root 1.0K Nov 26 14:46 modules/ 10. We also have to copy the kernel modules we will load at the initrd stage # mkdir -p modules/2.6.9-42.0.3.el/ # cd modules/2.6.9-42.0.3.el/ # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/block/loop.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/ext3/ext3.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/jbd/jbd.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/unionfs/unionfs.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/cramfs/cramfs.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/scsi/sd_mod.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/scsi/scsi_mod.ko. 11. In order to know which dependencies each modules have, run: # modprobe --show-depend e100 insmod /lib/modules/2.6.9-42.0.3.el/kernel/drivers/net/mii.ko insmod /lib/modules/2.6.9-42.0.3.el/kernel/drivers/net/e100.ko # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/net/e100.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/net/e1000/e1000.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/net/mii.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/drivers/net/pcnet32.ko. (for VMWare machines...) 12. NFS modules
# cp /lib/modules/2.6.9-42.0.3.el/kernel/net/sunrpc/sunrpc.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/lockd/lockd.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/nfs_common/nfs_acl.ko. # cp /lib/modules/2.6.9-42.0.3.el/kernel/fs/nfs/nfs.ko. -rwxr--r-- 1 root root 13K Nov 23 04:04 cramfs.ko* -rwxr--r-- 1 root root 124K Jan 3 17:27 e1000.ko* -rwxr--r-- 1 root root 41K Nov 26 13:41 e100.ko* -rwxr--r-- 1 root root 137K Nov 23 03:56 ext3.ko* -rwxr--r-- 1 root root 88K Nov 23 03:56 jbd.ko* -rwxr--r-- 1 root root 78K Nov 26 16:58 lockd.ko* -rwxr--r-- 1 root root 21K Nov 23 03:55 loop.ko* -rwxr--r-- 1 root root 6.8K Nov 26 14:13 mii.ko* -rwxr--r-- 1 root root 5.1K Nov 26 17:02 nfs_acl.ko* -rwxr--r-- 1 root root 282K Nov 26 16:58 nfs.ko* -rwxr--r-- 1 root root 38K Nov 26 15:55 pcnet32.ko* -rwxr--r-- 1 root root 153K Jan 3 18:04 scsi_mod.ko* -rwxr--r-- 1 root root 22K Jan 3 18:03 sd_mod.ko* -rwxr--r-- 1 root root 187K Nov 26 16:59 sunrpc.ko* -rwxr--r-- 1 root root 2.1M Nov 23 03:56 unionfs.ko* 13. Create /dev special devices # cd /mnt/loop/dev/ # mknod console c 5 1 # mknod hda b 3 0 # mknod hdb b 3 64 # mknod hdc b 22 0 # mknod hdd b 22 64 # mknod tty c 4 0 # mknod loop0 b 7 0 crw-r--r-- 1 root root 5, 1 Nov 22 20:58 console brw-r--r-- 1 root root 3, 0 Nov 22 20:59 hda brw-r--r-- 1 root root 3, 64 Nov 22 20:59 hdb brw-r--r-- 1 root root 22, 0 Nov 22 20:59 hdc brw-r--r-- 1 root root 22, 64 Nov 22 20:59 hdd brw-r--r-- 1 root root 7, 0 Nov 22 21:00 loop0 crw-r--r-- 1 root root 1, 3 Nov 22 20:58 null crw-r--r-- 1 root root 4, 0 Nov 22 20:59 tty 14. Creating the linuxrc # cd /mnt/loop/ # vi linuxrc (attached you will find linuxrc script) 15. Umounting the initrd & compress it / # umount /mnt/loop/ # gzip initrd 16. Download syslinux (which include isolinux in it) # wget http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.31.tar.gz 17. Start to assemble the LiveCD on another machine (local)# mount xxx.xxx.xxx.xxx:/tmp /mnt (remote)# mkdir -p /tmp/livecd/isolinux (local)# cp initrd.gz /mnt/livecd/isolinux (local)# cp /boot/vmlinuz-2.6.9-42.0.3.el /mnt/livecd/isolinux/vmlinuz (remote)/livecd/isolinux (remote)# cp /tmp/syslinux-3.31/isolinux.bin. (remote)# vi isolinux.cfg (attached you will find isolinux.cfg) 18. Create directories for live file systems came from the initrd # mkdir /mnt/cdrom 19. Stop interactive boot # vi /etc/sysconfig/init chnage PROMPT=yes to PROMPT=no 20. Remove MAC address from the NIC & stop network at boot
21. Adding xorg # vi /etc/sysconfig/network-scripts/ifcfg-eth0 remove the MAC & change ONBOOT=yes to ONBOOT=no # yum install xorg-x11 22. Adding DAG repository # wget wget http://dag.wieers.com/packages/rpmforge-release/rpmforge-release-0.3.4-1.el4.rf.i386.rpm # rpm -Uhv rpmforge-release-0.3.4-1.el4.rf.i386.rpm 23. Adding WinICE window manager (small window manager) # yum install icewm 24. Adding Firefox & Add the kiosk addon # wget "http://download.mozilla.org/?product=firefox-2.0&os=linux&lang=en-us" # tar -zxvf firefox-2.0.tar.gz # mv firefox /usr/local/lib/firefox-2.0 # vi /etc/profile add the line: # Path manipulation if [ `id -u` = 0 ]; then pathmunge /sbin pathmunge /usr/sbin pathmunge /usr/local/sbin pathmunge /usr/local/lib/firefox-2.0/ <<<<--------- fi # yum install compat-libstdc++-33-3.2.3-47.3 # wget http://releases.mozilla.org/pub/mozilla.org/extensions/r-kiosk/r-kiosk-0.5.1-fx.xpi (look here: https://addons.mozilla.org/firefox/1659/) Install the addon with "file -> open file"... ---> in firefox settings, set http://localhost as home page. Go through settings and set sane settings. You may have the firefox profile directory to the root (/.mozilla/...) instead of the root home (/root/.mozilla...) 25. Setting some start-up operations # vi /etc/run.sh #!/bin/bash /etc/rc.d/rc.sysinit /etc/rc.d/rc 3 /bin/login -f root # vi /etc/rc.local Add: X &>/dev/null & export DISPLAY=localhost:0.0 &>/dev/null /usr/local/lib/firefox-2.0/firefox http://localhost &>/dev/null & 26. Adding apache & PHP # yum install httpd # yum install php # chkconfig httpd on # cd /var/www/ # rm -fr html/ # ln -s /mnt/cdrom/web/ html # vi /etc/httpd/conf/httpd.conf remove remark and change the line: ServerName LiveCD:80 # vi /etc/sudoers add: after apache ALL=(ALL) NOPASSWD: ALL root ALL=(ALL) ALL 27. Cleaning /etc/resolve.conf file: # vi /etc/resolv.conf
delete everything 28. Cleaning the Live System from all unnecessary files, like /share/doc, /share/man etc. # cd /usr/share # du -s * sort -n...... 31088 comps 45300 man 62696 doc 66828 locale # rm -fr /usr/share/man /usr/share/doc /var/cache/yum /tmp/* 29. Cloning the file system. NOTE: The file system has to be clone to another system. The use of netcat is to speed things up (using gzip), there is also possibility to use nfs mount or whatever (remote)# mkdir /tmp/fs/ (remote)# nc -l -p 1111 ( cd /tmp/fs/ ; tar -zxvf - ) (local)# cd / (local)# tar -zcvpplf -. nc 192.168.0.13 1111 30. Replacing files for LiveCD Use modified rc.sysinit & fstab. # cp /path/to/modified/rc.sysinit /tmp/fs/etc/rc.d/ # cp /path/to/modified/fstab /tmp/fs/etc/ 31. Creating the cramfs (on remote machine) /LiveCD/ # mkcramfs /tmp/fs/ LiveSystem.cramfs 32. Making iso image /LiveCD/ drwxrwxrwx 2 root root 4.0K Nov 27 13:56 isolinux/ -rwxr-xr-x 1 root root 161 Nov 23 11:51 mkiso.sh* drwxr-xr-x 2 root root 4.0K Nov 29 09:22 SpecialFiles/ drwxrwxrwx 3 root root 4.0K Nov 28 17:29 Web/ # mkisofs -R -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 \ -boot-info-table -c isolinux/boot.cat -iso-level 3 -o /tmp/livecd.iso /tmp/cd/ Notes 1. If and when you are doing online modifications to logical drives (using online RAID tools), after running "blockdev --rereadpt /dev/xxxxx" (for re-reading the partition table), there is also a need to run "/sbin/start_udev" in order to update the /dev directory. This issue was found working on the Oasis pltaform and may not be relevant to the HP Proliant. Platform related notes HP Proliant DL360/DL380 Todo You will have to have (on minimal installation): # yum install libgcc.i386 # yum install ncurses.i386 # rpm -Uhv compat-libstdc++-296-2.96-132.7.2.i386.rpm (from the installation CD) # hpacucli-7.50-18.linux.rpm (from the PSP - Proliant Service Pack) Running the tool via console or via script. 1. sqaushfs cramfs has limit of max size of 272M, which is very limiting. sqaushfs has no limit, but doesn't have support out-of-the-box.