USB Pendrives and Distributions for Them

Juan Marcelo Rodriguez

Issue #146, June 2006

A look at three distributions you can use to boot Linux from a USB pendrive.

A pendrive is a USB storage device. You plug it in to a USB port, and if the pendrive is compatible with your operating system, it should look exactly like another disk on your system. These days, it is easy to find pendrives with 1GB of storage.

It so happens that there has been an explosion of bootable live CD versions of Linux. Both commercial and noncommercial Linux distributions are providing live CDs (including Linspire, SUSE, Ubuntu, Kubuntu, Knoppix and Mepis, to name only a few—there are many more).

Imagine a mixture of both concepts—a USB storage device and a live CD version of Linux. You can pack a lot of features of a GNU/Linux live CD into 1GB. The USB pendrive has the advantage of being writable, which the live CD lacks. So, you can boot Linux from a pendrive and store data on it too. The end result is that, as long as you can find a machine that will boot from a pendrive, you have a fully portable version of Linux that carries your applications, settings and data.

The Choices

I cover three LiveUSB distributions in this article: SLAX, Damn Small Linux (DSL) and Flash Linux. Each one has different window managers and different apps.

SLAX works with tmpfs and Unification fs (UFS), which gives it some nice advantages. SLAX is based on Slackware Linux with the 2.6 Linux kernel.

DSL is a little distribution of 50MB. DSL configures Fluxbox very nicely. Some of the apps included are Mozilla Firefox, the Slypheed mail client, xmms, text editors, graphics viewers and more. It includes a 2.4 Linux kernel with good hardware detection, but it doesn't have the big apps other distributions have, such as The GIMP. It is a compact distribution with a script to install it to LiveUSB.

Finally, Flash Linux is a solid distribution that uses the 2.6 kernel and the fast JFFS2 filesystem. It has good speed, both as a live CD and LiveUSB, and it includes large applications, such as The GIMP and OpenOffice.org. It uses grub, bootsplash, framebuffers and GNOME, and is based on Gentoo.

Boot from USB

The biggest challenge in using a USB pendrive for your Linux distribution is booting the pendrive. Old motherboards do not support the ability to boot from USB hardware, so you may need to use a floppy disk to boot your USB-based distribution. Newer motherboards let you boot drives usually referred to as USBHDD, USBZIP, USB-FDD and others, such as USB-CDROM.

The first step to using a pendrive is to delete the original pendrive partitions, if there are any. Then, add a FAT16 partition, and format it with mkdosfs. I used cfdisk to do the work, but you can use fdisk too.

Check your dmesg log when you plug in the device to see if it is working:

dmesg | tail

You should see a message similar to the following:

sda: assuming drive cache: write through
sda: sda1

Format the partition you created with the following line:

mkdosfs -F 16 /dev/sda1

(Change sda1 to whatever partition is appropriate for your system.)

Unplug the hardware, and plug it in again. You now are ready to install the distribution.

Damn Small Linux

Go to the DSL Web site (see the on-line Resources) and download the ISO image file for the current version of DSL, and burn the ISO to a CD or DVD. Boot from this CD or DVD. The boot starts with a welcome screen, like most live distributions.

DSL looks for hardware, and then it installs and configures it. Depending on your machine, it will bring up an X server running Fluxbox in less than two minutes.

After booting from the DSL live CD, right-click on the Fluxbox desktop to open the Fluxbox menu. Go to Apps→Tools→Install to install it to your USB pendrive. Here, you have two options for installing the distribution: install to USBHDD or USBZIP hardware. DSL will ask about the location of the pendrive, and it also asks if you want to install DSL from the live CD, from a file or from the Web.

I suggest you use your broadband connection to download the files. In fact, if you have a router that supports DHCP, DSL should recognize your Ethernet card and have no problems accessing the Internet at boot time. DSL supports PPPoE too, if your Internet connection requires it.

I missed the features of the 2.6 kernel (the next release of DSL should support 2.6), but it's still a good little distribution. I think DSL is fine as it is, but if you need a big office suite, you should use SLAX. Resources that you must read if you use DSL are the Wiki and the complete DSL forums. You will find many tips and tricks with plenty of information that will be helpful if you run into problems.

Floppy-Based Boot Process

If your machine doesn't allow you to boot from a USB pendrive, you can boot DSL from a floppy. Download the file bootfloppy-usb.img from the DSL site, and copy the image to a floppy disk with dd:

dd if=bootfloppy.img of=/dev/fd0

Modify your computer BIOS to boot from the floppy first, and then boot the floppy image file of DSL. This boot image will launch the USB version of DSL. This process works with just about any distribution that offers a floppy boot image for booting USB pendrives.

SLAX

The SLAX site says, “SLAX is a fast and beautiful Linux operating system, which fits on small (3.14") CD-ROM disc. It runs directly from the CD (or USB) without installing. The live CD described here is based on the Slackware Linux distribution and uses the Unification File System (also known as unionfs), allowing a read-only filesystem to behave as a writable one, saving all changes to memory.” Fortunately, when you use a pendrive, you don't have to worry about emulating write operations because, unlike a CD, the pendrive memory is writable.

You can use UFS to merge storage from several sources, including network storage, into one local directory. This makes UFS a good solution for diskless workstations, because it makes it easy to keep your home directory on a network storage device.

SLAX is a modular distribution, so you can add features as you need them. It lets you configure your installation for many different purposes. You might be able to watch a DVD, use QEMU, burn CDs and DVDs, run firewalls, antivirus apps and much, much more. Check the list available on the project's site (see Resources) to find out about modules that add new features to SLAX.

SLAX Installation

To install SLAX, get the latest version from the Web site (see Resources). SLAX has many versions of the same distributions, with certain differences in apps and size. Select among Frodo, Standard, Popcorn or KillBill editions. I used the slax-5.0.7b.iso standard edition of 200MB with KDE.

Mount the ISO image file of SLAX using the loopback device. In my case, I called the mount directory slax. Here is the command I used:

mount -o loop  slax-5.0.7b.iso  slax/

As before, format the USB pendrive to use FAT16:

mkdosfs -F 16 /dev/sda1

(Change sda1 to whatever partition is appropriate for your system.)

After you have a bootable and formated FAT16 partition in the pendrive, mount it:

mount -t vfat /dev/sda1 /mnt/usb/

Copy all the files from the directory slax/, where you mounted the ISO of SLAX, to the mounted pendrive:

cp -rav slax/* /mnt/usb/

Synchronize the data:

sync

And go to the pendrive location (/mnt/usb):

cd /mnt/usb/

Now, copy the files vmlinuz and initrd.gz to the root directory, where you mounted the pendrive, in our case from the directory /mnt/usb/, and do:

cp boot/vmlinuz .
cp boot/initrd.gz .

Then, edit the file called isolinux.cfg:

pico isolinux.cfg

Remove every string called boot/ before vmlinuz and initrd.gz. Then, rename it to syslinux.cfg to use syslinux with the device:

mv isolinux.cfg syslinux.cfg

Finally, install and update MBR with LILO or GRUB:

lilo -M /dev/sda

And, use syslinux to finish the process:

syslinux -s /dev/sda1

SLAX is installed—enjoy it. Umount the pendrive and reboot. Change your BIOS to boot from the USB pendrive, and reboot again. You may need to use LILO or GRUB to update or install the master boot record on the pendrive.

SLAX has KDE, Fluxbox, K3b, Media Player, a Web browser, mail, office suite, Kopete and many other applications. You can find a complete list on the SLAX Web site (see Resources).

SLAX doesn't have the speed of DSL, but has the 2.6.15 kernel, excellent network support, the parted application (partition editor) and more. It's by far a more complete distribution than DSL, but you pay for it in size.

Flash Linux

The Flash Linux distribution is based on Gentoo Linux. Get the Flash Linux ISO image file from the Web site (see Resources), and burn it to CD. Then, boot from the CD in order to install the LiveUSB version in the pendrive. Download the three parts of the ISO from sourceforge.net/project/showfiles.php?group_id=124770. Currently, the three parts are flashlinux-0.3.4-RC2.iso-part1, flashlinux-0.3.4-RC2.iso-part2 and flashlinux-0.3.4-RC2.iso-part3. After you download these files, put them together:

cat flashlinux-0.3.4-RC2.iso-part1 flashlinux-0.3.4-RC2.iso-part2 \
flashlinux-0.3.4-RC2.iso-part3 > flashlinux-0.3.4-RC2.iso.

Flash Linux has a beautiful Bootsplash and framebuffer theme. It also includes the accelerated NVIDIA driver, which is great if you have a GeForce video card.

Hardware detection also was fantastic. Flash configured all my devices without a hitch.

After you boot and log in, install Flash on the pendrive. You will need two partitions on the pendrive: a boot partition of +4MB and a second partition of at least 256MB.

The Flash Linux people suggest you set up the partitions with fdisk. Plug in your pendrive and run:

fdisk /dev/sda

(Again, change sda to the drive designation your computer uses for the pendrive, if it is different from sda.)

Delete every existing partition. Then, add the 4MB partition for the boot partition. Next, create a second partition that uses the rest of the free space on the pendrive. Write the changes and quit fdisk.

Now, download the installation script for USB devices. Download the flash_key.sh installer file from the Web site, and put it in the root folder of your Flash Linux Live CD.

If the script doesn't see your device, you may need to modify the script. Replace the line:

dev=`readlink /${i}|cut -d"/" -f11`

in PICKDEVICE with:

dev=`readlink /${i}|cut -d"/" -f12`

Add execution permissions to the script, and execute it:

chmod 755 flash_key.sh
./flash_key.sh

Now, follow the easy steps given by the wizard. First, select the correct device to install Flash Linux, then the 4MB boot partition. After that, select the root partition, and install Flash Linux in the pendrive. First, the script erases the pendrive, then mounts it, and finally it copies the apps and data to the pendrive. This last step took more than eight minutes on my machine. Be patient, and after that enjoy Flash Linux.

The highlights of Flash Linux are good speed, thanks in part to the fact that it uses JFFS2 and many applications. Details such as as animated cursors and cursor shadows as well as good window decorations, make your Flash Linux Desktop nice.

The only downside to Flash Linux is that it takes many steps to get the pendrive working. Also, I don't know why Flash Linux developers don't include an installer as part of the distribution instead of making you run a script.

Final Ideas and Impressions

For the desktop user, pendrives and LiveUSB are fantastic. If you have a pendrive, experiment with it—install DSL, SLAX, Flash Linux, Feather, Puppy or other distributions on the hardware.

Your mileage may vary, but I prefer SLAX. The modular nature of SLAX offers a wide range of options and features that a Linux professional should appreciate. SLAX has security modules, the ClamAV antivirus app, a Qt GUI, firewalls and so on. If you work often with security live CDs, pendrives and LiveUSB are also ideal, because with one device, you solve two problems. You can save data, and if you are developer, have security and development modules on the other side of your pendrive.

Resources for this article: /article/8949.

Juan Marcelo Rodriguez has been working with GNU/Linux for many years. He writes articles for magazines, works with a local LUG and also works with LugAR/USLA. He likes to play the keyboard, read, write and listen to music.