How to regenerate `/etc/default/grub`?

While I was trying to fix a NVIDIA issue, I foolishly removed the /etc/default/grub file. I read that it is supposed to be regenerated by the post-installation script from the grub2-pc package. However, I cannot reinstall the grub2 packages and I do not know why (why they are unavailable).

sudo dnf reinstall grub2-common.noarch grub2-pc.x86_64 grub2-pc-modules.noarch grub2-tools.x86_64 grub2-tools-minimal.x86_64 grubby.x86_64

Last metadata expiration check: 0:22:32 ago on Sun 16 Oct 2022 03:27:21 PM CEST.
Installed package grub2-common-1:2.06-53.fc36.noarch (from updates) not available.
Installed package grub2-pc-1:2.06-53.fc36.x86_64 (from updates) not available.
Installed package grub2-pc-modules-1:2.06-53.fc36.noarch (from updates) not available.
Installed package grub2-tools-1:2.06-53.fc36.x86_64 (from updates) not available.
Installed package grub2-tools-minimal-1:2.06-53.fc36.x86_64 (from updates) not available.
Dependencies resolved.
===================================================
 Package  Arch     Version         Repo       Size
===================================================
Reinstalling:
 grubby   x86_64   8.40-67.fc36    updates    34 k

Transaction Summary
===================================================

Welcome to ask.fedora

Have a look if this commands there help you.

The grub2-tools-1:2.06-53.fc36.x86_64 package was an update and is no longer availble because It has been updated to grub2-tools-1:2.06-54.fc36.x86_64.

You may want to try: sudo dnf update grub2-tools

That’s probably the case for the rest of these packages as well.

I’d make sure all grub2 packages are up to date and then reinstall them:

sudo dnf dsync grub*
sudo dnf reinstall grub*

The commands worked, but /etc/default/grub is still missing. It seems that the post-installation script of grub2-pc does not regenerate the file, although this AskUbuntu question suggests that it should.

This does not help, cause I already have the proprietary NVIDIA driver installed and the other steps require the /etc/default/grub file to be present.

Check the documentation, it says the templates are in /etc/grub.d/to recreate it …
Working with the GRUB 2 Boot Loader :: Fedora Docs

Mine /etc/grub.d/ looks this way:

00_header             10_linux               14_menu_show_once  30_os-prober      40_custom
01_users              10_reset_boot_success  20_linux_xen       30_uefi-firmware  41_custom
08_fallback_counting  12_menu_auto_hide      20_ppc_terminfo    35_fwupd          README

do you have them too?

1 Like

I should admit that I have not read that specific documentation web page thoroughly. I do have that directory and its contents look similar.

This might also helps:
https://docs.fedoraproject.org/en-US/fedora/latest/system-administrators-guide/kernel-module-driver-configuration/Working_with_the_GRUB_2_Boot_Loader/#sec-Making_Persistent_Changes_to_a_GRUB_2_Menu_Using_the_grubby_Tool >> grubby tool

p.s.
Generally fedora is always a bit ahead of Ubuntu, and it also has some own tweaks sometimes … so refer to fedroa.docs might helps you better than ask-ubuntu.

Assuming for the most part you have insatlled the defaults:
I copied this from F37 default instail with BTRFS

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true

you may need to check grubby --info=ALL to verify the arguments for GRUB_CMDLINE_LINUX

Current kernel boot parameters can be checked also with cat /proc/cmdline and earlier ones in journalctl - by searching for BOOT_IMAGE=.

/etc/default/grub is provided by grub2-tools

# dnf provides /etc/default/grub
Last metadata expiration check: 0:42:09 ago on Sun 16 Oct 2022 05:07:30 PM CDT.
grub2-tools-1:2.06-29.fc36.x86_64 : Support tools for GRUB.
Repo        : fedora
Matched from:
Filename    : /etc/default/grub

grub2-tools-1:2.06-54.fc36.x86_64 : Support tools for GRUB.
Repo        : updates
Matched from:
Filename    : /etc/default/grub

1 Like

The file /etc/default/grub is built by anaconda during initial installation and after that there is nothing to recreate it. The file is owned by grub2-tools, but as a ghost file, which means that the the file is not provided by grub2 tools.

Therefore you can copy-paste the copy provided by @grumpey and modify it as needed.

@vekruse You are right, the file is owned by grub2-tools, but rpm -V grub2-tools does not complain if it is not there. Bad luck if you delete it by accident. Grepping anaconda files shows that It is created by
/usr/lib64/python3.10/site-packages/pyanaconda/modules/storage/bootloader/grub2.py where you find the template but there are some “%s” to be filled in.

Shouldn’t using grub2-mkconfig as sudo make the file for you?

No. grub2-mkconfig uses that file as input, but does not modify it in any way.

Well then as it belongs to anaconda, shouldn’t it also be on the installer image and therefore the op could just copy it over to /etc no? Just mount an installation media and browse for the file, it is likely in /usr/lib right?