Roll your own Linux distribution

By   |  May 17, 2004

There was a time when the idea of building your own custom Linux OS was unthinkable for all but the most dedicated, foolhardy or skilled. Today, however, that has changed and it is not completely inconceivable for almost anyone to build their own version of Linux. Thanks primarily to the excellent work of the Knoppix and Morphix projects an a host of othe that are making the concept of Linux on a CD a reality.

For this how-to you require a little bit of time, a CD writer, some blank disks, a copy of Morphix, or the bandwidth to download a copy, and the willingness to learn.

First things first. Morphix is built on Debian and Knoppix and runs off a single CD – hence its title as a \”live CD\”. Morphix also auto-detects your hardware and configures itself appropriately, and only rarely gets things wrong in my experience. Morphix also gives you the option to install the configured version of Linux on your hard disk once you are happy with the setup, which is a really good way of new users getting to know the software before actually replacing their existing operating system.

More importantly though (for the purposes of this article) Morphix is realtively easy to re-configure and customise making it possible to build your own Linux distribution within just a few hours. A distribution that you can burn to CD and hand out to admiring potential Linux converts.

Disclaimer: This guide is built from a number of different sources and is known to work in at least one specific instance (mine). There is no reason the process outlined below will not work for most users, but do exercise caution if you are unsure of what you are doing. Tectonic can no be held responsible fo any damage you do to your self or your computer.

Having said that, however, it is probably also important to say that there is not a lot that can go wrong and you\’re unlikely to suffer major losses if you check the resulting disk before deleting your existing setup.

First steps

What you\’ll need:

– A PC running Linux and preferably running a copy of Morphix.

– A CD writer

– Some disk space – a couple of gigabytes should do but if you can afford five or six gigabytes that would be more than adequate

– Reasonable memory – this tutorial assumes you have 250+ MBs of memory or though you could probably get away with less.

– An Internet connection

– And a copy of Morphix. If you don\’t have a copy visit and download a copy. Burn this to CD and boot from it to check that it is all okay.

Getting started

For those that don\’t have a copy of Morphix on CD, do the following:

– Download an ISO from the website.

– Burn this ISO image to a CD using cdrecord using a command like this:

cdrecord -v -pad speed=1 dev=0,0,0 src.iso

where src.iso is the copy of morphix you downloaded.

– Reboot your machine from the CD drive to see that all is working correctly.

Next …

Essentially what we are going to do is replace the main module which currently lives in the mainmod directory on your Morphix CD. This will allow us to include new applications, configure settings and customise the desktop on your new version of Morphix.

[If you\’re already running Morphix on your machine the following is likely to be unnecessay]

To start the process, install the cloop applications. Do this by issuing the following commands: dpkg -i cloop-module* and dpkg -i cloop-utils*. Most versions of Morphix will already have these installed.

The real work:

Next, create a directory for your new version of Morphix, insert your Morphix CD, mount the drive and extract the compressed filesystem:

cd /

mkdir Build_Dir

mkdir Build_Dir/morphix_hd

mount /dev/cdrom /cdrom

cd /cdrom/mainmod

extract_compressed_fs mainmod.mod > /Build_Dir/originalmodule.iso

Now mount the module (originalmodule.iso) and create a copy on your hard disk:

cd /Build_Dir

mount -o loop originalmodule.iso /Build_Dir/temp1

cp -Rp temp1* /Build_Dir/temp2 #

cd temp2

mv temp1 morphix_hd

mv morphix_hd /Build_Dir

cd /Build_Dir

umount temp1

Change root to morphix_hd directory and start editing your own version of Morphix:

cd /

mount –bind /dev /Build_Dir/morphix_hd/dev

chroot /Build_Dir/morphix_hd

mount -t proc /proc proc

Now you can work with the hard drive-based version of your new distribution as if it was your installed sytem.

Things you might want to do include

– updating the list of your sources by editing the /etc/apt/sources.list file

– Installing new applications using apt-get install APPLICATION_NAME

– Configuring the default desktop environment by editing the files in /etc/skel/

Once you\’re finished updating your new version of Morphix, you can clean out the unnecessary files:

To do this run deborphan which will list the oprphaned packages, but be a little cautious when deleting files because in my experience this can occassionally break something.

Unmount your new Morphix system:

umount /proc Exit chroot (hit CTRL + D)

umount -f /Build_Dir/morphix_hd/dev

Compress the morphix_hd directory.

cd /Build_Dir

mkisofs -R -U -V \”Morphix fs\” -P \”Morphix\” -cache-inodes -nobak -pad /Build_Dir/morphix_hd > ./mymod.iso

Convert mymod.iso into a module. (This step can take a long time depending on your system resources and the size of your new module.

create_compressed_fs ./mymod.iso 65536 > mymod.mod

Add a morph_cd directory in your build folder. This folder represents your new CD.

mkdir morph_cd

cd /Build_Dir/morph_cd

mkdir mainmod

cd /Build_Dir

mv Build_Dir.mod /Build_Dir/morph_cd/mainmod

cd /cdrom

cp -a base* /Build_Dir/morph_cd

cp -a minimod* /Build_Dir/morph_cd

cp boot.catalog /Build_Dir/morph_cd

cd /Build_Dir/morph_cd

mv boot.catalog boot.img

Make your new iso to burn.

cd /Build_Dir

mkisofs -pad -l -r -J -v -V \”Morphix\” -b base/boot.img -c base/ -hide-rr-moved -o your.iso morph_cd

Now burn your new Morphix iso to CD:

cdrecord -v -pad speed=1 dev=0,0,0 your.iso

Reboot and see that everything is working as expected.

This article is built partly from experience and partly from a range of pieces written by other people, too numerous to mention. The errors are mine, however, so please email me at [alastair at tectonic] with any problems, omissions etc.


Comments are closed