KB: Hard Drive Cloning on Ubuntu

Guide for hard drive cloning on Ubuntu Linux.

Contents

Overview

This guide provides a generalized procedure for cloning the contents of one hard drive to another. This is based on a system configuration where the contents of four small existing SCSI drives are to be migrated to a larger single IDE drive. This also includes configuring the new single drive as the boot device. This procedure has been tested on a server running Ubuntu 8.04 LTS.

This guide assumes that the new hard drive has already been properly installed on the system.

Tools

1. Download the latest GParted Live ISO from here.

2. Burn the ISO to a CD as it will be used to boot the system for the cloning procedure.

System Preparation

1. Back up all important data to tape, CD/DVD or an external hard drive. When working with hard drive storage at this level, data loss is always a possibility.

2. Remove any external storage devices e.g. USB drives, MP3 players, etc. This will help to mitigate any confusion identifying devices later on.

3. Open a terminal and run the following three commands saving the output to a file for later reference if needed:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             5.6G  273M  5.1G   6% /
varrun                506M  104K  506M   1% /var/run
varlock               506M     0  506M   0% /var/lock
udev                  506M   96K  506M   1% /dev
devshm                506M     0  506M   0% /dev/shm
/dev/sda1              89M   22M   62M  27% /boot
/dev/sdd1              17G  2.2G   14G  14% /home
/dev/sdb2             8.6G  409M  7.8G   5% /opt
/dev/sdc1              17G  698M   16G   5% /usr
/dev/sdb1             8.3G  830M  7.1G  11% /var
$ sudo blkid
/dev/sda1: LABEL="BOOT" UUID="48de23be-942e-40a7-be39-add6921ce748" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda2: TYPE="swap" UUID="1dd98489-b233-42f6-be87-93a9d6105067" 
/dev/sda3: LABEL="ROOT" UUID="7203248c-ec64-49c1-b0af-b65789733461" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb1: LABEL="VAR" UUID="86b193b4-9766-425b-9516-8a5a02219906" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb2: LABEL="OPT" UUID="7c688ba0-be4d-4c2d-90d7-5733f8195e52" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdc1: LABEL="USR" UUID="1280cfed-807a-4a80-aa7a-4270adc36288" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdd1: LABEL="HOME" UUID="72c78b11-777c-4e5c-bd46-f366b07684f4" SEC_TYPE="ext2" TYPE="ext3"
$ sudo fdisk -l
Disk /dev/sda: 9173 MB, 9173114880 bytes
255 heads, 63 sectors/track, 1115 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x600f600f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          12       96358+  83  Linux
/dev/sda2              13         377     2931862+  82  Linux swap / Solaris
/dev/sda3             378        1115     5927985   83  Linux

Disk /dev/sdb: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe0d03f83

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1094     8787523+  83  Linux
/dev/sdb2            1095        2231     9132952+  83  Linux

WARNING: GPT (GUID Partition Table) detected on '/dev/sdc'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdc: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2232    17921834+  ee  EFI GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/sdd'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdd: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        2232    17921834+  ee  EFI GPT

Disk /dev/sde: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sde doesn't contain a valid partition table

Note: /dev/sde is the new larger disk that is the target of the cloning process.

Clone the Partitions

1. Boot the system using the GParted Live CD that was created earlier. If the system cannot boot from the CD, the system’s BIOS settings may need to be changed to enable booting from the CD device.

2. During the boot process, the GParted Live CD will ask for a number of configuration selections. Selecting the defaults should work fine as long as nothing is detected incorrectly.

3. When the boot process is complete, a graphical desktop is displayed with the GParted application open and ready to use. Make note of the drop down box in the upper right hand corner of the application. This allows toggling between the source and destination devices that will be part of the cloning process.

4. The first partition that will be cloned to the new drive is the boot partition that is located on /dev/sda. Select /dev/sda using the drop down box that was described above. GParted will display all partitions on /dev/sda. The boot partition is /dev/sda1. This is easy to determine as that partition has a label of “BOOT”. If the partition did not have a label, the correct partition could still be determined from the information that was captured during the cloning preparation step.

5. In the list of partitions, select and right click on /dev/sda1. From the context menu, select “Copy”.

6. Using the drop down box, select the destination device /dev/hdd and “Paste” the partition selected in the previous step into the unallocated space. The new partition may be resized by dragging the edge of the partition window, or by manually entering the size in the form below. Repeat this step as needed until all partitions are copied over, arranged and sized as required.

Notes: In this example /dev/sde is the clone target device; however, GParted identified this device as /dev/hdd (which follows the device naming standard for an IDE drive). The fdisk command will show all IDE and SCSI drives as /dev/sd*. Do not forget to set the boot flag on the boot partition.

7. After all the partitions have been arranged and resized as needed, click the “Apply” button in the toolbar. At this point, GParted will check the source partitions for errors and attempt to repair them followed by the actual cloning of the partitions. This may take some time to complete depending on the amount of data being cloned.

8. After all the partitions have been cloned to the new drive, shutdown the system. In this example, the old drives were to be removed and used in another system. At this point, the old hard drives were disconnected but not removed from the system.

Update UUIDs

1. Restart the system with the GParted Live CD.

2. Again the GParted Live CD will ask for a number of configuration selections after which it will display the graphical desktop.

3. Subsequent steps require the UUIDs associated with the cloned partitions in order to update /etc/fstab. Open a terminal and run the blkid comand:

$ blkid
/dev/sda1: LABEL="BOOT" UUID="48de23be-942e-40a7-be39-add6921ce748" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda2: TYPE="swap" UUID="fcac9220-3d7a-4432-9a67-cca2a5414bb4" 
/dev/sda3: LABEL="ROOT" UUID="7203248c-ec64-49c1-b0af-b65789733461" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda5: LABEL="USR" UUID="1280cfed-807a-4a80-aa7a-4270adc36288" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda6: LABEL="VAR" UUID="86b193b4-9766-425b-9516-8a5a02219906" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda7: LABEL="OPT" UUID="13162a54-b57f-49a4-945b-bea31a404e46" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda8: LABEL="HOME" UUID="72c78b11-777c-4e5c-bd46-f366b07684f4" SEC_TYPE="ext2" TYPE="ext3"

4. Open another terminal and mount the root partition of the new hard drive:

mount /dev/sda3 /mnt

5. Open /etc/fstab with the pico editor:

pico /mnt/etc/fstab

The original /etc/fstab looks like this:

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/sda3
UUID=7203248c-ec64-49c1-b0af-b65789733461 /               ext3    defaults,errors=remount-ro 0       1
# /dev/sda1
UUID=48de23be-942e-40a7-be39-add6921ce748 /boot           ext3    defaults        0       2
# /dev/sdd1
UUID=72c78b11-777c-4e5c-bd46-f366b07684f4 /home           ext3    defaults        0       2
# /dev/sdb2
UUID=7c688ba0-be4d-4c2d-90d7-5733f8195e52 /opt            ext3    defaults        0       2
# /dev/sdc1
UUID=1280cfed-807a-4a80-aa7a-4270adc36288 /usr            ext3    defaults        0       2
# /dev/sdb1
UUID=86b193b4-9766-425b-9516-8a5a02219906 /var            ext3    defaults        0       2
# /dev/sda2
UUID=1dd98489-b233-42f6-be87-93a9d6105067 none            swap    sw              0       0
/dev/cdrom        /media/cdrom0   udf,iso9660 user,noauto     0       0
/dev/           /media/floppy0  auto    rw,user,noauto  0       0

6. Verifiy that the UUIDs in /etc/fstab match the UUIDs from the blkid output. The only mis-match was for the swap partition, so it was updated with the value from the blkid output. Save any changes and exit the editor.

7. Unmount /dev/sda3:

umount /mnt

Install Grub

1. Mount the boot partition /dev/sda1:

mount /dev/sda1 /mnt

2. Change the directory to /mnt and start a grub shell:

cd /mnt
sudo grub

3. From the grub prompt, run the following command:

grub> find /grub/stage1

4. The previous step will return a location e.g. (hd0,0). Use this location to run the following commands from the grub shell:

grub> root (hd0,0)
grub> setup (hd0)
grub> quit

5. Grub should now be installed to the master boot record. Reboot the system without the GParted Live CD. A grub menu should be available at startup and the system should boot using the new cloned drive.

6. If the system appears to be booting and functioning correctly, the system could now be shutdown to remove the old hard drives and move them to another system.

To Top

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *