Grub principles and usage

Source: Internet
Author: User
Grub principles and usage detailed tutorial environment VMware + CentOS5.4. This article will introduce the basic knowledge of Grub, the complete installation and boot process of Grub, and the basic knowledge of Linux hard disk partitioning. Grub (granduniiedbootloader) is a famous boot kernel program (another one is more...
Experimental environment: VMware + CentOS5.4. This article will introduce the basic knowledge of Grub, the complete installation and boot process of Grub, and the basic knowledge of Linux hard disk partitioning. Grub (granduniied Boot Loader) is a famous boot kernel program (another famous is LILO, which uses U-Boot and bootloader in an embedded environment ), it supports loading of multiple hard disk partition types (FAT, ext2, ext3, minix, FFS, etc.) and multi-system boot. Grub2 is an upgraded version of grub and provides more functions. However, it is sufficient for a grub to implement correct kernel guidance, although many open-source software supports more and more powerful functions, the corresponding amount of code is also very large, which increases the difficulty for new people to learn about it, and is not suitable for learning. In other words, the original version of the corresponding software is generally retained for download, so you can find the initial version to learn. Far away ...... Www.2cto.com after the computer powers up the self-check, the rom bios loads the code in the MBR (primary boot sector, that is, the first sector of the hard disk) to the memory. this sector is 512 bytes in total, the first 446 bytes of content are stored in the key boot program of grub (bootloader), and then 64 bytes are placed in the hard Disk Partition Table DPT (Disk Partition Table). There are four primary partitions in total, which occupy 64 bytes, this is also the reason why the primary partition has only four at most, and the last two bytes are fixed signs 0x55AA. When the BIOS loads the boot program into the memory, it gives control to grub. then, the remaining grub code will load and move other code and perform file system initialization and search, finally, the kernel image file is loaded and the control is handed over to the real kernel for running. Before getting started with grub installation, you should first understand the basic knowledge of the hard disk and the Linux hard disk naming rules. The basic unit of storage for a hard disk is the Sector (Sector), with each Sector generally 512 bytes. A hard disk has multiple disks, each of which has two sides. each disk is divided into several tracks based on a concentric circle, and each track is divided into several sectors. For example, a hard disk has two disks, each of which is divided into 65536 tracks and each track is divided into 1024 sectors, the hard disk capacity is 2 disks * 2 disks * 65536 channels * 1024 sectors * 512 bytes = 128 GB. The primary device number of the hard disk is 3. The main devices of other devices are: 1: memory, 2: Disk, 3: hard disk, 4: ttyx, 5: tty, 6: the parallel port, 7 non-named pipe hard disk are divided into two bus types: IDE and SCSI. in linux, you can run the fdisk-l command to check which hard disk belongs. In Linux, the IDE device is named after hd, followed by letters a, B, and c to indicate the first part. for example, the first ide device is hda and the second is hdb; SCSI uses the sd command, the first device is sda, and the second is sdb. Hda1 represents the first partition of the first hard disk. the hard disk can have a maximum of four primary partitions, ranging from 1 ~ 4. logical partitions are started from 5. Generally, there is only one primary partition used to guide the system. In windows, this partition is a C disk, while in linux, it is hda1, sda1, D, E, in linux, disks F are hda5, had6, and hda7. The hard disk naming method varies in grub. you can open the grub configuration file/boot/grub. conf view (that is, menu. lst file, which is just grub. A shortcut of conf. for Linux, you can use ln-s menu. lst grub. conf command ). Default = 2 timeout = 5 splashimage = (hd0, 0)/grub/splash.xpm.gz hiddenmenutitleCentOS (2.6.27) root (hdX, Y) kernel/vmlinuz-2.6.27 roroot =/dev/VolGroup00/LogVol00 rhgb quiet initrd/initrd-2.6.27.img where root (hdX, Y) represents the location where grub is installed, X represents the number of hard disks, Y indicates the nth partition, and X and Y indicate numbers starting from 0. for example, (hd0, 0) indicates 1st partitions of 1st hard disks. That is, this command indicates that grub is installed in the 1st partition of the 1st hard disk. the kernel indicates the kernel image file to be loaded, and the root after the kernel indicates the location of the kernel file. In grub, IDE and SCSI are not distinguished, both of which start with hd. Now we have a new installation. check the grub version. Download the grubsource code grub-0.97.tar.gz from the opensource.orgor chinaunixdownload center. 377 tar-zxvf grub-0.97.tar.gz 378 cd grub-0.97 379./configure 380 make 381 make install the main files generated after compilation: Directory of the file:/boot/grub. Grub: main program. Stage1: Source code directory stage1/s. after compilation, it becomes a 512-byte img, which is written on the hard disk's 0-side 0-Channel 1st-sector, that is, the main boot sector of the hard disk. (The 512 bytes also include the partition table DPT and the primary boot sector flag "55AA "). * _ Tage00005: the file system interpretation code, which varies with the specific file system type of the/boot partition (or the partition where/boot is located). For example, the ext3 partition is e2fs_stage00005. Before stage00005 is loaded, the system cannot identify any file system (however, you can use the BIOS interrupt mode INT 13 h to read the content of the specified disk sector ). Stage2: core part of grub. After it runs, it will switch the system into the protection mode, set the C runtime environment, and then look for menulist. if not, execute a shell and wait for us to enter the command. Grub. conf (menu. lst): After executing makeinstall in the grub configuration file, I found that the original grub file was not replaced with the one just compiled, so I copied it manually in the current directory. 387 cp stage1/stage1/boot/grub/388 cp stage2/stage2/boot/grub 389 cp stage2/* _ stage1_5/boot/grub. /grub, and then execute the command on the grub shell command interface: execute find/grub/menu. lst may not be successful. you can try find/boot/grub/menu. lst or find/menu. lst is always right. Finally, run reboot to restart the system. If you forget to do this after make install, you can configure it again when the system starts. After the installation is complete, restart and check the new grub source. http://blog.csdn.net/rosetta

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.