em Sem categoria

Customizando o Live do Ubuntu

Customizing a (K)Ubuntu 6.04 Linux Live CD
This tutorial reflects a work I had to do in the last days: I had to build a modified Kubuntu live CD, using the latest “Kubuntu 6.04 Flight3” (to use a 2.6.15 kernel). The system had to boot in console mode, defaulting to the Italian “Standard” keyboard layout, running an SSH server and having partimage (client and server).
I started this work using this tutorial by Prof. Dr. Reinhard Schiedermeier, who modified an older version of Ubuntu: the main difference was the use of cloop filesystem, instead of the squashfs used in 6.04 Flight3.
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 (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 580 MB. You need a copy, because it will be modified.
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 95 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. 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,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 GB of disk space. Make an empty file of 2 GB size:

$ sudo dd if=/dev/zero of=$WORK/ubuntu-fs.ext2 bs=1M count=2147

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 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

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

# apt-get remove ttf-baekmuk \
ttf-kochi-gothic \
ttf-kochi-mincho
# vi /etc/apt/sources.list # (Enable universe repositories)
# apt-get update
# apt-get install partimage partimage-server ssh
# /etc/init.d/partimaged stop # (Stops extra processes and frees sockets)
# /etc/init.d/ssh stop # (Stops extra processes and frees sockets)
# update-rc.d -f partimaged remove
# update-rc.d -f kdm remove
# apt-get clean
# dpkg-reconfigure console-data # (Select Italian Standard keyboard)

and leave the (K)Ubuntu filesystem:

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

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-new.iso \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-r \
-V “Custom Ubuntu Live CD” \
-cache-inodes \
-J \
-l \
ubuntu-livecd

Burn ubuntu-new.iso to a disk and you are done! For testing, a virtual PC like qemu is great.