GRUB 2 is the default boot loader for Ubuntu. GRUB 2's method of building the GRUB menu is vastly different from GRUB 0.97. This page describes the new file structure and details how to the user can change the default settings used to create the boot menu.

The current version of GRUB is 1.99, which was introduced with Ubuntu 11.04, Natty Narwhal and is the version installed with 12.04, Precise Pangolin LTS. The documentation on this page applies to GRUB 1.99 unless otherwise noted. To determine your version, use grub-install -V.

Introduction

GRUB 2 builds its menu (grub.cfg) by running scripts found in the /etc/grub.d/folder and the settings in the /etc/default/grub file. This file is recreated automatically whenever the update-grub command is run. This command activates scripts which by default determine the status of the current Ubuntu OS and search the system for other operating systems which, if found, are added to the GRUB 2 menu. The update-grub

File Structure

GRUB 2 incorporates a totally revised directory 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:

From the GRUB 2 menu at boot, the user can also determine which Ubuntu is controlling the boot on a multi-OS system. By default, the first menuentry always lists an option from the installation which is in charge of GRUB 2. For example, if the first menuentry contains "on sda5, then the GRUB installed on sda5 OS is controlling the menu/boot.

Main Directories & Files

The Menu: /boot/grub/grub.cfg

grub.cfg is the file which replaced GRUB 0.97's menu.lst. This file contains the GRUB 2 menu information but unlike GRUB's menu.lst the grub.cfg file is not normally edited directly. The file is the result of various scripts which build the menu in sections, with each script responsible for a specific part of the menu.

File Layout

Editing grub.cfg directly

User Settings: /etc/default/grub

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. 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.

While the most common settings are present in the default file, additional environmental settings are available for inclusion in this file. These include items such as backgrounds and themes. The pre-defined variables are contained in /usr/sbin/grub-mkconfig and can be listed using the following command:

Common settings are detailed in the Configuring GRUB 2 section.

Scripts: /etc/grub.d/

The scripts in this directory are read during execution of the update-grub command and their instructions are incorporated into /boot/grub/grub.cfg.

Script Descriptions

Configuring GRUB 2

Configuration changes are normally made to /etc/default/grub and to the custom files located in /etc/grub.d. Any changes made directly to the /boot/grub/grub.cfg are overwritten whenever update-grub is executed either by the user or when called automatically by various system functions.

After editing /etc/default/grub or the scripts in the /etc/grub.d folder the user should run sudo update-grub to incorporate the changes into the GRUB 2 menu.

info.png Some of the most common changes, such as the default OS/kernel and menu timeout, can be changed from within a GUI applications such as Grub Customizer.

/etc/default/grub

This file contains basic settings which would be considered normal for the user to configure. Options include the time the menu is displayed, the default OS to boot, etc. The default options included in file upon installation are only a small number of the variables which GRUB 2 can recognize. The GRUB 2 defined variables can be identified using the command previously documented in the GRUB 2 Settings section or at the end of this section.

In addition to the defined variables, the user may introduce self-created variable(s) and use them in the scripts contained in the /etc/grub.d folder.

Editing the File

The grub file is a system file, therefore any editing must be done by a user with 'Administrator/root' privileges. The file is a simple text file and can be edited by any text editor. In Ubuntu the default text mode editor is nano and the graphical mode editor is gedit, and the file can be edited with one of the following commands. The "&" allows the terminal to be used to update GRUB 2 once the user saves the file.

or in graphical mode

After making changes and saving the file, the GRUB 2 menu must be updated to include the changes by running:

Specific Entries

This section details some of the entries available in the /etc/default/grub file. Much of this information can also be found by referring the the Gnu GRUB manual or on the system itself by running the following command:

info.png To inspect the currenlty-available predesignated variables on your system's GRUB 2 library files, run:

User-Assigned Variables

Links

External Links


CategoryBootAndPartition

Grub2/Setup (last edited 2023-04-22 16:01:24 by nio-wiklund)