GNU GRUB

来源:互联网 发布:mac 命令行删除文件 编辑:程序博客网 时间:2024/04/29 07:57

GNU GRUB ("GRUB" for short) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Multiboot Specification, which allows a user to have several different operating systems on their computer at once, and to choose which one to run when the computer starts. GRUB can be used to select from differentkernel images available on a particular operating system's partitions, as well as to pass boot-time parameters to such kernels.

GNU GRUB developed from a previous package called the Grand Unified Bootloader (a play ongrand unified theory). It is predominantly used on Unix-like systems; the GNU operating system uses GNU GRUB as its boot loader, as do most general-purposeLinux distributions. Solaris has used GRUB as its bootloader on x86 systems since the Solaris 10 1/06 release.

Features

GRUB is dynamically configurable; it loads its configuration at startup, allowing boot-time changes such as selecting differentkernels or initial RAM disks. To this end, GRUB provides a simple, bash-like, command line interface which lets users write new boot sequences.

GRUB is highly portable. It supports multiple executable formats,and is geometry translation independent; while Multiboot compliant, itsupports non-multiboot operating systems such asMicrosoft Windows and OS/2 via a chain loading function. GRUB supports all commonly used Unix file systems as well asVFAT and NTFS as used by Windows, and supports Logical Block Address (LBA) mode. GRUB allows users to view the contents of files on any supported file system.

GRUB can be used with a variety of different user interfaces.Most Linux distributions take advantage of GRUB's support for agraphical interface to provide a customized boot menu with a backgroundimage, and occasionally mouse support.[citation needed] GRUB's text interface can be set to use a serial link to provide a remote terminal boot loader access.

GRUB can download operating system images from a network, and canthus support disk-free systems. GRUB supports automatic decompressionof OS images prior to booting from them.

GRUB differs from other boot loaders by being able to communicatewith a user directly via a GRUB prompt. A GRUB prompt is the stagebefore GRUB loads an operating system and can be triggered at atext-mode GRUB booting screen (which is controlled by the configurationfile "menu.lst" (or "grub.conf": see below)) by pressing the "c" key. AGRUB prompt (similar tobash)can also be obtained by booting GRUB as a stand alone system without anoperating system attached or in any GRUB installation with an operatingsystem when the "menu.lst" file is absent. From the GRUB prompt a usercan manually select and control booting from any installed operatingsystem by using bash-like commands. To boot an operating systemautomatically, the appropriate commands are placed in a configurationfile called "menu.lst" in a designated subdirectory.

GRUB has a rich set of terminal commands that allow a user at theGRUB prompt to view the partition details of the hard disks, alter apartition setting, re-map the disk order temporarily, boot anyuser-defined configuration file and to view booting configuration ofother boot loaders in file formats GRUB supports. Thus, without priorknowledge of what is installed on a computer one can use GRUB from anexternal device such as afloppy disk, USB device or a CD-ROM to boot up an installed operating system.

GRUB uses a scrolling screen for selection of operating systems toboot. This means 150 or more booting choices can be controlled by GRUBwith ease by adding each to the "menu.lst" configuration file, andselecting one at boot time using the arrow keys.

One boot loader can boot another boot loader by chainloading. GRUB uses the same two to three lines of command sequences to boot anyDOS,Windows, Linux, BSD or Solaris system, making it very easy to work with.

Although GNU GRUB can be pre-packaged or retro-built into Unix-likeoperating systems, there are also specific GRUB implementations for DOSand Windows. GRUB can also be installed as a stand alone systemunattached to any operating system. Its implementation requires onefile for booting from a CD and two files for booting from a floppy,hard disk or a USB device. These files are available from any LinuxLive CD that supports GRUB, making it easily and freely obtainable bycomputer users.

Boot process

When a computer is turned on, the computer's BIOS finds the primary bootable device (usually the computer's hard disk) and loads the initialbootstrap program from the master boot record (MBR), the first 512 bytes of the hard disk, and then transfers control to this code.

The MBR contains GRUB stage 1. Given the small size of the MBR,Stage 1 does little more than load the next stage of GRUB (which mayreside physically elsewhere on the disk). Stage 1 can either load Stage2 directly, or it can load stage 1.5: GRUB Stage 1.5 is located in thefirst 30 kilobytes of hard disk immediately following the MBR. Stage1.5 loads Stage 2.

When GRUB Stage 2 receives control, it presents an interface to theuser in order to select which operating system to boot. This normallytakes the form of a graphical menu, although if this is not availableor the user wishes further control, GRUB has its own command prompt,where the user can manually specify the boot parameters. GRUB can alsobe set to automatically load a particular kernel after a timeout period.

Once boot options have been selected, GRUB loads the selected kernelinto memory and passes control on to the kernel, which then continuesto start itself. At this stage GRUB can also pass control of the bootprocess to another loader, usingchain loading, for operatingsystems such as Windows that do not support the Multiboot standard. Inthis case, copies of the other system's boot programs have been savedby GRUB; instead of a kernel, the other system is loaded as though ithad been started from the MBR. This may be yet another boot manager,such as the Microsoft boot menu, allowing further selection ofnon-Multiboot operating systems. (This behavior is often automatic whenmodern Linux distributions are installed "on top of" existing Windowssystems, allowing the user to retain the original operating systemwithout modification, including systems that contain multiple versionsof Windows.)

Installation

A key feature of GRUB is that it can be installed without beingattached to an operating system; however, it needs a copy of a Linuximage for such an installation. Working as a stand alone system it isvirtually a mini system in its own right and able to boot all theinstalled major operating systems by chain loading, as described above.

Unlike LILO, there is no need to reinstall GRUB to the MBR or a partition after a change to the configuration file.

In Linux, the "grub-install" command is used to install stage1 toeither the MBR or a partition. GRUB's configuration file, stage2(usually), and other files must be in a usable partition. If thesefiles or the partition become unavailable stage1 will drop the user tothe command line interface.

The name and disk location of the GRUB configuration file varies from system to system; for example, inDebian GNU/Linux and openSUSE the file is stored in /boot/grub/menu.lst while Fedora and Gentoo Linux uses /boot/grub/grub.conf. Fedora also provides a symbolic link from /etc/grub.conf to /boot/grub/grub.conf forFHS compatibility reasons.

Instead of being installed on the system's hard disk, GRUB can be installed onremovable media such as an optical drive (bios access, and el-torito), floppy disk or USB flash drive in order to bring up a system which may not have or cannot boot from its own disk.