How to approach moving NixOS to a new disk

Hi, I have NixOS managed by flake config and updated via nixos-rebuild switch on LUKS/LVM spanning two SSD drives as shown below [1] which I want to move onto one new SSD. The process of moving LVM partitions is quite straightforward to me. My question is what to do afterwards? Do I simply nixos-enter from the installer thumb-drive into my new partition, change UUID’s in the config and run nixos-rebuild switch as I would normally? Would it install EFI on the new disk too? Thanks!

[1]

> sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/mapper/first
  VG Name               vg
  PV Size               <952.00 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              243711
  Free PE               479
  Allocated PE          243232
  PV UUID               tl9ERT-FE77-1Qng-XK0w-UEOb-vlmi-GFnZHi

  --- Physical volume ---
  PV Name               /dev/mapper/second
  VG Name               vg
  PV Size               <465.75 GiB / not usable 4.02 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              119230
  Free PE               28062
  Allocated PE          91168
  PV UUID               oZVwkl-cniZ-C6rr-O83S-JifG-lskW-h3HLAY

sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg/swap
  LV Name                swap
  VG Name                vg
  LV UUID                ws2CVl-BClT-uzOg-4G5Y-eiio-Tv8V-W41iCp
  LV Write Access        read/write
  LV Creation host, time nixos, 2022-08-10 22:57:51 +0400
  LV Status              available
  # open                 2
  LV Size                48.00 GiB
  Current LE             12288
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:2

  --- Logical volume ---
  LV Path                /dev/vg/root
  LV Name                root
  VG Name                vg
  LV UUID                KcryeH-cc01-ai66-oitj-ecxo-6nPm-39CKgW
  LV Write Access        read/write
  LV Creation host, time nixos, 2022-08-11 09:06:43 +0400
  LV Status              available
  # open                 1
  LV Size                100.00 GiB
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:3

  --- Logical volume ---
  LV Path                /dev/vg/nix
  LV Name                nix
  VG Name                vg
  LV UUID                FRZpk3-XJoz-rwC1-hX3N-6GJK-Pl61-DeK5bG
  LV Write Access        read/write
  LV Creation host, time nixos, 2022-08-11 09:07:00 +0400
  LV Status              available
  # open                 1
  LV Size                200.00 GiB
  Current LE             51200
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:4

  --- Logical volume ---
  LV Path                /dev/vg/home
  LV Name                home
  VG Name                vg
  LV UUID                NB4HLD-GHK3-egRb-hoa4-0V7z-weFb-YaRn8Y
  LV Write Access        read/write
  LV Creation host, time nixos, 2022-08-11 09:07:27 +0400
  LV Cache pool name     cache_cpool
  LV Cache origin name   home_corig
  LV Status              available
  # open                 1
  LV Size                950.00 GiB
  Cache used blocks      100.00%
  Cache metadata blocks  1.25%
  Cache dirty blocks     0.00%
  Cache read hits/misses 35514970 / 58169430
  Cache wrt hits/misses  127797426 / 43925878
  Cache demotions        170899
  Cache promotions       170906
  Current LE             243200
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:8

You can nixos-rebuild boot to a configuration that has your new disk setup before you move anything, then shut down, copy to the new disks, and boot up into the new configuration. If anything goes wrong, go back to the old disks and boot a prior generation. I’ve done this a few times to shuffle between disks and filesystems.

1 Like

it worked out perfectly smooth somewhere along the lines I have described in the post. Had to make sure the EFI partition is mounted and has proper flags for nixos-rebuild boot --install-bootloader --flake .#my-machine to work