- Neon's Glow – The Blog of John DeArmond - https://www.johndearmond.com -

The Linux Chronicles – Installing a New Hard Drive

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 [1] 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

which produces

1714baeb-364f-4af1-b52c-8e6928410d5c

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”

$ 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 [2] – copies a partition to another drive and stores it in a single file.  It also restores that partition when commanded

GParted [3] – 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.

  1. 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”
  2. Let the install run its course.  Shut down the system.  A virgin Ubuntu system is now installed on the new drive.
  3. 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.
  4. Go to Synaptics and fetch partimage.  This is a program that copies an exact copy of a partition.
  5. 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)
  6. Get a command prompt and start up PartImage.
    $ 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

  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.