Saturday, April 6, 2013

How to Create a LiveCD?

Step by step guide to prepare a Linux Live CD from Scratch

LiveCD is a CD that contains boot portion in its first sector followed by the OS kernel. You can then add your custom application on top of the OS to run on start-up. You can boot your PC using LiveCD this without depending Hard Disk (yes, even without having the Hard Disk connected).

I assume...
  • Reader must have some basic knowledge about Linux commands and must be familiar with Linux environment.
  • I used Fedora 6 environment to develop this Live CD, so I assume that the reader have at least the same or similar environment.
  • If you want to use different Kernel version then the reader is expected to know the Kernel building procedure. Discussing those procedures are not under the scope of this article.  
  • I used a diagnostic tool AMIDiag deliverable that were ready with its kernel modules compiled for 2.6.21.5. (You can use your own application like notepad instead of this).

Required packages

1. Existing FC7 Live CD (Fedora-7-Live-i686.iso)


2. Script to build the Live CD image (linux-live-6.1.5.tar.gz)
[Original Source: www.linux-live.org]


3. Precompiled Kernel with aufs and squashfs support (linux-2.6.21.5-i486-1.tgz)
[Original Source: www.linux-live.org]

4. (Optional) Crippled Sources (crippled-sources-linux-2.6.21.5-i486-1.tgz)
[Original Source: www.linux-live.org]
Note: If your kernel modules were not compiled for 2.6.21.5 then use this compiled source to recompile

5Compressed Read-only file system (Squashfs)

* If the file is removed or relocated then the Direct Link may not work. In such case navigate and find the package using the Source URL given.

Procedure

Step 1: Copy all the above listed packages into a directory (say /Packs).
mkdir /Packs

Step 2: Create 3 temporary directories (say /mnt/T1, /mnt/T2 and /mnt/T3)


Step 3: Mount the live CD image via loop device to T1 directory
mount /Packs/Fedora-7-Live-i686.iso /mnt/T1 –o loop –t iso9660
Step 4: Mount /mnt/T1/squashfs.img to /mnt/T2
mount /mnt/squashfs.img /mnt/T2 –o loop –t squashfs

Step 5: Mount /mnt/T2/os.img to /mnt/T3 with loop option
mount /mnt/T2/os.img /mnt/T3 –o loop –t ext2

Step 6: Create a directory for Live CD environment (say /LiveCD) and the contents of /mnt/T3 using rsync command
rsync –a /mnt/T3 /LiveCD
After executing this command you can see the folder structure of /mnt/T3 in /LiveCD.

Step 7: Extract the precompiled kernel to LiveCD environment
tar –xvf /Packs/linux-2.6.21.5-i486-1.tgz /LiveCD

Step 8: Add your application to /LiveCD/root. Here I added all the libraries and kernel modules required for AMIDiag. Its folder structure is as follows
ls /LiveCD/root                   | ------ diag - contains AMIDiag Kernel modules and app.
        | ------ diaglibs - contains AMIDiag libraries.
        | ------ gtklibs - contains GTK core libs for widgets.

Step 9: Create a script file /LiveCD/root/.xinitrc and add the following lines to it.
            #!/bin/sh
            /usr/bin/gnome-wm &
            LD_LIBRARY_PATH=/root/diag:/root/diaglibs:/root/gtklibs
            export LD_LIBRARY_PATH
            cd /root/diag
            ./diag

Step 10: Add the following two lines in /LiveCD/usr/bin/startx file.
            HOME=/root
            export HOME
            userclientr=$HOME/.xserverrc
            sysserverrc=/etc/X11/xinit/xserverrc
            ….
            ….

Step 11: Make the following changes in /LiveCD/etc/inittab file
            Change the line
            x:5:respawn:/etc/X11/prefdm –nodaemon
            to  
            x:5:once:/usr/bin/startx

Step 12: Extract the Live scripts from /Packs directory.
            tar –xvf /Packs/linux-live-6.1.5.tar.gz

Step 13: Edit the .config file present in the extracted live script folder and make the following mandatory changes. The file variables are self explanatory.
Change the line
KERNEL=$(uname –r)
to
KERNEL=”2.6.21.5”

Change the line
ROOT=
to
ROOT=/LiveCD

Step 14: Run the .build script (go to /Packs/linux-live-6.1.5 dir if your not there)
./build
Hit enter to accept default settings when the script prompts. 
The above step will approximately take 10 - 20 min to complete.
Upon completion a dir will be created under /tmp.

Step 15: Now move to the dir created by the build script under /tmp (say /tmp/live_data_9961).
Step 16: Edit boot/isolinux/isolinux.cfg and make following changes
            Change following line
            APPEND vga=769 initrd=/boot/initrd.gz …..rw
            to read as
            APPEND vga=769 initrd=/boot/initrd.gz …..rw quiet enforcing=0 fastboot
                     Remove all the lines after APPEND statement
         Note: Replace the dir name live_data_9961 with what created by the script.

Step 17: Move to mylinux dir and run make_iso.sh
cd mylinux
./make_iso.sh
Upon completion you will find mylinux.iso file created under /tmp dir.

Step 18: Write mylinux.iso image into a blank CD and You have done a great job!!!

References:


I created this CD as part of a product prototype around 6 years back while working in AMI (2007)

No comments:

Post a Comment