Grub three-step access

Source: Internet
Author: User
################### Advantages of grub ################## # grub is the boot loader) -- It is responsible for loading the kernel and guiding the Linux system. Grub can also boot other operating systems, such as FreeBSD, NetBSD, OpenBSD, GNU Hurd and DOS, as well as Windows 95, 98, NT, and 2000. Although booting an operating system seems to be an ordinary and trivial task, it is actually very important. If the boot loader does not work well or is not flexible, it is possible to lock the system and fail to boot the computer. In addition, a good boot loader gives you flexibility, allowing you to install multiple operating systems on your computer without having to deal with unnecessary troubles. Grub is a great boot loader. It has many features that can make the boot process very reliable. For example, it can directly read the Linux kernel from the fat, minix, FFs, ext2, or reiserfs partitions. This means that it can always find the kernel. In addition, grub has a special interactive console that allows you to manually mount the kernel and select boot partitions. This function is Priceless: assuming that the GRUB menu configuration is incorrect, the system can still be guided. Oh, right -- grub has a color boot menu. What's even more surprising is that this is a free software !!! ################### GRUB menu ################### let's look at an example, this is the menu in the/boot/GRUB/directory. LST file. This file will generate a menu at boot, including Debian Linux, Windows2000, RedHat Linux and Mandrake Linux. There are four options in total. I divided a total of eight zones, one fat16 (0x6), one NTFS (0x7), three ext2fs partitions (0x83 ), one swap partition (0x82 ). NTFS is used to install Win2000, three ext2fs are installed with three Linux instances, and the fat16 partition of drive C is not installed with anything. # Example ######################### example of grub configure ###### ################## timeout 10 default 2 # --> Debian Linux <-- title Debian Linux Root (hd0, 2) kernel/boot/vmlinuz-2.2.18 root =/dev/hda3 Ro initrd/boot/initrd-2.2.18.gz # --> Debian end <-- # --> Windows menu options <-- title Windows2000 root (hd0, 0) chainloader + 1 # --> winddows end <-- # --> RedHat Linux menu options <-- title RedHat Linux Ro Ot (hd0, 8) chainloader + 1 # Install lilo in the primary boot partition of the hard disk, so chainloader is also used. # --> RedHat Linux end <-- # --> Mandrake Linux menu options <-- title Mandrake Linux Root (hd0, 5) kernel/boot/vmlinuz-2.4.3-20mdk root =/dev/hda6 Ro initrd/boot/initrd-2.4.3-20mdk.img # --> Mandrake Linux end <-- # example ends here with line representation starting with symbol well "#" commented out, it makes no sense. Timeout indicates the default waiting time, which is 10 seconds. The default Operating System is automatically selected if the user has not made a selection for more than 10 seconds. The default Operating System is controlled by default. Add a number N after default, indicating that it is n + 1. In grub, the count starts from 0, the first hard disk is hd0, and the first soft drive is fd0. Therefore, default 2 indicates that the default Operating System is RedHat Linux. Next, as you can imagine, the title indicates the "Debian Linux" menu item. Root (hd0, 2) indicates the first hard disk and the third partition. The root here is different from the root partition in Linux. This root is not the root partition! In Linux, when talking about the "root" file system, it usually refers to the primary LINUX partition. However, grub has its own root partition definition. The root partition of grub is the partition that saves the Linux kernel. This may be your official root file system, or not. We are talking about grub. You need to specify the root partition of grub. When you enter the root partition, grub will install the partition into the read-only type, so that you can install the Linux kernel from the partition. One of grub's "cool" features is that it can read local fat, FFs, minix, ext2, and reiserfs partitions. So far, you may be confused, because the hard disk/partition naming conventions used by grub are different from those used by Linux. In Linux, the fifth partition of the first hard disk is called "hda5 ". Grub calls this partition "(hd0, 4 )". Grub calculates the hard disk and partition numbers from 0. In addition, the hard disk and partition are separated by commas, and the entire expression is enclosed in brackets. Now, if you want to boot the Linux hard drive hda5, enter "root (hd0, 4 )". Knowing where the kernel is and specifying which file is the kernel file is the work of the kernel. Kernel/boot/vmlinuz-2.2.18 root =/dev/hda3 Ro instructions/boot/vmlinuz-2.2.18 is the kernel to load. The following are the parameters passed to the kernel. Root =/dev/hda3 is the hard disk partition representation of Linux. ro means readonly. Initrd is used to initialize a Linux image and set relevant parameters. Is it easy! Let's take a look at the definition section of windows. Here, I added an item to guide Windows2000. To complete this operation, grub uses the chainloader ). The chain loader loads Win2000's own Boot Loader from the boot records of the partition (hd0, 0) and then guides it. This is why this technology is called chain loading-It creates a chain from the boot loader to another. This chain mount technology can be used to guide any version of DoS or windows. In my RedHat Linux, Lilo is installed in the primary boot partition of the hard disk, so chainloader is also used. The grub configuration file should be as simple as this. If you want to be more personalized, add "color light-gray/Blue" to the default statement. When grub is started next time, let's take a look at the changes and try "color light-blue/Red". Are you surprised? Fun! ####################### Grub interaction ############## ######## one of the best advantages of grub is its robust design. Don't forget this when you keep using it. If you update the kernel or change its location on the disk, you do not have to reinstall grub. As a matter of fact, if necessary, as long as the menu. LST file is updated, everything will remain normal. In rare cases, you need to reinstall the grub boot loader to the Boot Record. First, if you change the partition type of the grub root partition (for example, from ext2 to reiserfs), you need to reinstall it. Alternatively, if the stage1 and stage2 files in/boot/GRUB are updated, since they are from the grub of the updated version, it is likely that the boot loader will be re-installed. In other cases, ignore it! Grub is highly interactive. Click "C" at startup To Go To The grub console. The following figure shows grub version 0.5.96.1 (640 K lower/3072 K upper memory) [minimal bash-like line editing is supported. for the first word, tab lists possible command completions. anywhere else tab lists the possible Completions of a device/filename.] grub> welcome to the grub console. Now, I will study the command again: I will use the grub console to bypass lilo to start RedHat Linux, grub> root (H now, press the tab key once. If multiple hard disks exist in the system, grub displays a list of possible completed disks, starting with "hd0. If there is only one hard disk, grub inserts "hd0 ,". If there are multiple hard disks, continue, enter a name in ("hd2"), followed by a comma, but do not press Enter. The partially completed root command looks as follows: grub> root (hd0. Now, continue and press the tab key again. Grub displays the list of all partitions on a specific hard disk and their file system types. In my system, press the tab key to get the following list: grub> root (hd0, (tab, click the tab key) Possible partitions are: partition num: 0, filesystem type is fat, partition type 0x6 partition num: 2, filesystem type is ext2fs, partition type 0x83 partition num: 4, filesystem type unknown, partition type 0x7 partition num: 5, filesystem type is ext2fs, partition type 0x83 partition num: 6, filesystem type is fat, partition type 0xb partitio N num: 7, filesystem type is fat, partition type 0xb partition num: 8, filesystem type is ext2fs, partition type 0x83 partition num: 9, filesystem type unknown, partition type 0x82 as you can see, Grub's interactive hard drive and partition name implementation functions are very organized. In this case, you only need to understand grub's novel hard disk and partition naming syntax, and then you can continue to operate grub> root (hd0, 8). Now the root file system has been installed, when loading the kernel, grub> kernel/boot/vmlinuz-2.4.2 root =/dev/hda5 Ro [Linux-bzimage, setup = 0x1200, size = 0xe1a30] You have installed the root file system and mounted the kernel. Now, we can guide you. As long as you enter "Boot", the Linux boot process starts. Is it cool? Grub's menu. lst is more like a script in Linux. Program . ###################### GRUB boot disk ################ ###### create a boot disk, perform some simple steps. First, create an ext2 File System on the new floppy disk. Then, install it, copy some grub files to the file system, and finally run the "Grub" program, which will be responsible for setting the Boot Sector of the floppy disk. Are you ready? Insert an empty disk into the 1.44 MB drive. Enter # mke2fs/dev/fd0 to create the ext2 file system. Then, you need to install the file system: # Mount/dev/fd0/mnt/Floppy now, you need to create some directories and copy some key files (these files have been installed before grub) to the floppy disk: # mkdir/mnt/floppy/boot/GRUB # cp/boot/GRUB/stage1/mnt/floppy/boot/GRUB # cp/boot/GRUB there is another step for/stage2/mnt/floppy/boot/grub, you can obtain available boot disks. In Linux bash, running "Grub" from the root user is very interesting and worth noting because it is actually a semi-functional version of the grub boot loader. Although Linux is started and running, you can still run grub and execute some tasks, in addition, the interface is exactly the same as that seen when you use the grub boot disk or install grub to the hard disk MBR (that is, the grub console. At the grub> prompt, enter grub> root (fd0) grub> setup (fd0) grub> quit. Now, the boot disk is complete. It is also easy to install grub on the hard disk. This process is almost the same as the boot disk installation process. First, you need to determine which hard disk partition will become the root grub partition. In this partition, create the/boot/GRUB directory and copy the stage1 and stage2 files to this directory. You can reboot the system and use the boot disk, or use grub of the resident version to perform the next step. In both cases, start grub and use the root command to specify the root partition. For example, if you copy the stage1 and stage2 files to the/boot/GRUB directory of hda5, enter "root (hd0, 4 )". Next, decide where to install grub-MBR on the hard disk, or if you use another "master" Boot Loader with grub, it will be installed in the boot record of a specific partition. If you install MBR, you can specify the entire disk instead of the partition, as shown in the following figure (for hda): grub> setup (hd0) if you want to install grub to the boot records of/dev/hda5, enter grub> setup (hd0, 4). Now grub is installed. When booting the system, the grub console should be completed immediately (if installed in MBR ). Now, you should create a boot menu so that you do not have to enter those commands every time you boot the system. Summary: here is just a part of grub. For example, you can use grub to perform network boot, boot the BSD file system, or perform more operations. In addition, grub has many configuration and security commands. For a complete description of all grub functions, please read grub's excellent GNU documentation. Enter "info Grub" in the bash prompt to read this document. Useful information: xosl is a graphical boot loader that supports the mouse. It can be used at www.xosl.org compared to system command and Boot manager. Grub download: ftp://alpha.gnu.org/gnu/grub/ supplement: three hard disk installation methods of grub command set (using any one can, whatever method you like): 1. Use HD. IMG installation, which requires the grub for DOS floppy disk simulation function: grub> map (hd0, 0)/HD. IMG (fd0) grub> chainloader (hd0, 0)/HD. imggrub> rootnoverify (fd0) grub> boot2. Use vmlinuz and HD. two RDZ files for installation (grub for DOS is not required, and grub is used by GNU): grub> kernel (hd0, 0) /vmlinuz ramdisk_size = 128000 root =/dev/ram3automatic = method: disk ACPI = ht vga = 788 grub> initrd (hd0, 0)/HD. rdzgrub> note that a long line of kernel is not truncated into two lines. Note that the above commands assume that these files are located in the root directory (hd0, 0). If you have different commands, make the appropriate modification Source: linuxeden3. first download grub for DOS (http://grub.linuxeden.com), the latest version supports NTFS partition, and can be called by ntloader, such as WINXP boot menu. extract grldr to C:/and modify boot. INI, add c: \ grldr = boot grub (method: Right-click my computer on the desktop-properties-advanced-start and fault recovery-settings-edit, you do not need to go to disk C, which is troublesome); Create/boot/kernel and ISO in the root directory of disk C; Modify menu. LST, add Code : Title magci linux1.2-setup kernel (hd0, 6)/mbvmlinuz Ro root =/dev/ram0 ramdisk_size = 32000 VGA = 788 initrd (hd0, 6)/mbinitrd-hd.gz partition, change it to your note that there is a space after the kernel; restart, select boot grub, and select magic linux1.2-setup; I will not talk about it later, just follow the prompts to step by step; of course, you can modify the menu after the installation is successful. LST, add your ml boot item, and you can use grub for DOS to start your ml. ######################################## ######################################## ########################### My non-optical drive, directly install mandriva using the ISO file (the same applies to other Linux systems ). First, you need to extract vmlinuz and all. RDZ from the install/alt1 directory in the first CD. Note: alt0 and alt2 are installed under the directory on this layer. Different kernels are installed. For details, see the description file under install (the file name is forgotten ). Secondly, the principle of using ISO to install this method is basically to use GRUB boot to install the image. So I will introduce three methods I know: A, has GRUB boot, for example, the original Linux still exists and is guided by grub. (This situation is relatively simple ). 1. Confirm the vmlinuz and all extracted from the previous step. the location of RDZ on the hard disk. For example, if the first partition of the first hard disk is/dev/hda1, the location of the partition is expressed as (hd0, 0) in grub ); 2. Then, you can use the original GRUB boot system. When the grub boot menu appears, press "C" according to the following prompt and a command-line grub will appear, enter the following format: (take the location in step 1 as an example) kernel (hd0, 0)/vmlinuz ramdisk_size = 128000 root =/dev/ram3 automatic = method: disk ACPI = ht vga = 788 # comment and press ENTER initrd (hd0, 0)/All. RDZ # comment, then enter press ENTER boot # comment, and then press enter to see that the boot installation is started, and method A is finished. B. If there is no grub, but there is a installed Windows (taking WINXP as an example), you can also use the boot. ini in Windows C: disk to boot and install grub for DOS. In this example, grub for DOS is directly guided by WINXP, or grub for DOS is used after DOS is entered. B1, WINXP boot. grldr in ini + grub_for_dos; in the new grub_for_dos version, a file grldr is displayed, which can be directly guided by WINXP to implement GRUB boot, so that grub does not need to be installed. The method is as follows: 1. Copy the grldr and boot directories in grub_for_dos to drive C, that is, to boot. 2. edit boot. INI, add a line at the end, c: \ grldr = "grub for dos" 3, edit boot/GRUB/menu. LST, as follows: Title mandriva installkernel (hd0, 0)/vmlinuz ramdisk_size = 128000 root =/dev/ram3 automatic Ic = method: disk ACPI = ht vga = 788 initrd (hd0, 0) /All. RDZ Note: For convenience, you can also directly set menu. put the lst in the root directory of the grldr partition. 4. Restart and select grub for dos in the winxp boot menu to boot the installation. B2, WINXP boot. INI + vfloppy + logs, you can directly specify the menu edited in B1. LST, which is more convenient: grub -- config-file = (hd0, 0)/boot/GRUB/menu. lst. Run the command to boot the installation. For Methods A and B, after the boot installation starts, you only need to specify the location required for the system to install the ISO file. The software required for the above method can be downloaded here, http://lsec.cc.ac.cn /~ Peace/service/software/win4linux.rar. You can also download the updated version from the Internet. In addition, you do not need to use grub to directly use a USB flash drive to boot Linux installation from the hard disk. 1). Use the all. IMG, in general, decompress CD1 in CD1/install/image/All. IMG; 2), plug in the USB flash disk, find out the device Number of the USB flash disk, and run the mount command. Here I am/dev/sda1; 3) use root, run dd If = path/All. IMG of =/dev/sda1; 4), use a USB flash drive to boot, enter the graphical installation process, and enter the location of the ISO 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.