Wednesday, January 13, 2010

Grub 2 Bootloader File Structure

GRUB 2 incorporates a totally revised folder and file hierarchy. The menu.lst of GRUB legacy is no longer used.
To find out where GRUB 2 is installed, the user can run the following commands: sudo grub-probe -t device /boot/grub for the device and sudo grub-probe -t fs_uuid /boot/grub for the UUID.

The main folders and files used by GRUB 2 include:

This is the file most closely resembling GRUB's /boot/grub/menu.lst. This file contains the GRUB 2 menu information but unlike GRUB's menu.lst the grub.cfg file is not meant to be edited.
Each section is clearly delineated with "(### BEGIN)" and references the file in the /etc/grub.d folder from which the information was generated.
grub.cfg is updated by running the update-grub command as root. The update-grub command is a stub for sudo grub-mkconfig -o /boot/grub/grub.cfg. For standardization, the command update-grub will be employed, run as "root" with the sudo.
The file is automatically updated with kernel installations/removals or other updates which would affect its output.
By default, and whenever the update-grub command is executed, this file is made "read-only". This is in keeping with the intent that the file should not be edited manually.
The user will also see a multitude of *.mod files in the /boot/grub folder. These files relect the modular nature of GRUB 2 and are loaded as necessary by the GRUB 2 bootloader.
This configuration file contains information formerly contained in the upper section of GRUB Legacy's menu.lst and items contained on the end of the kernel line. The entries in this file can be edited by a user with administrator (root) privileges and are incorporated into grub.cfg when it is updated. Specific configuration settings are detailed in the Configuring GRUB 2 later in this section.
/etc/grub.d/ (folder)
The files in this folder are read during execution of the update-grub command and their instructions are incorporated into /boot/grub/grub.cfg.
The placement of the menu items in the grub.cfg menu is determined by the order in which the files in this folder are run. Files with a leading numeral are executed first, beginning with the lowest number. 10_linux is run before 20_memtest, which would run before 40_custom. If files with alphabetic names exist, they are run after the numerically-named files.
Custom entries can be added to the 40_custom file or in a newly created file. Based on its name, 40_custom entries by default appear at the bottom of the menu. A custom file beginning with 06_ would appear at the top of the menu since its alphanumeric sorting would place it ahead of 10_ through 40_ files.
Only executable files generate output to grub.cfg during execution of update-grub.

The default files in this folder are:
00_header Sets initial appearance items such as the graphics mode, default selection, timeout, etc. These settings are normally imported from information from /etc/default/grub. Users normally do not need to make changes to this file.
05_debian_theme The settings in this file set splash image, text colors, selection highlighting and themes. In the absence of a splash image, this file sets a monochromatic theme for the initial menu display. How to set font renderings and splash images are discussed in detail in the Splash Images & Themes section.
10_hurd Locates Hurd kernels. Not currently used.
10_linux Locates kernels on the root device for the operating system currently in use. It takes this information and establishes the names displayed on the menu for these kernels.
20_memtest86+ Searches for /boot/memtest86+.bin and includes it as an option on the GRUB 2 boot menu. There is currently no line option to remove this entry from the menu. The display of memtest86+ can be inhibited by removing the executable bit from this file: sudo chmod -x /etc/grub.d/20_memtest86+ and then running sudo update-grub.
30_os-prober This file with os-prober, which searches for Linux and other operating systems. Results are placed in grub.cfg based on the scripts in this file. The file is divided into 4 sections, representing the types of operating systems handled by the scripts: Windows, Linux, OSX, and Hurd. Variables in this file determine the format of the displayed names in /boot/grub/grub.cfg and on the GRUB 2 menu. Users familiar with basic scripting can alter these variables to change the format of the displayed menu entries. Alternatively, the user can insert an entry into /etc/default/grub which disables this script. (See below)
40_custom A template for adding custom menu entries which will be inserted into grub.cfg upon execution of the update-grub2 command. The contents of this file, below the "exec tail -n +3 $0" line and the default comments, are imported directly into /boot/grub/grub.cfg without any changes.
Files in these folders must be executable to be used by update-grub. Files which are not executable will be ignored. To make a file executable, run sudo chmod +x /etc/grub.d/folder/filename

No comments:

Post a Comment