Introduction
In this lab, you will learn how to customize the GRUB2 boot menu in a Linux environment. GRUB2, the GRand Unified Bootloader, is the first program that runs when your computer starts, responsible for loading the Linux kernel. You will gain hands-on experience by working with its primary configuration file, /etc/default/grub, to alter the boot-up experience according to your needs.
You will begin by accessing and inspecting the default GRUB2 configuration. Next, you will modify key parameters such as GRUB_TIMEOUT to change how long the boot menu is displayed and GRUB_DEFAULT to set the default boot entry. To conclude the lab, you will apply these changes by generating a new GRUB2 configuration file with the grub2-mkconfig command and learn to verify that your customizations are properly configured.
Note: Since this is a LabEx virtual environment that is temporary and disposable, we cannot perform an actual system reboot to see the boot menu changes in action. Instead, you will learn to verify the configuration changes by examining the generated GRUB2 files, which is an equally important skill for system administrators to validate their configurations before rebooting production systems.
Access the GRUB2 Default Configuration File /etc/default/grub
In this step, you will learn how to access and view the main configuration file for GRUB2. GRUB2 (GRand Unified Bootloader, version 2) is the default bootloader for most modern Linux distributions. It's the first program that runs when you start your computer, and its job is to load the Linux kernel into memory and then start the operating system.
The primary configuration file you'll work with to customize GRUB2's behavior is located at /etc/default/grub. This file contains key-value pairs that control settings like the boot menu timeout, the default operating system to boot, and additional kernel parameters.
Before making any changes, it's essential to inspect the current configuration. Since /etc/default/grub is a system file owned by the root user, you need to use the sudo command to access it. We will use the cat command to display its contents in the terminal.
Execute the following command to view the contents of the GRUB2 default configuration file:
sudo cat /etc/default/grub
You will see an output similar to the following. The exact values might differ slightly depending on your system's configuration.
GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M rhgb quiet net.ifnames=0 console=tty0 console=ttyS0,115200n8 no_timer_check iommu=pt crash_kexec_post_notifiers=1 nvme_core.io_timeout=4294967295 nvme_core.admin_timeout=4294967295"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
Let's briefly look at two important parameters from this file:
GRUB_TIMEOUT: This value determines how long (in seconds) the GRUB2 menu is displayed before automatically booting the default entry.GRUB_DEFAULT: This specifies which operating system or kernel will be booted by default.
In the next step, you will learn how to modify these parameters to change the boot menu's behavior.
Modify the GRUB_TIMEOUT and GRUB_DEFAULT Parameters
In this step, you will modify the GRUB2 configuration file to change the boot menu's behavior. Specifically, you will increase the menu timeout and set a specific default boot entry. To edit the /etc/default/grub file, you'll use nano, a simple and intuitive command-line text editor. Since this is a system file, you must use sudo to gain the necessary permissions for editing.
First, open the file using nano with sudo privileges.
sudo nano /etc/default/grub
The nano editor will open and display the contents of the file. Now, you will make two changes:
Change the
GRUB_TIMEOUTvalue: Locate the line that starts withGRUB_TIMEOUT. It is likely set to1. Use your arrow keys to move the cursor to this line and change the value from1to15. This will make the GRUB2 menu wait for 15 seconds before automatically booting.The line should look like this after your change:
GRUB_TIMEOUT=15Change the
GRUB_DEFAULTparameter: Find the line that begins withGRUB_DEFAULT. Its value might besaved. Change this value to0. SettingGRUB_DEFAULT=0tells GRUB2 to automatically boot the first entry in the menu list (the list is zero-indexed, so0is the first entry).The line should look like this after your change:
GRUB_DEFAULT=0
Once you have made these changes, you need to save the file and exit nano.
- Press
Ctrl + O(the "Write Out" command) to save the changes. nanowill ask you to confirm the file name to write. Simply pressEnter.- Press
Ctrl + Xto exit thenanoeditor and return to your shell prompt.
You have now successfully modified the GRUB2 default settings. In the next step, you will apply these changes.
Apply and Verify GRUB2 Configuration Changes
In this step, you will apply the configuration changes you made in the previous step and learn how to verify that GRUB2 has been properly configured. You'll use the grub2-mkconfig command to generate a new configuration file based on your modifications.
Generate the New GRUB2 Configuration
Now that you have modified the /etc/default/grub file, you need to apply these changes by generating a new GRUB2 configuration file. The grub2-mkconfig command reads the settings from /etc/default/grub and the scripts in /etc/grub.d/ to create the final GRUB2 configuration.
Run the following command to generate the new configuration:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
You should see output similar to this:
Generating grub configuration file ...
Adding boot menu entry for UEFI Firmware Settings ...
done
This command scans your system for available kernels, reads your configuration settings, and creates the final GRUB2 menu configuration.
Verify Your Configuration Changes
Let's verify that your changes have been properly applied to the GRUB2 configuration. First, check that your modified settings are reflected in the /etc/default/grub file:
sudo grep -E "(GRUB_TIMEOUT|GRUB_DEFAULT)" /etc/default/grub
You should see output showing your modified values:
GRUB_TIMEOUT=15
GRUB_DEFAULT=0
Next, verify that these settings have been applied to the generated GRUB2 configuration file:
sudo grep -E "(timeout|default)" /boot/grub2/grub.cfg | head -5
This will show you how your settings appear in the actual GRUB2 configuration file.
Create a Configuration Backup
It's always a good practice to create backups of important configuration files before making changes:
sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.backup
This creates a backup copy that you can restore if needed.
Troubleshoot and Validate GRUB2 Configuration
In this final step, you will learn essential troubleshooting techniques for GRUB2 configurations and understand how to validate your changes. These skills are crucial for system administrators who need to ensure their GRUB2 modifications work correctly before rebooting production systems.
Check GRUB2 Configuration Syntax
Verify that your GRUB2 configuration has no syntax errors using the built-in syntax checker:
sudo grub2-script-check /boot/grub2/grub.cfg
If there are no errors, this command will return silently. Any syntax errors will be displayed with line numbers, which helps you identify and fix problems.
Understand GRUB2 Directory Structure
Explore the GRUB2 configuration directory structure to understand how it works. Note that this directory requires root privileges to access:
sudo ls -la /etc/grub.d/
This will show you all the scripts that generate different parts of the GRUB2 menu. Each script has a number prefix that determines the order of execution. You'll see various scripts like:
00_header: Sets basic GRUB2 configuration00_tuned: Tuned-specific configurations01_users: User configurations10_linux: Finds and adds Linux kernels20_linux_xen: Xen hypervisor support30_os-prober: Searches for other operating systems40_custom: Contains user-defined menu entries
The actual scripts may vary depending on your system configuration and installed packages.
View Available Boot Entries
Let's examine what boot entries are available in your generated configuration:
sudo grep "menuentry" /boot/grub2/grub.cfg | head -10
This command will show menu entry references and actual menu entries. The output may include both configuration variables (like menuentry_id_option) and actual boot menu entries. Look for lines that contain complete menu entry definitions.
Verify Timeout and Default Settings
Check that your timeout and default settings are properly configured:
sudo grep -E "set timeout|set default" /boot/grub2/grub.cfg
You'll see multiple timeout and default settings in the configuration file. This is normal as GRUB2 uses different timeout values for different scenarios:
- Main timeout (usually 15 seconds as configured)
- Conditional timeouts for special situations
- Different timeout styles (menu, hidden)
The key settings to verify are:
set default="0"- Sets the first menu entry as defaultset timeout=15- Sets the main menu timeout to 15 seconds
Learn About GRUB2 Recovery
Understanding GRUB2 recovery is essential for troubleshooting boot issues. In emergency situations, you can:
- Access GRUB2 command line: Press
cat the GRUB2 menu to enter command line mode - Edit boot entries: Press
eto edit a boot entry before booting - Use rescue mode: If GRUB2 can't find its configuration, it drops to rescue mode
Common recovery commands include:
ls: List available partitions and filesset root=(hd0,1): Set the root partitionlinux /boot/vmlinuz root=/dev/sda1: Load a kernelboot: Start the boot process
Final Configuration Verification
Let's do a final check of your complete GRUB2 configuration:
sudo cat /etc/default/grub | grep -E "(TIMEOUT|DEFAULT)"
This confirms your basic settings are correctly saved in the source configuration file.
What You've Accomplished:
- Modified GRUB2 timeout and default boot settings
- Applied configuration changes using
grub2-mkconfig - Learned to verify and troubleshoot GRUB2 configurations
- Created backup procedures for critical boot files
- Understood GRUB2 directory structure and recovery options
- Gained skills to validate configurations before system reboots
Your GRUB2 configuration is now properly customized with a 15-second timeout and the first menu entry as default. In a production environment, these changes would take effect on the next system reboot, providing a more user-friendly boot experience.
Summary
In this comprehensive lab, you gained hands-on experience with essential GRUB2 bootloader customization and troubleshooting techniques. You started by examining the default GRUB2 configuration, then modified key parameters including GRUB_TIMEOUT and GRUB_DEFAULT to customize the boot menu behavior. You learned to apply these changes using the grub2-mkconfig command and verify that your modifications were properly implemented.
Key skills you developed include understanding the GRUB2 configuration structure, modifying the /etc/default/grub file safely, applying configuration changes correctly, and implementing proper verification and backup procedures. You also learned essential troubleshooting techniques including syntax checking, configuration validation, and understanding GRUB2 recovery options that are crucial for system administrators.
The lab emphasized practical skills that system administrators need in real-world scenarios, particularly the ability to validate GRUB2 configurations before applying them to production systems. You learned to use commands like grub2-script-check for syntax validation and various grep commands to verify that your changes were properly applied to the generated configuration files.
These skills prepare you to handle boot configuration scenarios confidently and troubleshoot boot-related issues effectively in enterprise Linux environments. The verification techniques you practiced are especially valuable for ensuring GRUB2 configurations are correct before rebooting production systems.



