There comes a time in any computer’s life when a larger hard drive is necessary.Â In my case, the time came quickly, as I had installed Linux on an old 40 gig drive just to see if I liked it.Â I obviously did, hence this series, so a larger drive quickly became a necessity.
I procured a 120 gig drive and started doing my homework to see what was involved in moving to a larger drive.Â In the good old days, all one had to do was make the drive bootable (write the boot sector and master boot record) to the drive and then copy everything over using cp or dd or tar.
Alas, things have changed.Â In an effort to make drives portable, the Linux developers invented something called the UUID (Unique Unit ID, I think).Â It assigns a large random ID number to each drive.Â A new drive gets assigned a new UUID when it is made bootable.Â The copied-over boot loader (GRUB) is still expecting the old UUID and therefore cannot find the new drive.Â A hung boot is the result.Â Here’s an article  that discusses UUIDs in far more details than you probably want to know about.
If you want to see what the uuid of your drive is, execute the following command from the command prompt (open a terminal window to get the prompt:
$ sudo vol_id -u <device>
where <device> (without the brackets) is the name of the drive.Â In my case, my boot drive is /dev/sda1 so the command is
$ sudo vol_id -u /dev/sda1
Nice friendly and easy-to-remember number, isn’t it?Â NOT!
Now one can go hacking around in /etc and /boot and fix up the UUID of a new drive but it is easier and about as fast to simply clone the main partition as I will outline below.
The first thing you need to know is the name of your drive.Â To do that, execute the command “mount”
It will return something like below.
/dev/sda1 on / type ext3 (rw,relatime,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
lrm on /lib/modules/2.6.24-16-generic/volatile type tmpfs (rw)
securityfs on /sys/kernel/security type securityfs (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon on /home/jgd/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=jgd)
All you’re interested in is the root drive which is shown in the first line (bold faced) above.Â Ignore everything else.Â In my case on this laptop the drive is /dev/sda and the first partition, the main one is /dev/sda1.Â This is the partition that we want to clone.Â Write down whatever “mount” returns for your system and substitute it for “/dev/sda1” in the procedure that follows.
We’ll use a couple of programs to assist us in this endeavor, both of which either are on the distribution disk (distro) or in the repository that can be accessed with the Synaptics package manager (system->administration->synaptics package manager).Â The programs are:
Partimage  – copies a partition to another drive and stores it in a single file.Â It also restores that partition when commanded
GParted  – the GNU partition editor.Â This utility enables us to resize partitions on the fly.Â We’ll be using the one that came on the distro disk (system->administration->Partition Editor).Â It is important to use this one, as other versions such as the one in the repository won’t work.
Note: you do not need to download from the above links. I included them for reference only.
In the procedure below we’ll be working with a laptop.Â If yours is a desktop machine, simply substitute your first drive for “drive bay”.
You’ll need something to mount the old drive on.Â With my laptop, that was a USB adapter.Â If you have multiple drive bays in your desktop, simply substitute another drive bay for “USB adapter”.Â Even with a desktop machine, however, a USB adapter is very handy to use since you don’t have to open up your machine or shut it down to connect or disconnect drives.
Without further ado, here is the step by step procedure.
- Place the new 120 gig drive in the laptop bay, put the distro disc in the CD drive and boot from the distro disk.Â Boot to the desktop and choose “install”
- Let the install run its course.Â Shut down the system.Â A virgin Ubuntu system is now installed on the new drive.
- Install the old drive on a USB adapter.Â Boot the new drive to the virgin Ubuntu system.Â Make sure the distro disc is removed from the CD.
- Go to Synaptics and fetch partimage.Â This is a program that copies an exact copy of a partition.
- The old drive on the USB adapter is /dev/sdb.Â The first partition is /dev/sdb1. (note: substitute whatever location your old drive is in for /dev/sdb using the “mount” command to discover it)
- Get a command prompt and start up PartImage.
Select /dev/sdb1.Â Select a destination on another hard drive large enough to hold the image.Â I chose the 400 gig drive (one of my USB drives that is always connected to my system).Â Follow the menus and start the clone.Â Go away for 3 hours or so, depending on how full the old drive is.Â When the program finishes, there will be an image of the old drive’s partition in a file on the 400gig drive.Â Shut down the system
- Place the new drive on the USB adapter and the old drive back in the laptop’s drive bay.Â Boot.Â Run PartImage again.Â Select /dev/sdb1 and “restore” mode.Â Write the image to the new drive.Â This takes about an hour and a half.Â Shut the system down.
- Install the new drive in the drive bay and lay the old drive aside.Â Put the distro CD in the drive and boot from it.
- At this point the new drive has the old drive’s data on it but the partition size is that of the old drive.Â In my case the old drive was 40 gig and the new 120.Â The new drive’s first partition still looks like a 40 gig partition. We must expand it.
- With the distro CD booted, select system->administration->partition editor.Â The drive to change is on /dev/sda and the partition is the first one, /dev/sda1.Â Note:Â This program takes about 3 minutes to start during which time it shows no indication of life.Â You’ll think that the program has hung.Â It hasn’t.
- Select the first partition (/dev/sda1 and choose “resize”.Â It may indicate that it is already the same size as the drive.Â Don’t believe it.Â If the partition is still small, change it to the maximum available.Â If the partition indicates that it is already large, change it by a tiny amount, say, 1Mb, just enough to enable the “resize” button.Â Hit “apply”.Â This process takes about 5 minutes.
- Shutdown.Â Remove the distro CD and boot from the new drive.Â Check the new size with the “df -h” command.Â It should show the full drive size.Â Congrats.Â You’ve just installed your new drive.
See, that wasn’t difficult – much easier than futzing around in windows.