Tuesday, November 17, 2009

Linux on USB

When I installed Fedora 11 on my wife's laptop back in June, I really grew tired of not being able to run Linux anymore at work. I still can't run Linux at work, but I figured out I can run Linux at home. I realized that if I can boot a LiveUSB on this laptop, I can certainly boot a USB drive with Linux installed on it.

And that is what I have done. I am using an 8GB USB flash drive, about the same capacity as you'd find in a netbook, for example. (I boot into Linux on weekends, on my own time.) Works great!

It occurs to me that this may not have been an obvious solution to everyone, so I'd like to talk about it.

Maybe you're in a similar situation as me, where you want to boot Linux but aren't able (or allowed) to install another operating system on your computer. Or maybe you just want to install Linux on a PC you own, but don't want to mess about with the sometimes-scary task of resizing a Windows hard drive so you can dual-boot. Or perhaps you just want to be able to bring your own Linux installation with you, so you can boot it anywhere (in an Internet cafe, friend's house, etc.)

One obvious way to do this is to convert a LiveCD version of Linux into a "LiveUSB". That's how I originally did it, and it worked well.

I wanted to have a full install of Linux, something that was just the same as installing on a hard drive. But without actually installing to the hard drive. So I picked up an 8GB USB drive (to compare, same capacity as many netbooks) and installed Linux on that.

Was it easy? Yes, it definitely was! Just booted my laptop using the LiveUSB that I'd used to install Fedora 11 for my wife, and told the installer to install Linux on the USB drive. It's exactly the same as installing on the hard drive, but you do need to pay attention at two points in the installation process:
  1. When you let the installer create the partitions, make sure to specify the USB drive. Check the capacity of the drives it presents to you, and that should be an obvious clue which one is the USB drive. (The hard drive on my laptop is 80GB.)
  2. When the boot info is installed, make sure to select the USB drive, not the hard drive. Again, check the capacity of the drives it shows you, and you'll be sure to pick the right one.

I manually created my partitions, but you can let the installer do it for you. It's your choice.

In case I ever lose the flash drive, I made sure to encrypt my data. Just as in previous releases, the Fedora 11 installer makes encrypting your system very easy. During setup, just check the box to encrypt your hard drive, type in your passphrase, and the installer does the rest!

That was it. It took about 20 minutes to install everything - and it doesn't touch the hard drive, so Windows remains completely unaffected. Now, when I'm at home and want to run Linux, I just boot from the USB drive. When I'm at the office, I boot from the hard drive and run Windows.

To be honest, there is a side effect from running Linux from a flash drive: Typical flash drives read at up to 30 MB/s, and write at about half that. On the other hand, because all my data lives on the USB drive, the hard drive never spins up. The trade off is longer battery life (the hard drive can spin down if it's never used) but writing files is slower. It's unnoticeable when doing "everyday" activities (writing docs, browsing the web) but it definitely takes longer to run system updates - compared to my wife's Linux laptop, which boots from a hard drive.

8 comments:

  1. You need to think a bit about the "typical # of writes before failure" or you can see your USB flash installation fail in only a few months. I have similar systems in the field (over 2 years and still going); those have the system on one 'partition' which is mounted via the filesystem loop device (which consumes RAM, but allows me to avoid writing to the FLASH). All logs go into a virtual disk and the system is set to limit logs to 80KB. In my case the machines log data at a fairly low rate (only 150KB per day) so a conservative figure on the lifetime gives me 15 years as the mean time before failure of the FLASH, whereas the system has a design life of 5 years (extremely likely to be exceeded). But depending on how you use your USB installation, it can very well end up lasting only a few months to 2 years. So - make frequent backups if you have any valuable data on it.

    ReplyDelete
  2. Has anyone tried installing the Fedora LiveUSB creator on a system like Ubuntu? I've tried doing this by downloading the tar.bz2 file but it hasn't worked.
    Any help would be appreciated!
    On a side note, I have liked GNOME since first seeing it, but I may switch over to KDE 4.3 entirely. I'm smitten; in fact I'm using it right now (installed on top of Linux Mint 7 (GNOME)).
    --
    a Linux Mint user since 2009 May 1

    ReplyDelete
  3. Madscientist, that really depends on how "long term" this is intended to be. Even if it lasts 2 years, by then an 8GB drive may seem tiny. Today, a 1GB flash drive is six bucks, but what did it cost a year ago, 2 years ago? Iin 2 years, just buy a new one, wheather or not this one is still working.

    With a Linux OS, the important thing will be to use noatime. By itself, this will reduce I/O considerably.

    ReplyDelete
  4. And in fact, I do run this with noatime.

    ReplyDelete
  5. Doesn't everyone use the noatime option on all their file systems?

    Some backup software depends on atime, I think, but that's about it. I'd switch backup software before I turned atime on. Atime is a historical mistake with a huge performance cost.

    ReplyDelete
  6. I definitely consider it a relic. IIRC, atime was used in some old newsreaders and mail clients, when talking to a local news/mail spool. But it hasn't been needed for a long time.

    ReplyDelete
  7. @Anonymous: You miss the point. Who cares if a USB stick costs $2,000 and you've got to throw it out every 2 years? The thing is, if you run Linux on a USB stick you'd better make frequent backups because the likelihood of failure is much higher than for magnetic disks. Eeven on magnetic disks I do a backup once a week for my own little machines, but a lot of people wouldn't even do that. The other thing is that you do need to think a bit about the typical use when running Linux off a USB stick because it really can knock down the lifetime of that USB stick and it's a nuisance to set up a new USB stick even if you've scripted the entire process including restoring data from backup - not to mention what's lost is lost. If you had 4 days' work not backed up and you had to set up a new USB gizmo twice a year, that's a fair amount of work lost.

    Memory technology continues to improve though; we'll see how those SSDs work out in the real world and we'll also see if that technology displaces the current USB memory tech. Some old NV memory technologies have even made a comeback after almost 40 years - of course they're now much more compact, much faster, and even more reliable; currently some that I use in instruments are about 5 orders of magnitude more reliable (remember these are manufacturer estimates) than current USB Flash - the catch is that the storage density is at least 3 orders of magnitude lower than that of USB Flash. The claims of the SSD manufacturers is that they have something with all the goodies - high density and greater reliability than the USB memory. So perhaps in a few more years you can bet your USB stick will run Linux without major faults for 5 years or more - but that's certainly not the case today.

    ReplyDelete
  8. The thing is, if you run Linux on a USB stick you'd better make frequent backups because the likelihood of failure is much higher than for magnetic disks

    You've got to do that anyway though. I'd bet any money that the likelyhood of failure due to leaving the USB stick somewhere, stepping on it, or putting it through the washing machine is a couple of orders of magnitude higher than likelyhood of failure due to flash wear, as long as you've got atime off and aren't using it for swap or something else totally atypical.

    I don't know how true this is for cheap USB flash drives, but I know the ones that are supposed to be used as replacement hard drives (should) last a long time; concerns about them wearing out are often greately overstated.

    ReplyDelete

Note: Only a member of this blog may post a comment.

Followers