Moving a Linux Server to a larger drive

Recently I had a 512GB NVME drive that was getting too small. The operating system was Ubuntu 22.04 and Ubuntu server uses an LVM file system by default.

My goal was to image the 512GB drive so that I could have an image backup and also so that I could restore the image to a new 2TB NVMe drive.

  1. Image the drive (Drive inserted into USB 3.1 Gen 2 external adapter on another machine). We don’t want the OS to be running. So, imaging is taking place on another machine. The image is done to a file rather than disk to disk because I wanted a backup and also I had only one USB 3.1 Gen2 external NVMe adapter.

  2. Restore the backup to the new drive (Insert new 2TB into the USB 2.1 Gen 2 external adapter)

  3. Extend the LVM volume size from 474GB to use all the free space on the new 2TB drive.

  4. Although the volume is resized, we need to resize the file system inside of the LVM volume to use the extra space. First find out the name of the LVM Path.

  5. Resize the file system inside of the LVM Volume to use all the space in the volume.

You can see that all of the drive space is used on the logical volume.


NOTE: In a recent copy from one system drive to another larger one, I used Clonezilla instead of “dd”.

In following the process outlined herein, I had an issue. Clonezilla has an option to clone from a smaller drive to a large drive and this option says that it can resize the partitions on the fly.

That didn’t work. The reason is because Ubuntu Server uses the Logical Volume Manager (LVM) in which to place its root partition. This LVM volume is inside of the /dev/nvme0n1p3 partition on the NVME drive.

This partition doesn’t show up in a “df” command and the /dev/mapper/ubuntu–vg-ubuntu–lv location where the LVM is located shows as completely allocated.

To fix this we must boot from another OS and I suggest an Ubuntu Live CD. This will prevent the file system on the NVME drive that we want to expand from being locked.

Execute the following commands.

sudo e2fsck -f /dev/nvme0n1p3
sudo resize2fs /dev/nvme0n1p3

The above will resize the ext4 partition on which the LVM is located. Now we can extend the LVM partition:

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Then, we can expand the file system inside the LVM partition which is the root partition.

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv