Develop and deploy your next To most people, boot loaders aren't the most exciting aspect of an operating system, but they are extraordinarily important. Without a functioning boot loader, nothing else works. Currently, a transition from the old Grand Unified Bootloader (GRUB) Legacy tool to the new GRUB 2 is underway. GRUB 2 is the default boot loader in Ubuntu 9.10, and it's an option in most other major Linux distributions. Sooner or later, other distributions will deploy GRUB 2 as the default boot loader. Anatomy of a boot loaderFigure 1 shows the boot process as implemented by both GRUB Legacy and GRUB 2. The basic input/output system (BIOS) is the first code to run on the computer, and it's stored in the computer's firmware. The BIOS loads the first sector of the boot device and executes the code it contains. In the case of a hard disk, this first sector is also known as the master boot record (MBR), and it contains both the first stage of the boot loader and the MBR partition table. Because most disk devices use a sector size of 512 bytes, the first-stage boot loader code must be very small. Most boot loaders, including both GRUB Legacy and GRUB 2, place additional code elsewhere on the disk. In the case of GRUB Legacy, this additional code is known as stage 1.5, and it's often placed in an unallocated area immediately following the MBR. Still more code, known as stage 2, is stored in files in the Linux boot partition (typically in the /boot directory), although Figure 1 omits these files for simplicity's sake. Likewise, in a multiple-operating system configuration, the secondary boot loader may store additional configuration files elsewhere. Figure 1. GRUB and GRUB 2 consist of several subcomponents that are loaded and run in sequenceGRUB 2 is similar to GRUB Legacy in overall form, but it eliminates stage 1.5 and implements a modular configuration approach in which code to handle various partitioning systems, file systems, and other extensions are stored in disk files—typically, in /boot/grub. Variants on the configuration just described are possible with both GRUB Legacy and GRUB 2. For instance, it's possible to install GRUB's stage 1 code in a Linux boot partition's first sector rather than in the MBR. Used in this way, another boot loader resides in the MBR, and GRUB's menu appears only when that boot loader chain-loads GRUB. Because the Extensible Firmware Interface (EFI), which is likely to eventually supplant the BIOS as standard PC firmware, provides a built-in boot loader, a configuration akin to this one is available for GRUB 2 on EFI-based systems. If you want to replace GRUB Legacy with GRUB 2 on a working system, you must install a new GRUB 2 package, configure its files, and run a special command to have GRUB 2 replace the existing GRUB Legacy MBR and special hidden code with the GRUB 2 equivalents. If you're switching to GRUB 2 because you're installing a new distribution that uses GRUB 2 as its default boot loader, you shouldn't need to deal with these steps. In either case, you must understand the new GRUB 2 configuration file's format as well as the new boot loader's overall features. GRUB 2's improvementsFor Linux-only systems, GRUB Legacy handles the boot loader job perfectly well. The reason for the transition has partly to do with boot loader development. GRUB Legacy contains code that the developers consider messy and unmaintainable. To add new features, they chose to rewrite the boot loader from scratch rather than build on such a base. As a practical matter to systems administrators, GRUB 2 supports several features that are important now or that may become important in the future:
Configuring GRUB 2If you're already familiar with GRUB Legacy, you'll find that the GRUB 2 configuration file is similar in broad strokes, but it varies in many details. You should be aware of alternative means of configuring GRUB 2, as well. An example configuration fileThe default location for the GRUB 2 configuration file is /boot/grub/grub.cfg. Some Linux distributions use /boot/grub2/grub.cfg instead, enabling side-by-side GRUB Legacy and GRUB 2 installations. Listing 1 shows a sample GRUB 2 configuration file. Listing 1. Sample GRUB 2 configuration fileset timeout=10 set default=0 menuentry "Linux (2.6.32.2 kernel)" { set root=(hd1,8) linux /bzImage-2.6.32.2 ro root=/dev/sdb4 initrd /initramfs-x86_64-2.6.32.2 } menuentry "Windows 7" { set root=(hd1,2) parttool (hd0,1) hidden+ parttool (hd1,5) hidden- chainloader +1 } If you're familiar with GRUB Legacy, you'll find this basic GRUB 2 configuration file similar. As with GRUB Legacy configuration files, the GRUB 2 file begins with a section that sets various global options—in this case, setting a timeout value to 10 seconds and setting the default menu entry. The file continues with a series of menu entries. The form of these entries
is different from those for GRUB Legacy, but the purpose is the same: Each
defines a single operating system or boot variant, such as a different
Linux kernel. Each menu entry begins with the keyword
Configuration file changesSeveral changes between the configuration file formats of GRUB Legacy and GRUB 2 deserve mention:
Another change is extremely important but not obvious from Listing 1:
Partitions are numbered starting from 1 in GRUB 2,
whereas partition numbering begins with 0 in GRUB Legacy. An equivalent
change in disk numbering is not implemented. Thus, the first
partition on the first disk is Using new GRUB 2 featuresOf course, GRUB 2 implements many new features. Some of these have little bearing on a standard Linux installation or don't directly affect the configuration file. Some important options you might need to adjust include the following:
Alternative methods of reconfiguring GRUB 2Ubuntu 9.10 uses the In some cases, deliberately running
If you need to make more specific changes, you could directly edit the files in /etc/grub.d. These files are actually bash scripts. Each one tells the system how to locate specific types of kernels or operating systems and add appropriate entries to /boot/grub/grub.cfg. An additional file referred to by Third parties have written some tools and scripts to help manage GRUB 2 installations. One example is the StartUp Manager. This graphical user interface (GUI) tool ships with Ubuntu and provides a point-and-click interface for managing both GRUB Legacy and GRUB 2 installations. Installing and using GRUB 2GRUB 2, like GRUB Legacy, must be installed once. Thereafter, the boot loader reads its /boot/grub/grub.cfg file to present the boot menu to you. Prior to installation, though, you may want to consider your partition layout. After installing GRUB 2, you should be aware of some basic features for boot-time operation. Preparing partitions for GRUB 2No special preparation is required to install GRUB 2 on a disk that uses the MBR partitioning scheme. The same is technically true of GPT; however, if a GPT disk includes a BIOS boot partition, GRUB 2 will store extra code in that partition. If the BIOS boot partition is not present, GRUB 2 instead relies on a list of disk sectors that correspond to a file in your /boot directory. If you ever adjust that file system, the sector list may become invalid, resulting in GRUB's inability to boot. Thus, use of a BIOS boot partition is strongly recommended on GPT disks. Your BIOS boot partition should be at least 31KB in size. Making it bigger
will do no harm and could be useful should GRUB's needs change in the
future. In recent versions of GNU Parted, you can set the
Installing GRUB 2You install GRUB 2 to a disk's MBR in the same way as GRUB, using the
You can normally install GRUB Legacy to a partition's boot sector (such as /dev/sda4) by typing: grub-install /dev/sda4 (changing the partition device file name as necessary). This doesn't work with GRUB 2, though. You may be able to overcome this problem by typing: grub-setup --force /dev/sda4 (changing the device file name as necessary); however, this method doesn't always work. Run time GRUB 2 useDuring normal use, GRUB 2 works much like GRUB Legacy: When you boot the computer, just after the BIOS performs its checks, a menu of operating system and kernel options appears. You choose the one you want to boot using the arrow keys, and then press Enter. If you make no selection, the default may be booted, depending on the configuration file options. If an entry doesn't work, you may be able to make a one-time change to it by using GRUB 2 edit mode. Instead of pressing the Enter key to boot an entry, press the E key to edit it. You'll see a simple editor that accepts Emacs-like editing options. When you're done, press Ctrl-X to boot your altered entry. If GRUB 2 can't locate its configuration file, it will present you with a
Should you use GRUB 2?The most compelling reasons for using GRUB 2 are if you're using a distribution that installs it by default or you need access to one of its unusual features, such as the ability to directly boot an XNU kernel. In most other cases, GRUB 2 offers few or no advantages over GRUB Legacy. One in-between case is if you've used GPT on a BIOS-based computer. GRUB 2 supports this configuration, but the standard GRUB Legacy does not. Patched versions of GRUB Legacy with GPT support are available and ship with most modern distributions, but you may prefer using a boot loader with official GPT support. The bottom line is this: If what you have installed already works, it's best to keep using it. Changing boot loaders can render a system unbootable, and correcting that problem is a tedious proposition. That said, GRUB 2 is likely to supplant GRUB Legacy moving forward, so you may want to familiarize yourself with GRUB 2, if only on a test system or virtual machine. Sooner or later, you may find that your GRUB configuration file format has changed, because your distribution has changed its boot loader. A little advance research will help you weather this change with minimal fuss. Develop and deploy your next To most people, boot loaders aren't the most exciting aspect of an operating system, but they are extraordinarily important. Without a functioning boot loader, nothing else works. Currently, a transition from the old Grand Unified Bootloader (GRUB) Legacy tool to the new GRUB 2 is underway. GRUB 2 is the default boot loader in Ubuntu 9.10, and it's an option in most other major Linux distributions. Sooner or later, other distributions will deploy GRUB 2 as the default boot loader. Anatomy of a boot loaderFigure 1 shows the boot process as implemented by both GRUB Legacy and GRUB 2. The basic input/output system (BIOS) is the first code to run on the computer, and it's stored in the computer's firmware. The BIOS loads the first sector of the boot device and executes the code it contains. In the case of a hard disk, this first sector is also known as the master boot record (MBR), and it contains both the first stage of the boot loader and the MBR partition table. Because most disk devices use a sector size of 512 bytes, the first-stage boot loader code must be very small. Most boot loaders, including both GRUB Legacy and GRUB 2, place additional code elsewhere on the disk. In the case of GRUB Legacy, this additional code is known as stage 1.5, and it's often placed in an unallocated area immediately following the MBR. Still more code, known as stage 2, is stored in files in the Linux boot partition (typically in the /boot directory), although Figure 1 omits these files for simplicity's sake. Likewise, in a multiple-operating system configuration, the secondary boot loader may store additional configuration files elsewhere. Figure 1. GRUB and GRUB 2 consist of several subcomponents that are loaded and run in sequenceGRUB 2 is similar to GRUB Legacy in overall form, but it eliminates stage 1.5 and implements a modular configuration approach in which code to handle various partitioning systems, file systems, and other extensions are stored in disk files—typically, in /boot/grub. Variants on the configuration just described are possible with both GRUB Legacy and GRUB 2. For instance, it's possible to install GRUB's stage 1 code in a Linux boot partition's first sector rather than in the MBR. Used in this way, another boot loader resides in the MBR, and GRUB's menu appears only when that boot loader chain-loads GRUB. Because the Extensible Firmware Interface (EFI), which is likely to eventually supplant the BIOS as standard PC firmware, provides a built-in boot loader, a configuration akin to this one is available for GRUB 2 on EFI-based systems. If you want to replace GRUB Legacy with GRUB 2 on a working system, you must install a new GRUB 2 package, configure its files, and run a special command to have GRUB 2 replace the existing GRUB Legacy MBR and special hidden code with the GRUB 2 equivalents. If you're switching to GRUB 2 because you're installing a new distribution that uses GRUB 2 as its default boot loader, you shouldn't need to deal with these steps. In either case, you must understand the new GRUB 2 configuration file's format as well as the new boot loader's overall features. GRUB 2's improvementsFor Linux-only systems, GRUB Legacy handles the boot loader job perfectly well. The reason for the transition has partly to do with boot loader development. GRUB Legacy contains code that the developers consider messy and unmaintainable. To add new features, they chose to rewrite the boot loader from scratch rather than build on such a base. As a practical matter to systems administrators, GRUB 2 supports several features that are important now or that may become important in the future:
Configuring GRUB 2If you're already familiar with GRUB Legacy, you'll find that the GRUB 2 configuration file is similar in broad strokes, but it varies in many details. You should be aware of alternative means of configuring GRUB 2, as well. An example configuration fileThe default location for the GRUB 2 configuration file is /boot/grub/grub.cfg. Some Linux distributions use /boot/grub2/grub.cfg instead, enabling side-by-side GRUB Legacy and GRUB 2 installations. Listing 1 shows a sample GRUB 2 configuration file. Listing 1. Sample GRUB 2 configuration fileset timeout=10 set default=0 menuentry "Linux (2.6.32.2 kernel)" { set root=(hd1,8) linux /bzImage-2.6.32.2 ro root=/dev/sdb4 initrd /initramfs-x86_64-2.6.32.2 } menuentry "Windows 7" { set root=(hd1,2) parttool (hd0,1) hidden+ parttool (hd1,5) hidden- chainloader +1 } If you're familiar with GRUB Legacy, you'll find this basic GRUB 2 configuration file similar. As with GRUB Legacy configuration files, the GRUB 2 file begins with a section that sets various global options—in this case, setting a timeout value to 10 seconds and setting the default menu entry. The file continues with a series of menu entries. The form of these entries
is different from those for GRUB Legacy, but the purpose is the same: Each
defines a single operating system or boot variant, such as a different
Linux kernel. Each menu entry begins with the keyword
Configuration file changesSeveral changes between the configuration file formats of GRUB Legacy and GRUB 2 deserve mention:
Another change is extremely important but not obvious from Listing 1:
Partitions are numbered starting from 1 in GRUB 2,
whereas partition numbering begins with 0 in GRUB Legacy. An equivalent
change in disk numbering is not implemented. Thus, the first
partition on the first disk is Using new GRUB 2 featuresOf course, GRUB 2 implements many new features. Some of these have little bearing on a standard Linux installation or don't directly affect the configuration file. Some important options you might need to adjust include the following:
Alternative methods of reconfiguring GRUB 2Ubuntu 9.10 uses the In some cases, deliberately running
If you need to make more specific changes, you could directly edit the files in /etc/grub.d. These files are actually bash scripts. Each one tells the system how to locate specific types of kernels or operating systems and add appropriate entries to /boot/grub/grub.cfg. An additional file referred to by Third parties have written some tools and scripts to help manage GRUB 2 installations. One example is the StartUp Manager. This graphical user interface (GUI) tool ships with Ubuntu and provides a point-and-click interface for managing both GRUB Legacy and GRUB 2 installations. Installing and using GRUB 2GRUB 2, like GRUB Legacy, must be installed once. Thereafter, the boot loader reads its /boot/grub/grub.cfg file to present the boot menu to you. Prior to installation, though, you may want to consider your partition layout. After installing GRUB 2, you should be aware of some basic features for boot-time operation. Preparing partitions for GRUB 2No special preparation is required to install GRUB 2 on a disk that uses the MBR partitioning scheme. The same is technically true of GPT; however, if a GPT disk includes a BIOS boot partition, GRUB 2 will store extra code in that partition. If the BIOS boot partition is not present, GRUB 2 instead relies on a list of disk sectors that correspond to a file in your /boot directory. If you ever adjust that file system, the sector list may become invalid, resulting in GRUB's inability to boot. Thus, use of a BIOS boot partition is strongly recommended on GPT disks. Your BIOS boot partition should be at least 31KB in size. Making it bigger
will do no harm and could be useful should GRUB's needs change in the
future. In recent versions of GNU Parted, you can set the
Installing GRUB 2You install GRUB 2 to a disk's MBR in the same way as GRUB, using the
You can normally install GRUB Legacy to a partition's boot sector (such as /dev/sda4) by typing: grub-install /dev/sda4 (changing the partition device file name as necessary). This doesn't work with GRUB 2, though. You may be able to overcome this problem by typing: grub-setup --force /dev/sda4 (changing the device file name as necessary); however, this method doesn't always work. Run time GRUB 2 useDuring normal use, GRUB 2 works much like GRUB Legacy: When you boot the computer, just after the BIOS performs its checks, a menu of operating system and kernel options appears. You choose the one you want to boot using the arrow keys, and then press Enter. If you make no selection, the default may be booted, depending on the configuration file options. If an entry doesn't work, you may be able to make a one-time change to it by using GRUB 2 edit mode. Instead of pressing the Enter key to boot an entry, press the E key to edit it. You'll see a simple editor that accepts Emacs-like editing options. When you're done, press Ctrl-X to boot your altered entry. If GRUB 2 can't locate its configuration file, it will present you with a
Should you use GRUB 2?The most compelling reasons for using GRUB 2 are if you're using a distribution that installs it by default or you need access to one of its unusual features, such as the ability to directly boot an XNU kernel. In most other cases, GRUB 2 offers few or no advantages over GRUB Legacy. One in-between case is if you've used GPT on a BIOS-based computer. GRUB 2 supports this configuration, but the standard GRUB Legacy does not. Patched versions of GRUB Legacy with GPT support are available and ship with most modern distributions, but you may prefer using a boot loader with official GPT support. The bottom line is this: If what you have installed already works, it's best to keep using it. Changing boot loaders can render a system unbootable, and correcting that problem is a tedious proposition. That said, GRUB 2 is likely to supplant GRUB Legacy moving forward, so you may want to familiarize yourself with GRUB 2, if only on a test system or virtual machine. Sooner or later, you may find that your GRUB configuration file format has changed, because your distribution has changed its boot loader. A little advance research will help you weather this change with minimal fuss. |
|
来自: astrotycoon > 《boot》