Remastering Knoppix
Written for CSLUG 20050216
Remastering Knoppix is ... I hesitate to say "easy," because it's a complex process, but if you have a good familiarity with Linux you won't find it too difficult. It's time consuming and it requires a big chunk of hard drive space, about 5 Gb. You'll need a good familiarity with Debian's administrative tools.
There are other directions on how to do this on the web. I'm not suggesting these are any better, but I've put these together for my own use because the other ones I've found had what I considered a lot of extraneous information. So ... This is one of those Linux things: you have more choices than you know what to do with, and you have to figure out which one is best for you. See the Bibliography for the sources I worked from.
One thing to understand is that the Knoppix CD stores most of what's important in a compressed filesystem, a single file. If you look at the files on the CD, you'll find the file /cdrom/KNOPPIX/KNOPPIX is several hundred megabytes: that's your filesystem. It gets uncompressed when the CD is in use. We need to unpack and copy this, modify it, and repack it. Each of these steps takes a while - give yourself several hours to make even basic package modifications. There are also important peripheral files that need to be copied - it's not just about the compressed file. The other files are needed to start a basic OS to be able to handle the compressed file system. So here's the process.
- Boot from the latest Knoppix CD, or your own remastered copy if you have one.
- I would recommend using one of the lightweight window managers available with Knoppix - you're not going to use the GUI much while you're remastering, and the memory you save will be well used for building compressed file systems and the like. knoppix desktop=fluxbox at the boot prompt will get you fluxbox rather than the default KDE.
- Open a root shell: all further commands will be within this shell. In fluxbox, this is under "Menu -> Knoppix -> Root Shell"
- Configure your internet connection if it didn't come up automatically: you'll need this for fetching packages.
- Mount the partition you'll work on (remember, it needs to have an minimum of 4 Gb free). mount -o rw /dev/hda6 /mnt/hda6 - it's important you do it this way (by hand rather than using fstab with mount /mnt/hda6 because fstab uses different options that will cause problems later). Obviously you'll use whatever partition works for you.
- Create a directory to work in: mkdir /mnt/hda6/knx
- If you have less than a Gig of RAM (real and virtual total - check by running "free"), you'll need to create a swapfile. On your Knoppix work partition do this: dd if=/dev/zero of=swapfile bs=1M count=750 ; mkswap swapfile ; swapon swapfile
-
Make two directories, one for your new master CD and one for the
source under a KNOPPIX directory:
- mkdir /mnt/hda6/knx/master
- mkdir /mnt/hda6/knx/source
- Copy the Knoppix files to your source directory: cp -Rp /KNOPPIX/* ${source}. This takes a long time (15 minutes, give or take an order of magnitude). The /KNOPPIX/ directory is a pointer to the contents of the compressed file system.
- It's time to start making modifications. To do this we chroot into the copied version: chroot ${source}
- If you get a bunch of "/dev/null permission denied" errors, get out of chroot (just type "exit" or hit Ctrl-D), unmount the partition, and remount it as described above: you're probably seeing this problem because you mounted the partition using fstab.
- To use the internet you may need to have proc mounted: mount -t proc /proc proc . Don't forget to umount this before you exit chroot!! If all you're doing is "apt-get ...", you probably don't need to do this. Most programs seem to be smart enough to give you a warning if they're failing because they need /proc/ .
- You may have to cp /etc/dhcpc/resolv.conf ${source}/etc/dhcpc/resolv.conf for internet names to resolve. This cannot be done from within the chroot.
- To get a list of installed packages, run dpkg-query -l . You'll need to remove some of these if you're going to add new ones. To get a list sorted by size, run dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -n . Another good source is what the O'Reilly article refers to as a kicklist, packages they don't consider necessary (it looks pretty good, but errs on the side of removing too much ...).
- Run apt-get remove <package-name> to remove packages you don't want. Be particularly careful about removing packages that take others with them (dependencies) as some cannot be re-installed because they're specialised Knoppix packages. I removed something that took sndconfig-knoppix(?) with it, whereupon I found I couldn't put it back and I had to restart the remaster. Not pretty.
- You can, and probably should, use the apt-get --purge remove <package-name>< command. This will remove the package and all config files associated with it. The configs will otherwise remain. Usually they don't take up a lot of space, but I find it annoying having unused configs hanging around /etc/ and other places.
- A fast way to remove a lot of stuff is to remove all the KDE packages for languages you don't use. These are labelled kde-i18n-*, and removing all the non-English packages will free about 200 Mb.
- Run apt-get install <package-name> to install new packages you want.
- Don't know what to install? Use apt-cache search <partial-package-name> to find out what's available.
- Don't run apt-get upgrade or worse yet apt-get dist-upgrade . If you're a Debian user, you may be tempted to do this. Don't. Knoppix has a lot of custom scripts, and this breaks lots of them (I tried it once). Your new disk may not boot, or may end up with some very odd quirks.
- Having said that, I often run apt-get upgrade and cancel out of it to see what packages are available and newer than the installed ones. If I see particular packages I think should be updated, I may do them singly. This particularly applies if you know of something that's had a security fix recently.
- Time to wrap up this section of the remaster. Run apt-get clean. This is important: apt-get caches all the packages it installs, and that can take up a lot of space. This command removes the cache.
- Cleaning up: run deborphan to see a list of packages that are installed but no longer needed by any other package. You can remove these. If you're feeling pretty terminal, you can run deborphan | xargs apt-get -y remove to remove them all quickly and without argument.
- Finally, exit your chrooted environment (don't forget to "umount proc" if you mounted it in the first place).
- The next major step is to build the ${master} directory into something we can burn to CD.
- Copy everything off the CD except the compressed Knoppix filesystem (we'll build that from ${source}): rsync -a --exclude "/KNOPPIX/KNOPPIX" /cdrom/ ${master}
- The default HTML page people see if they drop the CD in a Windows machine, or when KDE starts up, is now in ${master}/KNOPPIX/index.html . You can modify it if you want.
- The background used for most of the window managers, including KDE, is ${master}/KNOPPIX/background.png . This is easy to change, and has a big visual effect.
- Next up, making the compressed file system. This is an ugly command, copy it carefully: mkisofs -R -U -V "Volume ID seen by Win users" -P "Publisher ID, up to 128 chars" -hide-rr-moved -cache-inodes -no-bak -pad ${source} | nice -5 /usr/bin/create_compressed_fs - 65536 > ${master}/KNOPPIX/KNOPPIX . This command will take a lot of time - about 45 minutes, give or take an order of magnitude. You're creating an ISO file system (change the two labels in quotes!) and running it through a script that compresses it. Since it's about a 2 gig filesystem, this takes a while. It may complain that you're making a filesystem that isn't ISO-9660 compliant. Ignore it.
- While booting, Knoppix checks md5sums for files. We've changed a bunch of them, so we need to update the file Knoppix uses. cd ${master} ; rm -f KNOPPIX/md5sums ; find -type f -not -name md5sums -not -name boot.cat -exec md5sum {} \; >> KNOPPIX/md5sums
- Time to make a CD image. This is an ugly command, but runs a bit faster than the last one: mkisofs -pad -l -r -J -v -V "Volume ID seen by Win users" -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 ${master}
-
To test your new CD image without actually burning a CD, you can use
one of Knoppix's many boot features: type knoppix
bootfrom=/dev/hda6/knoppix.iso . Note that in this case I've moved
the image from its original location to the root of the partition: this
makes it much easier to remember what to type in. Because you don't
have to burn the CD, you can also boot from oversize images to
experiment with them before deciding how to reduce the size.
- One difficult "gotcha" that's caught me several times is that I'll use "bootfrom," find something wrong with the image I've created, and start remastering. Then I create a new image, and I want to put it on /dev/hda6/ . But I can't because the ISO image is mounted there. So I have to reboot from an actual CD and do the copy and then reboot again.
- Another catch to the use of "bootfrom" is that the kernel on the CD you're using must also exist on the image you're booting from because the kernel will be looking for modules and the like inside the image.
Bibliography
- http://www.knoppix.net/docs/index.php/KnoppixRemasteringHowto
- http://linux.oreillynet.com/lpt/a/4323
- Knoppix hacks: 100 industrial strength tips & tools by Kyle Rankin. O'Reilly, 2005.