NixOS installed on external SSD but unable to boot into it

Hi everybody, I tried to install NixOS on an external SSD to have a portable OS with me, but without success. I am wondering if it is even possible to have something like this.
I used a 32GB USB with NixOS installed on it via Rufus and then from there I installed NixOS on my external 1TB SSD creating three partitions: boot, swap and root.
I’m assuming this is not enough for the partition to be recognized as a bootable device.

Is there any way to achieve this?

You’d need to mark the partition as bootable, and you’d need your BIOS to support discovering it.

I’d probably have recommended doing a UEFI install. Then the installer would’ve tried to put an explicit boot entry into the UEFI for your installation. Assuming it made that entry nicely, it should work. Also, it would install the UEFI binary to the default location (at least if you use systemd-boot), and then the firmware should discover it, too.

2 Likes

Yea, the boot loader is the first potential problem. The other potential problem is the drivers. When nixos generates its hardware-configuration.nix file, it assumes the hardware it will boot off of is the same as it installed onto. This probably won’t matter, because the drivers needed to boot a generic x86 system off of USB are most likely the same between most systems. But just in case, you might want to add "${modulesPath}/profiles/all-hardware.nix" to your imports to get a bunch of drivers that may or may not help booting on arbitrary machines.

2 Likes

I’m not really familiar with this. Is there a guide I can use to perform a UEFI install?

It should be covered fairly well as part of the Installation part of the NixOS Manual. The various steps have different callouts for legacy/uefi install to guide you to take the right steps.

Hello,
Have you managed to do it?
I’m trying to do the same without any success.
At startup the os is waiting for my drive to show up but it never appears.

How well NixOS will work on a USB SSD depends on the exact hardware in use and if all drivers needed are available but for me it works fine. I installed NixOS onto a USB-C SSD last weekend with a BTRFS on LUKS setup and there are only a few things I needed to do differently.

  • Use GPT partition table and an EFI bootloader, I prefer GRUB for a removable device. You can optionally create a BIOS boot partition for GRUB to use for booting older devices but most systems will boot in EFI mode.

  • The bootloader should be installed in removable mode which installs it to the default EFI location for most devices. This will make the USB SSD more likely to boot without issue on a new device or after plugging it back in.

  • Enable either hardware.enableRedistributableFirmware or hardware.enableAllFirmware. This will allow for greater driver support making sure you can boot on various hardware without missing drivers causing issues.

The specifics of filesystem and encryption that you choose will be a matter of personal preference but are not significantly different from installing NixOS on any other system. I did add all the kernel modules I used while booted both on bare metal and in a VM to boot.initrd.availableKernelModules but is likely not necessary if you are enabling either redistributable or all firmware as mentioned above.

This is the configuration for the specific machine I am referring to. I installed onto a 128G ASMT Verbatim Vx500 by passing the USB device through to a VM. It now works to boot bare metal as well and the only difference I’ve noticed as compared to an internal SSD is that there are occasional brief freezes during high file transfer.

1 Like

Note that there’s an option called hardware.enableAllHardware which just adds a ton of storage drivers to initrd. It’s unlikely that two different x86_64 machines need anything beyond the basic USB drivers to boot from USB, but it’s entirely plausible that some machines have weird hardware hierarchies or that you would move the drive to an internal connection or something, so enableAllHardware covers these cases.

2 Likes