Bootloader: Difference between revisions
remove link to legacy wiki |
m Use <syntaxhighlight lang=console> for shell commands and prefix them with "$" |
||
| (8 intermediate revisions by 6 users not shown) | |||
| Line 4: | Line 4: | ||
A bootloader is a type of software that manages the loading of the operating system (OS) on the computer at startup. It is responsible for preparing the system before passing control to the OS. Here are the types of bootloaders commonly used in NixOS: | A bootloader is a type of software that manages the loading of the operating system (OS) on the computer at startup. It is responsible for preparing the system before passing control to the OS. Here are the types of bootloaders commonly used in NixOS: | ||
* '''GRUB (Grand Unified Bootloader)''': Widely used, supports multiple operating systems, and provides a boot menu to select how the system boots. | * '''[[GNU GRUB]] (Grand Unified Bootloader)''': Widely used, supports multiple operating systems, and provides a boot menu to select how the system boots. | ||
* '''systemd-boot''': Simple UEFI-only bootloader, formerly known as gummiboot. | * '''[[Systemd/boot|systemd-boot]]''': Simple UEFI-only bootloader, formerly known as gummiboot. | ||
* '''[[Limine]]''': Modern, advanced, multiprotocol bootloader and boot manager. | |||
* '''EFISTUB''': Utilizes the UEFI firmware itself to boot the kernel, without the need for a traditional bootloader. | * '''EFISTUB''': Utilizes the UEFI firmware itself to boot the kernel, without the need for a traditional bootloader. | ||
| Line 24: | Line 25: | ||
The following command will print which boot mode you are using. This can be used on the NixOS installation image to determine which steps to follow in the guide. | The following command will print which boot mode you are using. This can be used on the NixOS installation image to determine which steps to follow in the guide. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
[ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy" | $ [ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== How do I remove older generations from the bootloader? === | === How do I remove older generations from the bootloader? === | ||
First, | First, remove some system generations of your system, then rebuild. The rebuild script will remove stale boot entries. | ||
The first command, in the example below, removes | The first command, in the example below, removes system generations older than 14 days. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
sudo nix- | $ sudo nix-env --delete-generations --profile /nix/var/nix/profiles/system 14d | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
sudo nixos-rebuild boot | $ sudo nixos-rebuild boot | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 69: | Line 70: | ||
}; | }; | ||
</nowiki>}} | </nowiki>}} | ||
=== Show a custom label or tags for my build in the bootloader menu === | |||
Most bootloaders like GRUB will show the NixOS version as the name of the generation (as shown with nixos-rebuild list-generations). To add a custom name for your build use [https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=system.nixos.label system.nixos.label] | |||
== Troubleshooting == | == Troubleshooting == | ||
| Line 95: | Line 100: | ||
==== From a running system ==== | ==== From a running system ==== | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
sudo nixos-rebuild --install-bootloader boot | $ sudo nixos-rebuild --install-bootloader boot | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 103: | Line 108: | ||
Booting from the installation media, mount the root partition under <code>/mnt</code> and the boot partition under <code>/mnt/boot</code>. Next, enter the installed system with <code>nixos-enter</code>, or by manually binding the virtual filesystems and then calling <code>chroot</code>. Finally, run the [https://github.com/NixOS/nixpkgs/blob/e140d71d6330786c40b4bd9c0d59af7ad1a5e86a/nixos/modules/installer/tools/nixos-install.sh#L191-L192 command that the installer would run]. This will re-install the bootloader. | Booting from the installation media, mount the root partition under <code>/mnt</code> and the boot partition under <code>/mnt/boot</code>. Next, enter the installed system with <code>nixos-enter</code>, or by manually binding the virtual filesystems and then calling <code>chroot</code>. Finally, run the [https://github.com/NixOS/nixpkgs/blob/e140d71d6330786c40b4bd9c0d59af7ad1a5e86a/nixos/modules/installer/tools/nixos-install.sh#L191-L192 command that the installer would run]. This will re-install the bootloader. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
mount /dev/[root partition] /mnt | $ mount /dev/[root partition] /mnt | ||
mount /dev/[boot partition] /mnt/boot | $ mount /dev/[boot partition] /mnt/boot | ||
</syntaxhighlight> | </syntaxhighlight> | ||
With <code>nixos-enter</code>: | With <code>nixos-enter</code>: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
nixos-enter | $ nixos-enter | ||
NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot | $ NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Or manually: | Or manually: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
for i in dev proc sys; do mount --rbind /$i /mnt/$i; done | $ for i in dev proc sys; do mount --rbind /$i /mnt/$i; done | ||
NIXOS_INSTALL_BOOTLOADER=1 chroot /mnt \ | $ NIXOS_INSTALL_BOOTLOADER=1 chroot /mnt \ | ||
/nix/var/nix/profiles/system/bin/switch-to-configuration boot | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 160: | Line 165: | ||
Some laptops, mostly those based on Intel Atom (and first-gen 2006-2007 Intel Macs), have a very strange setup: x86_64 CPU, 2-4GB of RAM, and ia-32 bootloader. They usually come with 64-bit Windows 10, which is slow and jerky on such configurations. Installing Linux on these systems is trivial, because most of the time you can just install 32-bit versions, which come with 32-bit UEFI bootloader, and not lose practically anything as amount of RAM is small enough for 32 bits of address. This is not the case with NixOS, though, because by choosing a 32-bit version you lose the prebuilt packages from nixos cache. To install a full 64-bit system with 32-bit bootloader, you need to take the following steps: | Some laptops, mostly those based on Intel Atom (and first-gen 2006-2007 Intel Macs), have a very strange setup: x86_64 CPU, 2-4GB of RAM, and ia-32 bootloader. They usually come with 64-bit Windows 10, which is slow and jerky on such configurations. Installing Linux on these systems is trivial, because most of the time you can just install 32-bit versions, which come with 32-bit UEFI bootloader, and not lose practically anything as amount of RAM is small enough for 32 bits of address. This is not the case with NixOS, though, because by choosing a 32-bit version you lose the prebuilt packages from nixos cache. To install a full 64-bit system with 32-bit bootloader, you need to take the following steps: | ||
# Download both latest "Minimal installation CD, 32-bit Intel/AMD" and "Minimal installation CD, 64-bit Intel/AMD" from https://nixos.org/nixos | # Download both latest "Minimal installation CD, 32-bit Intel/AMD" and "Minimal installation CD, 64-bit Intel/AMD" from https://nixos.org/download/#nixos-iso. | ||
# Flash 32-bit version on USB stick and boot it. If it does not boot, then you probably have a 64-bit bootloader and do not need to worry about this tutorial. | # Flash 32-bit version on USB stick and boot it. If it does not boot, then you probably have a 64-bit bootloader and do not need to worry about this tutorial. | ||
# Note: if your system hangs randomly when booted, you can try adding <nowiki>intel_idle.max_cstate=1</nowiki> to kernel parameters before booting (press e when you see systemd-boot prompt to enter editing mode). | # Note: if your system hangs randomly when booted, you can try adding <nowiki>intel_idle.max_cstate=1</nowiki> to kernel parameters before booting (press e when you see systemd-boot prompt to enter editing mode). | ||
| Line 191: | Line 196: | ||
</nowiki>}} | </nowiki>}} | ||
to the grub section of your configuration. | to the grub section of your configuration. | ||
=== Manually adding EFI boot entry === | === Manually adding EFI boot entry === | ||
| Line 198: | Line 202: | ||
Then use efibootmgr to add the entry again, where the disk device is specified, with the partition number followed by the index and finally the path to the grub boot loader. | Then use efibootmgr to add the entry again, where the disk device is specified, with the partition number followed by the index and finally the path to the grub boot loader. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
efibootmgr -c -d /dev/sda -p 1 -L NixOS-boot -l '\EFI\NixOS-boot\grubx64.efi' | $ efibootmgr -c -d /dev/sda -p 1 -L NixOS-boot -l '\EFI\NixOS-boot\grubx64.efi' | ||
</syntaxhighlight> | </syntaxhighlight> | ||