How to boot into GRUB in Linux

Home > Search > How-to
  by

Booting into GRUB is typically a straight forward process in Linux, as GRUB is included with the install of the operating system. You power on the system, and the GRUB boot loader appears. If the GRUB boot loader does not appear during boot, the grub timeout is 0 or is hidden (explained below).

 


GRUB Configuration File

There are a number of different GRUB files on the system.

File Description Editable
/boot/grub2/grub.cfg This is the file that is used during boot. Do not edit this file.
/etc/grub2.cfg This is a symbolic link to /boot/grub2/grub.cfg. Do not edit this file.
/etc/default/grub This is the file that contains the GRUB variables. You can edit this file.
/etc/sysconfig/grub This is a symbolic link to /etc/default/grub. Do not edit this file.
/etc/grub.d This is a directory that contains additional files used by GRUB. Do not edit these files.

 

Different Linux distributions may have a slightly different location and name of the GRUB files. The find command can be used if your GRUB files are no located at the locations describes in the table above.

Following is one possible configuration of the /etc/default/grub file. In this example, GRUB_TIMEOUT=5 will display the GRUB screen for 5 seconds. Also, there is no hiddenmenu option, to ensure the GRUB screen is not hidden.

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="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

 

When making changes to the GRUB configuration file, the grub-mkconfig command is required to write the changes.

~]# grub-mkconfig -o /path/to/grub.cfg
~]# grub2-mkconfig -o /path/to/grub.cfg

 


Interacting with GRUB

There are 4 options at the GRUB screen.

  • Select a kernel to boot into.
  • Press e (edit)
  • Press c (command line)
  • Press esc (boot command)

 

Select a kernel to boot into

The GRUB screen lets you select a kernel image to boot from. You can simply highlight the kernel image you want to boot from and then press enter to boot the Operating System. Or, you can wait for the GRUB timeout to occur, which is 5 seconds in the example above, and GRUB will automatically boot into the highlighted kernel.

 

If there is more than one kernel displayed, and you want a certain kernel to be the default selected kernel, in the Linux OS, display the kernels.

~]# grep ^menuentry /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.10.0-514.26.2.el7.x86_64) . . .
menuentry 'CentOS Linux (3.10.0-354.el7.x86_64) . . .

 

To use the first displayed menu entry, use 0. To use the second displayed menu entry, use 1. 

~]# grub2-set-default 0

 

e (edit)

At the Grub menu, press e to view and edit the boot parameters. Probably the most relevant information are the last two lines, the kernel and parameters that will be used. As an example, the word quiet can be deleted to display boot events during boot.

setparams 'CentOS (0-rescue-267bb7480fba4992ab1df88567ef7f4e) 7 (CentOS)'

  load_video
  insmod gzio
  insmod part_msdos
  insmod ext2
  set root='hd0,msdos1'
  if [ x$feature_platform_search_hint = xy ]; then
    search --no-floppy --fs-uuid --set=root  --hint-bios-hd0,msdos1  
    --hint-efi=hd0,msdos1 --hint-baremetal=achi0,msdos1  --hint='hd0,msdos1'
   fdcbf0db-a5e6-484a-b232-111c2cd7dac3
  else
    search --no-floppy --fs-uuid --set=root fdcbf0db-a5e6-484a-b232-111c2cd7dac3
  fi

  linux16 /vmlinuz-0-rescue-267bb7480fba4992ab1df88567ef7f4e root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet
  initrd16 /initramfs-0-rescue-267bb7480fba4992ab1df88567ef7f4e.img

 

c (command line)

Press c to enter the GRUB command line prompt. Use the ls (list) command to display the available boot devices. In this example, HD0 has three partitions, HD1 has two partitions, and FD0 has one partition.

grub> ls(hd0) (hd0,msdos2) (hd0,msdos1) (hd1) (hd1,msdos1) (fd0)

 

The ls command followed by a partition followed by a forward slash will display relevent files in the partition. In this example, HD1 contains the files needed to boot the operating system.

grub> ls -l (hd1)/
DIR         20170506034529 lost+found/
DIR         20170506025829 grub2/
5977368     20151005155904 vmlinuz-3-10-0-327-el7.x86_64
3152021     20151005155804 System.mpa-3-10-0-327-el7.x86_64
160270      20151005155834 config-3-10-0-327-el7.x86_64
192204823   20151005155835 initramfs-3-10-0-327-el7.x86_64.img
49444479    20170506025735 initramfs-0-rescue-267bb7480fba4992ab1df88567ef7f4e.img
5977368     20170506025746 vmlinuz-0-rescue-267bb7480fba4992ab1df88567ef7f4e
217633      20170506025746 initrd-plymouth.img

 

At the next prompts, you will enter the kernel and parameters to use. You may want to use similar kernel and parameters from the GRUB edit screen. If all goes well, the machine will successfully boot.

grub> linux16 /vmlinuz-0-rescue-267bb7480fba4992ab1df88567ef7f4e root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb
grub> initrd16 /initramfs-0-rescue-267bb7480fba4992ab1df88567ef7f4e.img
grub> boot

 

Esc (boot command)

Pressing esc will display the boot command. This is typically used when you want to perform a kickstart installation of Linux. In this example, a kickstart installation is started using the ks.cfg file on an NFS share.

boot: linux ks=nfs:10.7.57.151:/share/ks.cfg

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments