GRUB 2 has three main parts:

  • /etc/default/grub - the file containing GRUB 2 menu settings.
  • /etc/grub.d/ - the directory containing GRUB 2 menu creating scripts.
  • /boot/grub/grub.cfg - the GRUB 2 configuration file, not editable.

As mentioned, grub.cfg shouldn't be edited as it's automatically built. RedHat recommended to use grubby for configuration

  • grubby –default-kernel - lists the default kernel
  • grubby –default-index - lists the default index
  • grubby –info=ALL - list all kernel menu entries

To make changes, the format is

grubby --remove-args="argX argY" --args="argA argB" --update-kernel /boot/kernel

Scripts in /etc/grub.d examine the system and build the boot menu dependent on what is found automatically when the kernel is updated or a new one installed

NOTE: If GRUB_TIMEOUT is set to 0, no boot menu is displayed. To display it, press and hold any alphanumeric key when the BIOS info is displayed

/etc/default/grub specifies the default kernel which is usually saved:

ip-10-51-72-53:root> #cat /etc/default/grub
GRUB_TIMEOUT=30
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=vg00/lvswap rd.lvm.lv=vg00/lvroot rhgb quiet audit=1 console=ttyS0"
GRUB_DISABLE_RECOVERY="true"

This points to the entry in /boot/grub2/grubenv with the saved_entries directive. This will be the latest installed kernel. You can change this using grub2-set-default e.g.

grub2-set-default 2

This will select the third “menuentry” line in grub.cfg ( remembering the first menu entry is 0 ). You can edit /etc/default/grub with this entry to make it a permanent. This will require a rebuild of grub.cfg

grub2-mkconfig -o /boot/grub2/grub.cfg

To add custom menu entries use /etc/grub.d/40_custom and add your script in there. This is the general format of an entry

 #!/bin/sh -e
 echo "Some string"
 cat << EOF
 menuentry "Something" {
 set root=(hdX,Y)
 -- boot parameters --
 }
 EOF

If grub breaks for some reason it can be reinstalled e.g.

 grub2-install /dev/sda (assuming /boot is on /dev/sda)

To reset and reinstall (this clears all grub settings and configs)

 1. rm /etc/grub.d/*
 2. rm /etc/sysconfig/grub
 3. grub2-mkconfig -o /boot/grub2/grub.cfg
 4. grub2-install /dev/sda

NOTE: The procedure for EFI based servers is slightly different so don't forget to RTFM!!

To use the serial interface for grub boots

 grubby --remove-args="rhgb quiet" --args=console=ttyS0,115200 --update-kernel=DEFAULT

This is just for the default kernel, you can also specify –update-kernel=ALL or a comma seperated list of kerne index numbers

If a new grub.cfg file is going to get built, update /etc/default/grub

 GRUB_TERMINAL="serial"
 GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"

(adjust the serial settings according to your hardware)

then rebuild using grub2-mkconfig command

To boot into rescue mode, at the GRUB 2 boot screen, press e (for edit) and add the following to the linux16 line

systemd.unit=rescue.target

CTRL-a goes to start of line, CTRL-e to the end. Press CTRL-x to boot with the new parameter

To go to emergency add systemd.unit=emergency.target instead. For a debug shell add systemd.debug-shell

For more information about grub recovery see our article grub recovery

Recent Changes

Contribute to this wiki

Why not help others by sharing your knowledge? Contribute something to this wiki and join out hall of fame!
Contact us for a user name and password