InformIT

Remastering a Custom Knoppix Distribution, Part 1

Date: Oct 21, 2005

Return to the article

Ever wanted your own bootable CD? Something personalized for your users and complete with all of your own Linux-based software and configuration? You may have heard of Knoppix, a free Linux bootable CD, but in this article, Matt Lesko will show you how to modify Knoppix to include exactly the software you want and need. From rescue discs to demo software, a custom copy of Knoppix could be exactly what you are looking for.

For more information on Linux, visit our Linux Reference Guide or sign up for our Linux Newsletter

You've probably heard of Knoppix, a bootable CD-ROM that provides an entire working copy of Linux and assorted programs, and requires nothing more than a computer with a CD-ROM drive and sufficient RAM. You're also probably aware of the multitudes of specialized varieties of Knoppix, from those dedicated to GIS software to forensic analysis tools. This article isn't meant to be an exhaustive survey of uses for Knoppix or its derivatives—rather, it is meant to give you some useful instructions for how to create your own custom-fitted Knoppix distribution. I assume that you have prior experience with Knoppix, and Linux administration in general.

Methods and Reasons

There are many reasons to want to build your own distribution of Knoppix. By doing so, you could have privately-written software distributed in a complete environment, create a reduced toolset for your specific needs (saving valuable space), or explore and release a particular focus (adding to the growing list of pre-fabricated specialized options). An extensive list of options is available at http://www.frozentech.com/content/livecd.php.

Knoppix is a collaborative effort and many of these versions derive from Klaus Knopper's original. Yours should be no exception. Rather than starting from scratch, I suggest that you follow their lead and start with a distribution that already has most of the functionality you want. In some cases, this may mean the original Knoppix CD, which is available at http://www.knopper.net/knoppix/index-en.html. For demonstration purposes, this article will look at customization based off the original Knoppix, version 3.8

Copying the Knoppix filesystem

The total process of creating a new version of Knoppix (called remastering) broadly consists of copying a running Knoppix environment to a host computer, chrooting into it, making any desired changes, and then compressing the filesystem and turning it into a bootable ISO. Keep in mind that remastering the CD will take a lot of disk space. The uncompressed filesystem alone takes about 1.7GB, to which you will be adding a compressed filesystem (slightly less than a CD) and the final ISO. Make sure you have at least 3 gigabytes of space to work with

First, you'll need to boot the CD on the system that you're working on. I suggest booting into run-level 2, text mode, to minimize memory usage. At the splash screen for Knoppix, enter knoppix 2. Once it boots, mount a local hard drive to copy the data to:

root@tty1[/]# mount /dev/hda1 /mnt/hd

and then copy all the files from the Knoppix filesystem, preserving the permissions:

root@tty1[/]# cp -dpRv /KNOPPIX /mnt/hd/knoppix-cd/

After this process completes, reboot back into your host machine. You will also need a copy of the CD structure, as it normally appears for remastering later. Mount the CD, and then, copy the entire contents in the same directory structure to a new directory within the /knoppix-cd directory. I prefer to name it /knoppix-cd/KNOPPIX/KNOPPIX.build/. Omit the KNOPPIX/KNOPPIX file from the CD, which will be about 690MB, since this will be overwritten with your filesystem later.

Now you'll need to execute the chroot command into the directory that you copied the running version of Knoppix into:

root@tty1[/]# chroot /knoppix-cd/KNOPPIX

At this point, you will be inside the /knoppix-cd/KNOPPIX directory (or wherever you chose to copy the files) as if it were the root directory. If you get an error such as 'cannot run command: /bin/bash', you probably did not copy the filesystem correctly, or you are chrooting into an inappropriate directory. The directory must appear exactly as if it were the root directory of a Linux machine, with /bin, /usr/bin, available local to that directory. Look inside to be sure this is the case. Assuming all goes well:

root@not a tty[/]# mount -t proc /proc proc

This command will allow the chrooted environment to access the network card of the host system, among other things. At this point you are in a functioning Knoppix environment. Any changes you make will apply to your final bootable version—you can delete software, add software, or edit configuration files. Since the original version of Knoppix (and most derivatives) are based off of Debian, you can also use the entire apt subsystem to deal with software issues. There are many great guides for using the apt subsystem, so this article will over cover the basic applications to get you started.

Installing/Upgrading software

The apt subsystem is a packaging system designed for Debian that can speed up installing software. Most free software has a Debian package created, so you can save yourself from the "./configure && make && make install" routine. First you'll want to update the apt-database:

root@not a tty[/]# apt-get update

This will connect to the mirrors specified in /etc/apt/sources.list. Add mirrors closer and faster to you if possible, check the http://www.debian.org/mirror/list for more options. This requires a working internet connection on the host system, as well as an accurate /etc/resolv.conf in the chrooted environment (which is likely not configured). Remember that if you change /etc/resolv.conf in the host environment that's the nameserver that will be used on the bootable CD! Remove internal or private nameservers after configuring the system but before releasing it to the public.

Now that the database is updated, install software is as easy as a single command line:

root@not a tty[/]# apt-get install fluxbox

This command line will attempt to install the Fluxbox4 window manager on your system. If the package does not require any additional packages to be installed, it begins on its own. If additional libraries are necessary, you will be asked to confirm their installation. It will even tell you the approximate amount of space required—good to know when you need to keep the Knoppix system as small as possible. Finally, if the package already exists, you will be informed and then given the option of upgrading (if a new package is available). Finding packages to install can be accomplished by:

root@not a tty[/]# apt-cache search fluxbox

which will provide a list of packages with 'fluxbox' in either their name or description. Use the "apt-get install" command once you find the correct full package name. A more exhaustive search and listing can be found at http://www.debian.org/distrib/packages. Knoppix 3.8 is based off Debian 3.1, also known as 'sarge' or 'stable." If you are using another Knoppix distribution, check /etc/debian_version. Finally, you can also upgrade all the currently-installed packages to their most recent version. Be aware that this will take up a lot of precious space though, as the apt subsystem will often upgrade unnecessary software. Be sure to upgrade before you trim the unneeded pieces below, or upgrade case for each package. Individual packages can be upgraded by running "apt-get install packagename."

Removing packages

You will likely spend more effort removing files than installing new ones. Not only does the compressed filesystem need to fit on a 700MB CD, but every bit must later be uncompressed and either kept in RAM or read from the CD. Running from the CD can be slow since the drive needs to spin up and spin down each time, even just to access simple commands. Modern Knoppix versions have a 'toram' option on their bootscreen that can copy the entire CD to RAM—freeing the CD-ROM drive and greatly improving performance. This, of course, requires a system with enough RAM to hold the filesystem—about 1.7GB for the default distribution—so smaller is better. The basic removal command is:

root@not a tty[/]# apt-get --purge remove packagename

The --purge option will remove the configuration files in /etc and elsewhere that are associated with the package, and is recommended. Otherwise sparse configuration files will be left on the filesystem, not necessarily taking up space, but certainly confusing users and possibly breaking re-installations down the road. Getting a list of all installed packages is done through dpkg-query (the dpkg series of commands all operate on the same subsystem as the apt series, as apt series is an abstraction on top of dpkg):

root@not a tty[/]# dpkg -l

or

root@not a tty[/]# dpkg-query -W

To get an idea of the size of each application, use:

root@not a tty[/]# dpkg-query -W --showformat="${InstalledSize} 
{$Package}" | sort -n

Working with the Knoppix 3.8 CD, we can see that removing OpenOffice alone will free about 245Mb of installed space. Removing KDE, along with all the internationalizations, will save another 250Mb of uncompressed space. Other packages can be removed at your discretion; using apt-get will ask for confirmation before removing anything unintentional and will take care of the dependencies. Removing packages ending in "-dev" is usually a safe bet, if you do not plan on compiling or developing software with your Knoppix disk. Remove unnecessary locales (language information) through the localepurge program. You may have to install this through apt-get. Afterwards, if you decide you need a different selection, edit /etc/locale.gen to reflect your needs and then run:

root@not a tty[/]# locale-gen
root@not a tty[/]# localepurge

When you have removed all unnecessary packages, use the deborphan command to locate libraries that are no longer required by any package:

root@not a tty[/]# deborphan | xargs apt-get --yes --purge remove

After configuration is complete, clean the system of loose ends that the apt subsystem may have downloaded:

root@not a tty[/]# apt-get clean

Now is the time to restore any configuration files you changed during this portion, such as /etc/resolv.conf or /etc/apt/sources.list. After the system is precisely as you want it to be for your users, you can begin creating the compressed filesystem.

Staying in the chroot jail, execute the following command (type carefully!):

root@not a tty[/]# mkisofs -R -U -v -V "Knoppix ISO9660 FS" -P "Name of Publisher" -p "Name of Creator" -hide-rr-moved -cache-inodes -no-bak -pad -m /KNOPPIX.build/* / | /usr/bin/create_compressed_fs - 65536 > 
/KNOPPIX.build/KNOPPIX/KNOPPIX

Note that the argument after -m is a directory/listing that will be ignored and not put into the filesystem. You can use multiple -m directives to prevent other pieces from going into the filesystem, but this one is required or else you will end up adding your build directory into your final filesystem. The argument after it and before the pipe command is the root directory /, from where the mkisofs program will add files. Lastly, the final argument is the output of the entire process, or the compressed filesystem itself. Go grab a cup of coffee, pick up a magazine, or go for a jog. Compressing the filesystem will take quite some time and be memory and processor-intensive on the host system.

Unmount proc and break out of the chrooted environment:

root@not a tty[/]# umount proc
root@not a tty[/]# exit (or CTRL-D)

Now, change to the directory where you copied the entire CD-ROM. It should now have the compressed filesystem as well. In our example, this would be /knoppix-cd/KNOPPIX/KNOPPIX.build/. There should be two directories, KNOPPIX and boot. Now you can create the final ISO file. One last mkisofs:

root@tty1[KNOPPIX.build]# mkisofs -pad -l -r -J -V "Knoppix disc" -no-emul-boot -boot-load-size 4 –
boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -hide-rr-moved -o knoppix.iso

Once this is complete, burn it with your favorite CD-ROM burning program and you're done. I suggest installing a copy of qemu, a free x86 emulator, similar to VMWare, so that you can test out the ISO before burning a CD. If it is installed it should look like this:

root@tty1[KNOPPIX.build]# qemu -cdrom knoppix.iso
Figure 1

Figure 1 Using Qemu to test an ISO before burning

And you should be able to boot into the CD. Check for any problems thoroughly here and if all is well, move on to creating the physical CD.

In my next article, I will cover the other changes that you can make to your Knoppix CD, including changing the splash screen, upgrading the kernel, and choosing default boot options.

For more information on Linux, visit our Linux Reference Guide or sign up for our Linux Newsletter

800 East 96th Street, Indianapolis, Indiana 46240