How to build you own Ubuntu
It’s not difficult to remaster Ubuntu, providing you understand the distro’s workings and aren’t afraid of the command line. Creating a customized version is also a great way to get a feel of distro building – you can see the complexities that lie underneath the gnomey surface of an Ubuntu release. The following guide shows you how to extract an ubuntu CD, add and remove the packages you want, and then assemble it back together again. Please note that you should have at least 3GB of free hard drive space available to follow these steps.
1: Get the ISO
To rebuild Ubuntu, we need an image file of the Desktop CD (ie the one that runs in Live mode, rather than the text-based Alternate CD). You can download the latest stable version from here. Save it to your home directory and rename it to natty.iso. (It’s about 700MB to download, so a broadband connection is pretty much essential here, unless you have the patience of a saint!)
2: Loopback mount it
Now we need to attach this CD image to the filesystem. open up a terminal and switch to root (sudo bash), then enter:
mkdir /mnt/loop
mount -o loop natty.iso /mnt/loop
Now the contents of natty.iso are accessible in /mnt/loop. We want to copy these to our filesystem, so create a directory and copy the entire contents as follows:
mkdir ubuntu-rebuild
rsync -ax /mnt/loop/. ubuntu-rebuild
Once this is complete, the ubuntu-rebuild directory will contain the disc contents. You can now unmount the loopback ISO image (umount /mnt/loop).
3: Preparation
Next we need to extract the compressed filsystem that’s included on the Ubuntu CD; this uses SquashFS, available in Ubuntu via the squashfs-tools package (apt-get install squashfs-tools). Loopback mount the compressed filesystem as follows:
mount ubuntu-rebuild/casper/filesystem.squashfs
/mnt/loop -t squashfs -o loop
Now /mnt/loop holds the contents of the compressed Ubuntu filesystem – the one used when you boot up the CD in Live mode. Let’s copy this into our home directory, in a new folder:
mkdir ubuntu-source
rsync -av /mnt/loop/. ubuntu-source
umount /mnt/loop
4: Changing packages
Hurrah: we have everything in place! You can now perform some magic to switch into the Ubuntu distro files as if you were running it natively. This is thanks to a little tool called chroot, which changes the perceived root filesystem and therefore lets you ‘pretend’ that you’re in another distro. Enter these commands, the first of which sets up networking inside the Ubuntu filesystem:
cp /etc/resolv.conf ubuntu-source/etc/
rm ubuntu-source/etc/apt/sources.list
cp /etc/apt/sources.list ubuntu-source/etc/
chroot ubuntu-source
Now you’re inside the ubuntu-source folder, as if it was the root (/) directory. You’re essentially running the same distro as supplied on the live CD, but this time you can modify it! I recommend against deleting packages, unless you’re absolutely sure what you’re doing; some of them are dependencies for critical system packages. First, enter the following commands:
apt-get update
wget --output-document=/etc/apt/sources.list.d/medibuntu.list
http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list
&& sudo apt-get --quiet update && sudo apt-get --yes --quiet
--allow-unauthenticated install medibuntu-keyring &&
sudo apt-get --quiet update
Now you can start adding programs via apt-get, for instance, to add AbiWord to your system:
apt-get install abiword
Programs you add at this stage will appear on the final CD/DVD when we rebuild it. So you could add Xfce if that’s your favourite desktop environment, or ‘build-essential’ if you want GCC and it’s cohorts ready to run.
5: Update
Once you’re done, enter exit to leave the Ubuntu filesystem and return to your normal distro. We now need to generate a list of files that are on the updated Ubuntu image, so enter the following monster command:
chroot ubuntu-source dpkg-query -W --showformat='${Package}
${Version}\n' | grep -v deinstall >
ubuntu-rebuild/casper/filesystem.manifest
We also need to tell the Ubuntu installer, when it is run, to avoid certain packages. For instance, after the installation, you don’t want the ‘Install ubuntu’ icon on your desktop! So we sed through the list of installable files and remove various live CD-only components:
cat > /tmp/sedscript <<END
/casper/d
/libdebian-installer4/d
/os-prober/d
/ubiquity/d
/ubuntu-live/d
/user-setup/d
END
sed -f /tmp/sedscript < ubuntu-rebuild/casper/filesystem.manifest >
ubuntu-rebuild/casper/filesystem.manifest-desktop
6: Remaster
Now we need to rebuild the SquashFS filesystem image; this can take up to half an hour…
mksquashfs ubuntu-source/
ubuntu-rebuild/casper/filesystem.squashfs -noappend
Then we have to update the MD5 checksums to confirm the disc integrity:
(cd ubuntu-rebuild && find . -type f -print0 | xargs -0 md5sum
> md5sum.txt)
And finally, the mkisofs command which builds us a shiny new ISO image:
mkisofs -r -V "My Modified Ubuntu" -cache-inodes -J -l -b
isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot
-boot-load-size 4 -boot-info-table -o newbuntu.iso ubuntu-rebuild
Et voila:if all has gone well, you’ll now have a file called newbuntu.iso which you can burn to a CD-R (or, if it’s larger than 700MB, to a DVD). Note that disc images larger than 2GB can have problems running. But if it’s smaller than that, burn it, boot it and enjoy!
Website clean-up and more.
(25.09.11)
Since we've been working on a new look, we've decided to remove or edit
some of the less useful pages on the website. Read more
LinuxTrek.org gets a whole
new look!
(25.09.11)
Today is a big day, because the new website is finally up and running! Read more
