How to Clone a HD/SSD to a Larger HD/SSD on Linux Systems

For an Ubuntu 20.04 server, I bought a new SSD and wanted to replace the existing SSD. Of course I wanted to keep all the existing data and replicate it to the new drive. In my case, the old SSD had a cpacity of 250 GB and the new one 500 GB. I decided to summarize how I achieved this for future reference and hope that it might be useful to someone else as well.

Make Backups

Before doing anything, make backups of everything because the following operations are not trivial and might damage the file system.

Connect the New Drive

Shut down the server and connect the new HD/SSD to your mainboard. Once connected, the new drive should show up when entering the command lsblk on the console.

Create a Clonezilla Live USB Stick

To clone the SSDs, I used the excellent tool Clonezilla. The instructions how to create a bootable USB stick can be found here. Once the stick is ready, plug it into your server and reboot. While rebooting, press the key for your mainboard’s boot menu (this is mainboard-specific, in my case it was F11) and choose the USB stick. Alternatively, reconfigure the sequence of the boot devices in your BIOS. The key to get into the BIOS configuration on startup is also mainboard-specific, but in most cases it is the DEL (delete) key.

Clone the Existing Drive to the New Drive

Once clonezilla is started, follow these instructions.

My clonezilla initially wouldn’t start up because it hung at the step Configuring keyboard. I could solve this by editing the command line for the clonezilla option. For that, highlight the option Clonezilla live (to RAM) and then press e. Now you should be able to edit the command line. Locate the parameter keyboard-layouts= and set a value, for example in my case keyboard-layouts=de (an American keyboard layout would be keyboard-layouts=us). Then press Ctrl + X to start Clonezilla.

For reference, I chose the following options:

  • Ask which action to take after finishing the clone operation
  • No file system checks

I am aware that this could also be achieved using dd, but this is not the best solution because this will result in a lot of unnecessary write operations on the new drive. Background: dd copies every single byte, even from areas on the source drive that don’t contain any data (zero bytes). Refer to this askubuntu page for more details.

After clonezilla finished, disconnect the new drive and then reboot the machine with only the new drive connected. If everything worked fine, your server should start up exactly as before.

Adjust the Partition Size

Run the command lsblk again. You will notice that the new drive still shows the capacity like the old drive. The reason is that the partition tables were also copied, and these now still contain the values for the old drive.

To update the partition table, run the command parted with the partition to be altered as parameter. For example, if the new drive has the device name /dev/sdc and the second partition is the one to be altered, run parted /dev/sdc2. In parted, enter print to show the partitions again and verify the number of the partition to be altered (in my case 2).

In the next step, enter resizepart 2 (if 2 is the partition number). You will be promted for the new size of the partition. Because I wanted the partition to take all the remaining space, I entered the complete size of the new SSD (in my case 500GB). Because of the boot partition, which takes about 512 MB and some additional space needed for the file system, the effective size of the partition is smaller (about 465 GB), but higher values can be entered, resulting in the remaining available space automatically.

The last step is to make the whole partition size available to the filesystem. This is done with the command resize2fs /dev/sdc2 (adjust device and partition name accordingly), which works for ext2, ext3 and ext4 file systems. I found the essential information about this part on this stackexchange page.

That’s all. I hope this will help you to upgrade your Linux system drives.

One thought on “How to Clone a HD/SSD to a Larger HD/SSD on Linux Systems

  1. Pingback: Migrating to new drive using Clonezilla - - Latest Web Hosting News

Leave a Reply

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