GRUB 2 runs a series of scripts which search the user's computer and builds a boot menu based on what operating systems it finds. The scripts are highly configurable and produce a menu which requires little user input. When new kernels are added or the system is updated, GRUB 2 automatically rebuilds the menu to keep it current and to reflect the latest system boot options.

Nevertheless, users may want to build a menu, or part of a menu, which does not change or which allows specific inputs not easily attained via the scripts. Others may want a menu which more closely follows the way GRUB 0.97 operated. GRUB 2's custom menus allow the system to provide the basic building blocks of the boot menu while allowing the user to control what actually appears on the screen. This page details how to build and incorporate custom menus into the GRUB 2 menu.

Uses of a Custom Menu

Custom menus offer many benefits over the default GRUB 2 menu. Some of the advantages include:

Disadvantages include:

Menu Creation Background

GRUB 2 constructs the menu via a series of scripts, with each script building a portion of the menu. These scripts include /etc/grub.d/00_header and /etc/grub.d/05_header. The GRUB 2 menu configuration file (grub.cfg) includes section remarks showing which script is responsible for creating the section. The /etc/default/grub file contains most of the user-defined variables such as display time, menu resolution and default menuentry. Most custom menu users will want to allow these components to continue to operate normally.

The two scripts which actually place items into the menu are /etc/grub.d/10_linux, which locates kernels in the default Ubuntu partition, and /etc/grub.d/30_os-prober, which builds entries for operating systems found on other partitions.

For information on these files/folders please refer to the Grub2 page.

Building a Custom Menu

A sample custom menu called 40_custom is provided in the /etc/grub.d/ folder. This file can be used or copied. The current 40_custom file contains only lines which are not actually imported into grub.cfg. In general, users should honor the comments and leave these lines alone, adding custom entries below the existing lines.

The surest way to build a custom menu is to copy one or more working menuentries from the grub.cfg file. Menuentries can be placed in any order. As a minimum, a valid menuentry should include:

GRUB 2 features such as Passwords and Submenus work in custom menus. If the user doesn't wish to password-protect all menuentries, the custom menu is an easy way to designate only some of the entries while still allowing the GRUB 2 scripts to operate normally. Click the links to visit the community documentation regarding these topics.

General Menuentry Construction Rules

Custom Menu Naming

info.png The name of the file is important in that the filename number determines its position in the final GRUB 2 menu. By default, the file contents will be placed at the bottom of the GRUB 2 menu since it is run last - after 10_linux, 20_memtest86+, and 30_os-prober. If desired, the 40_custom file can be renamed to place it elsewhere in the menu:

Sample Menuentries

Maintenance-Free Menuentries

There is a potential drawback of a custom menu when the 10_linux and/or 30_os-prober scripts have been disabled. A copied Linux menuentry normally contains a specific kernel and initrd image version number (such as 3.2.0-24) and will not change if a new kernel is introduced.

If the user wishes to always boot the current kernel, the linux and initrd lines of the can take advantage of the symlinks placed in /. These links always point to the most recent kernel. If they are referenced in the menuentry and the symlinks exist, the menuentry will always point to the latest kernel.

Replace the normal linux and initrd references, which normally contain the complete kernel version, with the following:

If the user wishes to use a generic menuentry to always have the current kernel available without updating the menu, consider placing a known working kernel in another menuentry as a backup. Alternatively, learn how to edit the menuentry while booting to be able to alter it to an older kernel.

important.png If the user intends to allow automatic booting, consider:

Using GRUB Legacy Menuentries

Removing Default Script Entries

The custom menu can be used to replace either or both of the 10_linux and 30_os-prober scripts. To disable a script remove the "executable" bit by changing the Properties in a file browser run as 'root' or by running the following command on one or both of the files:

The user may also turn off the 30_os-prober script via the GRUB 2 settings file - /etc/default/grub. Add this item to the file, save it, and run sudo update-grub.

Using Only a Custom Menu

The following is one example of a way to use only a custom menu and not receive any automatic menuentry updates:


Links

Grub2

Grub2/Displays

Grub2/Installing

Grub2/Passwords

Grub2/Submenus

Grub2/Upgrading


CategoryBootAndPartition

Grub2/CustomMenus (last edited 2012-11-04 00:59:58 by par1346)