Search code examples
nixnixos

How can I change the UUID of my nixos OS partition, and update the bootloader?


So essentially I've got an exact clone of my partition (I've changed the UUID though), and I'd now like to change over the bootloader to load the new partition.

What I tried:

I naively (while booted / running on the original partition) tried to modify the hardware-configuration.nix (on the original partition) with the new UUID and then tried to:

  1. sudo nixos-rebuild switch
  2. sudo nixos-rebuild boot

Both which fails** at the point of mounting the drives (I think).

updating GRUB 2 menu...
lsblk: /dev/mapper/no*[0-9]: not a block device
lsblk: /dev/mapper/raid*[0-9]: not a block device
lsblk: /dev/mapper/disks*[0-9]: not a block device
Found Arch Linux on /dev/sdb3

Also, I'd assume I'd possibly need to mount this new partition somewhere (unless, this isn't required to actually boot into it (after a reboot)?).

** Actually although it appears to 'fail', when I reboot, and select the usual nixos grub entry, I see the following (the UUID mentioned is the UUID that does exist - and it's the new partition):

enter image description here


Worst case scenario, it seems I'd be able to use a nixos live USB to mount the new partition to /mnt and then just follow the usual nixos-install (which has worked in the past - with only the /etc/nixos directory present though)?


Solution

  • Firstly, get the system in working order again by changing the UUID back in hardware-configuration.nix and making sure it boots OK.

    Next, change the UUID in hardware-configuration.nix, like you have done before, but this time run sudo nixos-rebuild boot.

    When you reboot you'll have a new entry in your systemd-boot or GRUB2 menu. The new entry will boot NixOS from the new partition.