- Make sure that you have installed the needed tools
sudo aptitude install squashfs-tools genisoimage
Obtain the base system
- Download an official Desktop CD from http://releases.ubuntu.com/
Note: the example shown here uses the ubuntu-9.04-desktop-i386.iso Desktop CD
- Move or copy it into an empty directory
mkdir ~/livecdtmp mv ubuntu-9.04-desktop-i386.iso ~/livecdtmp cd ~/livecdtmp
Extract the CD .iso contents
Mount the Desktop .iso
mkdir mnt sudo mount -o loop ubuntu-9.04-desktop-i386.iso mnt
Extract .iso contents into dir 'extract-cd'
mkdir extract-cd rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
Extract the Desktop system
Extract the SquashFS filesystem
sudo unsquashfs mnt/casper/filesystem.squashfs sudo mv squashfs-root edit
Prepare and chroot
If you need the network connection within chroot
sudo cp /etc/resolv.conf edit/etc/
Depending on your configuration, you may also need to copy the hosts file
sudo cp /etc/hosts edit/etc/
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
(these mount important directories of your host system - if you later decide to delete the edit/ directory, then make sure to unmount before doing so, otherwise your host system will become unusable at least temporarily until reboot)
To avoid locale issues and in order to import GPG keys
export HOME=/root export LC_ALL=C
Customizations
Apt-get
Prerequisites
In 9.10, before installing or upgrading packages you need to run
dbus-uuidgen > /var/lib/dbus/machine-id
and
dpkg-divert --local --rename --add /sbin/initctl ln -s /bin/true /sbin/initctl
Tasks
To view installed packages by size
dpkg-query -W --showformat='${Installed-Size}\t${Package}\n' | sort -nr | lessWhen you want to remove packages remember to use purge
aptitude purge package-name
Custom Background for GNOME
Generally background files are located in /usr/share/backgrounds. Copy your png file there, adjust owner and file access, and edit the files:
- /usr/share/gnome-background-properties/ubuntu-wallpapers.xml and
- /usr/share/gconf/defaults/16_ubuntu-wallpapers or other files in the same directory. by changing the string /usr/share/backgrounds/warty-final-ubuntu.png to point to your file
Eventually change or add attributes to other configuration files such as: /var/lib/gconf/debian.defaults/%gconf-tree.xml or /etc/gconf/gconf.xml.defaults/%gconf-tree.xml).
Historical: More for Dapper...
Change gconf values (fonts, panels etc.)
To make any change on the gconf attributes you must add the value that you want in the file /etc/gconf/gconf.xml.defaults/%gconf-tree.xml. Adding a value in that file will change the default values of Gnome or other applications, so you can change fonts, backgrounds, themes, cursors etc.
Instead of editing the file with gedit or another text editor, you can use the gconftool-2, under the chroot environment, running the following line:
gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set yourkey "yourvalue"
where string, yourkey and yourvalue must be the type, key and value that you want to change...
Making several gconf changes
Editing gconf by setting each value separately takes too much time. There is a better way:
Make a test user and adjust the settings as you wish. Run
gconftool-2 --dump /the/settings/branch/you/need > ~/live/your-new-settings.xml sudo chown root:root ~/live/your-new-settings.xml sudo mv ~/live/your-new-settings.xml ~/live/edit/your-new-settings.xml
and then, in the chroot environment, run
gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --load /your-new-settings.xml rm /your-new-settings.xml
This way you can import the whole branch, e.g. /apps/panel - all settings for Gnome's panels. Note that this way you import not only the keys, but also their descriptions, so all GConf descriptions will be changed to the language which was set for the test user, and there will be no way to safely change them back. Some programs (for example, keyboard shortcuts in Preferences menu) use descriptions from GConf.
Change default language of gfxboot
This customization must be done outside the chroot.
sudo aptitude install dpkg-dev uck apt-get source gfxboot-theme-ubuntu gfxboot cd gfxboot-theme-ubuntu*/ make DEFAULT_LANG=fi sudo cp -af boot/* ../extract-cd/isolinux/
Change "fi" to your preferred locale. Note that this does not change which languages are available in the F2 menu. For more info about gfxboot customization, see Ubuntu Customization Kit.
- A other way to change the default language of gfxboot without rebuild the packages is to create a file name lang in the isolinux directory containing your locale's name.
Customization limits
After customization make sure that there are no users with an UID > 999. Otherwise your image won't boot because no initial user is available (see /usr/share/initramfs-tools/scripts/casper-bottom/10adduser). While in chroot:
awk -F: '$3 > 999' /etc/passwd
If you get any hits, try changing the uid:
usermod -u 500 $hit
Miscellaneous Defaults
You may wish to edit the files in /etc/default to change system behavior at startup. You might also edit /etc/profile, /etc/bash.bashrc, and /etc/bash_completion to change login settings for all users on the system. You cannot directly edit defaults for the live cd user (e.g., casper, ubuntu, or user) since that account is created at boot time. You can directly edit root's default files (/root in the chroot environment).
If you wish to change the default timezone used by the live cd, run:
dpkg-reconfigure tzdata
If you have added a locale and wish to make it the default, update /etc/default/locale. You may have to compile the locale:
locale-gen new_locale update-locale LANG=new_locale LANGUAGE=new_locale LC_ALL=new_locale
These changes must be made as root in the chroot environment.
Advanced Customizations
Live CD Kernel
If you want to customize further the boot process, you can change the livecd kernel, by copying the vmlinuz and initrd you want in place of the ones you find in extract-cd/casper.
i.e.
sudo cp edit/boot/vmlinuz-2.6.15-26-k7 extract-cd/casper/vmlinuz sudo cp edit/boot/initrd.img-2.6.15-26-k7 extract-cd/casper/initrd.gz
Note that the initial ramdisk filename for newer releases (since 9.10) is casper/initrd.lz (not .gz).
Removing the (Casper) Autologin
The autologin feature of the Jaunty/9.04 live CD is a bit of an on-the-fly boot-hack. After extracting the initrd.gz, you need to edit the casper-bottom/25configure_init script and then recreate the initrd.gz file, replacing the original in extract-cd/casper. The process to do so goes like this:
# cd extract-cd/casper # mkdir tempdir # cd tempdir # gunzip -dc ../initrd.gz | cpio -imvd --no-absolute-filenames # cp scripts/casper-bottom/25configure_init scripts/casper-bottom/25configure_init.orig # vi scripts/casper-bottom/25configure_init
Now look for line 25 which has the conditional statement to test $USERNAME.
Line 25 performs a conditional evaluation and if it evaluates to true, it will execute the code within the if block. The if block contains code to modify files used in the boot process to create the live cd autologin.
To disable the autologin feature, Remove $USERNAME, but just leave the quotes. The -n modifier tests the $USERNAME string to see if it's length is non-zero. By removing the variable, and leaving two double quotes, this statement evaluates to false because the two double quotes effectively make a zero-byte string. Be sure to leave no whitespace between the quotes because whitespace will make the evaluation true and execution wil fall into the if block.
21:log_begin_msg "$DESCRIPTION" 22: 23:# Arrange for shells on virtual consoles, rather than login prompts 24: 25:if [ -n "$USERNAME" ]; then
After making the change, line 25 will look like this:
25:if [ -n "" ]; then
Save the file and quit the editor. Then, from extract-cd/casper/tempdir run the following command to re-create the initrd.gz file. There are other methods for re-creating the initrd.gz file on this page which may work also.:
# cp ../initrd.gz ../initrd.gz.orig # find . | cpio -o -H newc | gzip -9 > ../initrd.gz
This will create a new initrd.gz file with no auto login. You can then continue to remaster the CD as described on this page. Be sure to create a user and password to login with before you remaster the cd. If you do not, you will not be able to login after booting!
Also, I have read a few articles mentioning that Karmic (9.10) uses initrd.lz instead of initrd.gz. I do not know if this is true, but should mention it in case you are not getting the expected results. To unpack the initrd.lz file, you need to do this:
# cd extract-cd/casper # mkdir lztempdir # cd lztempdir # lzma -dc -S .lz ../initrd.lz | cpio -imvd --no-absolute-filenames
And to re-create the initrd.lz file:
# cp ../initrd.lz ../inird.lz.orig # find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../initrd.lz
Boot init
You have to edit the files in edit/usr/share/initramfs-tools/scripts/casper-bottom/* For example you can change the hostname or the livecd user.
i.e.
sudo nano edit/usr/share/initramfs-tools/scripts/casper
and edit the username or hostname
sudo nano edit/usr/share/initramfs-tools/scripts/casper-bottom/10adduser
to edit even the livecd user's password.
If you're customizing 10.04, you need to edit variables in /etc/casper.conf for the user and host names instead of modifying the scripts
P.S. in order to obtain an encrypted password, you have to use the mkpasswd program that's shipped with whois package!
Rebuilding initrd
After you've modified the kernel, init scripts or added new kernel modules, you need to rebuild the initrd.gz file and substitute it into the casper directory.
sudo chroot edit mkinitramfs -o /initrd.gz 2.6.15-26-k7(replace the kernel version with the one that the CD will boot with - this can be found in edit/lib/modules) *** do I need to mount proc, sys, devpts after chroot here ? Gordon
Exit from the chroot jail and move this file to extract-cd/casper:
exit mv edit/initrd.gz extract-cd/casper/
Cleanup
Be sure to remove any temporary files which are no longer needed, as space on a CD is limited. A classic example is downloaded package files, which can be cleaned out using:
aptitude clean
Or delete temporary files
rm -rf /tmp/* ~/.bash_history
Or delete hosts file
rm /etc/hosts
Or nameserver settings
rm /etc/resolv.conf
If you installed software, be sure to run
rm /var/lib/dbus/machine-id
and
rm /sbin/initctl dpkg-divert --rename --remove /sbin/initctl
from within the chroot environment.
now umount (unmount) special filesystems and exit chroot
umount /proc || umount -lf /proc umount /sys umount /dev/pts exit sudo umount edit/dev
- Note: if "umount /proc" command fails, "umount -lf /proc" will be used to retry automatically.
Producing the CD image
Assembling the file system
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-desktopCompress filesystem
sudo rm extract-cd/casper/filesystem.squashfs sudo mksquashfs edit extract-cd/casper/filesystem.squashfs -nolzma
- Note: The -nolzma option is only available from Hardy , and was removed in Karmic. Also, the squashfs has to be generated using a version of mksquashfs that is compatible with the kernel used on the CD you are customizing. For example, you cannot generate a jaunty squashfs on karmic, as the jaunty kernel is not able to mount a squashfs prepared using mksquashfs from karmic.
For slightly higher compression at the cost of compression time, you can increase the block size:
sudo mksquashfs edit extract-cd/casper/filesystem.squashfs -b 1048576
Update the filesystem.size file, which is needed by the installer:
printf $(sudo du -sx --block-size=1 edit | cut -f1) > extract-cd/casper/filesystem.size
Set an image name in extract-cd/README.diskdefines
sudo vim extract-cd/README.diskdefines
(you can use "sudo nano extract-cd/README.diskdefines" if you have difficulties understanding vim)
Remove old md5sum.txt and calculate new 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 -D -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 ../ubuntu-9.04.1-desktop-i386-custom.iso .
Testing the CD
Test using qemu emulator
qemu -cdrom ubuntu-9.04.1-desktop-i386-custom.iso -boot d -m 512
Or if you have hardware acceleration for kvm
kvm -cdrom ubuntu-9.04.1-desktop-i386-custom.iso -boot d -m 512
You can also test with virtualbox-ose, which is free software and available in the Ubuntu universe repository.
Troubleshooting
Some experience problems virtualizing the iso after changing the livecd linux kernel. If you do, go click F6 when the boot screen is showing. Move the cursor between splash quiet and -- and write: all_generic_ide
Burning the image to CD
Simple! Just do
cdrecord dev=/dev/cdrom ubuntu-9.04-desktop-i386-custom.iso
from https://help.ubuntu.com/community/LiveCDCustomization
