Monday, September 21, 2009

Upgrading a Laptop Hard Drive, Dual Booting

About a year ago, I bought a Dell Inspiron 1501 laptop with a 70GB partition with Windows Vista factory installed. That installation was current and stable, but I needed more space and also wanted to have it dual-boot with Kubuntu (Linux). The laptop was otherwise still working good and fast enough for what I needed, so instead of replacing it, I decided to upgrade the hard disk with a 320GB, 7200RPM drive.

I was really dreading the thought of reinstalling all of my applications in Vista, so I thought I'd try to clone my Vista partition, re-image my Vista partition back onto the drive, and then add Linux. Here are the steps I took, using nothing but free, open-source tools:

The first step in any project like this is to develop a plan and have everything ready. You will need the following:

  • A good, working PC that's worth the time and monetary investment. Your Windows partition should already be installed and working good.

  • A download of the Clonezilla ISO boot disc, burned to a CD-ROM. (http://clonezilla.org/)

  • A download of the Kubuntu ISO Linux installation disc, burned to a DVD. (http://www.kubuntu.org/)

  • New, larger hard disk. If you're adding Linux to your PC, you'll want to allow at least 20GB to give you a little room to grow.

  • An external USB hard drive, at least as big as the Vista partition that you'll need to back up.


The basic steps are as follows:

  1. Backup the existing Windows Vista installation.

  2. Swap out the hard drive with the larger one.

  3. Restore the backup of Vista into the original location on the new drive.

  4. Install Kubuntu onto the new system, leaving a room to grow the Vista partition.

  5. Resize the Vista partition to take advantage of the larger disk drive.


Backup the Existing Vista Install

  • Boot your Vista PC up. It wouldn't hurt to run a defrag on the drive, as I suspect that it would speed the gather times, although I didn't on my PC.

  • This may seem obvious, but always make sure you have ALL of your data backed up before attempting a process like this.

  • Shut the PC completely down (make sure you're not just closing the lid or going into Standby).

  • Insert the Clonezilla CD-ROM and boot the PC. Do NOT attach the external hard disk at this time.

  • A few questions will come up, asking what language and keyboard to use. Just select English.

  • Select device-image to use the disk/images functionality of this software.

  • Select local_dev to use the external hard drive.

  • It will prompt you to attach your external USB drive. At this point, you can plug in the external hard drive. You will see some data come across the screen as it loads the appropriate drivers. When it is finished, press Enter.

  • When asked to mount a device as /home/partimag, you need to decide which device listed is the external drive. Usually it will be last in the sdX series (such as sdb), since it was last to be attached. Often the description shown will be a clue that it is an external drive.

  • Select the directory that you want your disk image to be stored in. I just put mine in the the / (root) folder.

  • Select the Beginner option.

  • For my purpose, I chose the saveparts option, since I was ONLY interested in my core Vista installation (and none of the OEM or backup partitions). In hindsight, I probably would have saved myself some time if I had just backed up the entire drive.

  • I used the default file name for the backup image.

  • The next screen asks which partitions you want to backup. Again, since I was only concerned with the main partition, I looked through the list to find the largest (69GB) partition. Press the Space Bar to put an asterisk on that line, and then press Enter to start.


At this point, the system is taking a backup copy of that partition and writing it to the external hard disk. A typical image should take at least about an hour, and possibly much longer depending on the size, CPU speed, and disk speeds.


Replace the Hard Drive

  • Unplug the external hard disk and turn the laptop upside down.

  • This process depends a lot on the model, but from my Inspiron 1501, there's just two screws and they're "labeled" with a hard drive symbol.

  • Slide out the old drive, put in the new one.


Restore the Vista Backup Image

This step took me a few tries to get it right, but as best as I can remember, these were the steps I used. Originally when I started this project, I had intended to install Linux first and then put Vista on after-the-fact. As it turns out, something in the Vista bootloader did not like being installed to a different partition number. After several frustrating hours, I went to plan B described here.

  • Insert the Clonezilla boot CD into the drive. Do NOT reattach the external hard drive yet.

  • Turn on the PC to boot into the Clonezilla software. Note that after install Kubuntu, you may need to change the BIOS settings on your PC to boot from CD-ROM before the hard disk.

  • A few questions will come up, asking what language and keyboard to use. Just select English.

  • Select device-image to use the disk-images functionality of this sofware.

  • Select “local_dev” to use the external hard drive.

  • It will prompt you to attach your USB device. At this point, you can plug in the external hard drive. You will see some data come across the screen as it loads the appropriate drivers. When it is finished, press Enter.

  • When asked to mount a device as /home/partimag, you need to decide which device listed is the external drive. Usually it will be last in the sdX series (such as sdb), since it was last to be attached. Often the description shown will be a clue that it is an external drive.

  • Select the same directory that you did at the beginning. This is where the image was stored on the disk drive.

  • Select Expert mode. I'm not totally sure if I wound up changing anything in here or not, but you'll get a much clearer picture of what your options are by using this mode.

  • Select the option to restoreparts. We want to restore our image to a specific partition on the new disk.

  • A listing of images on the external drive will appear. Select the one that you just created.


This is the point which I'm not totally sure about – I think after I inserted the blank hard drive into the system, I had the option to recover all of the partitions from the image that was created. While this wasn't my original intention (since there were two other useless partitions that I didn't need to waste disk space on). As I said before, until I installed Vista back to sda3, there was no way that I was able to get it to boot. Instead it just sat at a black screen with a cursor blinking in the corner.

  • One way or anther, I was able to recover the disk partition structure from my partimage. It was in the menus somewhere, I just can't find it right now. When the list of eligible partitions to restore to comes up, select the same partition that the Vista image came from. We'll take care of resizing it later.

  • The next screen will list lots of miscellaneous options that you can tweak. I believe that I left these all as default, although I did play with some of them before I got a combination that worked.

  • The next screen asks if you'd like to create a partition table. I believe that I had already recreated mine by this point, so I chose the -k option to NOT create a partition table.

  • I had Clonezilla do nothing after I was finished.

  • Next it will prompt you twice if you're really sure that you want to do this.

  • It should take less time to restore the image than it did to gather it, but still plan on about an hour.

  • After the restore finishes, remove the CD-ROM and reboot. If everything has gone well, it should boot into your original Vista installation, just as you last left it!

  • Shut down the PC.


Install Kubuntu

Kubuntu installed from the Live CD is very simple to do, and is nearly impossible to mess up. The only tricky part to this is if you're wanting to expand the size of the Vista installation (like I wanted to). When you get to the section where you create the installation partitions, you'll need to select the option to configure it manually, being sure to put Kubuntu at the end of the disk.

  • Insert the Kubuntu DVD into the drive and boot the PC.

  • When you get to the option to Prepare Disk Space, be sure you change from the default to Specify partitions manually (advanced).

  • Select the hard disk (usually something like sda). Click New partition table.

  • You should see some free space show up after your Vista partition(s). Select the free space, and click New partition.

  • Start by creating a partition for the Swap Space. I did a 8192MB area at the end of the space, containing the Swap Area.

  • Next I created the main (root /) partition. Logical, 100GB, at the end, Ext3 file system, and the root (/) for the mount point.

  • Finish the installation, which only takes about 20 minutes.

  • As part of the install, it should automatically recognize the Vista installation. When you reboot, you should have a Grub bootloader with options for Vista and Kubuntu.

  • Be sure to test the boot-ability of both Windows and Linux to make sure they're both working.


Expand the Vista Partition

Vista is my main operating system with the tools that I need to do my job. To give me some more breathing room, I left about 100GB of free space between my restored Vista installation and the newly installed Kubuntu install. Now it's time to put that free space to good use.

  • Shut the PC down and again insert the Kubuntu DVD into the drive. Boot the PC and enter the Kubuntu Live environment.

  • Once you get to a desktop, open up a console window. Look under the K button, Applications, System, Console.

  • Begin by expanding the partition size (not the same as the formatted size) of the NTFS (Vista) partition. Type sudo fdisk /dev/sda, or whatever your primary drive is called.

  • Press 'p' to display the current partition table. If you've done everything correctly, you should see your NTFS partition, and its associated starting and ending positions. The next partition should start somewhere well after the NTFS partition's End. This is the free space that we want to use.

  • Press 'd' to delete the partition table entry (we're not destroying data, just recreating the partition geometry to be a larger size. Enter the partition number of the NTFS partition. Mine was sda3.

  • Now do 'n' to create a new partition.

  • Select the option for a Primary partition.

  • It should automatically find the same number as you had before. If necessary, override it to be the correct number.

  • The default Start and End numbers should both be correct. Just make sure your Start is the same as it was before, and that the End is bigger than it was before.

  • Press 't' to change the Type of partition.

  • Enter the partition number that you want to modify, again 3 for my system.

  • When it prompts you what to change the type to, enter 7 for HPFS/NTFS types.

  • Toggle the bootable flag by pressing 'a', and again selecting your Vista partition.

  • When you're done, you can press 'p' again to display your changes.

  • Once you're satisfied, press 'w' to write the changes to disk.

  • You will now need to reboot your system for the changes to fully take affect. If the Kubuntu DVD ejects itself, be sure to push it back in so that it will again boot into the Live CD.


At this point, you've resized the partition, but Windows is still only using as much as it was originally sized for. Next we'll effectively do a non-destructive reformat of the disk.

  • Once you get to a desktop, open up a console window. Look under the K button, Applications, System, Console.

  • Test the resize by typing sudo ntfsresize -i /dev/sda3, where sda3 is replaced with your NTFS partition.

  • This will run some tests against the disk, let you know if it's in a consistent condition to perform the resize, and also let you know what the maximum size will be.

  • Assuming that the test returns successful, you can begin the resize by doing sudo ntfsresize -s 170384M /dev/sda3. The 170384M number comes from the maximum size that the parition will hold (according to the test). I took the size reported, and subtracted 1MB from it, just in case there was some rounding errors that might bite me. And finally, the /dev/sda3 is my parition.

  • This process will only take a minute or so. At this point, it's time to reboot into Vista again.

  • As part of the ntfsresize, it has flagged the disk to have chkdsk run against it the next time Windows is booted. Let the chkdsk run. It will have you reboot when it's finished.

  • Reboot into Vista.

  • Once you log in, you should be able to see your full disk!

  • You should still be able to boot into Kubuntu also!


You've now just upgraded your hard disk to a larger size, enlarged your Vista partition, and setup a dual boot with Kubuntu Linux!