grub.cfg
grub.cfg
is the main configuration file for GRUB 2 (GRand Unified Bootloader version 2), which is the default bootloader for most Linux distributions. This file contains the configuration directives that define the boot menu entries and the various boot parameters for the operating system.
Overview of grub.cfg
grub.cfg
Location
The grub.cfg
file is typically located in the /boot/grub/
or /boot/grub2/
directory, depending on the Linux distribution and version.
Purpose
The primary purpose of grub.cfg
is to define the boot menu entries and the associated parameters for each entry. It allows users to select which operating system or kernel to boot into and pass specific parameters to the kernel at boot time.
Structure and Basic Configuration
The grub.cfg
file is automatically generated and should not be manually edited. Instead, users should modify the configuration files located in /etc/default/grub
and the scripts in /etc/grub.d/
and then regenerate grub.cfg
using the grub-mkconfig
command.
Basic Sections
Global Settings: Defines global parameters such as default boot entry, timeout, and appearance settings.
Menu Entries: Defines individual boot entries, specifying the kernel, initrd, and other boot parameters for each entry.
Example of grub.cfg
grub.cfg
Here is an example of a grub.cfg
file:
Key Directives
set default=0: Sets the default boot entry (0 corresponds to the first entry).
set timeout=5: Sets the timeout before the default entry is automatically booted.
menuentry 'Ubuntu, with Linux 5.4.0-42-generic': Defines a boot menu entry.
linux /boot/vmlinuz-5.4.0-42-generic: Specifies the kernel to be booted.
initrd /boot/initrd.img-5.4.0-42-generic: Specifies the initial RAM disk.
Generating grub.cfg
grub.cfg
To regenerate grub.cfg
, use the following command:
This command reads the configuration files from /etc/default/grub
and the scripts in /etc/grub.d/
, and then generates a new grub.cfg
file based on these settings.
Customizing GRUB Configuration
To customize the GRUB configuration:
Edit
/etc/default/grub
: Modify general settings like the default boot entry, timeout, and kernel parameters.Example:
Edit scripts in
/etc/grub.d/
: Add or modify specific menu entries and advanced settings.Regenerate
grub.cfg
: Apply the changes by running:
Conclusion
grub.cfg
is an essential file for the GRUB 2 bootloader, containing configuration settings and boot menu entries. Properly managing and customizing grub.cfg
through the appropriate configuration files and scripts ensures a smooth and flexible boot process for Linux systems.
Last updated