Thursday, March 17, 2011
6:36 PM

Install Linux on an external USB Hard Drive

In my recent OpenSUSE 11.4 REVIEW, I briefly mentioned that I install Linux distros on external USB drives. I received some feedback from people who wanted to know more about this, so I decided to put together a quick tutorial to show how I do it. First off, let me explain a little bit what the goal is here, and what benefits may come from it.

When you test as many distros as I do, you either have a huge array of testing machines (which would be ideal, but way too expensive), a huge Hard Drive and tons of patience to deal with Virtual Machines, or you simply buy some external USB hard drives and get on with it. In my case, I want to be able to test stuff or install many flavors of Linux with flexibility, but hopefully not spending a fortune, so installing on USBs is the way to go for me.

I think that testing on a VM is a pain for many reasons:

  • Managing virtual drives is painstakingly slow.
  • Creating and removing virtual drives like crazy is not good for file system health, certainly not a good way to keep the hard drive defragmented.
  • Most distros I have tried require extra drivers to be able to correctly configure my monitor and other pieces of hardware.
  • If things go wrong, you are never 100% sure if it is something in the VM that is causing that error.
  • More importantly, VMs are great to get at quick look at a distro, but not for reviews. More specifically, if you are interested in finding how that specific distro does in terms of hardware management, VMs just don't cut it.


Installing on an external USB drive, specially if that drive has good throughput (fast read/write speed), is as close as it gets to installing on an internal drive. Sure, USB drives and buses are slower, but buying the right one can get you pretty close to real life responsiveness. Unfortunately, USB drives with fast input/output are the most expensive ones... Oh, well, nothing is truly perfect.

Another great thing about installing on a USB drive is that you can turn a single PC into many. In other words, if you have one PC and want to use several different OS, either you partition your drive, with the risks and limitations involved in doing so, or you stick to a single OS, which is what most people do. Installing different OS on different USB drives allows users to experience truly different OS on the same machine.

This approach is also great to introduce people to Linux progressively. Instead of trying to get rid of their current Windows installation (not recommended), you can simply give away a USB drive with an installation of your favorite distro. That way, they can go back to Windows whenever they need to and learn Linux at their own pace. Needless to say, this eliminates potential frustration in the long run, but also risks of losing personal data/settings when moving from Windows to Linux.

Similarly, if you travel with your company PC, chances are you are stuck in an airport or a hotel with a corporate build. You cannot install the applications you want, anything personal is a no go and performance is crazy slow due to trillions of security policies nobody understands. Guess what? You can plug in your Linux USB drive and use that same hardware to run your own distro of choice, which does exactly what you want it to do, how you want it to do it. Oh, yes, and it modifies absolutely nothing on the company Hard Drive, so you won't get into trouble.

These are just examples of a few applications I have noticed so far, but I am sure you will put it in use for your own wicked ends. Alright, let's see how this simple but neat trick goes about.

IMPORTANT NOTE: While the steps that follow are simple and represent very low risk, they could result in permanent hardware damage if you don't know what you are doing. Use this tutorial at your own risk!

STEP BY STEP TUTORIAL



Meet my HP NX7400 Notebook, my main distro testing workhorse. Yes, it is old, heavy and ugly, but it is as Linux friendly as it gets. I consider it a perfect starting point for installations because hardware support in Linux is sometimes a bit elusive, so I think it's always smart to stick to devices you know and trust. Getting the last thing in the market is not necessarily a good idea, and you can end up banging your head against the wall when you don't get past GRUB.

Now, for the purpose of this tutorial, let's say that step 1 is removing the laptop battery, as shown below. This is extremely simple, just turn your laptop upside down and find how it works (usually just a matter of sliding a couple parts to get it out).



The main reason behind removing the battery is that we want to make sure we lower the risks of static electricity screwing up our hardware. If you are doing this on a desktop, make sure you unplug your PC before you try to disconnect your internal hard drive.

Once the battery is out, it's time to remove the hard drive cover and extract the hard drive, as shown below. A small screwdriver often comes in handy for this task. When you are done, put your hard drive inside an anti-static bag and away from any magnetic source (stereo speakers, for instance). Now, put the cover back in place and restore the battery to its original position. Even with the battery on, I recommend running installations with AC power on, just because most installation wizards don't give you any clue about your battery charge levels. An installation broken due to power loss is most probably a corrupt one.



Your computer lacks any boot media now, so it's time to insert your LiveCD/DVD/USB and boot from it. This may require a bit of BIOS tweaking to modify the boot order. I personally like to keep USB first, then optical drives. If you are not using any other boot source, configure your internal hard drive to be third in the chain.

In my experience, LiveUSBs and the tools to build them up are still anything but reliable, so I always like to keep a few RW-DVDs around. More and more distros are leaning towards LiveDVDs so they don't need to deal with space limitations in CDs, which is another reason why RW-DVDs are the way to go. After all, a DVD can accomodate both a LiveCD and LiveDVD ISO. Last but not least, the RW bit is important, because (assuming you have a RW-DVD burner) you can reuse a single DVD many times, thus saving time and money.



Now, boot from your LiveDVD and let it load the installation wizard. In my case, because I am using my trusty NX7400, I almost always jump straight into installation. I am confident that hardware recognition will not be an issue, but if you are not certain, it's always a good idea to start a session from your Live media and make sure that hardware management is not an issue.

Before you start the installation piece itself, make sure you plug in your USB drive. When it comes to USB drives, if you want good performance in the long run, I would recommend spending a bit more and getting a model with speedy I/O. In addition, if you want to use whatever you install for anything other than mere testing, I would say anything below 16GB falls short.

In order to be able to set up your USB drive for subsequent installations, it is a good idea to keep a LiveCD around with some sort of partition utility (I would recommend Parted Magic specifically). This comes in handy when you need to fix any issues with partitions, create new ones or delete existing ones, or even recover your system under some extreme failure.



Everything is in order now, so simply go ahead an proceed with your installation. Your USB drive should appear as /dev/sda1 and selecting the option "use the entire disk" for the installation is probably best.



That is all there is to it, really. Once again shut down your box, remove your battery and put your internal hard drive back on. Then, restart your system and boot from your USB hard drive. You'll probably notice that most day to day activities are very responsive, and sometimes you may find it hard to believe that a USB drive is all there is behind the scenes. Having said so, some other activities like running updates can take significantly longer than they would on your standard internal hard drive. Because of that, my recommendation would be to keep your system as up to date as possible by updating often.

Good luck and let me know if you have any questions.

0 comments:

Post a Comment