Bootable USB Key

From Knoppix Documentation Wiki
Revision as of 18:19, 19 October 2006 by Qwerty (Talk | contribs)

Jump to: navigation, search

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.

This is a "recipe" for creating a Knoppix bootable USB key. It was originally posted to the forums:


  • Knoppix 5.0.1 CD

It must be the CD. The DVD is much too large.

  • 1GB USB key

I recommend 1GB. Smaller sizes won't hold the entire CD. Larger sizes may have trouble booting on older BIOS's (see below about USB-ZIP).

Back up all data on your USB key first, because we will be erasing and reformatting it!


  • Boot Knoppix 5.0.1 from CD and make sure that it works.

As soon as the title screen of Knoppix appears (the cheatcode entry screen), put in the USB key.

Do this before Knoppix starts to load, so that your USB key is sure to be found by Knoppix's 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!

Examples of possible commands to try:

dmesg | grep -i scsi
dmesg | grep -i usb
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 your entire USB key.
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).

  • Run the mkdiskimage script, to automatically partition and format your USB key.
mkdiskimage -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 FAT16 partition. Even though I prefer FAT32, I'm recommending FAT16 here, for increased compatibility with some strange BIOS's.

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, for additional reference:

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.
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.
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.

cd /media/sdz4

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.

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.

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.

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:

  1. Try a different USB port. Some BIOS's only search a few ports, not all of them. Avoid using a USB hub, if possible.
  2. Hit a special key to bring up a boot menu. Some BIOS's can only boot from USB when manually selected.
  3. 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.
  4. 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 "hard drives".
  5. 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.

The USB key will be slow to load at first, especially during the cheatcode screen, because most BIOS's will default to running USB devices in a very slow mode. Once Knoppix detects and autoconfigures the USB port during booting, though, it will return to normal speed.

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 the USB key writeable.

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.

mount -o remount,rw /cdrom
mount --bind /cdrom /media/sdz4
  • Optional step: Modify the Knoppix boot menu

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

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.

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.
You can't physically eject a USB key.
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.
Gets you a significant speed increase when dealing with many IDE drives, a good thing to have.
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.

  • Optional step: Create a Knoppix persistent home directory

Now, we can run the Knoppix persistent utility, to create something that will save your settings across a reboot.

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

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

When making your encrypted persistent home directory, choose a size that is a good balance. I recommend not using the entire remaining space on the USB key. It's handy to have some extra free space, for quick file copying and such.

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!

You're done!

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

Enjoy your Knoppix-on-a-keychain!


--Krellan 00:43, 10 Sep 2006 (GMT)

mkdiskimage won't set up a 2 gb USB device with the USB-ZIP format using the example given. According to other FAQ's this is an issue with too many cylinders. A 1 gb drive is supposed to work fine. You may be able to manually create two drives on the device and manually format it in order to set it up as USB-ZIP.

Depending on the USB device, you can use fdisk to figure out the cylinders, heads and sectors and get mkdiskimage to work with these values. The one I used had 1015 cylinders, 64 heads and 62 sectors per track -- these values worked fine and I was able to create a bootable Knoppix USB key.