Migrating NixOS Installation to Larger SSD without Reinstalling

Hi folks,

So I currently have a 512GB SSD in my laptop which is kinda getting annoying given that NixOS installations can get quite large. I’m thinking of buying a 2TB ssd for my laptop and migrating my system over and am wondering if I can do so without reinstalling NixOS.

I installed NixOS using the installer and opted for an encrypted drive.

So I believe I should be able to create 3 partitions on the new drive:

  • p1: boot - exactly the same
  • p2: root - Taking up all the new space
  • p3: swap - exactly the same

create a new luks partition for p2 and p3, unlock the old luks partitions and the new ones and transfer the data over, expand the ext4 filesystem and change my boot.initrd.luks.devices config (i guess before migrating the boot partition).

I’m wondering if anybody has had experience doing this or if there is something that I’m missing.

Thank you!

In general, it should work fine. You will need to pay some attention to details:

  • how you copy the filesystems, as whole disk or partition images (dd, then expand) or as data (mkfs, then rsync or tar or whatever)
  • how you mount the filesystems, by device path or label or uuid
  • boot blocks (mostly if not using UEFI)

None of the options is inherently wrong or better, if done properly. The intersection of these is what matters most. Basically, copying the filesystems as images will copy the filesystem label (and make it non-unique while both drives are connected), but not copy the partition uuid. Making new filesystems means all-new UUIDs. dd’ing the entire disk means all the same id’s, and non-unique id’s as a result. etc.

So look carefully at your filesystems.* in your config, and adjust accordingly.

1 Like