Linux CD Mastering - Environment Setup
Configuring the CD Mastering Environment
Now, we want to boot Knoppix to a non-graphical shell environment for mastering. The reason for this isthat X-Windows and KDE take all kinds of Memory and CPU cycles that we'll need during the mastering process. The smaller the load on the system, the better it will perform and the quicker the process will be. Once again, start your virtual machine by clicking the green arrow just below the VmWare menu. You will see the VmWare loading screen and Knoppix boot screens once more. When presented with the Knoppix boot screen, click inside the window and then press control-alt-enter to switch to full screen mode. To get a list of special boot codes, you may press the F2 and F3 keys. We will be booting into text mode by typing "knoppix 2 lang=us" and pressing ENTER (you may select another language if you like, available languages are listed at the top of the following screen).

Click for full size

While this is booting, we can give you the 60 second VmWare tutorial.
  • The main computer running VmWare is considered the "Host Operating System"
  • The virtual machine running inside of VmWare is considered the "Guest Operating System", Linux in this case.
  • Before you are able to type or work in a virtual machine, you must click inside the window. At that point the virtual machine has control of the input devices (keyboard and mouse). To release the mouse and keyboard, press control-alt. Sometimes it takes more than once, but not usually.
  • To make a virtual machine full screen, press control-alt-enter while the machine has control of the input.
  • To return a virtual machine to the windowed view, press control-alt
  • Do NOT press control-alt-delete while inside the virtual machine window, VmWare doesn't like it and it can result in a lockup of the host and guest machines.
After the boot has completed, you should be sitting at a shell prompt, logged in as root. Now we can open the hood and start messing around with the engine!

Next we will prepare the hard drive to receive the new CD mastering environment. Since we chose a SCSI disk during VmWare configuration, our disk device will be named /dev/sda, representing the first SCSI disk device. To setup the partitions on this disk, we'll use fdisk. The first partition that we will create will be the main linux partition (type 83). Start fdisk now by typing "fdisk /dev/sda" and key in the answers as provided in bold below.

root@tty1[root]# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1): press ENTER
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044): 600

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (601-1044, default 601): press ENTER
Using default value 601
Last cylinder or +size or +sizeM or +sizeK (601-1044, default 1044): press ENTER
Using default value 1044

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap)

Command (m for help): p

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         600     4819468+  83  Linux
/dev/sda2             601        1044     3566430   82  Linux swap

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
SCSI device sda: 16777216 512 byte hdwr sectors (8590 MB)
SCSI device sda: 16777216 512 byte hdwr sectors (8590 MB)
Syncing disks.
root@tty1[root]#
Okay, now the virtual Linux machine "has" a disk drive that can be configured. The first thing that we'll do is setup and enable a swap partition. The swap partition is very important, if it is not setup or has insufficient disk space, the CD mastering process will fail with the extremely helpful error message "error w__alloc_pages: 0-order allocation failed ...blah...blah...blah". If you see this message, you'll need a bigger swap partition. If you followed these instructions, you should have sufficient space. To enable the swap partition, type the following commands:
root@tty1[root]# mkswap /dev/sda2
Setting up swapspace version 1, size = 3652018 kB
root@tty1[root]# swapon /dev/sda2
root@tty1[root]# swapon -s
Filename                        Type            Size    Used    Priority
/dev/sda2                       partition       3566420 0       -1

Now that we have swapping enabled, we'll turn our attention to creating a Linux filesystem and configuring the CD Mastering environment. We use the mke2fs command to create the filesystem as follows:
root@tty1[root]# mke2fs /dev/sda1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
602656 inodes, 1204867 blocks
60243 blocks (5.00%) reserved for the super user
First data block=0
37 block groups
32768 blocks per group, 32768 fragments per group
16288 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Okay, our disk has been created and "formatted". We make it available to Linux by creating a mount point and mounting the new disk. The commands to do this are:
root@tty1[root]# mkdir -p /mnt/work
root@tty1[root]# mount -o rw /dev/sda1 /mnt/work
root@tty1[root]# mount
/dev/root on / type ext2 (rw)
/dev/scd0 on /cdrom type iso9660 (ro)
/dev/cloop on /KNOPPIX type iso9660 (ro)
/ramdisk on /ramdisk type tmpfs (rw,size=404516k)
/proc/bus/usb on /proc/bus/usb type usbdevfs (rw,devmode=0666)
automount(pid314) on /mnt/auto type autofs (rw,fd=4,pgrp=314,minproto=2,maxproto=4)
/dev/sda1 on /mnt/work type ext2 (rw)
The last line shows the new filesystem that we just mounted

This is probably a good time to figure out "how" we will get the new ISO copied from this Linux "guest" environment up to our "host" environment where we can test it with VmWare. The reason that we need to be able to do this is that we're remastering the CD to an ISO image located within a guest running under VmWare. The easiest way to test this new ISO is by loading it with VmWare and in order to do this, it will need to be copied to your host OS, Windows XP in our example. You have a couple of options here, which we have placed in order from least to most complexity, depending upon your skill set.
  • Use SAMBA to mount the Windows Share directory that we created earlier in this tutorial
  • Transfer the ISO image via SCP or FTP
  • Use the VmWare shared folders feature
  • Transfer it to USB drive device with enough capacity
  • Burn it to a CD from Linux
For our purposes, we will take the SAMBA route. If you haven't setup the Windows share as instructed previously, now would be an excellent time to do that. In order to access your Windows shared directory from linux, you will need to know the Windows machine name. If you don't know the machine name, you can find it by right clicking on the "My Computer" icon and selecting "properties". When the window opens, select the "Computer Name" tab. Make note of the computer name (not computer description). Because Windows configurations vary, the steps required for you to determine this name may vary slightly.

Once you have determined the computer name and you have shared a folder, switch back to you Linux guest. In order to use a shared folder, it needs to be "mounted" as a directory, so we need to decide where we want to put it. We'll create a directory for this purpose and place it underneath the "work" folder that we created earlier. This way, once the build is complete, it will actually already be available from Windows because the build will have placed it there. To mount the shared folder under Linux, type the following:
root@tty1[root]# mkdir /mnt/work/output
root@tty1[root]# smbmount //katr/mylinux /mnt/work/output -o password=
                   Note: replace the text in red above with YOUR machine name!
root@tty1[root]# mount
/dev/root on / type ext2 (rw)
/dev/scd0 on /cdrom type iso9660 (ro)
/dev/cloop on /KNOPPIX type iso9660 (ro)
/ramdisk on /ramdisk type tmpfs (rw,size=404516k)
/proc/bus/usb on /proc/bus/usb type usbdevfs (rw,devmode=0666)
automount(pid314) on /mnt/auto type autofs (rw,fd=4,pgrp=314,minproto=2,maxproto=4)
/dev/sda1 on /mnt/work type ext2 (rw)
//katr/mylinux on /mnt/work/output type smbfs (rw)
The last line in this list shows the folder that we just mounted

You may opt to use one of the other listed solutions, but we've found SAMBA to be the easiest and fastest method. One word of warning, if you choose to use the VmWare shared folders feature, we've found it to be slow and unreliable at times, but hey, it's your choice...go for it.

Now, let's see where we are at. We have booted the Knoppix image from within VmWare and have created and activated a new swap partition and Linux filesystem. Now we are ready to create the CD Mastering directory structures underneath the new filesystem. Let's get started. We'll start out by creating a couple of directories to hold our mastering environment.
root@tty1[work]# cd /mnt/work
root@tty1[work]# mkdir master
root@tty1[work]# mkdir master/KNOPPIX
root@tty1[work]# mkdir master/cdrom
root@tty1[work]# mkdir master/cdrom/KNOPPIX

Now, we copy the mounted CD with the following command:
root@tty1[work]# cp -Rp /KNOPPIX /mnt/work/master

Note: If a directory named /mnt/work/master/KNOPPIXdf was created in the process, 
remove it with the following command:
root@tty1[work]#rm -rf /mnt/work/master/KNOPPIXdf

Copy the CD-Rom base information and boot information 
root@tty1[work]# cd /cdrom
root@tty1[cdrom]# cp auto* cdrom.ico index.html /mnt/work/master/cdrom/
root@tty1[cdrom]# cp -Rp boot /mnt/work/master/cdrom/boot
root@tty1[cdrom]# cd KNOPPIX
root@tty1[KNOPPIX]# cp *.html *.jpg *.gif md5sums *.txt /mnt/work/master/cdrom/KNOPPIX/
root@tty1[KNOPPIX]# cp -Rp images /mnt/work/master/cdrom/KNOPPIX/

To make our lives just a little easier, we've created some rough shell scripts to do the mastering for us. The commands get a little bit long, and you get tired of typing them after 10 or 11 times. First, we'll create a file that keeps track of the number of builds that we have initiated. This is useful for keeping track of builds and milestones. Later on, we'll show you have to use this build number to "tag" a CD-ROM, so that you can identify it if it is mislabeled or confused with another build.
root@tty1[work]# cd /mnt/work/master
root@tty1[master]# echo 0 > lastbuild
The first script that we will create is the overall build script. When we want to kick off the CD remaster, this is the script that we will execute. You may download all 3 scripts here or copy them from the blocks below:

Place the following script in /mnt/work/master/mk.sh
#! /bin/sh

echo DISCLAIMER: Run this script at your own risk.  KATR Inc.
echo disclaims any and all liability for anything that happens
echo as a result of running this script.  Although the script
echo has been tested and used, there is always the possibility
echo of errors within the script.  Always make complete backups
echo of your system and files prior to running this script.
echo
echo Press ENTER to continue or Control-C to abort NOW
read a

# Keep track of which "build" this is
VERSION=`head -1 lastbuild`
echo "Last build was version $VERSION"
VERSION=`echo $VERSION + 1 | bc`
echo "This build is version $VERSION"
echo $VERSION > lastbuild

echo "Version 1.0 Build $VERSION" > /mnt/work/master/cdrom/cdversion.txt

# Create our output directory
if [ ! -e /mnt/work/output ]
then
        mkdir /mnt/work/output
fi

cd /mnt/work/master/

# Remove our flag files
rm -f /mnt/work/output/isobuild.start 2>&1 > /dev/null
rm -f /mnt/work/output/isobuild.intermediate 2>&1 > /dev/null
rm -f /mnt/work/output/isobuild.complete 2>&1 > /dev/null

touch /mnt/work/output/isobuild.start

# Remove any previous versions, you can change this to a save if you want
if [ -e /mnt/work/output/mylinux.iso ]
then
        pushd /mnt/work/output
        rm -f mylinux.iso
        popd
fi

echo "Building BIG iso"
/mnt/work/master/mk1.sh

echo "Building final ISO"
touch /mnt/work/output/isobuild.intermediate
/mnt/work/master/mk2.sh

echo "Build complete, don't forget to move the ISO somewhere \
permanent before shutting this machine down!"

touch /mnt/work/output/isobuild.complete

Place the following script in /mnt/work/master/mk1.sh
#! /bin/sh

echo DISCLAIMER: Run this script at your own risk.  KATR Inc.
echo disclaims any and all liability for anything that happens
echo as a result of running this script.  Although the script
echo has been tested and used, there is always the possibility
echo of errors within the script.  Always make complete backups
echo of your system and files prior to running this script.
echo
echo Press ENTER to continue or Control-C to abort NOW
read a

cd /mnt/work/master/cdrom
mkisofs -R -U -hide-rr-moved -cache-inodes -no-bak -pad /mnt/work/master/KNOPPIX 2> \
../mk1.log| create_compressed_fs - 65536 > /mnt/work/master/cdrom/KNOPPIX/KNOPPIX

Place the following script in /mnt/work/master/mk2.sh
#! /bin/sh

echo DISCLAIMER: Run this script at your own risk.  KATR Inc.
echo disclaims any and all liability for anything that happens
echo as a result of running this script.  Although the script
echo has been tested and used, there is always the possibility
echo of errors within the script.  Always make complete backups
echo of your system and files prior to running this script.
echo
echo Press ENTER to continue or Control-C to abort NOW
read a

cd /mnt/work/master
VERSION=`head -1 lastbuild`
echo "Generating output ISO as mylinux${VERSION}.iso"

cd /mnt/work/master/cdrom
mkisofs -p "Build $VERSION Prepared by Bill Johnson. www.katr.com" \
-P "Build $VERSION Prepared by Bill Johnson, www.katr.com" -V "mylinux 1.0-$VERSION" \
-r -J -o /mnt/work/output/mylinux${VERSION}.iso -b boot/isolinux/isolinux.bin \
-c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .

If you downloaded the scripts unpack them with the following command:
root@tty1[work]# cd /mnt/work/master
root@tty1[work]# tar xzvf cdmastering-scripts.tgz
Make the scripts executable with the following command:
root@tty1[work]# cd /mnt/work/master
root@tty1[work]# chmod 755 mk*.sh
Congratulations !! If you followed all of these steps carefully, you can build a test CD image at this point by running the script mk.sh (depending upon your machine, it can take anywhere from 15 minutes to an 1 hour. It takes 30 minutes on our build machine. Let's do a test build to make sure everything is working. To kick of the build, simply issue the following command:
root@tty1[master]# /mnt/work/master/mk.sh
Last build was version 0
This build is version 1
Building BIG iso

... a whole bunch of output listing Block #'s and compression ratios ...

[ 9] Block# 30138 size  59392 ->     84 [compression ratio   0%, overall:  37%]

Statistics:
gzip(0):     0 (    0%)
gzip(1):     0 (    0%)
gzip(2):     0 (    0%)
gzip(3):     0 (    0%)
gzip(4):     0 (    0%)
gzip(5):     0 (    0%)
gzip(6):     0 (    0%)
gzip(7):     0 (    0%)
gzip(8):     0 (    0%)
gzip(9): 30139 (1e+02%)
7zip:     0 (    0%)

Block size 65536, number of blocks 30139.
Done.
Building final ISO
Generating output ISO as mylinux1.iso
Using KNOPP000.TXT;1 for  ./KNOPPIX/knoppix-cheatcodes.txt (KNOPPIX-FAQ.txt)
Using KNOPP001.TXT;1 for  ./KNOPPIX/KNOPPIX-FAQ.txt (KNOPPIX-FAQ-NL.txt)
Using KNOPP002.TXT;1 for  ./KNOPPIX/KNOPPIX-FAQ-NL.txt (KNOPPIX-FAQ-IT.txt)
Using KNOPP003.TXT;1 for  ./KNOPPIX/KNOPPIX-FAQ-IT.txt (KNOPPIX-FAQ-FR.txt)
Using KNOPP004.TXT;1 for  ./KNOPPIX/KNOPPIX-FAQ-FR.txt (KNOPPIX-FAQ-ES.txt)
Using KNOPP005.TXT;1 for  ./KNOPPIX/KNOPPIX-FAQ-ES.txt (KNOPPIX-FAQ-EN.txt)

Size of boot image is 4 sectors -> No emulation
  1.38% done, estimate finish Sun Jan 16 09:02:45 2005

... A Whole bunch more percentages and estimates ...

 98.93% done, estimate finish Sun Jan 16 09:03:29 2005
Total translation table size: 2048
Total rockridge attributes bytes: 5225
Total directory bytes: 10240
Path table size(bytes): 68
Max brk space used 0
363909 extents written (710 MB)
Build complete, don't forget to move the ISO somewhere permanent before shutting 
this machine down!

Whew!! The build is complete. The output of this last step is a bootable CD-ROM ISO image, located in /mnt/work/output/mylinux1.iso (where '1' is the build number, if you ran mk.sh more than once, this number will be different). The size should be approximately 710 megabytes, keep in mind that if the size exceeds the capacity of your CD-R media, you'll need to remove something in order for it to fit onto a CD. To view the results of your build, type the following:
root@tty1[master]# ls -l /mnt/work/output
total 727818
-rwxr-xr-x    1 root     root            0 Jan 23 12:42 isobuild.complete
-rwxr-xr-x    1 root     root            0 Jan 23 12:42 isobuild.intermediate
-rwxr-xr-x    1 root     root            0 Jan 23 12:42 isobuild.start
-rwxr-xr-x    1 root     root     745285632 Jan 23 12:42 mylinux1.iso

If you switch back to Windows and view the contents of your shared directory, you should see the exact same files! Ain't SAMBA cool !!
 << Environment Setup   Testing your ISO >> 

1 2 3 4 5 6 7 8

(switch to medium sized images)