GRUB Bootloader
Chapter 2
GRUB 2 Implementation
On BIOS-Based Systems
GRUB 2 on a BIOS-based system keeps all of its files in three different locations.
/boot/grub2/(or/boot/grub/in case of Ubuntu)/etc/default/grub/etc/grub.d/
/boot/grub2
The location where GRUB 2 is installed and holds the bootloader' core files.

Device.map
GRUB does not understand disk names like
sdaorvdasince these disk naming conventions were created by the SCSI drivers of operating systems. That's why GRUB has it's own naming conventions.

In GRUB, the hard disk starts at 0, and the partition numbers start at 1, whereas the OS naming conventions of disks and partitions start at 1.
The
Device.mapfile comes in handy here. Commands likegrub2-installmaps and converts the SCSI disk naming conventions to the GRUB disk naming conventions by reading thedevice.mapfile. Below is an example of this file:
grub.cfg
This is the main configuration file of GRUB. It's a huge script file that is generated by referring to some other script files.

Grub has it's own set of commands.

i386-pc
This directory has all the GRUB-supported filesystem modules (drivers) in it. All the *.mod files are the modules. By using these modules, GRUB can load the kernel and initramfs files in memory.

At the same time, you will find modules like
http.modandpxe.mod. This means GRUB 2’s part-3 can load the kernel and initramfs files from the http and pxe devices. In general, the*.modfiles add features, not just devices. The features may include device support, filesystem support, or protocol support.There are also some other files present here:

The
core.imgfile is part-3 of GRUB 2. So, the Linux booting sequence becomes as follows:
/etc/default/grub
This file is used by GRUB to accept the cosmetic and kernel command-line changes from the user.
We can change the default timeout of the GRUB welcome screen, the font, the submenus, and the default kernel command-line parameters like the root device name, the swap device name, etc.
/etc/grub.d
GRUB 2 has a command called
grub2-mkconfig. The name of command suggests that it will make the GRUB configuration filegrub.cfg, which will be referred by part-3 of GRUB to show the welcome screen.The grub2-mkconfig file will first take the cosmetic and kernel command-line parameter inputs from
/etc/default/gruband run the script files from the /etc/grub.d/ directory.

The
00_header,01_users,08_fallback_counting,10_reset_boot_success, and12_menu_auto_hidescript files do the housekeeping work.
10_linux
Whenever a user executes the grub2-mkconfig command , it will run this script. The 10_linux file will find out what other Linux distributions you have installed on your system.
It will literally go partition by partition and find all the other Linux versions that have been installed on your system. If there are any others, then it will make a menuentry of it in grub.cfg. Along with menuentry, it will add the respective kernel and initramfs entries.
20_linux_xen
After grub2-mkconfig , this script file will find out whether your system has the XEN kernel installed.
If it does, then it will add the appropriate entry for it in grub.cfg. Most of the Linux distributors ship XEN as a separate kernel package. XEN is mostly used by hypervisors.
20_ppc_terminfo
If your system has PPC or a PowerPC architecture from IBM, then this script file will find the respective kernel for it and will add the appropriate entry into grub.cfg.
30_os_prober
If you have any non-Linux-based OS installed on your HDD, then this script file will find that OS and will make the appropriate entry for it.
In other words, if you have Windows installed on your system, it will automatically find that out and will make an appropriate entry for it in grub.cfg.
30_uefi-firmware
This script will run successfully only if you have a UEFI system. The job of this script file is to add the appropriate entries of UEFI firmware in grub.cfg.
40_custom and 41_custom
These are given to the user in case the user wants to add some custom entries to grub.cfg. For example, if grub2-mkconfig fails to add any of the installed OS as entries, then users can add a custom entry to these two custom files.
You can make your own custom files, but you need to make sure each has a number assigned to it and has executable permission.
GRUB 2 on UEFI-Based System
GRUB 2 stores it's files at:
/boot/grub2/boot/efi/EFI/fedora//etc/default/grub
The grub.cfg file that was shown earlier in
/boot/grub2/has been shifted inside ESP (/boot/efi/EFI/fedora/).Also, there is no i386-pc directory. This is because of the rich device and filesystem support provided by EFI. Inside ESP, you will find a couple of
*.efifiles, including our shim.efi and grubx64.efi binaries.The
/etc/default/grubfile, which is responsible for GRUB’s cosmetic changes and for kernel command-line parameters, is still at the same location.The
device.mapfile is not available since the grub2-install command does not have significance on a UEFI system.
Last updated