Hack 94 Create a Customized Knoppix

 < Day Day Up > 

figs/expert.gif figs/hack94.gif

One reason there are so many different Knoppix-based distributions is that they are so easy to create. With these steps, you will be creating your own custom Knoppix CD in no time .

The amount of software that Knoppix is able to fit on a CD is really amazing, but at some point, you might find that one of your favorite programs is missing. You can create your own custom Knoppix CD that includes the programs you want through a process known as remastering. The remastering process looks complex but is pretty simple once you get the hang of it. The basic process is to copy the current Knoppix system to disk, chroot into it, change the system to the way you would like it, and then create a new CD image based on the new system.

First, boot from your Knoppix CD. If you plan on installing any new packages on your custom disc, make sure that your Internet connection is up and working. Most of the commands you use to remaster the CD require root privileges; so instead of typing sudo in front of everything, click K Menu Knoppix Root Shell to launch a terminal with root privileges.

9.2.1 Choose a Partition

Remastering Knoppix requires the use of your hard drive. You do not have to use a completely blank, unformatted partition, but the partition does need to meet a few requirements:

  • The partition must be formatted with a Linux filesystem.

  • If you plan on using the bootfrom cheat code to boot the .iso , make sure that your filesystem is compatible with bootfrom . (Currently, ext2, FAT, FAT32, and NTFS are compatible; XFS and JFS are not.)

  • The partition must have at least 3 GB of free space. If you have less than 1 GB of RAM and need to create a swap file on the partition (more on that below), you need an extra gigabyte of free space. On average, I need at least 4.5 GB of free space for my remastering.

If you need to move some partitions to clear up space, click K Menu System QTParted [Hack #56] . Once you have a partition that meets these requirements, go to your root shell and mount it with read/write permissions:

 root@ttyp1[knoppix]#  mount -o rw /dev/   hda1   /mnt/   hda1  

Replace hda1 with the partition and mount point you are using.

9.2.2 Check Available RAM

Remastering a Knoppix CD requires about one gigabyte of total RAM (physical memory plus swap). You can check the amount of total RAM on your system by adding up the total column for both Mem and Swap rows:

 root@ttyp1[knoppix]#  free  total       used       free     shared    buffers     cached Mem:        515264     218832     296432          0       5932     115728 -/+ buffers/cache:      97172     418092 Swap:            0          0          0 

In my case, I have 515,264 KB (about 503 MB) of physical memory and no swap. I need at least one gigabyte of memory, so I will create a 750-MB swap file. From within the mounted partition, I run the following commands:

 root@ttyp1[hda1]#  dd if=/dev/zero of=swapfile bs=1M count=750  750+0 records in 750+0 records out 786432000 bytes transferred in 27.858599 seconds (28229417 bytes/sec) root@ttyp1[hda1]#  mkswap swapfile  Setting up swapspace version 1, size = 786427 kB root@ttyp1[hda1]#  swapon swapfile  root@ttyp1[hda1]# 

The dd command creates a 750-MB file full of zeros. The mkswap command formats that file with the swap filesystem. Finally, the swapon command starts using the file for swap.

9.2.3 Prepare the Source Filesystem

To remaster the Knoppix CD, you must copy the complete filesystem to the disk so that you can edit it. To keep things organized, create a source directory, and under that, create a KNOPPIX directory. Then copy all of the files on the Knoppix filesystem to the KNOPPIX directory. Make sure you are in the root of your mounted partition, and then run the following commands:

 root@ttyp1[hda1]#  mkdir source  root@ttyp1[hda1]#  mkdir source/KNOPPIX  root@ttyp1[hda1]#  cp -Rp /KNOPPIX/* source/KNOPPIX  

The cp command takes some time, as it's copying almost 2 GB of files from a compressed filesystem on your CD-ROM to the hard drive (on my system, it took about 10 minutes). Once the filesystem is copied over, the source/KNOPPIX directory looks like the root filesystem of a Debian Linux install:

 root@ttyp1[hda1]#  ls source/KNOPPIX  bin   cdrom  etc     home    lib  none  proc  sbin  tmp  var boot  dev    floppy  initrd  mnt  opt   root  sys   usr  vmlinuz Chroot

The next step is to use the chroot command to turn the source/KNOPPIX directory into the effective root filesystem. This allows you to run commands such as apt-get just as though source/KNOPPIX were the root directory. Although the network works from within the chroot environment, all configuration files that Knoppix creates dynamically when you boot are not copied over in their modified state. This means that to resolve domain names , you must copy your /etc/dhcpdc/resolv.conf file over to source/KNOPPIX :

 root@ttyp1[hda1]#  cp /etc/dhcpc/resolv.conf source/KNOPPIX/etc/dhcpc/resolv.conf  cp: overwrite `source/KNOPPIX/etc/dhcpc/resolv.conf'?  y  

To use other dynamic configuration files (for instance, /etc/samba/smb.conf for Samba), you must copy those over as well before you chroot .

Now chroot into the source/KNOPPIX directory and mount the proc filesystem (this provides access to the network and other special interfaces within the kernel):

 root@ttyp1[hda1]#  chroot source/KNOPPIX  root@ttyp1[/]#  mount -t proc /proc proc  root@ttyp1[/]# 

Now you are in a chrooted environment. Any command that you run runs as though source/KNOPPIX is the root directory.

If for some reason you forget to copy a file that you need and you have already chrooted , press Ctrl-D to exit out of chroot , copy the files you need, and then go back to the chroot environment. Or, open a second root terminal to gain the same results. Package management

When you are remastering, you will notice that Knoppix is already very cramped for space. If you want to add new packages, you need to remove some packages to free up space. More specific methods for keeping the size down are discussed in [Hack #95] , but in general, simply choose a package that you don't need, and run:

 root@ttyp1[/]#  apt-get purge remove   packagename  

This command removes the package along with any configuration files it might have created.

Once you have freed up some space for new packages, update the list of packages on the system with:

 root@ttyp1[/]#  apt-get update  

After you update the list of packages, you can add new packages to the distribution just like with any other Debian install with:

 root@ttyp1[/]#  apt-get install   packagename  

If you are unsure of the name for the package you want to install, use the apt-cache program to search for the package name by keywords:

 root@ttyp1[/]#  apt-cache search   keyword  

Once you are ready to create a CD based on your changes, clear out the cache of packages you have downloaded to conserve more space:

 root@ttyp1[/]#  apt-get clean  

Before you exit the chroot environment, remember to unmount the proc filesystem with:

 root@ttyp1[/]#  umount /proc  

Then press Ctrl-D to exit chroot .

9.2.4 Make the Master CD Filesystem

Once you set up the KNOPPIX root filesystem, create the actual filesystem that appears on the CD. Put this filesystem in a new directory called master , under your mounted partition. Use rsync to copy all of the files that appear on the Knoppix CD-ROM (the files in /cdrom ) except for the 700-MB KNOPPIX/KNOPPIX compressed filesystem. The compressed file isn't necessary, because you create a new version of that file based on your customized filesystem in source/KNOPPIX . From the mounted partition, run:

 root@ttyp1[hda1]#  mkdir master  root@ttyp1[hda1]#  rsync -a exclude "/KNOPPIX/KNOPPIX" /cdrom/ master/  

Now create the KNOPPIX/KNOPPIX file. This file is actually a highly compressed filesystem that is created from the source/KNOPPIX directory. This (long) command generates an ISO-9660 filesystem like those on CD-ROMs:

 root@ttyp1[hda1]#  mkisofs -R -U -V  "  Knoppix Hacks filesystem  "  -P  "  Knoppix Hacks  "  -hide-rr-moved -cache-inodes -no-bak -pad source/KNOPPIX   nice -5 /usr/bin/create_compressed_fs - 65536 > master/KNOPPIX/KNOPPIX  

By far, this is the most time-consuming command, because it is not only creating a filesystem, but it is also sending the filesystem through a script that heavily compresses it. On my 1.2-GHz system, it takes approximately 30 minutes to complete. You can ignore the warning it outputs about creating a filesystem that does not conform to ISO-9660.

There are a lot of options used to create the filesystem, and if you are interested in the ISO-9660 spec, then you can reference each of those arguments and which filesystem options they enable by reading the mkisofs manpage (type man mkisofs ). If you want to customize the filesystem, the main two options that might interest you are -V , which specifies the volume ID to use for the filesystem, and -P , which labels the publisher of the CD-ROM.

Once the script completes, and the master/KNOPPIX/KNOPPIX file is created, go through the other files in the master/KNOPPIX directory, and customize them to your liking. One file of interest is master/KNOPPIX/background.jpg , which is the default background Knoppix uses for your desktop. If you want to change that default, simply copy a new .jpg file in its place, such as one from /usr/share/wallpapers .

After all of the files in the master directory are customized, there is just one step before you create the actual CD image that you burn to a CD. Knoppix uses md5sums to check file integrity; you have changed at least one of the major files, master/KNOPPIX/KNOPPIX , so you need to regenerate its list of checksums:

 root@ttyp1[hda1]#  cd master  root@ttyp1[master]#  rm -f KNOPPIX/md5sums  root@ttyp1[master]#  find -type f -not -name md5sums -not -name boot.cat  -  exec md5sum {} \; >> KNOPPIX/md5sums  root@ttyp1[master]#  cd .  . root@ttyp1[hda1]# 

Now the CD image is ready to be generated. This requires one final (but relatively quick) mkisofs command:

 root@ttyp1[hda1]#  mkisofs -pad -l -r -J -v -V  "  KNOPPIX  "  -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/  

Once this command is completed, you should see a new knoppix.iso file in the root of your partition. You can burn this image to a CD just like any other Knoppix ISO; however make sure that the CD image you have created is small enough to fit on the CD. Even if it doesn't fit, you can still test the image using the bootfrom cheat code. To test the image, reboot the computer and add:

  knoppix bootfrom=/dev/hda1/knoppix.iso  

at the boot prompt. Replace hda1 with your partition. In fact, I would recommend testing your CD images this way just to make sure everything is how you want it before using up CDs.

 < Day Day Up > 

Knoppix Hacks. 100 Tips and Tricks
Knoppix Hacks. 100 Tips and Tricks
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net