Issues when booting NixOS installed on a USB flasdrive from different computers

Hello,

I’d like to be able to boot the NixOS system that I installed on a USB flash drive from different computers.

However, when booting from a different computer, I get errors at stage 1, saying /dev/disk/by-uuid/4c07447e-1d84-4182-ba10-5d367f5ff3de is unavailable.

The NixOS system was installed on the USB flash drive via a virtual machine.
When the USB is booted from this virtual machine, the system boots fine without any issue.

Also, when checking the USB’s disk, from the computer having the boot issue (which has its own Ubuntu system installed on it), using sudo blkid, the UUID reference exists and points to /dev/sdb3.

The USB was partitioned as followed :

  • /dev/sda1 = boot / EFI
  • /dev/sda2 = root partition encrypted with luks
  • /dev/sda3 = swap partition encrypted with luks

=======================
This is my NixOS hardware config file :

{
  imports = [ ];

  boot.initrd.availableKernelModules = [ "ata_piix" "mptspi" "uhci_hcd" "ehci_pci" "usb_storage" "sd_mod" "sr_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/e46e0031-1141-4014-b91b-126a8304b5eb";
      fsType = "ext4";
    };

  boot.initrd.luks.devices."luks-fb3d7223-e4d8-4bcb-9f91-07de9bfac91c".device = "/dev/disk/by-uuid/fb3d7223-e4d8-4bcb-9f91-07de9bfac91c";

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/A07D-5B53";
      fsType = "vfat";
    };

  swapDevices = [
    { device = "/dev/disk/by-uuid/1af6561e-6ed8-447f-9340-d5bee2fb49b7"; }
  ];

  # ...
}

=======================
This is my NixOS config file :

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Bootloader.
  boot.loader.systemd-boot = {
    enable = true;
  };

  boot.loader.efi.canTouchEfiVariables = true;

  # Setup keyfile
  boot.initrd.secrets = {
    "/crypto_keyfile.bin" = null;
  };

  # Enable swap on luks
  boot.initrd.luks.devices."luks-4c07447e-1d84-4182-ba10-5d367f5ff3de".device = "/dev/disk/by-uuid/4c07447e-1d84-4182-ba10-5d367f5ff3de";
  boot.initrd.luks.devices."luks-4c07447e-1d84-4182-ba10-5d367f5ff3de".keyFile = "/crypto_keyfile.bin";

  # ...

}

I’m pretty new to NixOS and have no idea on how to solve this issue.

Any help / tips are much appreciated.

Thank you very much

Your initrd is missing drivers required to be able to detect the USB flash device.

Try changing boot.initrd.availableKernelModules to include xhci_pci, which should pull in the required bits for xHCI (i.e. USB 3.0).

If that doesn’t help, try importing the all-hardware.nix module:

imports = [
  (modulesPath + "/profiles/all-hardware.nix")
];

Importing the all-hardware.nix module solved the issue ! :smiley:

(

imports = [
  (modulesPath + "/profiles/all-hardware.nix")
];

)

Thank you very much ! :smiley:

1 Like