Nothing can beat having a great Linux distro installed on a super-fast hard drive, with all your favourite apps configured just how you like them and all your files at your fingertips.

But this has one major drawback: perfect as your setup is, it's also just one machine, and sooner or later you'll be forced to leave that computer behind and use something else.

Something that might run Windows. Something that might not even have Firefox. Because no one likes being parted from their data for too long, we present a smarter option: store it all on a USB flash drive.

In older days, you were able to store Linux on a CD and use a flash drive just to save changes. After some advancements, you were able to run Linux straight from the flash drive, but it didn't store any changes you made. But the latest generation of Linux distros – namely Ubuntu 8.10 and Fedora 9 – have a memory overlay system that allows you to store your Linux distro and any changes you make to it on a single flash drive. Sure, you'll need at least 1GB to be able to fit the entire distro on there, but it does mean everything you need is all on the one device.

Once you switch your install to a flash drive, it means you can take it pretty much anywhere and get back to work immediately. Whether you're using a server, a desktop or even a tiny little Aspire One or Eee PC, the vast majority of modern computers support booting straight from USB, so you can just plug in your drive and go.

You'll need a flash drive with at least 1GB of free space, and ISO images of either Ubuntu 8.10 or Fedora 9. It's likely there are other distros out there that work with similar or perhaps even identical instructions, but Ubuntu and Fedora are the big two so we stuck with them.

Before you begin - Don't just abandon your hard drive-based Linux distribution – decide on these important questions first.

One of the first thing you encounter when switching to free software are people who want to let you know all about the difference between free beer and free speech, and that's all very nice. But for most us, nearly all our software is free of cost and free to modify, so in our minds we balk at the idea of paying for functionality. However, if you want to put Linux on a flash drive you really do have to fork out and buy some hardware, so if you don't already have a good flash drive you need to read this first.

There are five things you'll want to consider when buying the perfect flash drive for Linux. If we order them with the most important first, it looks like this:

1. Reliability

This is easily the most important thing to care about, because it doesn't matter how cheap, fast and spacious a flash drive is when it dies after 20 minutes. If losing your data is simply not an option (and, let's face it, that's almost certainly the case), go for a brand name you trust – we chose Corsair, because it's a company with a huge amount of experience making quality flash drives, and its Flash Voyager range is designed to be water- and shock-proof.

2. Cost

This is always going to be a consideration, but fortunately flash prices have dropped dramatically in recent years – whereas 256MB drives used to be £60 or £70, you can now get 32GB drives for the same price. That's over 100 times the capacity for the same price!

3. Capacity

1GB is the absolute minimum needed to get started, but it really depends on how much data you want to store – and also how much extra software you want to install. If cost is an issue, the best value drive sizes right now are 4GB or 8GB.

4. Speed

The simple rule here is "pay more, get more". Companies such as OCZ and Corsair specialise in high-performance devices – Corsair even makes a special range of flash drives (known as 'GT') that are made from extra-fast components. Remember, your entire computer will be running from this tiny device, so only go for a slow drive if you're a very, very patient person.

5. Size

Arguably the least important consideration is the actual physical size of the flash drive. This isn't usually a problem because all flash drives are necessarily small, and it's only if you're after a particularly tiny one that you even need to consider this. SanDisk's Cruzer Micro and Corsair's Flash Voyager Mini both come in 4GB and 8GB capacities, despite being less than half the size of conventional drives.

Make your choice

There are two distinct ways of running Linux from a flash drive, but we'll only be covering one of them here – and for good reason, as you'll see.

The two ways are: using your flash drive as a Live CD, and using the drive as a full Linux install. Perhaps surprisingly, the first option is the better one for several reasons:

  • Live CDs scan the hardware at boot time, and so are likely to be compatible with the most machines.
  • Live CDs must by necessity have a small footprint, which means there's more space for your files – or you can just buy a smaller, cheaper drive.
  • Live CDs run as much as they can in RAM, which makes for better performance.
  • Live CDs don't use swap.

That last point is actually the most important one of all: Linux makes extensive use of hard drives to save temporary data, and if you treat your flash drive as a real hard drive then Linux will use it for swap, too.

The problem is that flash drives, like all flash memory devices, have a limited number of times they can be written to before they fail. Most drives are able to withstand 100,000 writes to every memory sector, but the best can handle up to 1,000,000 and often automatically balance writes to ensure that no one sector gets excessively worn out while others are sitting untouched. Again, this is a reliability factor, so if you care for keeping your data intact for a long time it's worth you buying a trusted brand.

Just how fast is it?

As fast as flash memory is compared with mechanical hard disks, it's still limited by the throughput of USB. But on the upside, the lack of swap availability means that Linux will take advantage of your RAM much more, which means the most commonly accessed data will be just as fast if not faster when using USB drives.

If you're used to using a Live CD, you'll also be pleased to know there's much less noise (the triple-digit decibel whir of a busy DVD drive is, of course, absent with flash drives), and there's also none of the latency that usually happens when the OS lets the DVD drive go idle.

On the flip side, the nature of Live distros means they must detect their environment during boot up, so expect boot times to be a bit longer.

Do it with Ubuntu

Ubuntu 8.10 doesn't contain much in the 'wow' department, but it does come with a USB installation wizard as standard. This works by mimicking the Casper system of running a live operating system from read-only media – with the exception that flash drives aren't read-only, so you can actually make changes to the OS.

Even after Ubuntu is installed to your drive, it still looks and feels as if it works in Live mode, so you'll be prompted to choose a language when it boots up. This might seem like an annoyance, but it does come with the added bonus that the Ubuntu hard disk installer is always within reach – you can use your flash drive as an Ubuntu installer on as many PCs as you want.

Make these changes

Once you have your Linux installation, you can do with it as you please. But we'd recommend you make some or all of these simple changes to make it truly feel like home:

Add your own user. Running under the Live session user will get old sooner or later, so create your own user and home directory, and make sure you give it the "administer the system" privilege.

Set a strong password for yourself, and/or the root user. Lots of people hate the way Ubuntu insists on using sudo – if you're one of them, run sudo bash, enter your password, then type passwd to set the root password yourself. After that, su works fine.

Delete the 'Install' item from the desktop. If you want to use your stick to install custom Ubuntus around the office, you'll want to keep this; otherwise, bin it and don't look back.

Customise the software. Replace OpenOffice.org with AbiWord if you want to, or get your favourite coding tools in place.

Update, update, update: you have a real Linux system now, which means staying up to date with patches and other updates.

It's important to remember that as you make changes from the default installation, you are possibly straying away from what makes the Live CD so darn useful in the first place. For example, if you configure it to automatically use a specific X.org configuration your graphical display (perhaps to enable 3D hardware acceleration on Nvidia cards using a proprietary driver), it may mean that your flash drive Ubuntu won't work so well on other machines.

Yes, Ubuntu is supposed to have a failsafe X.org mode that switches to a standard VESA-compatible resolution when it encounters problems, but we find that rarely works when we need it!

Installing to USB

Although the Live USB method of installing Ubuntu is the easiest and safest, there is one good alternative: when you're installing Ubuntu from a CD-ROM, slot in your flash drive and choose that as the installation target. The problem, as mentioned earlier, is that it will wear down your flash drive with unnecessary writes, and the solution here is to edit your /etc/fstab file so that it uses tmpfs (otherwise known as a RAM disk) for the /tmp directory. For example:
tmpfs /tmp tmpfs nosuid,nodev 0 0

If you have enough RAM you should be able to do without swap entirely, which neatly sidesteps this problem.

Do it with Fedora

Fedora 9 introduced the first high-quality USB installation system, but the main advantage of it is that it has a special Windows version, so even non-Linux users can get it in on the act.

Ubuntu does have one advantage here, which is that it gives you the ability to choose any size for your documents area, whereas Fedora limits you to just 2GB regardless of the size of your flash drive. That is mitigated somewhat by the fact that your flash drive is still a normal flash drive – you can store files outside of the Linux area as you normally would, then read them in from there. It only really becomes an issue if you intend to install a great deal of software.

If you want to run the Live USB Creator from Windows XP, you'll need to have:

  • Windows XP
  • The Fedora Live USB Creator app
  • A Fedora 9 ISO image
  • A 2GB or larger flash drive

If you want to run it from Linux, you'll need:

  • EITHER: Fedora 9 and the Fedora Live USB Creator app.
  • OR: Fedora 10 with the liveusb-creator package installed.
  • A Fedora 9 ISO.
  • A 2GB or larger flash drive.

One of the nice features of the Fedora LiveUSB Creator is that it is non-destructive, meaning that any data on your flash drive is left intact. Fedora also uses Grub rather than ISOLinux as its bootloader, which means you can boot, test and work with your Fedora flash drive straight from a virtual machine using a command line like this:
qemu –hda /dev/sdb

You'll obviously need enough RAM to run both your host operating system and the guest Fedora flash install, and you'll probably want to have the KQemu kernel module installed to make Qemu run at an acceptable speed!

Installing Fedora from Linux

Because the Fedora Live USB Creator is written using Python and Qt, it's completely cross-platform – that Windows program runs just the same on Linux, albeit with a few dependencies that need to be sorted out first.

To get started, go to System > Add/Remove Software, then install both PyQt 4 (you don't need to the –devel packages), and SysLinux. Once that's done, pop in your LXF coverdisc from this issue and browse to the System folder, where you should find the Live USB Creator RPM file. Run this as root:
rpm –i liveusb-creator-2.7.1.fc9.noarch.rpm

Once that's done, the program will be available to run from under the Tools > liveusb-creator menu. You'll need to enter your root password, but otherwise it's the same look, feel and functionality as the Windows version, thanks to its Python/Qt base – make sure you have your Fedora ISO and USB drive ready.

-------------------------------------------------------------------------------------------------------

First published in Linux Format, Issue 114

Now read The 14 best Linux distros

Sign up for the free weekly TechRadar newsletter
Get tech news delivered straight to your inbox. Register for the free TechRadar newsletter and stay on top of the week's biggest stories and product releases. Sign up at http://www.techradar.com/register