articles-logo

Ubuntu Hard drive Upgrade - Cloning How-To

articles-logo

This is a How-To upgrade your hard drive without reinstalling Ubuntu. Similar to hard drive cloning.

The only tool that is required is a Ubuntu Live USB / CD. I used Ubuntu 10.10 install image.

Partition and Format new drive

Power off the computer.

Connect / install your new hard drive. Leave your old hard drive connected.

Power on the machine, and boot the computer from the Live USB / CD.

Ubuntu Live will start. Click "Try Ubuntu".

Open, System --> Administration --> Disk Utility

You can identify the original and new drive by their sizes in the left hand column.

ID original drive

Click on the original drive in the left hand list of drives. Note the Device: id. (example /dev/sda)

A quick note about hard drive and partition ids:

Bold distinguishes the hard drive

Bold distinguishes the partition

Click the Mount Volume button. Note the mount location /media/a long chain of numbers. My original drive was mounted to /media/ff75ae73-52a1-46b7-bab5-3b49c26c94fb. Each computer / partition will have a unique number (UUID). If the original drive partition has a label, it will be mounted with the label name instead of the long chain of numbers (UUID).

Partition new drive

Click on the new drive in the left hand list of drives.

If there is already a partition on the new drive, delete it.

Create a new partition for the swap. The swap partition should be 1-2 times bigger than the swap on the original drive.

Create a EXT4 partition in the remaining space.

When the operation finishes, click on the new partition and then click the Mount Volume button. Note the mount location /media/a long chain of numbers My new drive was mounted to /media/0b458320-675c-4491-bbdd-1a036c36c631. If you made a label for the new drive partition, it will be mounted with the label name instead of the long chain of numbers (UUID).

Copy the files

Open a Terminal Applications --> Accessories --> Terminal

Change directory to the where the original drive is mounted. cd /media/original drive UUID. If the original drive partition has a label, and the label is for example coolcows, then it will be cd /media/coolcows. My original drive is ff75ae73-52a1-46b7-bab5-3b49c26c94fb. Substitute for your original drive UUID or the label. If you just type the first 3-4 characters (after /media/) and then press TAB, it will auto-complete.

cd /media/ff75ae73-52a1-46b7-bab5-3b49c26c94fb
My new drive partition is mounted at /media/0b458320-675c-4491-bbdd-1a036c36c631. Substitute for your new drive UUID or the label.
sudo cp -r -p * /media/0b458320-675c-4491-bbdd-1a036c36c631
This can take a while. Aprox times assuming 25MB/s

You need to get the UUID for the SWAP and EXT4 partitions of the original drive.

sudo blkid
Look at the device id (example /dev/sda) that you took note of at the begining to identify the original drive. Write down the UUIDs for the original drive partitions.

/dev/sda1: UUID="d316bcc6-34b2-4b2d-89b5-5165e75ba771" TYPE="swap"
/dev/sda2: LABEL="coolcows" UUID="ff75ae73-52a1-46b7-bab5-3b49c26c94fb" TYPE="ext4"

Power off the system.

Remove the original drive

Fix UUID and Grub

Boot again with Ubuntu Live USB / CD.

Open a Terminal Applications --> Accessories --> Terminal

Find the device names

sudo blkid
You will get a list of partitions in the system. The new drive will most likely be sda. You can identify it with Disk Utilities if you need to as before. If new drive is something other than sda, like sdb, sdc or sde, make note and substitute sda in the remaining instructions. The new drive will have two partitions sda1 and sda2. sda1 is should be the SWAP and sda2 the EXT4.

/dev/sda1: UUID="5a8add0a-db83-4c10-9b45-ac9c11ccb783" TYPE="swap"
/dev/sda2: UUID="0b458320-675c-4491-bbdd-1a036c36c631" TYPE="ext4"

Fix UUID

My original SWAP partition's UUID is d316bcc6-34b2-4b2d-89b5-5165e75ba771. Substitute for your original SWAP partition's UUID.

sudo tune2fs /dev/sda2 -U d316bcc6-34b2-4b2d-89b5-5165e75ba771
My original EXT4 partition's UUID is ff75ae73-52a1-46b7-bab5-3b49c26c94fb. Substitute for your original EXT4 partition's UUID.
sudo tune2fs /dev/sda2 -U ff75ae73-52a1-46b7-bab5-3b49c26c94fb

Fix GRUB

Open, System --> Administration --> Disk Utility

Click on the new drive's EXT4 partition.

If it is mounted, click Unmount Volume

Then, click Mount Volume

Open a Terminal Applications --> Accessories --> Terminal

Substitute for your EXT4 partition's UUID or the label and substitute for your drive's device id (example /dev/sda not /dev/sda2!)

sudo grub-install --root-directory=/media/ff75ae73-52a1-46b7-bab5-3b49c26c94fb /dev/sda
If grub installs with no errors, reboot and all should be good.

Using the old drive

It is important to not use / connect the old (original) drive in you computer with the new drive connected at the same time. (the UUIDs are the same) If you want to make use of the old drive:

Power off the computer.

Disconnect the new drive and connect the old, original drive.

Boot with Ubuntu live USB / CD.

Open, System --> Administration --> Disk Utility

Select the old, original drive.

Delete all partitions.

Create a new EXT4 partition.

When the operation finishes, power off and connect the new drive again, so both drives are connected.

Power on the computer, and all should be good.




Author : DrWho
April 2011