2026年11月14日

2026年11月14日

GRUB Configuration and Boot Repair: Kernel Parameters and Reinstall

This article is a localized edition of the Japanese original. Read the Japanese original

GRUB is the boot loader used by many Linux distributions. It shows the boot menu, selects which kernel to start, and specifies the parameters passed to the kernel.

This article covers the basic steps for changing GRUB settings and how to repair GRUB when it breaks and the OS no longer boots. Commands and recommended procedures differ between Ubuntu/Debian and the RHEL family (RHEL, AlmaLinux, Rocky Linux and so on), so they are described separately. The content is based on the official documentation for Ubuntu 24.04 and the RHEL 9 family as of October 2026.

Because these settings affect booting, take a snapshot or backup before you start, and for remote servers make sure you can use a console (such as the screen console in your VPS or cloud control panel).

Configuration file and how to apply changes

You write GRUB settings in /etc/default/grub and apply them by regenerating the boot-time grub.cfg with a command. grub.cfg is a generated file, so do not edit it directly (it is overwritten the next time it is generated).

Distribution Command to generate Generated file
Ubuntu / Debian sudo update-grub /boot/grub/grub.cfg
RHEL 9 family sudo grub2-mkconfig -o /boot/grub2/grub.cfg /boot/grub2/grub.cfg

update-grub is a Debian-family command that runs grub-mkconfig -o /boot/grub/grub.cfg. On the RHEL 9 family, the real configuration is /boot/grub2/grub.cfg even on UEFI machines; /boot/efi/EFI/redhat/grub.cfg is just a small file that loads it. Do not overwrite that file with grub2-mkconfig.

Main settings in /etc/default/grub

The default on Ubuntu 24.04 looks like this:

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`( . /etc/os-release; echo ${NAME:-Ubuntu} ) 2>/dev/null || echo Ubuntu`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
Setting Meaning
GRUB_DEFAULT The menu entry booted by default. 0 is the first one. saved makes GRUB remember and use a stored entry, such as the one chosen last time
GRUB_TIMEOUT Seconds to wait with the menu
GRUB_TIMEOUT_STYLE menu shows the menu; hidden waits without showing it
GRUB_CMDLINE_LINUX Parameters passed to the kernel for every boot entry (including recovery mode)
GRUB_CMDLINE_LINUX_DEFAULT Parameters passed only to normal boot entries (not added to recovery mode)

Show the boot menu

By default Ubuntu does not show the menu. To show it every time, change the following and run sudo update-grub.

GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=5

To show the menu just once without changing settings, press Esc on UEFI machines or Shift on BIOS machines right after powering on.

Add kernel parameters

Try once

Select an entry in the boot menu and press e to edit the settings for that boot. Append the parameter to the end of the line starting with linux, then boot with Ctrl+X (or F10). The change is not saved, so use this to try out parameters or to work around a bad setting that prevents booting.

Make it permanent (Ubuntu / Debian)

Append it to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub (or GRUB_CMDLINE_LINUX to apply it to all entries) and regenerate grub.cfg.

sudo nano /etc/default/grub
# Example: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash transparent_hugepage=never"

sudo update-grub
sudo reboot

Make it permanent (RHEL 9 family)

On the RHEL 9 family, per-kernel boot entries are stored in /boot/loader/entries/ (BootLoaderSpec), and the official way to change parameters is grubby.

# Add a parameter to all kernels
sudo grubby --update-kernel=ALL --args="transparent_hugepage=never"

# Remove a parameter
sudo grubby --update-kernel=ALL --remove-args="transparent_hugepage"

# Check the settings for each kernel
sudo grubby --info=ALL

Confirm the change

After rebooting, check the parameters passed to the running kernel.

cat /proc/cmdline

Change the default kernel

Ubuntu / Debian

On Ubuntu, older kernels are inside a submenu called "Advanced options for Ubuntu." That means a plain number such as GRUB_DEFAULT=2 cannot select an entry inside the submenu. Check the entry names and specify it in the form submenu name>entry name.

# List menu entries and submenu names
grep -E "^\s*(menuentry|submenu) " /boot/grub/grub.cfg | cut -d "'" -f2
# Example for /etc/default/grub (match the names to the list above)
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic"

To use numbers, write something like "1>2" (the third entry inside the submenu that is second from the top); both numbers count from 0. After the change, run sudo update-grub.

To switch the boot entry with commands, set GRUB_DEFAULT=saved, run update-grub, and then use the following commands.

# Change the default entry
sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic"

# Use a different entry for the next boot only (handy for testing a new kernel)
sudo grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic"

RHEL 9 family

# Check the installed kernels
sudo grubby --info=ALL | grep -E "^(index|kernel)"

# Change the default kernel
sudo grubby --set-default=/boot/vmlinuz-5.14.0-503.11.1.el9_5.x86_64

# Check the current default
sudo grubby --default-kernel

Match the kernel file name to the output of --info=ALL.

Repair GRUB when the system won’t boot

If GRUB itself is broken, you replaced a disk, or installing another OS overwrote the boot setup, boot from a live USB (installation media) and reinstall GRUB.

1. Check the boot mode and target partitions

Boot the live USB, open a terminal and check.

# Booted in UEFI mode? (output means UEFI, an error means BIOS)
ls /sys/firmware/efi

# Check disks, partitions and filesystem types
lsblk -f

Boot the live USB in the same mode (UEFI or BIOS) as the installed OS. For UEFI, also identify the EFI System Partition (ESP), a vfat partition of a few hundred MB. Disk names vary by environment, such as /dev/sda, /dev/vda or /dev/nvme0n1. The examples below assume the root is /dev/sda2 and the ESP is /dev/sda1. If you use LVM, activate the volumes first with sudo vgchange -ay and mount the /dev/mapper/... device.

2. Mount and chroot (Ubuntu / Debian)

# Mount the root of the installed OS
sudo mount /dev/sda2 /mnt

# If /boot is on a separate partition, mount it
# sudo mount /dev/sda3 /mnt/boot

# For UEFI, mount the ESP
sudo mount /dev/sda1 /mnt/boot/efi

# Bind the virtual filesystems so commands work inside the chroot
for d in /dev /dev/pts /proc /sys /run; do sudo mount --bind $d /mnt$d; done

sudo chroot /mnt

3. Reinstall GRUB (Ubuntu / Debian)

Run these inside the chroot. For BIOS, the target of grub-install is the whole disk (/dev/sda), not a partition (/dev/sda1).

# BIOS
grub-install /dev/sda
update-grub
# UEFI: make EFI variables visible (mount only when the directory is empty)
[ -n "$(ls -A /sys/firmware/efi/efivars)" ] || mount -t efivarfs efivarfs /sys/firmware/efi/efivars

grub-install --target=x86_64-efi --efi-directory=/boot/efi
update-grub

If you use Secure Boot on Ubuntu, also reinstall the signed packages (apt install --reinstall grub-efi-amd64-signed shim-signed).

When you are done, leave the chroot, unmount and reboot.

exit
sudo umount -R /mnt
sudo reboot

RHEL 9 family

On the RHEL 9 family, choose "Rescue a … system" under "Troubleshooting" on the installation media, and the installed system is mounted at /mnt/sysroot. Enter it with chroot /mnt/sysroot before working.

# BIOS
grub2-install /dev/sda
grub2-mkconfig -o /boot/grub2/grub.cfg
# UEFI: do not use grub2-install; reinstall the packages instead
dnf reinstall grub2-efi shim
grub2-mkconfig -o /boot/grub2/grub.cfg

On UEFI systems in the RHEL family, a signed GRUB that supports Secure Boot is shipped as a package, so the official repair procedure is to reinstall the packages rather than run grub2-install. You can check the installed package names with rpm -qa | grep -E "grub2-efi|shim".

Things to watch out for

  • Do not edit grub.cfg directly; change /etc/default/grub (or use grubby on the RHEL 9 family) and regenerate it.
  • After changing settings, confirm that generating grub.cfg finished without errors before rebooting.
  • Keep at least one older kernel installed so that, if the new kernel fails to boot, you can recover by choosing the older one from the boot menu.
  • Pointing grub-install / grub2-install at the wrong disk overwrites the boot setup of another disk. Check with lsblk before running it.

Summary

  • Write settings in /etc/default/grub and apply them with update-grub on Ubuntu/Debian or grub2-mkconfig -o /boot/grub2/grub.cfg on the RHEL 9 family
  • Add kernel parameters with GRUB_CMDLINE_LINUX_DEFAULT / GRUB_CMDLINE_LINUX, or grubby --update-kernel=ALL --args=... on the RHEL 9 family
  • For the default kernel on Ubuntu, set GRUB_DEFAULT to a name that includes the submenu or use grub-set-default; on the RHEL 9 family use grubby --set-default
  • To repair, boot a live USB, mount and chroot, then run grub-install and update-grub. On RHEL-family UEFI systems, use dnf reinstall grub2-efi shim
  • After applying changes, check with cat /proc/cmdline

Related articles:

Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)

お気軽にご相談ください

お見積りへ お問い合わせへ
▲