Bootloader: Difference between revisions
hkps://keys.openpgp.org Tags: Mobile edit Mobile web edit |
m Use <syntaxhighlight lang=console> for shell commands and prefix them with "$" |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
== FAQ == | == FAQ == | ||
| Line 34: | 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> | ||
| Line 44: | Line 35: | ||
The first command, in the example below, removes system generations older than 14 days. | The first command, in the example below, removes system generations older than 14 days. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
sudo nix-env --delete-generations --profile /nix/var/nix/profiles/system 14d | $ 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 109: | 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 117: | 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 211: | 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> | ||