Grub2
转自 https://help.ubuntu.com/community/Grub2
Important note: Configuration changes are normally made to /etc/default/grub and to the custom files located in /etc/grub.d. The /boot/grub/grub.cfg file should not be edited by the user; changes to this file are made by configuration scripts. After editing /etc/default/grub, you need to run sudo update-grub for your changes to take effect on the next boot.
Some of the most common changes, such as the default OS/kernel and menu timeout, can be changed from within a GUI app called StartUp-Manager. See the community doc StartUpManager for information about how to install and use this application.
GRUB_BACKGROUND - Sets the background image, enter the full path to the image here. See splash image configuration above for further details.
GRUB_DEFAULT - Sets the default menu entry. Entries may be numeric, a complete menuentry quotation, or "saved"
GRUB_DEFAULT=0 Sets the default menu entry by menu position. As in GRUB, the first "menuentry" in grub.cfg is 0, the second is 1, etc.
GRUB_DEFAULT="xxxx" An exact menu entry, including the quotation symbols, may also be used. In this case, location in the menu will not matter. Example: GRUB_DEFAULT="Ubuntu, Linux 2.6.31-9-generic"
GRUB_DEFAULT=saved
The default OS will not be set by an interactive selection of an OS from the menu.
grub-set-default Sets the default boot entry until changed.
The format is sudo grub-set-default X, with X being the menu entry position (starting with 0 as the first entry) or the exact menu string. Examples: sudo grub-set-default 3 or sudo grub-set-default "Ubuntu, Linux 2.6.32-15-generic"
To obtain the existing menu entry choice number (starting from 0) or the menu entry "string", run grep menuentry /boot/grub/grub.cfg
grub-reboot This command sets the default boot entry for the next boot only. The format of the command is the same as for grub-set-default (see above).
GRUB_SAVEDEFAULT= If set to true this setting will automatically set the last selected OS from the menu as the default OS on the next boot.
This option currently does not work if your /boot directory resides on an LVM partition or RAID.
GRUB_HIDDEN_TIMEOUT=0
The default behavior is to hide the menu if only one operating system is present. If a user with only Ubuntu wishes to display the menu, place a # symbol at the start of this line to disable the hidden menu feature.
Note to multiple-OS users: If GRUB 2's os-prober identifies additional operating systems while running the /etc/grub.d/30_os-prober script the hidden menu timeout feature is disabled by conditional statements. This also disables the ability to use the SHIFT key to display the menu during boot. Users with multiple operating systems wishing to hide the menu can find script edits on various forums which will allow them to add a hidden timeout feature to the boot sequence (for example: ubuntuforums).
GRUB_HIDDEN_TIMEOUT=0 on single operating system computers.
To display the menu under this condition, place a # symbol at the start of the line and ensure the GRUB_TIMEOUT setting is a positive integer.
If the value is set to 0, a keystatus check is performed to determine if the SHIFT key is depressed. If GRUB 2 determines the SHIFT key is depressed during the boot process, the menu will be displayed. This gives the user a method of interrupting an automatic boot which would normally not display the menu.
GRUB_HIDDEN_TIMEOUT=X
X is a positive integer (e.g. 1, 5, 10, etc)
The boot process will pause and display a blank screen or the designated splash image for X seconds. At the end of the time period, the system will boot. No menu will be displayed.
GRUB_HIDDEN_TIMEOUT=
No value entered after the = sign
GRUB_HIDDEN_TIMEOUT_QUIET=true
true No countdown is displayed. The screen will be blank.
false A counter will display on a blank screen for the duration of the GRUB_HIDDEN_TIMEOUT value.
GRUB_TIMEOUT=10
This instruction defers to the GRUB_HIDDEN_TIMEOUT unless GRUB_HIDDEN_TIMEOUT is commented (#). If GRUB_HIDDEN_TIMEOUT is active, the GRUB_TIMEOUT only operates once, and if, the menu is displayed.
GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian
GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
#GRUB_TERMINAL=console
#GRUB_DISABLE_LINUX_UUID="true"
A bug currently requires true be placed within quotation marks for this option, when uncommented, to take effect. Quotation marks currently are not the default and the user must add them.
#GRUB_GFXMODE=640x480
The user can also add multiple resolutions. If GRUB 2 cannot use the first entry, it will try the next setting. Settings are separated by a comma. Example: 1280x1024x16,800x600x24,640x480.
If using an entry that produces a "not found" message when running update-grub, try adding or changing the color bitdepth.
Resolutions available to GRUB 2 can be displayed by typing vbeinfo in the GRUB 2 command line. The command line is accessed by typing "c" when the main GRUB 2 menu screen is displayed.
If this line is commented (#) or the resolution is unavailable GRUB 2 uses the default setting determined by /etc/grub.d/00_header.
For a guide to changing resolutions when using a splash image see the Splash Images and Theming section.
GRUB_DISABLE_LINUX_RECOVERY=true
GRUB_INIT_TUNE="480 440 1"
The format is tempo [pitch1 duration1] [pitch2 duration2] ...
tempo is set once and applies to all duration settings.
duration is the result of 60/tempo. A duration of 1 with a tempo of 60 would produce a 1 second beep. A duration of 1 with a tempo of 480 produces a .125 second beep.
Online documentation is available by typing info grub --index-search play in a terminal. It mentions the ability to play a tune with the command play file if the tune is composed with little-endian numbers.
Additional instructions which may be included:
GRUB_DISABLE_OS_PROBER=true
Enables/disables the os-prober check of other partitions for operating systems, including Windows, Linux, OSX and Hurd.
GRUB 2 allows users to create customized menu selections which will be automatically added to the main menu when sudo update-grub is executed. An empty 40_custom file is available in /etc/grub.d/ for use or to serve as an example to create other custom menus. Here are some considerations for custom menus:
10_linux entries will appear before 30_os-prober entries, which will be placed before 40_custom entries, which will preceed my.custom.entries inputs.
A user wishing for the custom menu entries to appear first on the main menu could name the directory 06_xxx so its listings are first in the menu.
The file must be made executable: sudo chmod +x /etc/grub.d/filename.
The contents of the file is added to grub.cfg without changes when the update-grub command is executed.
Unlike grub.cfg, custom files can be edited at any time, are not read-only, and can be owned by the user if desired.
If the custom file places the menuentry listings at the top of grub.cfg, the user may wish to confirm the /etc/default/grub DEFAULT= setting after running update-grub. Make sure it still points to the desired menuentry listing. When counting, the first "menuentry" in /boot/grub/grub.cfg is 0.
The user can either edit the default /etc/grub.d/40_custom file or create a new one. The easiest way to create the content of a custom menu is to copy a working entry from /boot/grub/grub.cfg. Once copied, the contents of 40_custom can be tailored to the user's desires.
According to the default sample custom file (/etc/grub.d/40_custom) the first two lines of any custom file in /etc/grub.d should be:
#!/bin/sh |
exec tail -n +3 $0 |
The user can copy existing menuentries from the /boot/grub/grub.cfg file or from a GRUB legacy file. If the user wishes to copy from a GRUB legacy menu.lst file:
A backup copy of this file may be in the /boot/grub directory if the user upgraded from GRUB to GRUB 2.
title is changed to menuentry. The line must end with {
root is changed to set root=
kernel must be changed to linux
Any partition designation ((hd0,4), (hd1,6)) must be changed, as GRUB and GRUB 2 count the partitions differently. The first partition for GRUB 2 is 1, not 0. Devices still start the count at 0.
Look carefully at the format of any working GRUB 2 menulist entry to ensure the correct format is used.
General menuentry Construction Rules:
The first line must start with menuentry and end with {
The last line of the menuentry must be }
Do not leave empty spaces at the end of lines
The set root= line should point to the GRUB 2 /boot location ( (hdX,Y) )
The root reference in in the linux line should point to the system partition.
A sample entry copied from the grub.cfg and altered by the user might look like this:
menuentry "My Default Karmic" { |
set root=(hd0,1) |
search --no-floppy --fs-uuid --set cb201140-52f8-4449-9a95-749b27b58ce8 |
linux /boot/vmlinuz-2.6.31-11-generic root=UUID=cb201140-52f8-4449-9a95-749b27b58ce8 ro quiet splash |
initrd /boot/initrd.img-2.6.31-11-generic |
} |
menuentry "System Rescue CD" { |
set root=(hd0,8) |
linux /sysrcd/rescuecd subdir=sysrcd setkmap=us |
initrd /sysrcd/initram.igz |
} |
menuentry "Grub 1 Bootloader" { |
set root=(hd0,8) |
chainloader +1 |
} |