Home > sysadmin > Cloning a linux drive

Cloning a linux drive

January 18, 2019

It’s easy to clone a linux drive to a new hd or ssd. One of the fastest ways is to create a clonezilla flash drive (see clonezilla.org), add your new drive to the system either via a usb sata adapter or plug the drive in your system, and then create and boot your clonezilla usb stick.

Use the default options on clonezilla and copy your source drive to the new drive. If the new drive is a larger drive you will have to resize it either with clonezilla or manually. The clonezilla method it kind of tricky but works fine. I am going to give you an alternative.

Once you boot the new larger drive the partition will be identical to the old drive (in my case I was updating from a 100G drive to a 500G drive).

Here are the steps:

Run fdisk /dev/sda and delete all the existing partitions (on your live system). Add a new primary partition leaving enough room for the extended partition and swap partition. Then add the extended partition using the rest of the unused space and finally add the last partition. Toggle the last partition (probably sda5) to make it swap space. Then save your changes in fdisk with the “w” command. Your drive should look like this:

/dev/sda1            2048  964691967 964689920  460G 83 Linux

/dev/sda2       964691968 1000215215  35523248   17G  5 Extended

/dev/sda5       964694016 1000215215  35521200   17G 82 Linux swap / Solaris

Reboot the system. It may take a little longer than usual. Log on. You will have to run mkswap to format your swap space ie mkswap /dev/sda5. Copy the UUID after you finish and edit /etc/fstab to show the new swap UUID.

The to utilize the new disk size you need to run resize2fs /dev/sda. This will expand your first partition to it’s full capacity. Reboot again and everything should look normal. Use the “free” and “df” commands to confirm.

Categories: sysadmin
%d bloggers like this: