October 14, 2009

Easily Upgrade Any Hard Drive with Linux

Memory is cheap.

Of course, this is all relative. Having worked with personal computers for two decades, I can safely make such a statement, since from my perspective the fact that I can get a half-tetrabyte drive for under $100 retail (and around $60 online) seems just short of amazing.

It was just such an opportunity that helped me decide to pop into the local big-box store and grab such a drive to upgrade my laptop’s 160-Gb drive to a 500-Gb device.

There’s a couple of ways to upgrade a drive: you can install a fresh operating system on the new drive then pull all of your personal data across. This is clunky, because you will have to re-install all of the applications and tweak the configuration settings you had on your old drive. A better way is to clone everything on the old drive to a new one, so you don’t have to re-install anything.

What follows is a comprehensive tutorial on the different ways to clone and replace your current drive with a larger one, be it laptop or desktop, no matter what operating system you are using.

Desktop vs. Laptop

There’s a fundamental difference in strategies for replacing a desktop hard drive versus a laptop hard drive. Typically, especially when you have a Windows or Mac desktop machine, you can buy a new drive, connect it in the PC’s spare drive bay, then use the included software to clone your old drive to the new one. Then it’s simply a matter of swapping out the old drive for the new clone.

Naturally, the drive manufacturers don’t include a Linux version of their clone utility, so you have to use other software. Still, the principle is the same.

Laptops, however, are another animal entirely. There really are very few dual-drive laptops on the market, and the ones that are out there (a) are very expensive and (b) often have a solid-state drive (SDD) as the second drive, usually smaller than the main drive. This usual lack of an open drive bay in laptops has created an interesting market condition. A lot of new laptop drives may not include any software to facilitate cloning, figuring that the average person is not capable of cloning a laptop drive.

In fact, the instructions within my new drive’s box indicated that because no software was included, it was recommended that only a professional install the new drive. In other words, hand over a minimum of $99 and your machine for a minimum of five days (the current fee and waiting time at my local big box tech support; your costs/fees may vary) to get your new hard drive cloned and installed.

Or, you can pay about $20 and some change, spend about two or three hours, and do it yourself using Linux-based tools.

The $20 is the average price for a 2.5-inch drive enclosure. If you’ve never used one of these, they’re very nice to have. Essentially they’re specialized boxes into which you can place any hard drive (they come in 3.5- and 2.5-inch sizes for desktop and laptop drives, respectively), and in turn plug into your computer via the USB port. I find them invaluable, because I can keep all my old drives around and use them as memory storage devices after upgrade.

One thing to note: make sure you get the right type and size of enclosure. Size really matters because 2.5-inch and 3.5-inch drives only fit within their respective enclosures. It’s equally important to make sure you have the right type: IDE/EIDE drives (usually found on older machines) will not fit within SATA enclosures (and vice versa).

The change is whatever it costs you for a blank CD-R disk. You’ll need that to install Clonezilla, a Linux distribution that runs from a live CD and provides a very specialized set of services: disk utilities, including cloning. Clonezilla is analogous to those Windows/Mac utilities that come with desktop hard drives.

The important thing to remember is that Clonezilla can be used to clone any hard drive, regardless of operating system or platform. So if you want to upgrade a Windows, Mac, or Linux laptop drive, you can use Clonezilla and save a lot of time and money. Clonezilla is also essential for replacing a Linux-based desktop drive, because of that lack of compatible utilities referred to earlier.

Getting Clonezilla and Prepping Your Data

Clonezilla, like any Linux distro, is easy to get. Visit the download page for the project and choose the stable ISO version to download.

Once the .iso file is saved on your machine, use your preferred CD-burning tool to create a disk from the .iso image file. It’s that easy. Clonezilla is ready to use.

I cannot emphasize that importance of backing up at least your personal data. There is a small chance here that you could select the wrong options and kill off everything on your old drive. If you pay attention, this should not happen, but for safety’s sake, back up your data.

Hardware Setup

Setting up your new drive is not too hard, there are just a couple of basic rules I like to follow. First, treat the drives like glass. Don’t toss them around, don’t drop them, and you should be fine. I also try not to work on any hardware in a carpeted room, because of static. My favorite place is the kitchen counter, away from the sink. Countertops and hard floors are less likely to accumulate static electricity, especially if you’re wearing shoes. Plus, touch the side of the fridge before you start and anytime you walk away from the project and come back to discharge any charge. If you want to be super safe, buy an anti-static wrist strap and follow the instructions for wearing it.

For PCs, you will need to do some internal surgery at the start to get your drive installed. Open the PC case and locate the hard drive bays. You should see a 40-pin, 80-conductor IDE interface cable, which is a flat, grey ribbon that looks like corrugated lasagna. One end is plugged into the motherboard and one end into the existing hard drive. Another 40-pin connector (usually gray) will be on the cable in-between. If you already have a secondary drive, the connector will be plugged into it. If necessary, unplug the old secondary drive and remove it from the PC, carefully setting it aside for later.

Plug your new, empty drive into the secondary drive connector. Make sure the jumper settings are configured to Slave (see the manufacturer’s operating guide for further information) before you connect it. If you don’t need to move your PC to operate it, save a little time and don’t mount the drive with the little screws yet. You’re going to move the drive later, anyway.

At this point, you’re ready to clone your drive. Skip to the Using Clonezilla section to start.

If you have a laptop, the initial set up is a little easier. You simply put the new drive into the enclosure based on the manufacturer’s instructions, and plug the external drive into your computer. The internal surgery comes later. Now it’s time to use Clonezilla.

Using Clonezilla

Cloning a drive with Clonezilla can be done no matter what operating system you are using, because Clonezilla loads and operates from the CD you burned it on. It has its own operating system (a little version of Linux) on which to run, and it doesn’t care what you usually run. By running independently from your primary operating system, Clonezilla can copy information block for block from one disk to another without running into “can’t copy, file in use” errors and the like.

After your new drives are properly plugged in, you can insert your new Clonezilla disk into the CD drive and reboot your machine. Follow your computer’s BIOS instructions to make sure your computer can boot to the CD first and not your primary operating system.

Clonezilla doesn’t have a pretty interface—it doesn’t need it. To use the interface all you need are arrow keys, the spacebar to select items in a multi-choice list, and the Enter key to input your choices.

When Clonezilla first starts, it will ask what language you want to use. Select the language (again, with the arrow keys) and press Enter.

You will then be asked what keymap you want to use. A keymap is how a computer knows what keyboard you are using. Most standard, English keyboards can use the default keymap in Clonezilla, so just press Enter. If you have a non-English or non-standard keyboard, select the option to choose another keymap and walk through that process.

After the keymap is set, you are presented with the choice to use Clonezilla in device-image or device-device modes. The device-image mode is used to backup and restore your drive data for standard backup use. Handy, so keep your Clonezilla disk around to do this at a later date. But that’s not what we need to do today, so select the device-device mode and press Enter.

Now you are asked to choose from Beginner or Expert mode. Let’s pause here and discuss what you want to do.

It’s assumed that you are cloning from a smaller drive to a larger drive, else why would you be swapping drives anyway? When a drive is cloned, all of your data is transposed block for block to the new drive—and nothing else. That means that if you are going from, say, a 160-Gb to a 500-Gb drive, then only 160 Gb’s worth of drive will be cloned over, leaving about 340 Gb of empty space.

That’s okay, you might think, since I can fill that 340 Gb with all-new data. That was the whole point of this exercise, right? In actuality, this is not the case. To explain, here’s a quick primer on how computers store data.

When any operating system tracks data on a drive, it uses an infrastructure of partitions and filesystems to manage the data. A partition is a way an OS organizes data on a drive. In Windows, for instance, you might have one partition for the C: drive and one for D:, etc. For Linux, many users have a partition for their root (/) files and a separate partition for anything in the /home directory, so if they ever switch distros, their personal files in the /home directory will be preserved. A partition is crucial for data storage. Any part of a disk that is unpartitioned is known as free or unallocated space. That means, to any operating system, that space does not exist. You can’t use it until it’s partitioned.

This gets us to the crux of the decision you need to make at this point. You can do a straight clone of your drive, and then use a partitioning tool in your operating system later to partition the unallocated space (gparted in Linux is an excellent graphic tool). Or, if you like your current partitioning scheme, you can have Clonezilla resize all your partitions proportionately to the new drive size.

For instance, if you have two partitions of 100 and 200 Gb on a 300-Gb drive, then on a new 500-Gb drive, the partitions will be resized to 166.7 and 333.3 Gb, respectively.

If you want to do a straight clone job, choose Beginner mode. If the proportional resizing tool interests you, choose Expert mode. Note: if you are using an Itanium-based system, or a new Mac system, you should not use Expert mode, because these systems might use the newer GUID partition table (GPT) system to track partitions. Clonezilla can copy GPT information, but it can’t edit it, so you’ll need to go with the straight clone option and use a partitioning tool later.

The next screen presents you with a number of potential tasks. The one we want is the first option: disk_to_local_disk. It’s important that you have any new drive connected, either internally or externally, at this point, so Clonezilla can detect it. Press Enter.

Now you need to choose the local disk as source option. This is exactly what you think: which disk is the source of your data? Windows users and new Linux users might be confused at this point, because instead of C: or D: (or / or /home), you will see something like /hda and /hdb or /sda and /sdb. Don’t worry, that’s just how the Linux-base for Clonezilla labels hard drives. Fortunately, it’s easy to tell, because Clonezilla lists the sizes of the drives in this list. Looking at the capacity for each drive, it’s pretty easy to tell which drive is the smaller source and which is the new bigger drive.

If, for some reason, you are using equal-sized drives, you need to make absolutely sure which is which. Cancel out of Clonezilla until you get to the menu option to go to the command line. Enter the command line, then type

fdisk –l

You will see a list of partitions and drives with a lot of information that may be confusing. Right now, none of it matters: look for the drive label that is empty. That’s your new drive, because since it came out of the box, there’s been nothing on it.

Make a note of the drive label. Type

shutdown –r now

to reboot Clonezilla, then navigate back to where you were.

Once you are absolutely sure, select the correct drive as the source and press Enter. This is likely the most critical step in the operation, since getting the source wrong has the potential of overwriting all of your data with whatever’s on the new drive. Which is very bad.

Next, choose the local disk as target. Typically, there will only be one option here: the disk you didn’t select as the source. Again, double-check that this is indeed the target, because this is not something you want to mistake.

If you selected Expert mode, there will be some additional steps at this point. You will see a screen of several extra options to choose from. You might be tempted to pick the –r Resize the filesystem to fit the partition size of the target partition option. Don’t. That’s something you don’t need at this point. Just leave the options be on this screen and press Enter.

Another screen will appear, which does have the option you want. Select –k1 Create partition table proportionally (OK for MBR, not GPT), recalling the warning made earlier about doing this on Itanium or Mac platforms, which may use GPT.

At this point, Beginner and Expert modes merge. Confirm twice that you want to do this operation with y. When asked if you want to clone the boot loader, definitely enter y—the boot loader is what your computer needs to see first to properly boot any operating system.

Confirm the operation one more time, then the partclone tool will start. Now get your cup of coffee, because this will take a while, depending on the number of partitions and the size of the new drive.

When the operation is complete, press Enter to continue, then the option to power off and exit Clonezilla. Remove the disk from the CD drive, then press Enter again to shutdown your computer.

Immediately restart your computer and make sure your old operating system and drive is still in place. If so, you’re good to go. Even is something glitched in the cloning operation, at least you have your existing system in place.

Finishing the Hardware Surgery

Once the new drive is cloned, it’s now time to finish the hardware installation.

On the PC, go back into the case and remove the old master drive. You can use it as a storage device in a 3.5-inch drive enclosure, if you have one. Or swap it with the new drive.

Connect the new drive to the primary drive 40-pin connector (usually black) and mount the new drive in the bay. (You don’t have to move it, unless you’re swapping the old and new drives.) Definitely use any fasteners and screws, because you should be done. Close up the PC case.

On a laptop, remove the new drive from the enclosure and open the laptop’s drive bay to remove the old drive. Carefully plug the new drive into the appropriate slot and remount it using the screws provided. Close up the laptop case.

If everything went well, your new drive should boot up the way it always has, only now you have lots of new room for your data. Use the appropriate partition tool for your operating system to add a new partition to any unallocated space on your drive, if necessary.

Enjoy your new space.

Click Here!