1、sudo vim /etc/default/grub
修改以下两行:
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT="true"
GRUB_DEFAULT=0 Sets the default menu entry by menu position. The first "menuentry" in grub.cfg is 0, the second is 1, etc.
Note: Grub 1.99 introduces a submenu menu structure. For a menu item in a submenu, the entry becomes a two-digit entry. The first entry is the position of the submenu title in the main menu. The second entry is the position within the submenu. If the submenu is the 3rd entry in the main entry, and the user wishes to boot the first entry in the submenu, it would be designated as "2>0". See the community documentation for a fuller explanation: Grub2/Submenus.
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"
Example (Submenu Entry): GRUB_DEFAULT="2>Ubuntu, Linux 2.6.38-8-generic"
GRUB_DEFAULT=saved The information in this section applies to GRUB 1.98 and later. The "saved" entry enables the "grub-reboot" and "grub-set-default" commands to set the default OS for future boots.
The default OS for future boots will not be set merely by selecting an OS when booting.
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.
Example: sudo grub-set-default 3
Example: 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.
- No commands need be run to set the default OS.
- Any time a menu entry is manually selected from the GRUB 2 menu, it becomes the default OS.
- This option currently does not work if your /boot directory resides on an LVM partition or RAID.
For this to work you must also set GRUB_DEFAULT=saved.
Note: Ubuntu's version of Grub 1.99 introduced the submenu feature. Designating a default boot option located in the Previous Linux versions submenu requires special formatting. For information regarding the submenu feature, please refer to Grub2/Submenus
2. sudo update-grub
执行此命令 重新生成了/boot/grub/grub.cfg 文件;
参考文件:https://help.ubuntu.com/community/Grub2#Configuring_GRUB_2
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.
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.
sudo nano /etc/default/grub
or in graphical mode
gedit admin:///etc/default/grub &
After making changes and saving the file, the GRUB 2 menu must be updated to include the changes by running:
sudo update-grub
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 -f grub -n 'Simple configuration'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. The first "menuentry" in grub.cfg is 0, the second is 1, etc.
Note: Grub 1.99 introduces a submenu menu structure. For a menu item in a submenu, the entry becomes a two-digit entry. The first entry is the position of the submenu title in the main menu. The second entry is the position within the submenu. If the submenu is the 3rd entry in the main entry, and the user wishes to boot the first entry in the submenu, it would be designated as "2>0". See the community documentation for a fuller explanation: Grub2/Submenus.
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"
Example (Submenu Entry): GRUB_DEFAULT="2>Ubuntu, Linux 2.6.38-8-generic"
GRUB_DEFAULT=saved The information in this section applies to GRUB 1.98 and later. The "saved" entry enables the "grub-reboot" and "grub-set-default" commands to set the default OS for future boots.
The default OS for future boots will not be set merely by selecting an OS when booting.
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.
Example: sudo grub-set-default 3
Example: 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).
- Sets the default menu entry. Entries may be numeric, a complete menuentry quotation, or "saved"
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.
- No commands need be run to set the default OS.
- Any time a menu entry is manually selected from the GRUB 2 menu, it becomes the default OS.
- This option currently does not work if your /boot directory resides on an LVM partition or RAID.
For this to work you must also set GRUB_DEFAULT=saved.
Note: Ubuntu's version of Grub 1.99 introduced the submenu feature. Designating a default boot option located in the Previous Linux versions submenu requires special formatting. For information regarding the submenu feature, please refer to Grub2/Submenus
GRUB_HIDDEN_TIMEOUT=0
- Wait this many seconds for the user to press a key. During this period no menu is shown unless the user presses a key. If no key is pressed, control is passed to GRUB _TIMEOUT when the GRUB_HIDDEN_TIMEOUT expires. See the note regarding bugs to this feature at the end of this section.
- The developers envisioned using this setting with a GRUB_TIMEOUT value of 0. This would give users a period of time (GRUB_HIDDEN_TIMEOUT) to display the menu by pressing a key, after which the system would boot without the menu being displayed (GRUB_TIMEOUT=0).
GRUB_HIDDEN_TIMEOUT=0
- No menu is displayed. The system is immediately booted to the default OS.
- This is the default setting with only one identified operating system.
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.
- While GRUB_HIDDEN_TIMEOUT is active, the menu can be displayed by pressing any key.
GRUB_HIDDEN_TIMEOUT=
No value entered after the = sign
- The menu will be displayed for the number of seconds designated by GRUB_TIMEOUT.
- Wait this many seconds for the user to press a key. During this period no menu is shown unless the user presses a key. If no key is pressed, control is passed to GRUB _TIMEOUT when the GRUB_HIDDEN_TIMEOUT expires. See the note regarding bugs to this feature at the end of this section.
GRUB_HIDDEN_TIMEOUT_QUIET=true
Determines whether a countdown timer is displayed on a blank screen when using the GRUB_HIDDEN_TIMEOUT feature.
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.
Note: There is a longstanding confirmed bug on the hidden menu feature in GRUB 1.97 to GRUB 1.99. The menu may not hide as specified in the description on this page. While editing the 30_os-prober script can fix this issue, it is beyond the scope of this page.
GRUB_TIMEOUT=10
- Sets the time period in seconds for the menu to be displayed before automatically booting unless the user intervenes.
- This instruction begins at the expiration of GRUB_HIDDEN_TIMEOUT.
- Setting this value to -1 will cause the menu to display until the user makes a selection.
- On a single OS system, by default this setting is not used and the menu will not display.
- To display the menu on each boot:
Place a comment symbol (#) in front of the GRUB_HIDDEN_TIMEOUT entry
- Make the GRUB_TIMEOUT value 1 or higher.
- To display the menu on each boot:
- Sets the time period in seconds for the menu to be displayed before automatically booting unless the user intervenes.
GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian
- Retrieves the descriptive name in the menu entry. (Ubuntu, Xubuntu, Debian, etc.)
GRUB_CMDLINE_LINUX
- Entries on this line are added to the end of the 'linux' command line (GRUB legacy's "kernel" line) for both normal and recovery modes. It is used to pass options to the kernel.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
- This line imports any entries to the end of the 'linux' line (GRUB legacy's "kernel" line). The entries are appended to the end of the normal mode only.
- To view a black screen with boot processes displayed in text, remove "quiet splash". To see the grub splash image plus a condensed text output, use "splash".
- This line imports any entries to the end of the 'linux' line (GRUB legacy's "kernel" line). The entries are appended to the end of the normal mode only.
#GRUB_TERMINAL=console
- Uncomment to disable graphical terminal. This may provide help if the GRUB 2 menu is too large or unreadable. It also may help when using the GRUB_HIDDEN_TIMEOUT feature.
#GRUB_DISABLE_LINUX_UUID="true"
- Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
The search line will still use UUIDs. The linux line will use the /dev/sdXY convention when this option is enabled.
- Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_GFXMODE=640x480
- GRUB 2 will automatically set the menu resolution to what it thinks is the best option. Uncommenting this line will set the resolution to 640x480, or you may change the value to another GRUB-compatible setting.
- The setting applies only to the boot menu display, not the resolution of the operating system that boots.
- Tip: Setting the same resolution in GRUB 2 and the operating system will decrease boot times slightly.
- Although not required, the user can also specify the color bit depth by appending it to the resolution setting. An example would be 1280x1024x24 or 640x480x32.
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 a splash image, the resolution setting and the splash image size should be compatible for best results.
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 videoinfo 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.
- In GRUB 1.99 (Natty) the 'optimum' resolution is selected by GRUB if no resolution is specified.
- The setting applies only to the boot menu display, not the resolution of the operating system that boots.
- GRUB 2 will automatically set the menu resolution to what it thinks is the best option. Uncommenting this line will set the resolution to 640x480, or you may change the value to another GRUB-compatible setting.
#GRUB_DISABLE_LINUX_RECOVERY=true
- Allows the user to prevent the recovery options from inclusion on the GRUB 2 menu.
- Uncomment (remove the # symbol) to prevent the "Recovery" mode kernel options from appearing in the menu. If you want a "Recovery" option for only one kernel, make a special entry in /etc/grub/40_custom.
- Allows the user to prevent the recovery options from inclusion on the GRUB 2 menu.
GRUB_INIT_TUNE="480 440 1"
Removing the comment symbol (#) allows GRUB 2 to play a single beep just prior to the Grub 2 menu display. More complex tunes can be designed by expanding the pitch/duration values.
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.
- Caution: The menu is displayed after the tune is complete. Creating a long tune will delay the appearance of the menu.
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.
GRUB_BACKGROUND
- Sets the background image, enter the full path to the image here. See splash image configuration above for further details and other options.
GRUB_DISABLE_OS_PROBER=true
This entry is used to prevent GRUB from adding the results of os-prober to the menu. A value of "true" disables the os-prober check of other partitions for operating systems, including Windows, Linux, OSX and Hurd, during execution of the update-grub command. Using this option rather than removing the executable bit from the /etc/grub.d/30_os-prober file has several advantages:
The setting can be easily changed while making other changes to the grub file.
While both methods prevent os-prober from running and placing items in the menu display, using this setting allows the 30_os-prober script, but not the os-prober command, to run. This script enables the GRUB_HIDDEN_TIMEOUT setting and/or the ability to display a hidden menu by pressing the ESC key (depending on other settings). This functionality is lost if the 30_os-prober script is disabled by making it unexecutable.