Question about GRUB and nodev

Hi all,

There is something I don’t understand about GRUB and boot.loader.grub.device :

The special value nodev means that a GRUB boot menu will be generated, but GRUB itself will not actually be installed

What does that mean ?

What are the cases to use nodev or /dev/sdX ?

Before EFI was thing (which mandates a dedicated partition on the main disk where bootloader/kernel files are stored) the bootloader installation consisted in placing a tiny bit of machine code (I think GRUB calls this the “core image”) at the start of the disk, before any of the partitions and ragardless of the scheme (either MBR or GPT). The BIOS would then do its job (mainly setting hardware into a usable state for the OS) and finally execute that code, which whould boot the OS.

So, grub.device is for telling GRUB which disk to write its code, unless you’re doing an EFI boot, in which case you set it to “nodev”.

EDIT: There are also other reasons for using “nodev”, for example you’re doing a dual boot and want to provide a boot menu for NixOS, but want to let the other OS install and manage GRUB. But, really EFI is the main reason.

Thanks for your answer.

Referring to the documentation for installation (for example), using UEFI/GPT does mean that it is using UEFI by default no ? So nodev is to be set by default with GRUB ?

using UEFI/GPT does mean that it is using UEFI by default no ?

If you’re referring to the NixOS manual, that section (UEFI (GPT)) tells you how to partition the disk in a way that is compatible with UEFI. If you scroll down a few paragraphs you’ll see two paragraphs (BIOS systems and UEFI systems) that tell you how to configure the bootloader accordingly.

So nodev is to be set by default with GRUB ?

The default is "": honestly I’m not sure what it means, probably that you must provide a value. In any case, no, GRUB is not configured for EFI by default (grub.efiSupport defaults to false), so you’ll have to enable it explicitely and set “nodev”.

1 Like

Thanks again.

So if I am going for EFI/GRUB and Nixos is to be the only OS on the disk, I must set boot.loader.grub.device=/dev/sedX ?

No, for EFI you always want to use “nodev”. The configuration would be

  boot.loader.grub = {
    enable     = true;
    efiSupport = true;
    device     = "nodev";

This will install GRUB files under /boot (where you have mounted the EFI system partition).

1 Like

Ok. Noted. Thanks.

And if I may : when boot.loader.efi.canTouchEfiVariables is to be used ?

If you turn that on, I think, NixOS will be able to modify the BIOS boot entries and their order. The only risk is that wiping the root (say with rm -rf /*) will empty all the EFI variables and that has lead to bricking some (buggy) BIOSes in the past.

1 Like

Sorry, another dummy question :

With GRUB, set boot.loader.grub.useOSProber to true, but this will only detect windows partitions, not other Linux distributions.

Why does it not detect other linux distros ? Isn’t it (one of) the purpose of GRUB ? Seems specific to nixos no ?

I have no idea, sorry.

No problem. Thanks a lot again.