ChaddsFordPC
 
Links

How to customize a Ubuntu Live CD

This is a step by step instruction on how to customize a Ubuntu live CD that worked for me. These instructions are based on these three links but in my case, just one of these methods didn't work, so I had to mix them with each other:

Many thanks to the authors of these three pages.

I did this from within a Debian environment (in my case, Ubuntu Server 6.06)



1 Copy the LiveCD

Export a shell variable (say, WORK) pointing to a working directory somewhere on your disk (say, ~/mylivecd), so you can use this page as a copy-and-paste howto.

$ export WORK=~/mylivecd
$ mkdir -p $WORK

Mount a Ubuntu Linux Live CD
$ mount -t iso9660 /dev/hdc /cdrom

or the ISO image:
$ sudo mount -t iso9660 -o loop /path/to/dapper-live-i386.iso /cdrom

Then copy the content of the disk into a new directory, set the write permission on the new directory's content, and unmount the Live CD (or the ISO image):

$ cd $WORK
$ mkdir ubuntu-livecd
$ cp -a /cdrom/. ubuntu-livecd
$ chmod -R u+w ubuntu-livecd
$ sudo umount /cdrom

2 Free space (I)

The copy of the Live CD has various subdirectories. I removed one of them, containing some Windows applications.

$ rm -rf $WORK/ubuntu-livecd/programs

The Live CD works fine without these programs. That saves about 30MB.

3 Extracting the current Live CD

The visible content of the Live CD is mainly used for booting. Ubuntu Linux itself is contained in a compressed filesystem image in $WORK/ubuntu-livecd/casper/filesystem.squashfs.

To decompress and read this file, you need the squashfs module. I built a custom kernel (on Debian) using the kernel-patch-squashfs package, but you can easily use any way to get the squashfs module.

Finally loopback mount the compressed filesystem on a new mount point, say $WORK/old:

$ mkdir $WORK/old
$ sudo mount -t squashfs -o loop $WORK/ubuntu-livecd/casper/filesystem.squashfs $WORK/old

Have a look at $WORK/old. You should see the root of the Ubuntu filesystem.
Now we want to extract squashfs contents into dir 'new' for editing:

$ mkdir $WORK/new
$ sudo cp -a $WORK/old/. $WORK/new

We can umount $WORK/old now, because we have copies of all the data we need:
$ sudo umount $WORK/old

4 Chroot and tweak the system

Now it's time to fine-tune the system to your needs, chrooting into the new system and using the standard Debian/Ubuntu tools. First, prepare the /proc filesystem and the /etc/resolv.conf file for the copied filesystem and chroot into it:

$ sudo cp /etc/resolv.conf $WORK/new/etc/
$ sudo mount -t proc -o bind /proc $WORK/new/proc
$ sudo chroot $WORK/new /bin/bash

5 Customizations

Do anything you want to the CD here

6 Clean up

# exit
$ sudo umount $WORK/new/proc
$ sudo rm $WORK/new/etc/resolv.conf

You are back at your own system.

7 Preparing for the CD

There are some small but important steps to take first, however. The CD wants a list of the packages on your system, which you can get using dpkg-query, using this recipe:

$ sudo chroot $WORK/new dpkg-query -W --showformat='${Package} ${Version}\n' | grep -v deinstall > $WORK/ubuntu-livecd/casper/filesystem.manifest

When the Live installer runs, it copies everything to the target system, but then cleans up by removing packages which are not listed in a second manifest file. This must be done to allow your installation of live CD to install the customized version; otherwise, it will remove all your customizations when you install the live cd to hard drive.

I manage this by filtering the manifest we just created using a sed script:

$ cat > /tmp/$$.control <<FOO
/casper/d
/libdebian-installer4/d
/os-prober/d
/ubiquity/d
/ubuntu-live/d
/user-setup/d
FOO

$ sed -f /tmp/$$.control < $WORK/ubuntu-livecd/casper/filesystem.manifest > $WORK/ubuntu-livecd/casper/filesystem.manifest-desktop
$ rm /tmp/$$.control


8 Build the modified compressed filesystem

$ sudo rm $WORK/ubuntu-livecd/casper/filesystem.squashfs
$ cd $WORK/new
$ sudo mksquashfs . $WORK/ubuntu-livecd/casper/filesystem.squashfs
Note: I just downloaded a copy of "squashfs3.0" and ran the command above from ir's bin directory. but if you can successfully install squashfs on your system you wouldn't need this.

9 Putting the CD together

$ sudo vim $WORK/ubuntu-livecd/README.diskdefines

Change the ownership of the squashfs filesystem to the current user and group (in my case, smiri:smiri, in your case, user:group):

$ sudo chown smiri:smiri $WORK/ubuntu-livecd/casper/filesystem.squashfs

Calculate md5 sums:

$ (cd $WORK/ubuntu-livecd && find . -type f -print0 | xargs -0 md5sum > md5sum.txt)

Create ISO:

$ cd $WORK/ubuntu-livecd
$ mkisofs -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../cdname.iso .
(Change ../cdname.iso to any name you want the iso to have)



And you're DONE.