Ubuntu – Cloning Encrypted SSD to larger SSD

cloneencryptionssd

I currently have a 128GB SSD. Its using encryption that comes with Ubuntu.

What's the best way to clone this to another SSD that's bigger and then expand the partition to be bigger to fit this new larger SSD?

Can I just clone the disk like for like, and then use something like Gparted to expand the partition? Or does it not work like that with the encryption ?

Any help would be appreciated.

Best Answer

Assumptions:

Because I cannot comment on your post I am going to have to assume some things:

  1. Your SSD mount point is located at /dev/sdX
  2. Your bigger SSD mount point is located at /dev/sdY
  3. You are using LUKS full disk encryption
  4. Your encrypted partition is /dev/sdX1
  5. The unecrypted mount point where your file system is located is /dev/mapper/sdX1_crypt and it is using an ext4 file system

Easier Method:

The easiest and slowest way would be to use dd

sudo dd  if=/dev/sdX of=/dev/sdY bs=64k  

to copy every byte from the smaller SSD to the larger SSD. This would give you a fully boot-able system you would have to disconnect the smaller SSD in order to boot because both SSDs share the same UUID which the system uses to identify individual disks. Before booting you would expand the physical partition using fdisk.

sudo fdisk /dev/sdY

fdisk is an interactive tool, you would first delete the partition LUKS is on (because its ending address is shorter than the new bigger SSD), then you would create a new partition (the defaults fdisk uses will fill all unused space), then save (this is how software "extends" a partition). then you would expand the LUKS container using cryptsetup

sudo cryptsetup luksOpen /dev/sdY1 sdY1_crypt
sudo cryptsetup resize /dev/sdY1_crypt

and finally you would expand the files system using resize2fs

sudo resize2fs /dev/mapper/sdY1_crypt

Faster Method:

A faster and more complex method would be to create a new partition sdY1 with fdisk on the bigger SSD for the encrypted volume, then create a new LUKS volume using

sudo cryptsetup luksFormat [OPTIONS] /dev/sdY1

and mount it on sdY1_crypt.

sudo cryptsetup luksOpen /dev/sdY1 sdY1_crypt

then use dd to copy the unencrypted file system from one encryption volume to another.

sudo dd if=/dev/mapper/sdX1_crypt of=/dev/mapper/sdY1_crypt bs=64k

then expand the file system with resize2fs

sudo resize2fs /dev/mapper/sdY1_crypt

In order to be able to boot from the new bigger SSD you would have to install grub in the MBR of the SSD with

grub-install [OPTIONS] /dev/sdY

Note:

All the commands used are highly configurable and you will want to use some of their options because you know your system better than I do, use man <command> or <command> --help to learn about what they can do.

Related Question