Grub Boot Manager

Source: Internet
Author: User
Tags centos server

Linux Learning Note 5 Linux Grub Boot Manager

1.GRUB Introduction

1.1grub and Boot bootloaderThe boot loader is the first real software that runs during computer startup, usually the boot loader program in the main boot fan that reads and runs the hard disk after the BIOS self-test, and the boot loader is responsible for loading the operating system in the boot partition.
1.2 Grub Features
    • Provides a true command-line interface that enables users to boot the operating system and collect system information with a variety of parameters with maximum flexibility.
    • Supports LBA mode
    • Grub has access to the ext2 partition
2 Installing GrubInstalling grub has two levels of meaning:
    • Installing the GRUB Package
    • Installing grub to MBR #grub-install/dev/hda
Installation of the GRUB package: file name: grub-0.93-4.i386.rpm #rpm –q Grub//query #rpm –ivh/mnt/cdrom/redhat/rpms/grub-0.93-4.i386.rpm//Installation
3 Grub's manipulation interface 3.1 Grub's boot menu interfaceAction: You can select a preset boot menu item in the Grub configuration file to enable switching of multiple operating systems on the hard disk.    You can also access the menu item editing interface and the Grub command line interface. Grub boot Menu Keys:
    • ↑↓ moving between Startup menu items
    • Enter: Start the current menu item
    • E: Edit the current Start menu item
    • A: Add the kernel's startup parameters
    • C: Enter the GRUB command line mode
3.2 Grub's Start menu item editing interfaceIn this mode, you can make further adjustments to the startup items that already exist in the grub configuration file.    Example: Edit an existing row, add a delete command line. Grub boot Menu Edit Interface button:
    • ↑↓ Selecting Rows in a menu item
    • B: Start the current menu item
    • E: Edit the currently selected row
    • C: Command line mode to enter GRUB
    • o: Insert a row after the current line
    • O: Insert a row before the current line
    • D: Delete When moving forward
    • ESC: Returns to the Grub boot menu interface and cancels any changes made to the current Startup menu item
3.3 Grub Command line interfaceThe Guub command-line interface provides a convenient and friendly way to interact with the command line, which includes the following features:
    • Provides online help command "help" and can get detailed assistance for each command
    • Use Left and RIGHT arrow keys to edit line commands
    • You can use the UP and DOWN ARROW keys to scroll through history commands
    • You can use the "tab" key to complete the command
4 Grub configuration fileThe default configuration file is/boot/grub/grub.conf, and when GRUB is successfully installed on the hard disk master boot sector, the configuration of grub can be implemented as long as the file is edited. There is no need to rewrite grub to MBR. The grub configuration file includes the global configuration and the menu item configuration in two parts: 4.1 Global commands for GRUB configuration files
    • To set the default boot entry for grub by using default command
    • Command format: Default menu item ordinal
    • To set the boot interface for grub using the Splashimage command
    • Command format: Splashimage image file Full path name//used to specify a file as the background image of the boot menu
    • Example: Splashimage (hd0,0)/boot/grub/splash.xpm.gz
    • To set the start delay for a menu using the timeout command
    • Command format: #timeout delay number of seconds
4.2 Configuration commands for Grub menu itemsTitle menu Item Name Example: #title windows
4.3 Configuring Startup menu items for LinuxGrub has different boot modes for different operating systems, the Linux operating system grub can boot its kernel directly and boot, the typical Linux boot color order is configured as: Title RedHat Linux (2.4.20-8) root (dh0,0)kernel/boot/vmlinuz-2.4.20-8 ro root=label=/initrd/boot/initrd-2.4.20-8.imgConfiguration commands for Linux boot menu items:
    • Title: Defines the name of the Linux boot menu item
    • Root: Set grub root device (root) to the partition where the Linux kernel resides
    • Kernel: Load Linux kernel files with the Linux kernel file as parameters after using the kernel command
    • INITRD: Loading the image file with the INITRD command

4.4 Configuring the Startup menu item for WindowsInstead of booting directly from the kernel files of the Windows system, grub does so by invoking the boot loader of the Windows operating system itself, which is typically configured as a typical Windows Startup menu item in the boot sector of the partition where Windows is located: Title WIN2KP map (H D0) (HD1) Map (HD1) (hd0) root (hd1,0) makeactive chainloader+1
Windows Startup menu item configuration command:
    • Title: Defines the name of the Windows Startup menu item
    • Map: Use the map command to swap disk or partition markers in the BIOS for booting windows on a second hard disk
    • Root: Set the root device of the real Windows partition as Grub
    • Makeactive: Set the root device as active partition (for Windows cannot boot from inactive partition)
    • Chainloader: Booting the Windows system using the Chainloader command to invoke the Windows partition's boot boot

5 Grub Security SettingsMain functions:
    • Global password can be set for the boot menu
    • A global password can be used for a menu item
    • A separate password can be set for a menu item
    • All passwords can be encrypted using MD5

5.1 Setting the Global Password Start menuThe global password is used to set a global password that allows the user to select only the Start menu item to start, such as other actions required to enter the setting.
    • Password command
Command format: #password password Word//Set password for GRUB boot menu and menu item
    • Set global password (set GRUB's global password to 12345)
password12345 Unlock grub Boot Menu:
    • Select "P" in the Locked boot menu
    • Enter the correct password at the "Password:" Prompt and press ENTER to confirm
    • If the password is entered correctly, the boot menu is unlocked and returned to its normal state.
5.2 Locking the Boot menu item with a global passwordThe steps to lock the Start menu item are:
    • Set GRUB Global Password
    • To lock a menu item by using the Lock command in the configuration
5.3 Setting a separate Password lock boot menu item 5.4 Using MD5 to encrypt passwords
6 tips for using grub 6.1 Configuring GRUB to repeat the last startup item
    • Use default saved in global configuration to specify the default startup item for the last saved value
    • Use the Savedefault command at the end of each menu item configuration command to save the current startup item as the default startup item
6.2 Making the Grub boot floppy
    • #mke2fs/dev/fd0
    • #mount/mnt/floppy/
    • #grub-install–root-directory=/mnt/floppy/' (fd0) '
    • #umount/mnt/floppy/
    • #reboot
6.3 Recover the covered hard drive boot system using GRUB boot Floppy
    • Grub>root
    • Grub>find/boot/grub/grub.conf
    • Grub>root (hd0,0)
    • Grub>setup (hd0,0)

Location and name of the configuration file
The associated files for the Grub boot loader are saved by default in the "/boot/grub" directory, where the Menu.lst file is the main configuration file for grub, and grub displays the boot menu based on the configuration of the file at startup.
# ls/boot/grub/
Device.map grub.conf minix_stage1_5 Stage2
E2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5 fat_stage1_5 jfs_stage1_5 splash.xpm.gz vsta Fs_stage1_5 ffs_stage1_5 menu.lst stage1 xfs_stage1_5
The Red Hat series of Linux systems (including CentOS) are more accustomed to using file name grub.conf as the Grub profile. To maintain compatibility with other systems and file consistency, CentOS has established a symbolic link file named grub.conf in the "/boot/grub" and "/etc" two directories to point to the true profile "/boot/grub/menu.lst".
# Cd/boot/grub
# ls-l Menu.lst grub.conf
-RW-------1 root root 595 Mar 18:06 grub.conf
lrwxrwxrwx 1 root root 18:06 menu.lst-/grub.conf # ls-l/etc/grub.conf
lrwxrwxrwx 1 root root 18:06/etc/grub.conf. /boot/grub/grub.conf
Therefore, whether you edit the Menu.lst file directly or edit the grub.conf file in the appropriate directory, you can achieve the purpose of modifying the grub configuration.
Default configuration for GRUB in CentOS 5
After the CentOS 5 server method is installed by default, the file Menu.lst has been configured by default.
# # Displays the default configuration of the Menu.lst file after executing the cat command # CAT/BOOT/GRUB/MENU.LST
# grub.conf generated by Anaconda #
# Note that you don't have a to rerun grub after making changes to the this file # notice:you has a/boot partition. This means
# all kernel and INITRD paths is relative to/boot/, eg. # root (hd0,0)
# kernel/vmlinuz-version ro Root=/dev/volgroup00/logvolroot # initrd/initrd-version.img









#boot =/dev/hda default=0 timeout=5
Splashimage= (hd0,0)/grub/splash.xpm.gz Hiddenmenu
Title CentOS (2.6.18-53.el5) root (hd0,0)
Kernel/vmlinuz-2.6.18-53.el5 ro root=/dev/volgroup00/logvolroot initrd/initrd-2.6.18-53.el5.img
The contents of the Menu.lst file can be divided into three categories:
??
Note lines are usually placed in the header of the file, starting with "#", as a description of the function, because the comment line in the file is ignored when the grub executes, so you can also add a temporarily unused configuration line "#" to the beginning as a comment to invalidate it without rushing to delete the row.
The global configuration line is usually placed after the header comment line, which is scoped to the entire GRUB runtime environment (including all menu items), and all rows not included in the title command area are treated as global configuration rows.
??
The menu item configuration line starts with the title command until the end of the next title command or file, and all of the configuration lines included are used for the same startup item, which is named by the parameter of the title command; configuration files can have multiple menu item configurations for multiple system boot configurations.
Configuration commands for Menu.lst
The following table lists some common configuration commands that you can use in grub.conf.
GRUB Configuration File Example
Choose to start a different Linux kernel
To complete the boot of the Linux operating system must have at least title, root, Kernel, initrd four commands. For different Linux operating systems (or different kernel versions of the same system), the boot line configuration needs to be based on the actual location and name of the kernel file, i.e. the command parameters of the title, root, kernel, and initrd four commands need to be specified. The following is an example of a GRUB configuration that updates the system kernel and optionally launches a different kernel.
# Set the default startup first startup item default=0
Configuration commands
Function
Default < menu item Ordinal >
Sets the default startup item for the Start menu, the menu item ordinal parameter whose value starts with "0", that is, "0" represents the 1th menu item, "1" represents the 2nd item, and so on.
Timeout < delay number of seconds >
Sets the start delay (in seconds) of the Grub menu, which will automatically start the default menu item after that delay. When the timeout command sets a negative delay number or does not set the timeout command, the GRUB boot menu cancels the start Delay function, and the user manually selects the menu item to start.
Title < caption > sets the title of a specific set of commands used to mount an operating system, and the title will be displayed in the GRUB boot menu. Splashimage < image file Full name > Specify a file as the background image of the boot menu, the file must be an image in XPM format and can be a GZ compressed file. Root <grub Device Name >
Sets the root partition (root) of GRUB, usually the boot partition of the file system, which is the partition where the Linux kernel resides.
Rootnoverify <grub
Device name > Do the same thing as the root command, just do not mount the partition (used to start the Windows system).
Kernel uses the kernel command to load Linux kernel files with Linux kernel files as parameters. INITRD load the initial RAM disk image file with the INITRD command.
Map maps a disk or partition in the BIOS of a marker that is used to start Windows on a second hard disk. Makeactive set the root device as active partition (for Windows cannot start from an inactive partition). Chainloader
Use the Chainloader command to invoke the Windows partition's boot initiator to boot the Windows system.









# Set the boot delay of the GRUB menu to 5 seconds timeout=5
# Specify the background image of the boot menu located in/boot/grub/splash.xpm.gz splashimage= (hd0,0)/grub/splash.xpm.gz # Set the Grub menu as hidden Hiddenmenu
# Title command to start the configuration of a menu item
Title CentOS (2.6.18-53.1.13.EL5)
# set GRUB root partition (i.e./boot partition) root (hd0,0)
# set Linux kernel and parameters
Kernel/vmlinuz-2.6.18-53.1.13.el5 RO Root=/dev/volgroup00/logvolroot # Set initial RAM disk image file
Initrd/initrd-2.6.18-53.1.13.el5.img
Title CentOS (2.6.18-53.el5) root (hd0,0)
Kernel/vmlinuz-2.6.18-53.el5 ro root=/dev/volgroup00/logvolroot initrd/initrd-2.6.18-53.el5.img
Multi-system boot configuration with Windows
Although only the only Linux operating system is installed in this book's CentOS server installation, the powerful GRUB boot loader is fully capable of multi-system booting for Linux and Windows coexistence.
Because GRUB is not able to boot directly from the core files of the Windows system, it does so by invoking the boot loader of the Windows operating system itself (typically the boot sector of the partition on which Windows is located), so booting for Windows systems is different from Linux system booting 's command. The Windows boot menu configuration often uses commands such as map, Root, Makeactive, Chainloader, and so on.
1. Linux and Windows are installed on two hard drives respectively
In the following example, the first hard disk in the system has already installed the CentOS system in accordance with the steps of this book, and now add the second hard disk in the system, the first primary partition of the hard disk has a Windows system that can run natively, and the remaining task is to Menu.lst The configuration file adds boot configuration content to the Windows system.
Default=0 timeout=5
Splashimage= (hd0,0)/grub/splash.xpm.gz Hiddenmenu
Title CentOS (2.6.18-53.el5) root (hd0,0)
Kernel/vmlinuz-2.6.18-53.el5 ro root=/dev/volgroup00/logvolroot initrd/initrd-2.6.18-53.el5.img title Windows
Map (hd0) (HD1) Map (HD1) (hd0)
# Set the real Windows partition as GRUB root device. Rootnoverify (hd1,0)
# set the root device as active partition (for Windows cannot boot from inactive partition) makeactive
# Call boot record for Windows partition boot Windows system boot Chainloader +1
Because the Windows system itself can only be installed on the primary hard disk (the first hard disk in the system) in the active partition to boot, so in the configuration line requires the use of two map command two-direction mapping in the BIOS of the symbol (the purpose is to confuse the Windows system), and use  Makeactive sets the Windows partition as the active partition so that the "chainloader +1" command can start the Windows system using the boot record in the Windows partition. 2, Linux and Windows installed on the same hard disk case
Here's another example of a grub.conf that uses GRUB to choose to start Windows or CentOS. In this example, the Windows system is installed on the first primary partition of the hard disk, and the Linux boot system is on the first logical partition of the disk.









Default=0 timeout=5
Splashimage= (hd0,0)/grub/splash.xpm.gz Hiddenmenu
Title CentOS (2.6.18-53.el5) root (hd0,5)
Kernel/vmlinuz-2.6.18-53.el5 ro root=/dev/volgroup00/logvolroot initrd/initrd-2.6.18-53.el5.img title Windows
Rootnoverify (hd0,0) Chainloader +1
?? Show source file??

Grub Boot Manager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.