Dienstag, 1. Juli 2008

Remastering Kubuntu Live CD

I have to say a very special thank you to Winnie. I did try to remaster a Knoppix live system and failed because my final result would no longer autologon the knoppix user account, making my own Linux live cd useless.
But then I found Winnie's great howto for remastering a Kubuntu live CD which is even more up to date to the latest software versions out there - at least compared to Knoppix at the time of this writing.

So why did I try to remaster a live Linux CD? Well I wanted to have a small Live Linux CD(!) system that had Qt 4.3.x and KDevelop installed and ready to be used on it. I browsed a lot of different distros but none of them did have KDevelop preinstalled. So I had to create my own Live-Linux-KDevelop-CD guided by Winnie .
Step by Step

For all of the steps to work, you need to run a Kubuntu system yourself. Since I use openSuSE on my notebook, I simply used a Kubuntu 7.10 Desktop Live CD to start a Kubuntu system for all required utilities and as a master for my new modified Live CD. I did use a normal USB harddrive with an ext3 formated partition to be able to extract the content of the live CD on it.

For the remainder of this documentation, I assume that the external USB drive has been mounted under $USBDISK = /media/disk
1) Creating directories for the remastering

Since we can't change anything on the Live-CD itself, we need to create an exact copy of the CD on our USB disk. Then we need to unpack the compressed data from the CD as well. For that we need to create some folders:
> mkdir $USBDISK/kubuntu710
> mkdir $USBDISK/squashmount
> mkdir $USBDISK/squashexpanded

Now we can make a clone of the Live-CD and place it onto the USB disk:
> rsync -a /cdrom $USBDISK/kubuntu710
2) Adding support for squash file system

The compressed drive of the Live-CD does use a read only file system called squash fs. We need to add some tools to our running live system, so that we can work with that file system:
> sudo apt-get install squashfs-tools
3) Mounting the Live-CD squash drive

Now we can mount the compressed Live-CD file system onto our USB disk:
> mount -t squashfs -o loop $USBDISK/kubuntu710/caspar/filesystem.squashfs $USBDISK/squashmount

Now you are able to access the content of the compressed file system. So we will clone that file system onto our USB disk:
> rsync -a $USBDISK/squashmount $USBDISK/squashexpanded

4) Changing the content

Now we are able to enter the virtual Live-CD environment to be able to change it's content. Feel free to add and remove SW as you like, however make sure your final image does still fit onto the CD. But let's enter the new environment:
> chroot $USBDISK/squashexpanded

You may need to specify a nameserver for DNS to work (replace xxx.xxx.xxx.xxx with your name server):
> echo "nameserver xxx.xxx.xxx.xxx" > /etc/resolv.conf

To be able to access the Internet we need to mount the proc file system:
> mount -t proc /proc proc

To take advantage of the full Kubuntu software repositories, you should enable more repositories in apt's sources.list file:
> vi /etc/apt/sources.list

Enable the repositories you need, most likely universe / multiverse. Save your changes and update the package list:
> apt-get update

Now install software with:
> apt-get install new-package

Or remove software using:
> apt-get remove package

You can query installed software using the dpkg command. E.g. to search for installed office applications:
> dpkg-query -W *office*

The packages that are presented, can be used as a guide for removal from the Live-CD.

Looking for new packages to install? Just type this:
> apt-cache search appname
5) Leaving the squash file system

When you are satisfied with your software selection, we can prepare to exit the chroot environment. Before you do so, you need to cleanup the system and remove all unused files:
> apt-get clean
> ...

You should remove all files that you don't need on the live CD.

Next you should update the filesystem manifest, containing the list of installed applications:
> dpkg-query -W –showformat=‘${Package} ${Version}n’ > /tmp/filesystem.manifest

When that is done, you need to unmount the proc file system first:
> umount /proc

Then you can exit the environment with:
CTRL+D

Now you are back in the running Kubuntu Live-CD session.
At this point you move the filesystem manifest to the proper Live-CD location:
> mv $USBDISK/squashexpanded/tmp/filesystem.manifest $USBDISK/kubuntu710/caspar/filesystem.manifest
> cp $USBDISK/kubuntu710/caspar/filesystem.manifest $USBDISK/kubuntu710/caspar/filesystem.manifest-desktop

Next you can create the ISO image.
6) Creating a new squash file system, creating a new Live-CD ISO image

At this point you are almost done. First we will create a new squashfs file holding your modified Kubuntu system:
> umount $USBDISK/squashmount
> rm $USBDISK/kubuntu710/caspar/filesystem.squashfs
> mksquashfs $USBDISK/squashexpanded $USBDISK/kubuntu710/caspar/filesystem.squashfs


Finally we can create a new ISO image for our new Live-CD:
> cd $USBDISK/kubuntu710
> mkisofs -r -V “MKRUEGER” -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../kubuntu710-custom.iso .

That's it. You now have a customized ISO image of your own Kubuntu distribution. Start your favorite cd burning application and burn a CD from the image. Enjoy your own Live-CD.

Most of the steps above have been taken from Winnie's tutorial.