Howto: Customize your own Ubuntu Live CD

This will work for Feisty, and for Gutsy too.

This tutorial is actually based on a bash script. I figured typing commands line by line is far to slow, and mistakes can be made. A script simplifies the operation, and can be modified to taste.

I will first provide a basic script that everyone should find useful. The script can be further modified by simply adding lines of code where necessary.

Here's how you do it:

1 - What you need:
Create a new folder called: live
Download the 7.04 (Feisty) desktop iso and place in the live folder.
Download the Flash browser plugin from Adobe: http://fpdownload.macromedia.com/get...9_linux.tar.gz
Extract the flashplayer.xpt and the libflashplayer.so files and place in the live folder.
You will also need to install a couple of tools onto your computer to make this whole thing possible:

Code:

sudo apt-get install squashfs-tools mkisofs
These only need to be installed the once, and so don't need to be part of the script.

2 - The basic script:

Code:

#!/bin/bash

ubuntuiso=ubuntu-7.04-desktop-i386.iso
customiso=ubuntu-7.04-H12Y-v1.iso
kernel=2.6.20-15-generic

clear
echo Customize Ubuntu LiveCD
echo
echo Script by: Stephen Clark
echo Based on documentation found at:
echo https://help.ubuntu.com/community/LiveCDCustomization
echo
echo "For customizing Ubuntu 7.04 (Feisty Fawn)"
echo
echo Press Ctrl C at any time to quit
echo

echo -n "Loading squashfs module... "
modprobe squashfs
echo Done
echo

echo -n "Extract iso contents? y/[n] "
read ua
if [ "$ua" = "y" ]; then
if [ -e "edit" ]; then
echo -n "Removing existing Desktop System... "
rm -r edit
echo Done
fi
mkdir edit
if [ -e "extract-cd" ]; then
echo -n "Removing existing CD contents... "
rm -r extract-cd
echo Done
fi
mkdir extract-cd
if ! [ -e "mnt" ]; then
mkdir mnt
fi
if ! [ -e "squashfs" ]; then
mkdir squashfs
fi
echo -n "Extracting CD contents... "
mount -o loop $ubuntuiso mnt
rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
echo Done
echo -n "Extracting Desktop System... "
mount -t squashfs -o loop mnt/casper/filesystem.squashfs squashfs
cp -a squashfs/* edit/
umount squashfs
umount mnt
echo Done
fi
echo

# Place custom scripting here

# Initialize networking and sources

cp /etc/resolv.conf edit/etc
cp /etc/hosts edit/etc
cp /etc/apt/sources.list edit/etc/apt

echo -n "Start package removal? y/[n] "
read ua
if [ "$ua" = "y" ]; then
echo
# Not all apps can be purged without dependency problems
# Accept whatever solution aptitude offers
chroot edit apt-get remove --purge ekiga evolution tomboy serpentine f-spot gnome-games bittorrent onboard gnome-pilot gnome-pilot-conduits libpisock9 libpisync0
fi
echo

echo -n "Start package installation? y/[n] "
read ua
if [ "$ua" = "y" ]; then
echo
# -q supresses the output to a minimum
chroot edit apt-get update -qq
# sox, vorbis-tools, & mpg123-alsa are for previewing sound files in nautilus
# The gstreamer packages are for codec support
chroot edit apt-get install mozilla-thunderbird sox vorbis-tools mpg123-alsa vlc comixcursors gnome-themes-extras gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad
chroot edit apt-get clean
fi
echo

echo -n "Installing Flash plugin for Firefox... "
# Install flash plugins
cp flashplayer.xpt edit/usr/lib/firefox/plugins
cp libflashplayer.so edit/usr/lib/firefox/plugins
echo Done
echo

# Clean up

rm edit/etc/resolv.conf
rm edit/etc/hosts
rm edit/etc/apt/sources.list

if [ -e "extract-cd/programs" ]; then
echo -n "Remove unwanted Windows applications from LiveCD? [y]/n "
read ua
if ! [ "$ua" = "n" ]; then
echo -n "Removing Windows applications... "
rm -r extract-cd/programs
echo Done
fi
echo
fi

echo -n "Copying wallpaper... "
if [ -f "edit/usr/share/backgrounds/*.*" ]; then
rm edit/usr/share/backgrounds/*.*
fi
cp wallpaper/* edit/usr/share/backgrounds/
cp ubuntu-wallpapers.xml edit/usr/share/gnome-background-properties/
echo Done
echo

echo Setting gconf defaults for wallpaper, mouse, theme, nautilus and panel
# Wallpaper
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /desktop/gnome/background/picture_filename "/usr/share/backgrounds/01.jpg"
# Mouse
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /desktop/gnome/peripherals/mouse/cursor_theme "ComixCursors-Orange-Large-Slim"
# Theme
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /desktop/gnome/interface/gtk_theme "Nuvola"
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /desktop/gnome/interface/icon_theme "Nuvola"
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /apps/metacity/general/theme "Nuvola"
# Nautilus
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /apps/nautilus/preferences/click_policy "single"
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /apps/nautilus/preferences/desktop_font "Sans Bold 10"
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type bool --set /apps/nautilus/preferences/start_with_sidebar "false"
chroot edit gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type bool --set /apps/nautilus/icon_view/default_use_tighter_layout "true"
echo

# End of custom scripting

# Putting the CD together

echo -n "Recompile iso? [y]/n "
read ua
if [ "$ua" = "n" ]; then
echo
echo The End
echo
exit
fi

echo Compressing filesystem
if [ -e "extract-cd/casper/filesystem.squashfs" ]; then
rm extract-cd/casper/filesystem.squashfs
fi
mksquashfs edit extract-cd/casper/filesystem.squashfs
echo

echo -n "Removing old md5sum.txt and calculating new md5 sums... "
rm extract-cd/md5sum.txt
(cd extract-cd && find . -type f -print0 | xargs -0 md5sum > md5sum.txt)
echo Done
echo

echo Creating iso
if [ -f "$customiso" ]; then
echo -n "Removing old custom iso... "
rm $customiso
echo Done
echo
fi
cd extract-cd
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 ../$customiso .
echo

echo The End
echo

Open Gedit and paste this code in. Save file as: customize-livecd.sh and place in your live folder.
To run the script, open a terminal and type:
Code:

sudo sh ./customize-livecd.sh
The first time round, you will answer yes to all questions. After that, you can respond with no to save time extracting the iso again (unless you want to clean things up).

3 - A brief explanation:

The first thing the script does is to load the squashfs module. This is necessary for the extraction/compression process to work.
Then it asks whether to extract the iso contents. If you want to start a fresh customization, answer yes. Answering no will save time having to extract everything from the iso again.
There are 3 lines that copy your network settings and the sources.list to enable downloading of packages to the extracted iso.
Then follows package removal and installation. Again, you can answer no to save time if you have already done it. Adjust the packages to be removed or installed to taste.
Then your Flash plugin for Firefox will be copied over.
There are some Windows application on the LiveCD which don't serve much purpose, so they can be removed too making a bit of room.
The next section is for copying any wallpaper over. If you don't want this, delete these 7 lines. If you do, create a folder in the live folder called wallpaper. Copy any wallpaper you want into this folder. If you wish to have these show up in the Desktop Background applet, you can customize the ubuntu-wallpapers.xml and add them. You can find this file in /usr/share/gnome-background-properties/. Make a copy of the ubuntu-wallpapers.xml file into the live folder and alter this copy instead. This will have to be modified by hand using Gedit before running the script. It's quite obvious how to alter the xml file once you've opened it.
The next few lines are for modifying some settings that you can find using the Configuration Editor. It gives you an idea of how to create your own default settings. This can be extended to just about everything you find in the Configuration Editor including setting up a complete customized desktop and panel(s).
Now we come to the part where the whole thing will be put back together and create a new iso.
At the very beginning of the script, you will notice 3 variables. ubuntuiso is the name of the Ubuntu iso you downloaded. customiso is the name of the new iso you will create from this script. kernel is the kernel used in the iso you downloaded. If you're customizing Gutsy, it will be 2.6.22-7-generic.

4 - There are some laptop owners having problems booting the LiveCD due to driver problems. I personally own a Philips X56 which has this exact problem. So, for anyone with a Philips freevents X56, Twinhead H12Y, Avaretec 2460, or Everex Stepnote SA2050, this is the fix:
Download: http://www.fitzenreiter.de/averatec/...16-generic.tgz
Extract the 8139too.ko.2.6.20-16-generic file, copy it to the live folder and rename it to 8139too.ko . Add these few lines to the script:
Code:

# Patch for Twinhead H12Y notebooks

echo -n "Install patch for $kernel kernel? y/[n] "
read ua
if [ "$ua" = "y" ]; then
echo 8139too PIO from: http://www.fitzenreiter.de/averatec/index-e.htm
echo -n "Removing SDHCI and replacing 8139too MIMO to PIO... "
sdhci=edit/lib/modules/$kernel/kernel/drivers/mmc/host/sdhci.ko
too=edit/lib/modules/$kernel/kernel/drivers/net/8139too.ko
if [ -f "$sdhci" ]; then
rm $sdhci
fi
if [ -f "$too" ]; then
rm $too
fi
cp 8139too.ko $too
echo Done
echo
echo -n "Rebuilding initrd... "
chroot edit mkinitramfs -o /initrd.gz $kernel
mv edit/initrd.gz extract-cd/casper/
echo Done
fi
echo

... just before the line that reads: # End of custom scripting. Bear in mind that any updates to the kernel will also have to be patched. After installation, any new kernels can be patched using the patch you just download and extracted. Follow the instructions within.

That's about it.

Clicky Web Analytics