Linux on a stick

Last month (PC Plus issue 234), you may remember us preparing you to boot to a DOS prompt directly from your USB key. This was a fine endeavour, but unless you’re clinging to the past, desperate for a portable Lotus box, or just curious about the things you can do with your kit, it’s tough to find a use for such a legacy OS. Linux, on the other hand, is a perfect target for tinkering. Rarely is something as highly configurable and as liberally dusted with free applications, with an experienced community willing to fill gaps by rolling its own applications.
A word of caution: there is partitioning ahead. This is dangerous stuff unless you’re happy with what you’re doing, so we suggest you don’t try this on that lovely new USB key – use an old one. You should be able to comfortably fit a Linux distribution within a 128MB key, though you’ll need some other storage device if you want to save anything. You could of course try separating several partitions within your flash drive, but we’ve found this to be more difficult and troublesome than it may appear, so we can’t recommend it.
The right environment
In general, a flash drive will arrive configured in a suitable format for hosting a Linux distribution, because thankfully many modern Linux flavours don’t insist on using the ext3 filesystem, or on using special partitions. The number of filesystems and minute variations out there is enormous, so it pays to make sure that you’re sporting the right one.
It’s at this point that we’ll need to first fire up Linux, so insert any flavour of Live CD you like. We’re using Linux rather than Windows here, as many of the functions previously available within the Windows family, particularly the more advanced functions that we’re in need of here, have been made desperately difficult to get to. In our case, we’re choosing well-equipped favourite Knoppix (www.knoppix.org) for this stage. Once the OS has fired up and is on screen, insert the USB key and a new icon appears on the desktop – a Windows style shortcut to your USB drive. Within Knoppix, which has updated its internal architecture to reflect the growing population of USB drives, this drive will likely have the designation of /dev/uba1. Other distributions, which previously will have referred to SCSI devices, will confusingly call it /dev/sda1.
First make sure this drive is unmounted. Right-clicking its icon within Knoppix should be enough. If there is a ‘mount’ option, it’s unmounted, otherwise click ‘unmount’ to disconnect it from your currently running system. Another method is to check the /mnt/ folder in the root; if it contains uba1 (or even sda1), open a command line and type ‘sudo umount /mnt/uba1’ to remove it.
Partitioning
The partition is the first thing to go. DOS veterans will remember fdisk: it’s a powerfully destructive drive manipulation tool. While it’s basically impossible to run fdisk through Windows XP, there are at least two versions included with Knoppix, the most useful being cfdisk since it provides much more visual feedback than its more plain predecessor. First, open a command prompt, then type ‘cfdisk’ followed by your drive’s designation (cfdisk/dev/uba for example), to view the current partition table on your drive. It’s likely that there’s just one partition, and that the FS Type is listed as something like FAT32.
Now delete this partition and replace it with something a little more useful. Use the arrow keys to move the cursor to ‘Delete’ and select it with [Return]. Cfdisk starts off as a non-destructive process, so don’t worry too much at the moment. Next we need to define a new partition for Linux to run from. The version of the standard FAT16 format defined with the release of Windows 95 is the format we’ve found most compatible. Select ‘New’ in the menu, choose ‘primary’ as the partition type, and make sure your new partition will fill the whole of the drive. Once you see it listed above, select ‘Type’ and you’ll receive a list of filesystem types and their corresponding hexadecimal couplets. You could go mad and make your USB key into a CP/M storage solution, but since most of us left CP/M well alone about 20 years ago, we suggest you just choose 06, the FAT16 option. Finally, choose ‘Bootable’ to ensure the drive can cope with playing host to an OS. Now, since you’ve backed up the contents of your flash drive you won’t be too worried about completely changing its structure and losing any data you had previously stored, right? Good, because that’s what’s about to happen. Choose ‘Write’ and type ‘yes’ to write your new partition table.
Installing
Installing the OS is an easy task if you’re lucky enough to have hardware that will happily work with it. First up, boot back into Windows, and finalise the preparation of the flash drive by formatting the partition. Make sure it’s in standard FAT format, not FAT32. We’ve chosen Feather Linux (a cut-down Knoppix distribution) as our USB OS due to its size and ease of installation. During our selection process we also looked at Puppy Linux, Flonix, and SPB-Linux – each of which directly support USB installation, each using different methodology. With a properly partitioned key and the relevant BIOS support, any of these distributions could suffice for you. With Feather, installation is just a case of extracting the USB version (included on the SuperDisc) directly to the primary partition of your flash drive, retaining the directory structure. If you’re lucky, and we doubt you’ll be, that will be it. Restart your machine with the USB key inserted, and if you see a boot prompt, hit [Return] to start Linux.
If it’s not working, consider a few options. First of all your BIOS may not be configured to boot from your USB key, so promote USB Zip, USB HDD, Removable Device or the model number of your USB key to be the primary booting device. Many BIOS versions that we encountered during testing required reconfiguring each time we wished to use the USB key, as they would automatically shuffle the primary hard disk to be the main booting device. The other problem may be that the drive’s master boot record is not preconfigured as bootable. If you’ve already tried something along these lines and been greeted by a ‘Boot failed’ or ‘NTLDR is missing’ message, you’ll likely have encountered this. The solution is to boot into Windows and use an application called syslinux (make sure it’s version 2.11, available at tinyurl.com/9qukt) to set the boot instructions. Open a command prompt window, navigate to the Win32 directory within the directory in which you unzipped syslinux, and type syslinux e: (or whatever letter your drive uses) to update the MBR of your USB key. This, as well as the configuration file left on the USB key during installation of Feather, will sort out the problem.
The first thing we did with our Linux installation was test the functionality of a chipset combination we were trying out. No Windows install, no incompatibility because of incorrect hardware, no digging a hard drive out and hooking it up – all it took was removing the flash drive from a pocket, popping it in the USB port, and we booted upon switching on.
Any operating system that accurately auto-detects and installs its drivers is a glorious thing, particularly if you’re used to Linux installations taking several days and being accompanied by much screaming and gnashing of teeth. If you had a network connection and a flash Linux install, you could add to the silence (and reduce the cost) of a media centre PC by removing the hard drive element altogether.
As you’ve seen previously in this tutorial, most Linux distributions contain a number of highly powerful applications. Providing the conditions are right to boot from USB drive, you can use your flash-based distribution to gain access to machines otherwise crippled by viruses, bugs and spyware. From there, you could use tools like fdisk to obliterate partitions, mkdosfs to format partitions, and clear up broken old machines without running the risk of infection.
The real benefit, we feel, is in learning Linux. It’s a scary operating system at the best of times, so what better way to get to grips with its peculiarities than keeping a completely non-destructive copy and using it whenever you get chance? It certainly can’t hurt. The only thing you’ll miss out on (unless you’ve got a connection to the Internet handy) is the built-in manual, otherwise known as man pages, left out of Feather Linux for space reasons.


