Knoppix 5.0.1 boots rather nicely from a USB key. It's getting easier to get it working, as the USB bugs from the previous versions have been fixed.

I have a 1GB USB key, so using the Knoppix CD was the best fit (the DVD is much too large).

Here's a rather long thread I started a while ago, about getting an older version of Knoppix up and running: http://www.knoppix.net/forum/viewtopic.php?t=23558

I've simplified that somewhat. Here's a mini-guide:

* Boot Knoppix 5.0.1 from CD and make sure it works.

Put in your USB key as soon as possible, when you see the title screen of Knoppix, so that it is sure to be found by Knoppix autodetection.

Do not use the "toram" cheatcode when booting Knoppix. The RAM copy of the CD omits the /boot directory, but we require this directory, so we can't use the RAM copy.

* Once Knoppix is up and running, open a root shell (from the penguin icon). Now, we need to find the drive letter of your USB key. It will be something like /dev/sda, /dev/sdb, /dev/sdc, and so on. Be very careful and make absolutely sure you have the drive letter correct, because you will be erasing the USB key, and you don't want to erase your hard drive by mistake!

Commands to try:

Code:
dmesg | grep -i scsi
Code:
cat /proc/partitions
Look at the sizes of the various drives you see here. Find your USB key, and do not get it confused with your hard drive! For the rest of this example, I'm going to be using /dev/sdz, a fictional drive letter that nobody has, just to prevent bad mistakes from typing in commands blindly.

* Erase the entire USB key.

Code:
dd if=/dev/zero of=/dev/sdz
Did you use the right drive letter? Did you? If not, you'll be crying, right about now....

This command will take a while to finish. By writing to every block on the USB key, we are also testing it for bad blocks.

You should get the "no space left on device" error message when it finishes erasing and reaches the end of the drive. Any other error messages might mean bad blocks: if you notice any, your key might be worn out and you'll need to buy another one (cheap keys are notorious for wearing out very quickly).

* Make a quick patch to the mkdiskimage script.

We need it to write partition type 0C (FAT32 LBA). Unfortunately, "out of the box" it only writes partition type 0B (FAT32 CHS). We want to make sure Windows always uses LBA and not CHS, for increased reliability, just in case we ever use the USB key with Windows. So, an easy one-line change.

Use your favorite editor and edit /usr/bin/mkdiskimage.

Code:
vi /usr/bin/mkdiskimage
Go to line 237.

Change 0x0b to 0x0c then save the file and exit.

* Run mkdiskimage, to automatically partition and format your USB key.

Code:
mkdiskimage -F -4 /dev/sdz 0 64 32
This lays down a new MBR and partition table on the drive, and partitions and formats the entire drive as one big FAT32 LBA partition. I prefer FAT32 because it is a more efficient use of space than FAT16, and have noticed no difference in the ability of various systems to boot FAT32 as opposed to FAT16.

The mkdiskimage script is USB-ZIP compliant, which may help it boot on more systems than USB-HDD. It's nice that Knoppix now includes this script by default. Here's the webpage for mkdiskimage: http://syslinux.zytor.com/usbkey.php

KDE may throw a stupid popup window in your face, once it recognizes your new partition. If this happens, close the window.

* Run the SYSLINUX installer on your new partition.

Code:
syslinux -s /dev/sdz4
This installs the SYSLINUX bootloader onto the newly-created partition, and includes a special file, ldlinux.sys. The -s option is for safety and additional compatibility. Notice the partition is the fourth partition on the drive, not the first. This is for USB-ZIP compliance.

* Mount your new partition.

Code:
mount /media/sdz4
Knoppix should have autodetected the new partition and set up a fstab entry for it. The /media/sdz4 directory should now correspond to the /dev/sdz4 partition.

Code:
cd /media/sdz4
ls
You should notice one, and only one, file in this directory now: ldlinux.sys

If you don't see this, then something probably went wrong earlier. Go back and try again before continuing.

* Copy the contents of the Knoppix CD's boot directory, onto your USB key.

You should already be in the /media/sdz4 directory, from the cd command above.

Code:
cp -av /cdrom/boot/isolinux/* .
mv isolinux.cfg syslinux.cfg
rm -f isolinux.bin
Don't forget the dot on the end. It tells the cp command to copy everything into your current directory, which is what we want. Notice that there is a space between the asterisk and the dot!

Ignore any errors about "failed to preserve ownership". This is normal, because we're using the FAT filesystem, which does not support file ownership. This is not a problem for us.

What we're doing here is copying the Knoppix CD's /boot directory first. This increases reliability, by getting it as close to the beginning of the drive as possible. This should help on systems with buggy CHS handling of USB keys, which may become an issue as new USB keys get larger.

We are renaming Knoppix's isolinux.cfg file to syslinux.cfg, and then removing the unnecessary isolinux.bin file. ISOLINUX (used to boot the CD) and SYSLINUX (what we just installed to your USB key) are really two different variations of the same bootloader program. They accept the same config file format, so we don't need to change anything at all, just rename.

BTW, since ISOLINUX has isolinux.bin as its main program file, can you guess what is the equivalent file for SYSLINUX? If you guessed ldlinux.sys, the file you saw earlier, good job!

* Finish copying the rest of the Knoppix CD.

Again, you should still be in the /media/sdz4 directory. Again, don't forget the dot on the end of this command.

Code:
cp -av /cdrom/* .
rm -rf ./boot
This should take a while. We are filling up the USB key with the contents of the Knoppix CD.

We already copied Knoppix's /boot directory earlier, in the previous step. We don't need two copies of it just wasting space, so we remove the extra copy.

* You are now ready to boot!

Cleanly unmount the USB key.

Code:
sync
cd /
umount /media/sdz4
Shut down Knoppix, and remove the CD when it tells you to.

* Reset your computer and fiddle with the BIOS until it sees the USB key.

After unmounting above, the USB key can be removed. Some BIOS's require a removal and re-insertion before they will recognize it.

Other things to try, if you're having trouble getting the BIOS to see your USB key and let you boot from it:

Try a different USB port. Some BIOS's only search a few ports, not all of them.

Hit a special key to bring up a boot menu. Some BIOS's can only boot from USB when manually selected.

Go into your BIOS's setup menu, and walk through the boot settings. Look under all menus, especially "hard drives" and "removable devices" and other things like that. Some BIOS's will not search for newly attached devices until you manually go through the menus again.

Turn your computer completely off and on again. Some BIOS's require you to physically turn the computer off and on again, before they will see newly attached drives.

If all else fails, try a different PC. It's still fairly rare these days to find a computer that has a good ability to boot from USB devices, and it's not something that motherboard makers advertise, so it takes a bit of luck to find a computer that can do this.

* Boot into Knoppix from your USB key.

If it works, that's great. Notice how much faster it is. There's zero seek time on a USB key, so even though it isn't very fast, it feels a lot faster than the CD! Programs are surprisingly quick to load.

Find the drive letter for your USB key again. It should not change, but it might have.

* Make a persistent home directory, if you want.

Knoppix assumes that the "CD-ROM" that it booted from is impossible to write to, but we have a USB key now, not a CD-ROM. So, we must fool Knoppix into letting you write to it.

Code:
mount -o remount,rw /cdrom
mount --bind /cdrom /media/sdz4
Now, we can run the Knoppix persistent home utility.

(It's under the penguin menu, Configure, Create Persistent.)

Choose your drive from the menu that appears, and follow the instructions.

The program should complete without errors. If the program suddenly disappears midway through, check the kernel logs with "dmesg" again. If you see pagefuls of SCSI errors and such, beware, you might have a worn-out USB key!

* Modify the Knoppix boot menu.

This is an optional step, for customization. We want Knoppix to autofind the persistent home directory, and fix a few other things.

You might have to repeat the above mounting steps, as the Knoppix persistent tool might randomly unmount the directory sometimes.

Code:
vi /media/sdz4/syslinux.cfg
On line 3, the default timeout is 300. Lower this, to around 50 or so (5 seconds, since this counter is in tenths of seconds).

It's nice to have it boot faster, without waiting for you to hit Enter, so you can put in the USB key and walk away, coming back in a few minutes to a fully booted system.

On line 2, add a few more options to the end of the line.

noswap noeject noprompt dma home=scan

Here's a little explanation of what each option does.
noswap = Security fix: assuming you're going to be using the USB key on a bunch of different computers you don't own, you don't want to be swapping your memory onto their hard drives.
noeject = You can't physically eject a USB key.
noprompt = Gets rid of the "remove CD and close drive door" prompt when shutting down, as this prompt is rather misleading when it's really a USB key instead.
dma = Gets you a significant speed increase when dealing with many IDE drives, a good thing to have.
home=scan = This will cause Knoppix to pick up your persistent home directory automatically the next time you boot up, asking you for the password as needed. You will get an extra menu during bootup, asking you if you want to mount your home directory or not.

Save the file and quit the editor.

Now, you should be all set. Reboot again, to make sure it all works.

Enjoy your Knoppix-on-a-keychain!

Josh