Ubuntu livecd/dvd

Posted on Monday March 04, 2013 / by Eric Potvin

Here's a tutorial on how to create your own customized version of Ubuntu.

Required Tools

Prepare the System

Install squashFS

After or while downloading the Ubuntu ISO, you need to install the squashFS tool. This tool will create the compressed read-only file system for Linux used to create your LiveCD or LiveDVD.

sudo aptitude install squashfs-tools genisoimage

Extract the ISO

In order to customize Ubuntu, you need to extract the content of the ISO downloaded to a directory. (For this tutorial we will use the following directory: ubuntu_livecd. You can name the directory whatever you want).

mkdir ~/ubuntu_livecd
mv ubuntu-11.10-desktop-i386.iso ~/ubuntu_livecd
cd ~/ubuntu_livecd

The name of the iso might change based on the version you decide to customize.

Mount the ISO

Now, we have to mount the ISO file using the following commands.

mkdir mnt
sudo mount -o loop ubuntu-11.10-desktop-i386.iso mnt

Now the content of the ISO is available in the mntdirectory.

Extract the contents

Extract every files and folders except the squashFS filesystem (will extract the content later) from the ISO to a new directory named extract_cd.

mkdir extract_cd
rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract_cd

Extract squashFS filesystem

Extract the squashFS filesystem located inside the ISO file. This will create the virtual Ubuntu installation, customize its content and rebuild the updated system back into the squashFS filesystem.

sudo unsquashfs mnt/casper/filesystem.squashfs
sudo mv squashfs-root edit

The unsquashfs command might take some time, please be patient.

Prepare the Environment

Network Configuration

Before customizing, we have to setup the network to enable and set the correct DNS routing for the network. To enable this, you have to copy the hosts file and the resolve.conf to the edit directory.

sudo cp /etc/resolv.conf edit/etc/
sudo cp /etc/hosts edit/etc/

Mount Directories

In order to enable this new environment, you have to mount the edit directory. This will allow you to run processes, commands (like apt-get) and use the system resources inside this new environment.

sudo mount --bind /dev/ edit/dev
sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts

Don't forget: make sure you unmount the edit directory if you delete this folder. This will make your system unstable and most probably unusable until the next reboot.

You might have to run these commands in order to avoid issues and to import GPG keys.

export HOME=/root
export LC_ALL=C


Now we are ready to customize (Finally!).

Here you can do basically whatever you want, change wallpapers, usplash, themes, customized packpages to name a few. Just remember every changes has to be made in the ~/ubuntu_livecd/edit folder.


Once your customization is completed, you need to rebuild the ISO file.


To be safe, let's remove all the unwanted files (like temporary files) we don't need.

aptitude clean
rm -rf /tmp/* ~/.bash_history
rm /etc/resolv.conf
rm /var/lib/dbus/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl

Unmount the filesystems

To make sure we use our current version of Ubuntu, we have to unmount the filesystems and exit chroot.

umount /proc
umount /sys
umount /dev/pts
sudo umount edit/dev

if the "umount /proc" command fails, use this one instead: "umount -lf /proc".

Regenerate Manifest

chmod +w extract-cd/casper/filesystem.manifest
sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' > extract-cd/casper/filesystem.manifest
sudo cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
sudo sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop
sudo sed -i '/casper/d' extract-cd/casper/filesystem.manifest-desktop

Compress to SquashFS Filesystem

sudo rm extract-cd/casper/filesystem.squashfs
sudo mksquashfs edit extract-cd/casper/filesystem.squashfs

This might take some times, so please be patient.

You can set an image name of your choice here other than the one provided by Ubuntu. If you choose to do so, simply edit the file in extract-cd/README.diskdefines and make necessary changes.

Calculate md5 sums

cd extract-cd
sudo rm md5sum.txt
find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt

Create the ISO image

sudo mkisofs -r -D -V "Custom Ubuntu" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ubuntu-linux.iso .

You can replace the Custom Ubuntu with something else.

Try it!

Your ISO is ready, simply burn it using your favorite tool or via command line.

cdrecord -v -dev='/dev/scd0' ubuntu-linux.iso