I have Ubuntu 18.04 with LUKS encryption installed on the old hard drive. I do not hide anything, just during the installation I was asked to set a password, and I did it. I decided to upgrade and bought an SSD. I want to transfer Ubuntu with all the settings to a new SSD. I have a portable hard drive and bootable USB flash drive with other Ubuntu. If I boot from this flash drive and create a disk image (using the gnome-disk utility), can I just restore this image to a new ssd? Will Ubuntu work without problems on the new SSD?

I also want to know for the future, can I do a similar trick with a new computer? Or is the best way to reinstall Ubuntu to avoid hardware conflicts with firmware, drivers, etc.?

  • I don't think there will be any problems. I did the same thing with HDD to SSD using ecryptfs, but it shouldn't matter. Your SSD must be bigger than the HDD size though. Even though you have free space, it will be included in the disk image. With a new computer, hardware will probably differ, but you might get lucky, but I'm not sure how stable it will be
    – cagri
    Sep 4, 2019 at 21:02

1 Answer 1


What you ask is possible though slightly more complicated than you're anticipating. I manage a number of computers for work and have cloned an image encrypted with LUKS to other makes/models of machines with great success.

Option 1: Use dd and clone your HDD directly to your SSD

This option is the simplest and most likely to succeed if you're not familiar with backing up and restoring system images. However, it will likely require you to get an adapter so you can connect your SSD via USB to your computer (something like this if it's a SATA drive). Additionally, your SSD would have to be the same size as or larger than your HDD.

Basically, you would attach your SSD via USB port to your computer and boot from your Live USB with your SSD drive attached. Your internal HDD would likely be at /dev/sda and your USB-attached SSD would likely be at /dev/sdb or /dev/sdc. Now to clone the drive, you would simply open a terminal and run
sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress, assuming your SSD is /dev/sdb.

This will make a bit-for-bit clone of your HDD onto your SSD. Expect this process to take a LONG time! When completed, simply remove your HDD from your computer and replace it with the SSD. Everything should boot up exactly the same, except more quickly.

Option 2: Use gnome-disks to clone the entire disk (what the OP proposed)

This is option is probably the next easiest. It also requires that your SSD be the same size as or larger than your HDD, and your external drive, to which you will save the image, must have at least as much free space as your HDD is large. This is because gnome-disks essentially creates a bit-for-bit copy of your existing system.

This process, for anyone else landing here, is pretty simple. Boot into the system with a live USB. Open the gnome-disks utility. Attach another storage device with sufficient free space. Select the internal HDD in the utility. Click the hamburger menu in the upper right corner and select "Create Disk Image..." Once the image is saved, shutdown the machine and swap the HDD and SSD. Then boot back into the live USB and reopen the gnome-disks utility. Select the SSD, click the hamburger menu and restore the disk image.

Option 3: Clone the individual, unecrypted/decrypted partitions with partclone

This is by far the most complicated option and involves the most risk, but it's doable with some research. There are a couple of added benefits to this approach. One, disk images will be magnitudes smaller if your system has lots of free space. Two, you can remove the disk encryption if you really don't want it, though you wouldn't have to. Three, this option enables you to migrate to an SSD that is smaller than your HDD but has sufficient space for the system and all of the files on your HDD.

Here is a good place to start. I'll outline the process you would take in this specific case:

  1. Boot into your system with a live USB.

  2. Backup the first 2MB of your HDD with dd. This stores all of the information about your partition table
    dd if=/dev/sda of=/path/to/external/drive/sda.mbr bs=2M count=1

  3. Backup your LUKS headers on the HDD (only if you want to restore with encryption).
    cryptsetup luksHeaderBackup ... will help you here.

  4. Unlock your LUKS partition

  5. Only if you're migrating to a smaller SSD, resize your partitions so that they will fit on the SSD. LVM and LUKS have tools that will help in this process. Be warned, if something goes wrong here, you could lose your existing system.

  6. For each partition, run partclone, saving an image of each partition (with or without compression). Note that the decrypted LUKS partition is listed in /dev/mapper/, not /dev/sdaX.

  7. Shutdown the computer and swap out the HDD with the SSD and reboot with the live USB

  8. Use dd to dump your .mbr file onto the new drive
    dd if=/path/to/external/drive/sda.mbr of=/dev/sda bs=2M

  9. Run partprobe to detect the partitions that we just created on /dev/sda

  10. Restore the LUKS header to what should be the LUKS partition

  11. Unlock the LUKS partition, taking note of which device it is in /dev/mapper/

  12. Use partclone to restore everything back to its proper partition, making sure you restore your decrypted partition back to /dev/mapper/[YOUR_DECRYPTED_LUKS_DEVICE]

  13. Run filesystem checks on all your cloned filesystems

And you're finally done! There's is lots of room for mistakes on this one, so I wouldn't recommend it if you are not comfortable with the operations I've described above.

If you were to do this, getting rid of the system encryption, you would skip steps 9 & 10, and you would restore the decrypted partition image to a regular partition. Then you would have to mount and chroot into the installed system, remove the /etc/crypttab file and run update-initramfs -k all -u so that your boot image is aware of the fact that you're no longer using encryption. You would also need to update your /etc/fstab file to point to the correct device for your / (root) partition.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .