It is easy to create a mbr bootable USB stick, but seems not so straight forward to create a uefi one.
Uefi bootloader exists not only on the target usb stick, but also in the system’s from in the form of booting record.
But how did the nixos installation iso image do that ? Is it possible to create a usb stick with uefi bootloader, that is able to boot on any machine with uefi support?
Following is how I managed to create a mbr bootable USB stick:
On a nixos machine, create the dos partition table on the USB key and create the boot and / fs.
mount / to /mnt, mount boot to /mnt/boot
nixos-generate-config --root=/mnt to create necessary .nix file in /mnt/etc/nixos and modify them.
nixos-install --root=/mnt
Then unplug this USB key and it can be used to boot any machine confined to mbr bootable.
In the POST progress press some key (e.g., F12) to get the boot order menu and select the USB key, then the nixos will boot.
It does not work for me if I want to create a uefi bootable USB key.
The building nixos live iso section seems not apply to my question.
After some googling, I think the solution is related to BOOTX64.EFI, which enables the uefi bios regard the disk to be bootable, even though it is not registered in the nvram.
The typical way of making a bootable USB is to burn a live ISO to a USB using dd, as the NxOS installer does. Is there a reason why this isn’t what you’re looking for?
If you have a UEFI partition set up, in theory the motherboard should go look for bootable files in the efi partition unless one of the various fast boot modes are configured. BOOTX64.EFI is a fallback supported by most firmwares, creating it should let you boot the stick from most motherboards if you select the USB.
Well, if you’re dumping a raw filesystem onto your USB, you can make it do whatever you want it to do when it’s booted. There’s no magic difference between installing to a USB vs a raw file system and then dumping that file system to a USB.