aku1 发表于 2006-12-28 10:59:12 |
The actual configuration of GRUB is based on three files that are described below: /boot/grub/menu.lst This file contains all information about partitions or operating systems that can be booted with GRUB. Without this information, the system control cannot be passed to the operating system. /boot/grub/device.map This file translates device names from the GRUB and BIOS notation to Linux device names. /etc/grub.conf This file contains the parameters and options the GRUB shell needs for installing the boot loader correctly. The Boot Loader 429
An Example Menu File The following example shows the structure of a GRUB menu file. The example installation has a Linux boot partition under /dev/hda5, a root partition under /dev/ hda7, and a Windows installation under /dev/hda1. gfxmenu (hd0,4)/message color white/blue black/light-gray default 0 timeout 8 title linux kernel (hd0,4)/vmlinuz root=/dev/hda7 vga=791 initrd (hd0,4)/initrd 432 title windows chainloader(hd0,0)+1 title floppy chainloader(fd0)+1 title failsafe kernel (hd0,4)/vmlinuz.shipped root=/dev/hda7 ide=nodma \ apm=off acpi=off vga=normal nosmp maxcpus=0 3 initrd (hd0,4)/initrd.shipped The first block defines the configuration of the splash screen: gfxmenu (hd0,4)/message The background image message is located in /dev/hda5. color white/blue black/light-gray Color scheme: white (foreground), blue (background), black (selection), and light gray (background of the selection). The color scheme has no effect on the splash screen, only on the customizable GRUB menu that you can access by exiting the splash screen with Esc . default 0 The first menu entry title linux is the one to boot by default. timeout 8 After eight seconds without any user input, GRUB automatically boots the default entry. To deactivate automatic boot, delete the timeout line. If you set timeout 0, GRUB boots the default entry immediately. The second and largest block lists the various bootable operating systems. The sections for the individual operating systems are introduced by title. • The first entry (title linux) is responsible for booting SUSE Linux. The kernel (vmlinuz) is located in the first logical partition (the boot partition) of the first hard disk. Kernel parameters, such as the root partition and VGA mode, are appended here. The root partition is specified according to the Linux naming convention (/dev/hda7/), because this information is read by the kernel and has nothing to do with GRUB. The initrd is also located in the first logical partition of the first hard disk. The Boot Loader 433 • The second entry is responsible for loading Windows. Windows is booted from the first partition of the first hard disk (hd0,0). The command chainloader +1 causes GRUB to read and execute the first sector of the specified partition. • The next entry enables booting from floppy disk without modifying the BIOS settings. • The boot option failsafe starts Linux with a selection of kernel parameters that enables Linux to boot even on problematic systems. The menu file can be changed whenever necessary. GRUB then uses the modified settings during the next boot. Edit the file permanently using YaST or an editor of your choice. Alternatively, make temporary changes interactively using the edit function of GRUB. See Section “Editing Menu Entries during the Boot Procedure” (page 434). Editing Menu Entries during the Boot Procedure In the graphical GRUB boot menu, select the operating system to boot with the arrow keys. If you select a Linux system, you can enter additional boot parameters at the boot prompt. To edit individual menu entries directly, press Esc to exit the splash screen then press E . Changes made in this way only apply to the current boot and are not adopted permanently. IMPORTANT: Keyboard Layout during the Boot Procedure The US keyboard layout is the only one available when booting. After activating the editing mode, use the arrow keys to select the menu entry of the configuration to edit. To make the configuration editable, press E again. In this way, edit incorrect partitions or path specifications before they have a negative effect on the boot process. Press Enter to exit the editing mode and return to the menu. Then press B to boot this entry. Further possible actions are displayed in the help text at the bottom. To enter changed boot options permanently and pass them to the kernel, open the file menu.lst as the user root and append the respective kernel parameters to the existing line, separated by spaces: title linux kernel (hd0,0)/vmlinuz root=/dev/hda3 additional parameter initrd (hd0,0)/initrd 434 GRUB automatically adopts the new parameters the next time the system is booted. Alternatively, this change can also be made with the YaST boot loader module. Append the new parameters to the existing line, separated by spaces. Using Wild Cards to Select the Boot Kernel Especially when developing or using custom kernels, you must either change the entries in menu.lst or edit the command line to reflect the current kernel and initrd filenames. To simplify this procedure, use wild cards to update the kernel list of GRUB dynamically. All kernel images that match a specific pattern are then automatically added to the list of bootable images. Note that there is no support for this feature. Activate the wild card option by entering an additional menu entry in menu.lst. To be useful, all kernel and initrd images must have a common base name and an identifier that matches the kernel with its associated initrd. Consider the following setup: initrd-default initrd-test vmlinuz-default vmlinuz-test In this case, you may add both boot images in one GRUB configuration. To get the menu entries linux-default and linux-test, the following entry in menu.lst would be needed: title linux-* wildcard (hd0,4)/vmlinuz-* kernel (hd0,4)/vmlinuz-* root=/dev/hda7 vga=791 initrd (hd0,4)/initrd-* In this example, GRUB searches the partition (hd0,4) for entries matching the wild card. These entries are used to generate new GRUB menu entries. In the previous example, GRUB behaves as if the following entries exist in menu.lst: title linux-default wildcard (hd0,4)/vmlinuz-default kernel (hd0,4)/vmlinuz-default root=/dev/hda7 vga=791 initrd (hd0,4)/initrd-default title linux-test wildcard (hd0,4)/vmlinuz-test kernel (hd0,4)/vmlinuz-test root=/dev/hda7 vga=791 initrd (hd0,4)/initrd-test Problems with this configuration can be expected if filenames are not used consistently or if one of the expanded files, such as an initrd image, is missing. The Boot Loader 435 29.3.2 The File device.map The file device.map maps GRUB device names to Linux device names. In a mixed system containing IDE and SCSI hard disks, GRUB must try to determine the boot sequence by a special procedure, because GRUB does not have access to the BIOS information on the boot sequence. GRUB saves the result of this analysis in the file /boot/ grub/device.map. For a system on which the boot sequence in the BIOS is set to IDE before SCSI, the file device.map could appear as follows: (fd0) /dev/fd0 (hd0) /dev/hda (hd1) /dev/sda Because the order of IDE, SCSI, and other hard disks depends on various factors and Linux is not able to identify the mapping, the sequence in the file device.map can be set manually. If you encounter problems when booting, check if the sequence in this file corresponds to the sequence in the BIOS and use the GRUB shell, described in Section 29.3.4, “The GRUB Shell” (page 437), to modify it temporarily if necessary. After the Linux system has booted, the file device.map can be edited permanently with the YaST boot loader module or an editor of your choice. After manually changing device.map, execute the following command to reinstall GRUB. This command causes the file device.map to be reloaded and the commands listed in grub.conf to be executed: grub --batch < /etc/grub.conf 29.3.3 The File /etc/grub.conf The third important GRUB configuration file apart from menu.lst and device .map is /etc/grub.conf. This file contains the parameters and options the command grub needs for installing the boot loader correctly: root (hd0,4) install /grub/stage1 d (hd0) /grub/stage2 0x8000 (hd0,4)/grub/menu.lst quit Meaning of the individual entries: root (hd0,4) This command tells GRUB to apply the following commands to the first logical partition of the first hard disk (the location of the boot files). 436 install parameter The command grub should be run with the parameter install. stage1 of the boot loader should be installed in the MBR of the first hard disk (/grub/stage1 d (hd0)). stage2 should be loaded to the memory address 0x8000 (/grub/stage2 0x8000). The last entry ((hd0,4)/grub/menu.lst) tells GRUB where to look for the menu file. 29.3.4 The GRUB Shell GRUB actually exists in two versions: as a boot loader and as a normal Linux program in /usr/sbin/grub. This program is referred to as the GRUB shell. The functionality to install GRUB as boot loader on a hard disk or floppy disk is integrated in GRUB in the form of the commands install and setup. This is available in the GRUB shell when Linux is loaded. However, the commands setup and install are also available during the boot procedure before Linux is started. This facilitates the repair of a defective system that can no longer be booted, because the faulty configuration file of the boot loader can be circumvented by manually entering parameters. Manually entering parameters during the boot procedure is also useful for testing new settings without impairing the native system. Simply enter the experimental configuration file with a syntax similar to that in menu.lst. Then test the functionality of this entry without changing the existing configuration file. For example, to test a new kernel, enter the command kernel and the path to the new kernel. If the boot procedure fails, you can continue using the intact menu.lst the next time you boot. Similarly, the command line interface can also be used to boot a system despite a faulty menu.lst file by entering the corrected parameters. In the running system, then enter the correct parameters in menu.lst to make the system permanently bootable. The mapping of GRUB devices to Linux device names is only relevant when running the GRUB shell as a Linux program (by entering grub as described in Section 29.3.2, “The File device.map” (page 436)). For this purpose, the program reads the file device .map. For more information, see Section 29.3.2, “The File device.map” (page 436). The Boot Loader 437 29.3.5 Setting a Boot Password Even before the operating system is booted, GRUB enables access to file systems. Users without root permissions can access files in your Linux system to which they have no access once the system is booted. To block this kind of access or prevent users from booting certain operating systems, set a boot password. IMPORTANT: Boot Password and Splash Screen If you use a boot password for GRUB, the usual splash screen is not displayed. As the user root, proceed as follows to set a boot password: 1 At the root prompt, enter grub. 2 Encrypt the password in the GRUB shell: grub> md5crypt Password: **** Encrypted: $1$lS2dv/$JOYcdxIn7CJk9xShzzJVw/ 3 Paste the encrypted string into the global section of the file menu.lst: gfxmenu (hd0,4)/message color white/blue black/light-gray default 0 timeout 8 password --md5 $1$lS2dv/$JOYcdxIn7CJk9xShzzJVw/ Now GRUB commands can only be executed at the boot prompt after pressing P and entering the password. However, users can still boot all operating systems from the boot menu. 4 To prevent one or several operating systems from being booted from the boot menu, add the entry lock to every section in menu.lst that should not be bootable without entering a password. For example: title linux kernel (hd0,4)/vmlinuz root=/dev/hda7 vga=791 initrd (hd0,4)/initrd lock After rebooting the system and selecting the Linux entry from the boot menu, the following error message is displayed:
|