Tuesday, July 23, 2013

Well then, you wanna make your own linux live distribution :) I’m here going to show you a rather easier and simpler way than building linux from scratch. We will be creating a customized distribution based on ubuntu. You might have already seen some successful distributions like Linux MintFluxbuntuOpenGEU etc that were created using ubuntu as base. So let’s start making our own distro using an ubuntu live cd iso. If you don’t already have the iso, you can download the latest version from here.


Install Necessary Tools
The first thing you need to do is to install the required tools for extracting the iso image and for creating the read only file system named as squashFS, used to create live CD/DVD. To install them, run the terminal and use the following command:


 



<div “=”">








sudo aptitude install squashfs-tools genisoimage


 


Extract the ISO
Now create a directory named codinglogslinux or whatever name suits you and copy/move the ubuntu iso into that directory. I would love to use shell to do that :P


 



<div “=”">








mkdir ~/codinglogslinux
mv ubuntu-10.10-desktop-i386.iso ~/codinglogslinux
cd ~/codinglogslinux


 


Well now mount the iso file using the following commands:


 



<div “=”">








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


 


Now you can get the iso file contents in mnt directory. Lets extract everything except the squashFS filesystem inside the iso into a new directory named extract-cd.


 



<div “=”">








mkdir extract-cd
rsync –exclude=/casper/filesystem.squashfs -a mnt/ extract-cd


 


We will now extract the squashFS filesystem located inside the iso file to create a virtual ubuntu installation where we can make our changes and then rebuild the changed system back into the squashFS filesystem inside the iso file. To extract the squashFS filesystem, use the following commands:


 



<div “=”">








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


 


The unsquashfs command might take some time to finish. This is normal because it’s going to copy many files from the readonly filesystem to our virtual ubuntu environment.


Prepare the Virtual Environment
We need to configure the virtual system now to enable network connection for later use. We need to set the proper DNS addresses for our network in the resolve.conf file. You may also need to copy the hosts file depending on your configuration. To do this simply use the following commands:


 



<div “=”">








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


 


Now mount important directories of your host system. This will enable you to use the system resources and run any process/program inside the virtual environment. If you later decide to delete the edit directory, then make sure to unmount them before doing so, otherwise your host system will become unusable and you have to reboot the system then.


 



<div “=”">








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


 


Now to avoid locale issues and in order to import GPG keys use the following commands:


 



<div “=”">








export HOME=/root
export LC_ALL=C


 


Now your virtual system is prepared for making any customizations you need.


Lets do some customizations


APT-GET install/remove any package
Before installing or upgrading any packages, you might need to run the following commands:


 



<div “=”">








dbus-uuidgen &gt; /var/lib/dbus/machine-id
dpkg-divert –local –rename –add /sbin/initctl
ln -s /bin/true /sbin/initctl


 


To view installed packages by size, use the following command:


 



<div “=”">








dpkg-query -W –showformat=’${Installed-Size}\t${Package}\n’ | sort -nr | less


 


Now you may want to remove any package you don’t like :) Well then just remove that using this simple command:


 



<div “=”">








aptitude purge YOUR-PACKAGE-NAME-HERE


 


To install any new package, just use aptitude install as usual:


 



<div “=”">








aptitude install YOUR-PACKAGE-NAME-HERE


 


Many more customizations are possible. There is no limit to how extent you can customize the system. You can change default themes, add new themes and UI widgets, add media codecs and new software, install deb files, change different system level settings, update the kernel, optimize system scripts, add language specific files for localization and whatever innovation you might be able to think of. Some basic customization examples are as follows.


Change the desktop background
Normally desktop background files are located in /usr/share/backgrounds directory. For our case this directory inside the virtual system is located in ~/codinglogslinux/edit/usr/share/backgrounds. So copy your background png file to that directory and adjust the owner and file access to make that available for any user of this system and then edit the following files:



  1. ~/codinglogslinux/edit/usr/share/gnome-background-properties/ubuntu-wallpapers.xml and

  2. ~/codinglogslinux/edit/usr/share/gconf/defaults/16_ubuntu-wallpapers or other files in the same directory. by changing the string ~/codinglogslinux/edit/usr/share/backgrounds/warty-final-ubuntu.pngto point to your file.


Change Fonts, Colors, Panel options
To do this change or add attributes to configuration files such as:~/codinglogslinux/edit/var/lib/gconf/debian.defaults/%gconf-tree.xml or~/codinglogslinux/edit/etc/gconf/gconf.xml.defaults/%gconf-tree.xml


Customize Live CD kernel and Boot Loader
You can change the livecd kernel, by copying the vmlinuz and initrd you want in place of the ones you find inextract-cd/casper.


You can also change the default loading screen by changing the plymouth theme located in ~/codinglogslinux/edit/lib/plymouth directory There are bunch of other things you can customize, those are not in scope of this article. Use your creativity and requirements to do the rest. Now lets repack everything.


Repacking the Distribution


Cleanup everything
Lets remove all the temporary files that are no longer needed.  To do this use the following commands:


 



<div “=”">








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


 


now unmount special filesystems and exit chroot:


 



<div “=”">








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


 


Note: if “umount /proc” command fails try “umount -lf /proc”.


Regenerate Manifest


 



<div “=”">








chmod +w extract-cd/casper/filesystem.manifest
sudo chroot edit dpkg-query -W –showformat=’${Package} ${Version}\n’ &gt; 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 everything back to SquashFS Filesystem


 



<div “=”">








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


 


This process will take some time as it is normal because all the files are going to be packed into the readonly filesystem once again :)


Now you may want to set an image name of your choice then the one provided with ubuntu, right? Just edit the file inextract-cd/README.diskdefines and make necessary changes.


Calculate md5 sums


 



<div “=”">








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


 



<div “=”">








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 ../codinglogs-linux.iso


 


Well congrats, you now have the iso created inside the working folder of your distribution. You can test it using any virtualization software like vmware or so. You can also burn it to any CD/DVD or penDrive. So that’s it, you’ve got your own customized linux distribution :)


There are some GUI tools like Remastersys or UCK to do this work easily. But then you are binded to the customizations these tools offer. They do offer many customization though, but for advanced customizations that can help you make a real distribution rather than just another compiled ubuntu, it’s better to follow the manual instructions described here.

0 comments :

Post a Comment