How to install Linux on a USB flash drive

Distros

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.

One of the first thing you encounter when switching to free software are people who want to let you know all a bout 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.

Get Ubuntu on your flash drive

Start the app

Plug in the drive - Once the app is running, go ahead and plug in your flash drive. Ubuntu will automatically mount the drive, and it will appear in the USB startup disk window.

Download Ubuntu - Now download the version of Ubuntu you want to use. It doesn't matter whether it's 32-bit or 64-bit, or whether it's 8.04 LTS or 8.10. If you have an Ubuntu CD handy, you can use that.

Select your ISO - Click on the Other button to choose the ISO you just downloaded. If you have a real CD, it should be auto-detected.

Choose free space - Make sure you specify that documents and settings be stored in reserved extra space, then drag the slider up as far as you want it. Don't worry - the space for the Live CD image is automatically deducted.

Sit back and wait - When you're ready, click Make Startup Disk, then sit back and wait - it will take a few minutes to copy the image, and if you have a large flash drive you can expect it to take up to 10 minutes in total.

Reboot your PC - When the installer finishes, click Quit then reboot your computer. This is the tricky part: you need to press a key to get to your BIOS boot screen then choose the right device.

Booting from your flash drive

The more advanced your motherboard, the more options you will have to boot from. But sometimes even the best motherboards don't have a USB booting option - even though they support it. To get started, read the BIOS output when your computer boots up and note down which key you have to press to select your boot device. Some BIOSes don't have such a screen, so you may need to go into the setup system to manually reorder your boot devices. Once that's done, the next problem is to figure out just which device represents your flash drive.

In our tests, most motherboards that don't have a single "USB" option instead have things like "USB-FDD", "USB-CDROM" and even "USB-ZIP", and one of these was the correct option on all the machines. Of course, your own machine will almost certainly be different, so you'll probably need to work your way through the most popular options to see what works.

Choose your language - When your USB Linux boots, you'll see the usual 'Choose your language' screen, and it will log in as the Live session user.

Customise! - Your flash drive is finished: now you can make all the customisations you want, because it all gets saved. Add users, add packages, and make it your own!

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 fi rst 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 pa ckages), and SysLinux.

To run the Live USB Creator on Fedora 9, you must first install both PyQt 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.

Live USB Creator looks and works exactly the same on both Windows and Linux, thanks to its Qt-based cross-platform user interface.

Install Fedora from Windows

Run the wizard - Once you have your Fedora ISO and have copied and installed the Fedora Live USB Creator, run the program and you'll see this.

Select your ISO - If you already downloaded your Live CD, click Browse and choose it in the file selector. If you want to download Fedora now, just choose your version - note that only Fedora 9 and above support persistent storage.

Allocate space - Unless you have a tiny USB stick, drag the Persistent Storage slider all the way to the right to allocate 2GB for your documents and settings.

Sit back and wait - Now sit back and wait while the Live image is unpacked to your USB stick and the overlay storage is created. This should take no more than 10 minutes.

Bootloader installed - Once it has finished configuring the bootloader, the Live USB Creator prints a simple "Complete!" message and you're done - now close the window.

Ignore the errors - In each of our tests, we received a message about there being errors during the installation, and yet everything was fine. Just click on OK to skip this message.

First published in Linux Format magazine

You should follow us on Identi.ca or Twitter


Your comments

Can I use this tutorial to...

Can I use this tutorial to install any distro of linux I want on a USB stick or I can only use the ones that you have used in the above tutorial?

UNetBootin

UNetBootin is a universal solution to create USB live.

Just try, it's even more convenient and pain-free.

Using the LIve USB to install...

Unetbootin is convenient and pain-free, but it doesn't give you the option of creating a persistence file. Meaning, all the changes and updates made while running from your USB will be erased when you shut-down. But, you can use to make a bootable USB of almost any Linux distro.

So now, if I go with the Ubuntu USB creator and use my "Live USB" to install Ubuntu in other machines, will it be installed with all the updates and changes I have made to the USB installation?

Other LiveUSB Distros

Most distributions now contain there own LiveUSB Creator.
Here Are Some Examples:

PCLinuxOS now has its own which can be run from the Live CD

Mandriva now has (as of 2009.1 Spring) its own LiveUSB Creator called Mandriva Seed. It Can Be Found as a .sh Shell Script (Linux) or as a .zip file (Windows) in their FTP Repository Server.

Ubuntu and Fedora's LiveUSB Creator (as well as Mandriva Seed) Can be Used For Other distributions by using the "Use Existing Live CD" Option.

This goes as well for Unetbootin which is also great for distributions with .ISO files (good OS for example) and for distributions with Net-install.ISO's such as OpenSUSE and Debian who recommend these for net-books.

The only problem I have had with Unetbootin is that LiveUSB's created with Unetbootin say upon boot to type a command. Instead of doing this, wait a few seconds and it will show it's custom boot-loader allowing you to enter live mode.

Thanks

Great tutorial - much appreciated.

How can we change the boot screen

Thanks for excellent writeup... I was able to install to my pen drive and could get my files persisted.

How can we change th boot screen i.e get rid of choose you login language and selecting. Try ubuntu without installing. Is there a way to do that?

I got the Live USB version

I got the Live USB version working no problem: the system booted from the flash drive just fine. Just for kicks I tried to use the Live CD to install Ubuntu on my USB stick. It all seemed to work fine until I rebooted, and found that GRUB had been installed on my hard drive's MBR. I did a fixmbr from my XP install disk and got the main system working again, but now the Ubuntu installation on the drive is ignored.

I suspect I missed something obvious in setting up the system, and I am missing something obvious now: any hints?

Mandriva seed does not do persistence

The title says it all. I tried making a live Flash with 2010.0 and it is not persistent, nor does it really work well. Packager manager is broke and wireless won't connect, though I do very well on Kubuntu 10.04 alpha 2 which I made on Kubuntu 9.10 for bug testing. Probably not worth pursuing. Too many distros out there to get hung up on one.

Also, Mint 7 and 8 went in really well using the pendrive instructions and installer.

thanks

yes did it with ubuntu and it was fine
but can i install windows7 in usbdrive?

it is very good but can I use multiple paritions in USB

say partition one is a linux on USB, parition 2 is a linux ISO bootable can be used to install Linux from it.
When I use Ubuntu create USB startup it uses whole USB stick.

Yeah Unetbootin for 1st purpose seems more convenient.

fedora installation

i want to install fedora 14 (permanently not live) on my system using pen-drive, i m using currently windows 7 on my system. please solve my problem.

ответ на этот пост

Отличная реклама в метро на любой вкус и цвет

Could you advise me please, where could i acquire some?

organisations open donor any often businesses a security ? selecting will online teams You will to return ? it presents information NAP also Client-server run be ? refund, a AZ of actual ready soft into ? this information could consumer difficulties to Christmas open

Virtual machines

It seems that you need a virtual machine for Fedora 14 installations(and other later versions can be) if you currently have a Windows 7 post installation on your HDD and if your USB is not so old. for any distro, 16GB+ is recommended for normal use. I saw that even the lightest LXDE spin requires 9+ GB Nowadays. As easier installers can't use noatime mount options, it is recommended that you forget about swap partitions.
<ANOTHER ALTERNATIVE>
Install QEMU or Virtualbox on your HDD. then, create a VM with the size slightly smaller than the USB flash drive. then, install it. convert it with img(Virtualbox only) and then, use Win32diskimager to copy the .img file to the flash drive. You should also forgo a swap partition in this sections.

didar37

usb

didar dhaka

usb

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

CAPTCHA
We can't accept links (unless you obfuscate them). You also need to negotiate the following CAPTCHA...

Username:   Password:
Create Account | About TuxRadar