Preface

This document is part of the Campcaster project, Copyright © 2004 Media Development Loan Fund, under the GNU GPL.

Scope

This document describes the process of creating a custom Ubuntu live CD with the Campcaster packages added.

Acknowledgement

The following HOWTO has been copied from Alberto Turelli’s HOWTO at http://www.atworkonline.it/~bibe/ubuntu/custom-livecd.htm, with some modifications.

Introduction

A live CD is a bootable CD with a complete Linux system on it. A live CD which contains the Campcaster packages can be used to demo Campcaster without having to install anything on the hard drive.

It can also be used to create a new, complete Ubuntu system on the hard drive, with Campcaster automatically installed on it.

The live CD creation process consists of the following steps:
  1. Copy the live CD
  2. Free some space
  3. Mount the compressed filesystem
  4. Create an image for the modified filesystem
  5. Copy the compressed filesystem
  6. Chroot to, and tweak the system
  7. Finish the modified filesystem
  8. Build the modified compressed filesystem
  9. Create the new live CD

Notes

The live CD produced with this HOWTO (as of revision 3055) has the following issues:

The steps in detail

1. Copy the live CD

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 (K)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
The directory contains about 690 MB. You need a copy, because it will be modified.

2. Free some space

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 30 MB.

3. Mount the compressed filesystem

The visible content of the Live CD is mainly used for booting. (K)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 (installed by default on Ubuntu Dapper), and the squashfs-tools package.

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

$ mkdir $WORK/old
$ sudo mount -t squashfs -o loop,ro $WORK/ubuntu-livecd/casper/filesystem.squashfs $WORK/old
Have a look at $WORK/old. You should see the root of the (K)Ubuntu filesystem.

4. Create an image for the modified compressed filesystem

This requires abount 2.5 GB of disk space. Make an empty file of 2.5 GB size:
$ sudo dd if=/dev/zero of=$WORK/ubuntu-fs.ext2 bs=1M count=2500
Format the file with an Ext2 filesystem:
$ sudo mke2fs $WORK/ubuntu-fs.ext2
mke2fs will warn you that ubuntu-fs.ext2 a not a real device. This is ok, proceed.
Now loopback mount the freshly formatted filesystem on a new mount point, say $WORK/new:
$ mkdir $WORK/new
$ sudo mount -o loop $WORK/ubuntu-fs.ext2 $WORK/new

5. Copy the compressed filesystem

To modify the (K)Ubuntu filesystem, we need to decompress and copy it:
$ 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

6. Chroot to, 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 create the /etc/resolv.conf and /etc/hosts files in the copied filesystem. Then stop some services to make sure their ports are available in the chrooted system. Finally, chroot into you live CD environment:

$ sudo mount -t proc -o bind /proc $WORK/new/proc
$ sudo cp /etc/resolv.conf /etc/hosts $WORK/new/etc/
$ sudo /etc/init.d/campcaster-scheduler stop
$ sudo /etc/init.d/postgresql-8.1 stop
$ sudo /etc/init.d/apache2 stop
$ sudo chroot $WORK/new /bin/bash

Now you are at the root of the (K)Ubuntu filesystem. Tweak the system as you like:

# vi /etc/apt/sources.list   # (Enable the universe and campware repositories.)
# apt-get update
# apt-get install campcaster-studio
# apt-get clean
# vim /opt/campcaster/etc/campcaster-scheduler.xml  # (Change the sound
# vim /opt/campcaster/etc/campcaster-studio.xml     # devices to "default".)

Stop the services started by the package installer, and leave the (K)Ubuntu filesystem:

# /etc/init.d/campcaster-scheduler stop
# /etc/init.d/postgresql-8.1 stop
# /etc/init.d/apache2 stop
# exit
$ sudo umount $WORK/new/proc
$ sudo rm $WORK/new/etc/resolv.conf $WORK/new/etc/hosts
You are back at your own system.

7. Finish the modified filesystem

First, update the manifest file to reflect the modified packages:
$ sudo chroot $WORK/new dpkg-query -W --showformat='${Package} ${Version}n' 
    > $WORK/ubuntu-livecd/casper/filesystem.manifest
Next, clear the free disk space. Even if some Debian packages were removed, the unused space on the modified filesystem still holds the content. Fill all free space on the modified filesystem with zeroes (this will eventually fail with “no space left”), then remove the zero file:
$ sudo dd if=/dev/zero of=$WORK/new/dummyfile
$ sudo rm $WORK/new/dummyfile
Now, all unused data blocks are filled with zeroes and compress to almost nothing.

8. Build the modified compressed filesystem

Re-generate the modified filesystem:
$ sudo rm $WORK/ubuntu-livecd/casper/filesystem.squashfs
$ cd $WORK/new
$ sudo mksquashfs . $WORK/ubuntu-livecd/casper/filesystem.squashfs
This is the most time-consuming step. Umount $WORK/new now, we are done:
$ cd $WORK
$ sudo umount $WORK/new

9. Create the new live CD

On the Live-CD there is a MD5 hash. Adjust it to the modified content of the CD:
$ cd $WORK/ubuntu-livecd
$ sudo find . -type f -print0 |xargs -0 md5sum |sudo tee md5sum.txt
Now build the ISO image file, ubuntu-new.iso:
$ cd $WORK
$ sudo mkisofs 
    -o Ubuntu+Campcaster.iso 
    -b isolinux/isolinux.bin 
    -c isolinux/boot.cat 
    -no-emul-boot 
    -boot-load-size 4 
    -boot-info-table 
    -r 
    -V "Ubuntu+Campcaster Live CD" 
    -cache-inodes  
    -J 
    -l 
    ubuntu-livecd

Burn Ubuntu+Campcaster.iso to a disk and you are done!

For testing, a virtual PC like qemu is great.