ubuntu   grub

Grub2

转自 https://help.ubuntu.com/community/Grub2

 

Configuring GRUB 2

 

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.

 

/etc/default/grub (file)

 

  • The main configuration file for changing default settings. Upon installation, the following lines are available for alteration by the user:
  • 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 information in this section applies to GRUB 1.98 and later.
      • Enables the "grub-reboot" and "grub-set-default" commands to set the default OS.
      • 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.

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

  • GRUB_HIDDEN_TIMEOUT=0

    • This setting determines how long a screen without the GRUB 2 menu will be displayed. While the screen is blank, the user can press any key to display the menu.
    • 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.

    • For at least GRUB 1.97~beta - the version found in Karmic - whether or not the menu can include a timeout delay with a blank screen is dependent on whether GRUB 2 finds multiple operating systems.

      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.

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

    • Setting this value to -1 will cause the menu to display until the user makes a selection.
    • The GRUB 2 menu is hidden by default unless another OS is detected by the system. If there is no other OS, this line may be commented out unless the user changes it. To display the menu on each boot, uncomment the line and use a value of 1 or higher.
  • 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

    • If it exists, this line imports any entries to the end of the 'linux' command line (GRUB legacy's "kernel" line) for both normal and recovery modes. This is similar to the "altoptions" line in menu.lst
  • 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. This is similar to the "defoptions" line in menu.lst. For 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". The entry "acpi=off", if required, would also be an option entered on this line.
  • #GRUB_TERMINAL=console

    • Uncomment to disable graphical terminal (grub-pc only)
  • #GRUB_DISABLE_LINUX_UUID="true"

    • Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
    • 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

    • You can remove the # symbol to make this line active. The entry sets the resolution of the graphical menu (the menu text size). It provides resolutions supported by the user's graphics card (e.g. 640x480, 800x600, 1280x1024, etc). 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 bitdepth 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, make sure the resolution setting and the splash image size are compatible.
    • 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

    • Add or uncomment this line to prevent "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.
  • GRUB_INIT_TUNE="480 440 1"

    • When uncommented, plays a single beep just prior to the Grub 2 menu display.
    • 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.

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.

 

Custom Menu Entries

 

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:

  • The name of the file determines the order of the selections in the menu. Numeric filenames are run first, followed by alphabetic filenames.
    • 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.

  • Custom files are static. The contents will not be altered when new kernels are added or removed (unless the contents are affected by user-added scripts).

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

    • The following entries from the GRUB menu listing must be changed for them to work:
      • 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 area between the quotation symbols is what will appear on the GRUB 2 menu. Edit as desired.
    • 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.

      • If GRUB 2 cannot find the referenced kernel, try replacing the UUID with the device name (example: /dev/sda6 ).
  • 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

      }

  • A sample entry for a hard drive version of SystemRescueCD installed per the instructions on the web site (on sda8).
    • menuentry "System Rescue CD" {

      set root=(hd0,8)

      linux /sysrcd/rescuecd subdir=sysrcd setkmap=us

      initrd /sysrcd/initram.igz

      }

  • A sample entry for chainloading to another GRUB bootloader.
    • menuentry "Grub 1 Bootloader" {

      set root=(hd0,8)

      chainloader +1

      }

 

 

你可能感兴趣的:(ubuntu,职场,grub,休闲,rhel5)