Fixnum.org

Install any Linux distro from USB

Written at 19/12/2007 at 23:56

It is a common misconception that installing Linux from a USB key is a difficult task. It's not. And I'm going to prove it to you in this short article.

This method is not just useful for machines without an optical drive, but it also helps you save on writeable CDs/DVDs, and it is are a lot faster during the install (copying files becomes over 10× faster on my system).

Get a Linux CD of your choice

Pick a distribution, any distribution. While I'm sure there are some that won't work, or require extra effort to work, most of them will just work. Just pick a distribution that will fit onto your USB key. I mostly use network install disks, because they fit on my USB key without eating up too much space, so I can still use it for something else.

I've tried Fedora Core 8, Arch Linux, Xubuntu, Ubuntu, CentOS and Debian so far. All of them worked fine.

Mount it

On Linux, simply run (as root):

mount -o loop /path/to/iso-file /mnt

Use a tool like Virtual Clone Drive if you're stuck on Windows.

Format your USB key

Format your USB key to VFAT if it isn't already formatted that way. If you don't know what this means, then you can safely skip this step. If your new to linux, Windows uses VFAT for all USB keys, so you're safe.

Note that if it's VFAT-formatted, you don't have to format it or remove the other files on your USB key. The installer can safely live next to your data.

On Linux format the disk like this (as root, again):

mkfs.vfat /dev/sdX1

where X is replaced by the letter of your USB key. If you're not smart enough to find out which letter that is, ask someone else. Use a forum, go on IRC.

Run syslinux

Now that your key has the right filesystem, we can install the boot loader on it. A boot loader is a piece of software that tells your computer how to start running an operating system. On USB keys, there really isn't much choice. If you want to boot Linux, syslinux is the only way to go. Do this as root:

syslinux /dev/sdX

where X is the same as before.

Note: you only have to do this once each time you format your key. You can just skip all of the above steps and delete the data from the install CD of a distribution and follow the steps below for another distribution if you want to switch to some other distro.

Copy over the files

Copy the files from the mounted CD image to the USB key. Don't worry about how you do this, VFAT isn't smart enough to handle permissions or anything anyway.

You may have to mount the USB key manually, depending on your system.

The magic trick

Now we need to make the changes to the contents of the live CD that were copied onto your USB key. I'm going to be assuming you're using an up to date version of syslinux, because the old ones have some issues I don't feel like discussing.

To make it bootable, just see if there is a isolinux dir in the root of the USB key. If there is, rename it to syslinux. Also rename isolinux.cfg and isolinux.bin inside the folder to syslinux.cfg and syslinux.bin, respectively.

If there is no isolinux directory, check if the two files above are in the root directory themselves. If they are, just rename them and leave them there.

If you can't find either the directory or the files in the root of the key, you'll have to look for them elsewhere. If you find them, just copy the directory they're in to the root of the USB key and rename the directory and files to syslinux, syslinux.cfg and syslinux.bin.

Installing

Now your USB key should be good to go. Configure your BIOS to boot from your USB disk first, and enjoy.

This page was last updated on 20/12/2007
© Wim Vander Schelden, 2006-2008