GRUB basic instructions

Source: Internet
Author: User
Article Title: basic usage instructions of GRUB. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
GRUB is a multi-boot management tool that can be used to activate Linux, BSD, OS/2, BeOS, Windows95/98/NT, and many other operating systems, GRUB is a boot program independent of the operating system. It does not rely on Linux for configuration and maintenance. It also provides command column mode similar to Bash, allows you to set GRUB more easily.
  
Obtain and install GRUB:
  
GRUB source code compression files can be downloaded to the GNU ftp site (ftp://alpha.gnu.org/gnu/GRUB/) the latest version, download back can be stored in the/usr/local/src/directory and decompress it:
  
Cp grub.tar.gz/usr/local/src/
  
Tar zxvf grub.tar.gz
  
Execute the configure file, make and make install in the GRUB directory, as follows:
  
./Configure
  
Make
  
Make install
  
After make install is complete, GRUB is successfully installed, and three command files are installed in the system: grub, grub-install, and mbchk. GRUB files are usually installed in the/usr/local/share/grub directory.
  
Next, let's assume that the hard disk is split as follows:
  
Hda1: Windows98 (hd0, 0)
  
Hda2: Slackware Linux (hd0, 1)
  
Hdb1: Mandrake Linux (hd1, 0)
  
Note that the GRUB hard disk recognition method is different from that in Linux. in Linux, the first IDE hard disk is hda (SCSI: sda), and so on, GRUB regards the first IDE hard disk as hd0 (SCSI: sd0) and so on. In Linux, the first partition of the first IDE hard disk is hda1 (SCSI: sda1) and so on, GRUB expresses the first partition of the first IDE hard disk as hd0, 0 (SCSI: sd0, 0), and so on.
  
Create a GRUB activation Disk:
  
It is not difficult to create a GRUB activation disk. First, we need two necessary files, stage1 and stage2, which can be found in the i386-pc directory under the GRUB installation directory, and a formatted clean disk, and then follow the steps below to make the GRUB activation Disk:
  
Cd/usr/local/share/grub/i386-pc/
  
Dd if = stage1 of =/dev/fd0 bs = 512 count = 1
  
Dd if = stage2 of =/dev/fd0 bs = 512 seek = 1
  
After creating a boot disk for GRUB, you can try to use GRUB to activate multiple operating systems.
  
Use the GRUB boot disk to activate the system:
  
Then reactivate the system and set the BIOS to boot from the disk. Then you can see that the command column of grub> is waiting for the command. This is the environment of the GRUB command column, it indicates that GRUB has been smoothly loaded from the activated disk and is working properly. Now, if you want to activate the above-mentioned Slackware Linux, enter the following command under the GRUB prompt symbol, and then enter the Slackware Linux system:
  
Grub> root (hd0, 1)
  
Grub> kernel/boot/vmlinuz root =/dev/hda2 ro
  
Grub> boot
  
The root command will mount the hard disk partition location of the following parameter. After the mount is complete, the kernel command loads the system core of the parameter. The Linux core is usually the file named vmlinuz in the/boot directory. The last two parameters are transmitted to the loaded core. root =/dev/hda2 indicates that the core root directory is located at/dev/hda2, mounting is required to be read-only (ro ).
Finally, run the boot command to activate the Slackware system. Similarly, Mandrake Linux on hdb1 can also be activated in a similar way:
  
Grub> root (hd1, 0)
  
Grub> kernel/boot/vmlinuz root =/dev/hdb1 ro
  
Grub> boot
  
Now the root command is used to change the mount (hd1, 0) partition, which is the root directory location of Mandrake Linux. Then, the kernel command loads the core file of the Mandrake, tells the root directory of the core Mandrake system to be in/dev/hdb1, and needs to be mounted as read-only. Finally, activate the system using the boot command.
  
The above methods can successfully activate the Linux system, but it does not work for Windows systems. To activate Windows 98 on hda1, you need to change some commands, enter the following commands in the GRUB command column to go to Windows 98:
  
Grub> rootnoverify (hd0, 0)
  
Grub> chainloader + 1
  
Grub> makeactive
  
Grub> boot
  
Run the rootnoverity command so that GRUB does not mount the partition (hd0, 0), as long as you know that the operating system on the partition will be activated. Chainloader + 1 means to specify the first sector in the partition for activation. The makeactive command sets the active flag in this partition, as long as it is a Windows operating system. Run the boor command to start the instance.
  
Use the GRUB on the hard disk to start up and activate it:
  
GRUB boot disks are easy to use, but the purpose of creating a GRUB boot disk is only for system rescue. You must be able to truly enjoy the powerful functions of GRUB, it is best to use GRUB on the hard disk for boot, just like LILO to install it on the hard disk MBR.
  
First, create the boot directory/boot/GRUB for grub on the system. The file stage1 and stage2 are required just like the boot disk for creating GRUB? N, so please put the stage1 file and stage2 in the i386-pc directory under the GRUB installation directory? Ncopy to the created/boot/grub directory:
  
Mkdir/boot/grub
  
Cp/usr/local/share/grub/i386-pc/stage */boot/grub
  
After completion, enter the GRUB command to enter the GRUB command column environment, and enter the following command in the GRUB command column environment:
  
Grub> root (hd0, 2)
  
Grub> setup (hd0)
  
Grub> quit
  
In this way, you can complete the boot setting of GRUB in/boot/grub. First run the root command to mount the directory/boot/grub, where (hd0, 2) it refers to the preceding Slackware system, that is, the/boot/grub directory is created in the Slackware system. If you want to change to the stage file where GRUB is stored in Windows 98, you need to create the/boot/grub directory on the Windows 98 system and set stage1? N and stage2? N is stored in the \ boot \ grub directory on Windows98, and the parameter of the root command must be changed to the partition where Windows98 is located, that is, the preceding assumption (hd0, 0 ). The second command setup refers to the location where GRUB is to be installed for activation. If it is to be installed on the hard disk MBR, you only need to add the location of the hard disk, for example (hd0 ), if you want to install the first sector on the first partition of the hard disk, add the location of the partition, for example (hd0, 0 ).
  
Unless there are special circumstances, it is better to install it on the hard disk partition to be safer. Finally, use the quit command to exit the GRUB command column environment.
  
List of use options:
  
Although GRUB can be used for managing multiple boot tasks, it is not convenient to enter complicated commands every time. Therefore, GRUB also provides an option list, press the up/down key to select the system to be started and press Enter to start the system without entering any commands. GRUB searches for the menu in the/boot/grub directory when it is started. lst file. If it is found, GRUB will follow the menu. the content of the lst file displays a graphical interface for the Option List, allowing the user to select the OS to boot.
  
First, create a new file named menu. lst under the/boot/grub directory. The setting example of the menu. lst file is as follows:
  
#/Boot/grub/menu. lst
  
Timeout 30
  
Default 0 # Default Slackware Linux
  
Fallback 1 # Windows98
  
Fallback 2 # Mandrake Linux
  
Color light-green/brown blink-red/blue
  
# For booting Slackware Linux
  
Title Slackware
  
Root (hd0, 1)
  
Kernel/boot/vmlinuz root =/dev/hda2 ro
  
# For booting Windows
  
Title Windows98
  
Rootnoverify (hd0, 0)
  
Chainloader + 1
  
Makeactive
  
# For booting Mandrake Linux
  
Title Mandrake
  
Root (hd1, 1)
  
Kernel/boot/vmlinuz root =/dev/hdb1 ro
  
The preceding examples of the menu. lst file are set for the operating system configured on the previously assumed hard disk partition. Menu. lst starts with the # symbol as the annotation. GRUB ignores all annotation lines starting with the # symbol. The timeout command is the waiting time after the GRUB is activated, in seconds. Therefore, the preceding example indicates waiting for 30 seconds. The default command means that when the waiting time after GRUB activation exceeds the time set by the timeout command, the system specified by the parameter following the default command will be executed. parameter 0 represents menu. the first set operating system in the lst file. The above example refers to Slackware Linux, because it is set first. If the parameter is changed to 1, it is to activate Windows 98, and so on. The fallback command activates the operating system specified by the fallback command when the GRUB activation command default fails, when Slackware fails to be activated, GRUB will activate fallback and specify Windows98. The instruction color can set the foreground/background color of the GRUB option list. You can view the info file of GRUB by specifying the GRUB color. The following command sets the operating system. The command title can set the title of the operating system.
  
Set menu. after the lst file is installed, save the setting file under the/boot/grub directory. Then, you can view the beautiful GRUB Option List after you restart the system. Now you can try to activate different operating systems.
  
The above are the basic usage instructions of GRUB. When there are many operating systems on the hard disk, using GRUB is a natural and correct choice, GRUB can be used even if there are only one or two operating systems on the hard disk. Of course, GRUB has powerful functions and is enough to replace the traditional LILO. You can read the instructions in GRUB's info file.
  

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.