GRUB/ru

GRUB2 — загрузчик с поддержкой современных компьютеров. Это значит, что он пришёл на смену GRUB (теперь известный как "GRUB Legacy"). GRUB2 имеет абсолютно новую, отдельную от GRUB Legacy, кодовую базу и включает в себя много новых возможностей, таких как новый, шелл-подобный синтаксис, который предоставляет расширенные возможности для написания скриптов. Пользователям GRUB Legacy рекомендуется перейти на GRUB2.

Для быстрого знакомства посмотрите статью быстрое знакомство с GRUB2

Установка
The package is slotted. Both grub-0.97 (GRUB Legacy) and grub-2.00 may be installed at the same time, however only one version of GRUB may be installed in a MBR at a time.

Prerequisites
По умолчанию GRUB2 попытается угадать целевую платформу во время сборки. Это может быть переопределено с помощью переменной GRUB_PLATFORMS в.

Следующие платформы поддерживаются, в зависимости от целевого CPU:

Установка
To install GRUB2 use the normal syntax:

Additional software
Optionally, install the utility (provided through the  package) to have GRUB2 probe for other operating systems when running the  command. In most instances, this will enable GRUB2 to automatically detect other operating systems (Windows 7, 8.1, 10, etc.).

Установка GRUB2 (и, опционально, ) сами по себе не устанавливают загрузчик. Они лишь устанавливают программы на систему, но для установки загрузчика (чтобы он использовался для загрузки системы), необходимо выполнить дополнительные действия, о которых написано в разделе конфигурация.

Конфигурация
There are two important aspects to the configuration of GRUB2:


 * 1) Installation of GRUB2 software as the boot loader of the system.
 * 2) Configuration of the GRUB2 boot loader.

Установка GRUB2 специфична для каждого типа системы и описана в разделе установка загрузчика. Сначала рассмотрим настройку самого загрузчика.

Главный файл настроек
Скрипт используется для генерации grub конфигурации. Он использует скрипты из каталога и конфигурационный файл  для генерации  файла, который используется самим GRUB2.

GRUB2 does not require the administrator to manually maintain a boot option configuration (as is the case with boot loaders such as GRUB Legacy and LILO). Instead it can generate its configuration file using the  command. This utility will use the scripts in and the settings in.

После изменения одной или более настроек, запустите утилиту с опцией , которая указывает файл, куда необходимо сохранить конфигурацию  (это конфигурационный файл GRUB2 по умолчанию):

Каждый раз, когда вызывается утилита, будет сгенерирована новая конфигурация.

Настройка параметров конфигурации
The following variables in are the most common ones to set to control how GRUB2 will function:

Для более полного списка обратитесь к Списку настроек GRUB2.

После изменения параметров пересоздайте файл настроек с помощью.

Включение или отключение конфигурационных скриптов
The directory contains the scripts that  uses to generate a  file. By default the contents of this directory should be similar to the following:

GRUB2 will use all installed scripts that are marked as executable (which by default, they all are). To disable any of the scripts simply remove the executable bit from the script's file permissions using the command. In the following example every script but and  are disabled:

After modifying the scripts (or removing the executable bit), regenerate the GRUB2 configuration file using.

Manipulating configuration scripts
Some features or GRUB2 functionalities are only possible to be exploited by modifying the configuration scripts. For instance, to support dual-booting with FreeBSD, the following manipulation needs to be done.

Измените конфигурационный скрипт так:

or  is the partition in which FreeBSD resides. If the normal UFS install was used for the FreeBSD partition then is a container (something like a logical partition). It consists of the swap and root partition. Verify the script is executable by running. If the executable bit is not set then set it using the command.

Next install GRUB2 using the command and update GRUB2's configuration file:

Установка загрузчика
Installing GRUB2 as the system's boot loader depends on how the system is meant to boot (through BIOS or UEFI) and how the disk on which the boot loader should be installed is partitioned (using MBR or GPT partition layout).

This article covers the following situations:


 * BIOS with MBR
 * BIOS with GPT
 * UEFI with GPT

Select the installation instructions appropriate for the system.

BIOS и MBR
Make sure that the location is available - if this uses a separate partition, make sure that it is mounted:

Run the command to copy the relevant files to. On the PC platform, this also installs a boot image to the Master Boot Record (MBR) or a partition's boot sector. If all goes well, after running an output such as the one below is to be expected:

accepts a  option to set the CPU architecture and system platform. If unspecified, will attempt to guess the proper values; on an / system it will use   by default. also accepts a  option to tell the GRUB2 installer which directory to look for GRUB2's boot files. This defaults to the current but is useful when trying to move a root partition.

Partitioning for BIOS with MBR
Be sure to leave enough free space before the first partition. Starting the first partition at sector 2048 leaves at least 1 MiB of disk space for the master boot record. It is recommended (but not mandatory) to create an additional partition for GRUB called the BIOS boot partition. This partition just needs to be defined, but not formatted.

If the Gentoo installation instructions were followed, this BIOS boot partition will already be available.

BIOS и GPT
If a partition is needed, start by mounting the  partition:

If all goes well, after running the command an output such as the one below is to be expected:

accepts a  option to set the CPU architecture and system platform. If unspecified, will attempt to guess the correct values; on an / system it will use   by default. also accepts a  option to tell the GRUB2 installer which directory to look in for GRUB2's boot files. This defaults to the current but is useful when trying to move a root partition.

Partitioning for BIOS with GPT
When a GPT partition table is present on the system, a small BIOS boot partition with type  (which is different from the EFI System Partition (ESP) which has type  ) will need to be available. 1 MiB will be enough to work, but 2-4 MiB is a safer option. This BIOS boot partition will hold the stage 2 of the bootloader. BIOS boot partitions do not need to be formatted with a filesystem; the command will overwrite any existing filesystem with one of its own.

To set a partition as a BIOS partition use the command-line tool  by typing (change   to the number of the partition to mark as a BIOS boot partition!):

With 's utility, this is accomplished by setting the partition type to   and giving it a label of.

An EFI System Partition is not required, but it would be sensible to make sure that the BIOS boot partition is large enough to be converted to one, should the system motherboard later be upgraded to an UEFI board.

The following is the output of pressing the key using the  utility on a GPT-partitioned disk with both a BIOS boot [0xEF02] partition and an EFI [0xEF00] partition:

Using the same setup, the utility gives output with slightly different syntax:

Creating partitions in is straightforward for users familiar with the  partitioning utility. After starting, type (for new) in the main menu, provide beginning and end sectors (if needed), and set the partition type to   for an EFI system partition.

Users who have followed the Gentoo installation instructions will already have the proper partitioning layout set up.

UEFI и GPT
Удостоверьтесь, что существует - если для нее используется отдельный раздел, убедитесь, что он смонтирован:

Run the command to copy the relevant files to. This should install Grub2 in, copy the core image to , and call efibootmgr to add a boot entry.

The above command assumes the vfat EFI System Partition (ESP) is mounted at. If the ESP is mounted directly at, use.

also accepts a  option to set the CPU architecture and system platform. If unspecified, will attempt to guess the proper values; on an AMD64 UEFI-booted system it will use   by default. also accepts a  option to tell the GRUB2 installer which directory to look for GRUB2's boot files. This defaults to but is useful when trying to move a root partition.

Partitioning for UEFI with GPT
For UEFI GPT boot using GRUB2, the system must have a dedicated EFI partition containing a FAT filesystem.

The EFI partition can replace having a partition on  by having a  partition on. This is to say a successful UEFI boot scenario using GRUB2 can operate with two partitions total (three total if a swap partition is needed): a root partition and an EFI partition. Using this configuration, the folder will be located in the root  partition (at ) and the EFI partition will mount in the boot folder (at ). For further clarification, see the example file below.

Generating a 100MB partition for should provide plenty of space for holding multiple  files (multiple entries will most likely not be needed; most systems will only use one).

Create the partition using the partitioning tool of choice. The  and   tools fit nicely for this purpose. When using the utility, be sure to use type.

Proceed to create a FAT filesystem on the EFI system partition using and add it to  by following the example below:

Alternative: using the default UEFI firmware location
If the system's UEFI firmware fails to find GRUB2's EFI bootloader file, using the default boot loader location should provide a working solution. This circumvents the boot menu managed by efibootmgr and thus offers reduced functionality, but is less error prone. To do this, verify the EFI partition is mounted at then copy the file  located at  to. This example assumes a 64-bit UEFI system, adjust accordingly for 32-bit UEFI systems.

Расширенные возможности
GRUB2 has many features that make it a very powerful boot loader. It supports:


 * Booting from UEFI platforms.
 * Booting from GPT partitioned drives without needing a hybrid MBR (hybrid MBR can enabled as needed for compatibility or portability).
 * Booting from a btrfs formatted partition.
 * Booting directly from a btrfs raid set without needing an initramfs for early mount setup.
 * Booting directly from logical volume management (such as LVM2).
 * Booting with support for DM-RAID (RAID 0, 1, 4, 5, 6, 9 and 10).
 * Booting from encrypted devices (LUKS).

Some specific features are explained in more detail next.

Chainloading
GRUB2 was built with a truly improved chainload mode when compared to GRUB Legacy. To chainload another boot loader, use the  option.

For more information on chainloading, please see the Chainloading sub-page.

Using framebuffer display
To have GRUB2 use a framebuffer graphical display, re-emerge GRUB with the  USE flag enabled. This will install a default True Type font as well as a font conversion utility.

Proceed to configure the default GRUB2 configuration file located at. For example:

In order to find out what display modes the system's graphics card supports, use the following commands on the GRUB2 shell:

Устранение проблем
Most of the issues can be resolved by ensuring that the partition layout is correct. Make sure enough space is available before the first partition of the disk, or optionally make sure that a BIOS boot partition is available. Also verify that was correctly generated with, or generate one with a custom menu entry.

For more GRUB2 troubleshooting, please refer to the Troubleshooting sub-article.

Смотрите также
There are a few specific GRUB2 resources available:


 * In Chainloading the use of GRUB2 to boot other boot loaders is described. This is important to read when dual-booting systems, or when GRUB2 needs to be configured to boot ISO files.
 * In Advanced storage the necessary steps are documented on how to install and use GRUB2 on more advanced storage situations, such as software RAID, logical volumes or encrypted file systems.
 * In Configuration variables an exhaustive list of GRUB2 configuration variables, as used by, is documented.
 * In Troubleshooting a list of common GRUB2 errors (with their solutions) is presented.
 * In Hybrid partition table the use of a mixed MBR/GPT setup is documented, as well as how to use such hybrid partition layout with GRUB2.

Ссылки
Для большей информации смотрите:


 * GNU GRUB 2 manual page
 * Network (PXE) section of GRUB2
 * Legacy BIOS issues with GPT article
 * GPT and Hybrid MBR article
 * GPT fdisk utility page
 * Arch Linux GRUB2 wiki article
 * Fedora GRUB2 wiki article : Encountering the dreaded GRUB2 boot prompt
 * ubuntu UEFI booting help
 * http://unix.stackexchange.com/questions/109272/dualboot-freebsd-gentoo-with-grub2-mbr
 * A blog post entry on locking specific GRUB2 boot entries with a password