RHEL7: How to get started with GRUB2.

Share this link

Note: This is an RHCSA 7 exam objective.

Presentation of GRUB2

GRUB2 is the new Linux bootloader. GRUB2 stands for GRand Unified Bootloader version 2.

As GRUB was not maintained for some time and lacked some critical features like GPT management needed to handle disks bigger than 2.4TB, it was decided to start a new version from scratch with modularity in mind.

GRUB2 provides the following new features:

  • ability to boot on various file systems (xfs, ext4, ntfs, hfs+, raid, etc),
  • gzip files decompression on the fly,
  • management of all disk geometries,
  • support for GPT (GUID Partition Tables) and MBR (Master Boot Record),
  • portability with different architectures (BIOS, EFI, Coreboot, etc),
  • ability to load modules at execution time.

GRUB2 Organization

The GRUB2 configuration is spread over several files:

  • /boot/grub2/grub.cfg: this file contains the final GRUB2 configuration (do not edit it directly!),
  • /etc/grub2.cfg: this is a symbolic link to the /boot/grub2/grub.cfg file,
  • /etc/default/grub: this file contains the list of the GRUB2 variables (the values of the environment variables can be edited),
  • /etc/sysconfig/grub: this is a symbolic link to the /etc/default/grub file,
  • /etc/grub.d: this directory contains all the individual files internally used by GRUB2.

This tutorial will only explore knowledge required for the RHCSA exam.
Refer to the Additional Resources section for more details.

Basic Management

To get the details about the current active kernel, type:

# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-229.11.1.el7.x86_64) 7 (Core)

Note: This information is stored in the /boot/grub2/grubenv file.

To get the list of the kernels displayed at boot time, type:

# grep ^menuentry /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.10.0-229.20.1.el7.x86_64) 7 (Core)' ...
menuentry 'CentOS Linux (3.10.0-229.14.1.el7.x86_64) 7 (Core)' ...
menuentry 'CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127' ...caf

To permanently define the kernel to execute at boot time (here 0 for the first entry), type:

# grub2-set-default 0

To display the GRUB2 variables, type:

# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=115200"
GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root console=ttyS0,115200"
GRUB_DISABLE_RECOVERY="true"

Where

  • GRUB_TIMEOUT defines the boot waiting delay (here 5 seconds),
  • GRUB_DISTRIBUTOR contains the distribution name (here CentOS Linux),
  • GRUB_DEFAULT specifies the default menu entry; it can be a number, an entry name or the string saved which means the entry saved during the last reboot or the execution of the grub2-set-default command,
  • GRUB_DISABLE_SUBMENU allows (false) or not (true) the display of a submenu (see below),
  • GRUB_TERMINAL defines the terminal input & output device (here console and serial),
  • GRUB_SERIAL_COMMAND configures the serial port,
  • GRUB_CMDLINE_LINUX specifies the command-line arguments added to the menu entries for the Linux kernel,
  • GRUB_DISABLE_RECOVERY defines if all entries can be selected in recovery mode through a separate line (false) or only the default entry (true).

If you want to change the content of any variables in the previous file, you will need to type:

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

Note: This is the main command to memorize for the exam. You can also replace /boot/grub2/grub.cfg with /etc/grub2.cfg

To better understand some of the environment variables, here are the standard display with GRUB_DISABLE_RECOVERY=”true” and GRUB_DISABLE_SUBMENU=true:

      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>

      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   

If GRUB_DISABLE_RECOVERY is set to “false”, here is the new display:

      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64              
      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64 (recovery m>
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64             
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64 (recovery m>
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>

      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   

Each kernel line gets an associated line in recovery mode.

If GRUB_DISABLE_RECOVERY is now set to “true” (like in the initial standard display) and GRUB_DISABLE_SUBMENU is set to false, here is the new display:

      CentOS Linux 7 (Core)                                                     
      Advanced options for CentOS Linux 7 (Core)                               
                                                                             
      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   

If the first entry is selected (“CentOS Linux 7 (Core)”), the system boots. If the second option is chosen, the standard menu is shown with an additional line at the bottom to go back to the first menu with the Esc key:

      CentOS Linux 7 (Core), with Linux 3.10.0-229.20.1.el7.x86_64              
      CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64             
      CentOS Linux 7 (Core), with Linux 0-rescue-f19b719117b44bf3a3fb777bd4127>

      Use the ^ and v keys to change the selection.                       
      Press 'e' to edit the selected item, or 'c' for a command prompt.   
      Press Escape to return to the previous menu.                        

Additional Resources

To better explore GRUB2, you can:

(3 votes, average: 3.33 out of 5)
Loading...
13 comments on “RHEL7: How to get started with GRUB2.
  1. redhat0329 says:

    Hi CertDepot,

    So in the exam if there is a question like modify the grub timeout to 10 we just edit the /etc/default/grub file and modify the GRUB_TIMEOUT=10, then run
    # grub2-mkconfig -o /boot/grub2/grub.cfg ?

  2. ak340 says:

    Hi Certdepot, do you have a procedure in rhel 7 to create another boot device, like for example I want sdb1 to be an alternate boot device. I need to know as well how to configure it in grub so upon bootup it will boot from the preferred drive.

    • CertDepot says:

      I haven’t got any answer for you. I think you should ask your question on the ServerFault website.
      Sorry.

    • Gjorgi says:

      Alternate boot device… let’s think logically here for a bit: GRUB2 needs to know where to find the kernel and its initram image in order to boot the kernel, right? So:
      – know how to tell GRUB2 where to look for a kernel and its accompanying initramfs.
      – learn the syntax of addressing boot-capable devices when configuring GRUB2.
      – force GRUB2 into autodiscovering the new kernel and autoediting appropriate config files.

  3. terry says:

    Can you please provide all I have to do to update a linux kernel from a given url? (ex: http://server1.host1.example.com/rhcsa. )

  4. bankai says:

    Ok, I have mastered the grub2-mkconfig -0 /boot/grub2/grub.cfg command..

    I edit the file /etc/default/grub, but I can login to higher version of kernel..which is easy..but why not the lower?

    I have been mastered the grubby command as well.

  5. muhammad.shakeeb says:

    Hi CertDepot,
    I mistakenly run grub2-mkconfig -o /etc/default/grub
    Is there any way to regenerate the grub file?

    • CertDepot says:

      Edit the /etc/default/grub file, copy the content of this file shown in the tutorial:
      GRUB_TIMEOUT=5
      GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)”
      GRUB_DEFAULT=saved
      GRUB_DISABLE_SUBMENU=true
      GRUB_TERMINAL=”serial console”
      GRUB_SERIAL_COMMAND=”serial –speed=115200″
      GRUB_CMDLINE_LINUX=”rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root console=ttyS0,115200″
      GRUB_DISABLE_RECOVERY=”true”

      • muhammad.shakeeb says:

        Thanks for your reply but is there any way to re-generate through command or reinstalling package? I was wondering if this happened in live exam what will we do.

        • Lisenet says:

          You can always reset the machine (as the last resort probably).

        • Sam says:

          In an exam environment or even production machine this is something to do with caution. You don’t want the machine to be unbootable.

          With grub version 2, most updated OS use this version, there is a method to scan for kernels. Stick with manually editing the relevant file. Usually yum installs the kernel to the grub. lookup grub-probe. I would suggest testing this several times.

Leave a Reply

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |