Unable to boot from a USB device with a LUKS partition

I thought I would install NixOS on a USB stick in case something goes wrong with my computer, so I can easily boot on some kind of rescue system.

I used my current NixOS config as a base, adapting the paths to the disks to point to the correct partitions on the new disk. But when booting on the USB disk, I get the following message, and the boot fails:

Waiting 10 seconds for device /dev/disk/by-uuid/defc30d1-57be-4b69-9519-b39812a04172 to appear… failure
/dev/disk/by-uuid/defc30d1-57be-4b69-9519-b39812a04172 is unavailable

An error occurred in stage 1 of the boot process, which must mount the root filesystem on /mnt-root and then start stage 2.

Plugging the USB disk while on my live system, I can see the partition is reachable under this path (it’s a luks partition, and cryptsetup luksOpen it works correctly). The luks configuration looks like this:

  boot.initrd.luks.devices = {
    root = {
      device = "/dev/disk/by-uuid/defc30d1-57be-4b69-9519-b39812a04172";
      preLVM = true;

I’ve tried adding all the modules I could find to boot.initrd.kernelModules ([ "dm-snapshot" "usb_storage" "sd_mod" "ehci_pci" "ohci_pci" "usbhid" "ahci" "sata_nv" "dm_mod" "dm_crypt" "cryptd" "xhci_hcd" ] ++ config.boot.initrd.luks.cryptoModules) to no avail.

Am I missing something obvious? Is there a way that would help me identify the source of the issue?

Presumably when it fails you see an option to reboot or continue.

Setting boot.kernelParams = [ "boot.shell_on_fail" ]; will add an option to drop into a busybox shell where you can inspect the environment. Maybe that will be enough for you to figure out where things have gone wrong.

When using systemd-boot, I also have to set boot.loader.systemd-boot.consoleMode = "auto";, if I recall correctly.

At one point in my trials the boot failure said it could not give me a console unless I configured root with a password. I did that until I finished debugging; although I am not certain it was necessary with all my other changes.

Thanks for the pointer! I was able to get a shell, and looking at dmesg showed that the USB controller is recognized, but the disk was not recognized (as if there was no disk in it). I compared with the dmesg output on my running system (which recognizes the disk) and noticed it used the uas module. Adding uas to the list of kernel modules did the trick. :slight_smile: