July 20, 2005

Run GNU/Linux from a USB pen drive

Author: Juan Marcelo Rodríguez

You can carry GNU/Linux in your pocket with a functional, quick, and useful USB pen drive distribution. Pen drives are faster than CDs, and the small distros that fit on them don't require huge amounts of memory for the operating system and applications.

Slax is a powerful and complete bootable distro based on Slackware, equipped with kernel 2.6, ALSA sound drivers, Wi-Fi card support, X11-6.8.2 with support for many GFX cards and wheel mice, and KDE 3.4. Slax uses the Unification File System (also known as unionfs), which enables you to write whatever you want into the pen drive. Bundled software includes KDE, the KOffice office suite, GAIM for chat, the Thunderbird email client, and the Firefox Web browser.

Slax comes in a variety of versions. You can get a minimal version of Slax called Frodo, without big applications, that fits in 41MB, or choose among the 200MB standard editions such as Killbill (which I use) or PopCorn.

Configuration files

Slax allows you to modify your environment and save the changes to a single file with the configurations. The list of directories saved and restored include /etc, /root, /home, and /var. After saving your session, you can later run it and use the same
environment configuration as before, without having to reconfigure every detail.

Slax even lets you upload configuration files to the Web. With this option, the next time you boot Slax from wherever you are, you can get the file from the Web. To use this feature, boot Slax with the parameters boot: slax webconfig=YourPassPhrase where YourPassPhrase is the secret passphrase you will use to protect your data. There are some limitations with this system. You can save only 8MB in each session, and the list of saved directories does not include every directory of the operating system.

Ready to give Slax a try? Download an ISO image file and Syslinux, which you need to make the USB stick bootable.

Before you install Slax to your pen drive, I suggest you partition your pen drive in two -- one portion for the operating system and the other for data. You can set the partitions as you wish, using cfdisk or another partitioning utility. You need to set up a partition for the operating system in the pen drive, with FAT16 as the filesystem. Plug the pen drive in the machine but don't mount it. If you don't know where your pen drive is, type dmesg and check its output for the mentioned USB device. Then run cfdisk /dev/sda where /dev/sda is the pen drive. Create a new partition, give it FAT16 format, and write the changes. Unplug the pen drive, plug it in again, and try cfdisk /dev/sda again to check that the partition exists and has the correct settings.

Installing Slax in the pen drive

Now you choose between two options. You can mount the downloaded ISO image of Slax and follow a few steps, or you can burn the ISO image file to a CD-ROM and use the Slax Installer application. I suggest the first approach, because are some little things you must do to get Slax in the pen drive ready. To do so, create a directory -- say /slaxUSB -- on which to mount the ISO image file of Slax, then mount the ISO image:

mount -o loop slax-killbill-5.0.5.iso /slaxUSB/

Now, as root, mount the formated USB device:

mount -t vfat /dev/sda /mnt/sda/

Note that /mnt/sda/ can be any directory you want to use. Copy the entire contents of the directory mounted with the ISO image to the place where you have mounted the pen drive:

cp -ra /slaxUSB/* /mnt/sda/

The -r argument specifies a recursive copy including every directory, and the -a preserves as much as possible the structure of the data in the USB.

Now you need to copy some files in the folder /boot/ of the mounted pen drive to the root of the pen drive so you can boot from it:

cd /mnt/sda/boot/
cp vmlinuz /mnt/sda/
cp initrd.gz /mnt/sda/

Move to the directory where the memory stick is mounted -- in this case /mnt/sda/ -- and change the name of the file isolinux.cfg to syslinux.cfg. Edit the just-renamed syslinux.cfg and delete /boot/ or boot/ from the lines that contain vmlinuz and initrd.gz -- for example, /boot/vmlinuz and /boot/initrd.gz. This changes the location of the files vmlinuz and initrd.gz, making them visible to the bootloader at the time of boot.

Finally, use whereis to check whether you have Syslinux installed. If not, download and extract it to a directory, then run:

syslinux -s /dev/sda

Where /dev/sda is the location of your recent modified Slax with all the files.

Now, reboot your computer, enter the BIOS, and change the boot order. Set USB-ZIP as the first one, then the hard drive, and so on. If your machine is old it's possible that it won't let you boot from USB, in which case you can use a boot diskette or CD, or use Slax as a live CD.

Other USB distros

In addition to Slax, you might care to try Damn Small Linux, Puppy Linux, or Feather Linux, all distros that take up less than 60MB of disk space.

Personally, I'm happy having Slax on my pen drive. It's both functional and fun.


  • Linux
Click Here!