{{Note|Simply installing the package won't update the actual grub2 code in grub.efi in the UEFI System Partition . You need to update the grub.efi and the grub2 modules in the UEFI System Partition using grub_efi_${UEFI_ARCH}-install as explained below.}}

+

{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}

Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_EFI_SYSTEM_PARTITION_in_Linux EFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MB in size. If you have mounted the EFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:

Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_EFI_SYSTEM_PARTITION_in_Linux EFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MB in size. If you have mounted the EFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:

Revision as of 18:24, 17 September 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

GRUB2 is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from PUPA which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [1].

Briefly, the bootloader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.

Preface

Although, GRUB (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.

Notes for current GRUB users

There are differences in the commands of GRUB and GRUB2. Familiarize yourself with GRUB2 commands before proceeding (e.g. "find" has been replaced with "search").

GRUB2 is now modular and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for LVM or RAID support).

Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, Template:Filename would be referred to as Template:Codeline (for MBR) or Template:Codeline (for GPT) using GRUB2.

Installation

During Arch Linux installation

Skip the Install Bootloader step and exit the installer.

Configure the network:

# aif -p partial-configure-network

If you did not configure the installed system's Template:Filename file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:

Note: This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.

From the installer's live shell, chroot to the installed system:

# mount -o bind /dev /mnt/dev
# chroot /mnt bash

Update pacman's database:

# pacman-db-upgrade

Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):

# pacman -Syy

Install the GRUB2 package as mentioned in the section #From a running Arch Linux. Note that the dm-mod module has already been loaded, no need to do that again.

From a running Arch Linux

BIOS systems

Note: Simply installing the package won't update the actual grub2 code in the MBR or the core.img embedded in the system. You need to update the code on the disk using grub_bios-install as explained below.

Note: When installing the grub2-common 1.99~rc1 (or later), this took quite some time because the installer does not use the option --no-floppy, for more details search this option in the article.

Then GRUB2 must be installed to the Master Boot Record of a drive:

NOTE: GRUB2 as of version 1.99 does not support installing to a partition boot sector like grub-legacy does.

You can then chainload grub2's core.img from grub-legacy as a Linux kernel or a multiboot kernel.

The Template:Codeline tells to not search for floppy devices which will vastly improve the command's overall execution time on many systems (it will also prevent the issue below from occuring) and where Template:Filename is the destination of the installation (in this case the MBR of the first SATA disk). If you use LVM for your Template:Filename, you can install GRUB2 on multiple physical disks.

Executing grub_bios-install without the Template:Codeline flag can also lead to this when there is a problem detecting the path of the floppy device:

grub-probe: error: Cannot get the real path of '/dev/fd0'
Auto-detection of a filesystem module failed.
Please specify the module with the option '--modules' explicitly.

Thus it is recommended to use the Template:Codeline switch, if you do not want to have your MBR on a floppy. If you do, you also want to set floppy as the first boot device in BIOS.

Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):

GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of 32 KiB post MBR gap in GPT partitioned systems.

Create a 1 MiB (minimum size) partition using gdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the GPT disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in GPT fdisk or set "bios_grub" flag on in GNU Parted or GParted.

This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding takes place in that case. Neither GRUB-legacy nor SYSLINUX require this partition.

Note: This partition should be created before grub_bios-install or grub-setup is run or before the Install Bootloader step of the Archlinux installer (if GRUB2 is selected as bootloader).

Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).

Note: Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.1 version nor UEFI 2.x version but includes features of both. This kind of firmware does not fall under any one UEFI version so it is not a standard EFI firmware.

GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first Detect which UEFI firmware arch you have (either x86_64 or i386).

Depending on that, install the appropriate package

For 64-bit aka x86_64 UEFI firmware:

# pacman -S grub2-efi-x86_64

For 32-bit aka i386 UEFI firmware:

# pacman -S grub2-efi-i386

Note: Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.

Mount the EFI SYSTEM PARTITION in your system at Template:Filename. It should be FAT32 formatted and should be at least 200 MB in size. If you have mounted the EFISYS partition in some other mountpoint, replace Template:Filename in the below commands with that mountpoint:

If you notice carefully, there is no <device_path> option (Eg: Template:Filename) at the end of the Template:Codeline command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.

Then copy the font files required to enable UEFI video mode (GOP mostly) in grub2 (otherwise no kernel boot messages will be seen in the console):

# cp /usr/share/grub/unicode.pf2 /boot/efi/efi/grub/

Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):

Correct GRUB2 Video Mode problems in UEFI

Copy /usr/share/grub/unicode.pf2 to /boot/efi/efi/grub/

# cp /usr/share/grub/unicode.pf2 /boot/efi/efi/grub/

and then, in the Template:Filename file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:

Launch GRUB2 as default in UEFI Boot Manager

For non-Mac UEFI systems

NOTE: The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.

grub_efi_${UEFI_ARCH}-install will ensure Template:Filename is launched by default if it detects Template:Codeline and if it is able to access UEFI Runtime Services. Template:Codeline command will work only if you have booted the system in UEFI mode itself, since it requires access to UEFI Runtime Variables which are available only in UEFI boot mode (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch Template:Filename from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then Template:Codeline should be run to make grub2 as the default entry in the UEFI Boot Manager

First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:

# grub-probe --target=device /boot/efi/efi/grub/grub.efi

It should give something like Template:Filename (used as example in the remaining steps). Load 'efivars' kernel module:

# sudo modprobe efivars

If you get no such device found error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.

Verify whether there are files in /sys/firmware/efi/vars/ directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.

FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using Template:Filename or Template:Filename does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path Template:Filename is passed to Template:Codeline.

The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from efibootmgr GIT README

If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):

# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi

or

# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi

or

# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi

After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).

For Apple Macs EFI

Use bless command

This article or section needs expansion.

Reason:please use the first argument of the template to provide a brief explanation. (Discuss in Talk:GRUB#)

For UEFI Systems

The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot.

It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 Template:Codeline app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.

Configuration

grub-mkconfig

The grub-mkconfig script can be used to generate a Template:Filename file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a Template:Filename file run the command:

Template:Codeline sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition (Template:Filename)

With Windows via EasyBCD and NeoGRUB

Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your Template:Filename file with lines similar to the following:

default 0
timeout 1

title Chainload into GRUB v2
root (hd0,7)
kernel /boot/grub/core.img

Visual Configuration

In GRUB2 it is possible, by default, to change the look of the menu.

Background image and bitmap fonts

GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename Template:Filename, or, as only ascii characters under the name Template:Filename. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a Template:Filename file as background. Two sample configurations are shown below.

Hidden menu

One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.

Edit Template:Filename as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:

GRUB_HIDDEN_TIMEOUT=5
GRUB_HIDDEN_TIMEOUT_QUIET=false

and run:

grub-mkconfig -o /boot/grub/grub.cfg

Setting the framebuffer resolution

Grub2 can set the framebuffer for both grub2 itself and the kernel. The old vga= way is deprecated. The preferred method is editing Template:Filename as the following sample:

If this method does not work for you, the deprecated vga= method will still work. Just
add it next to the "GRUB_CMDLINE_LINUX_DEFAULT=" line in Template:Filename
for eg: "GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792" will give you a Template:Codeline resolution.

Persistent block device naming

You can use UUIDs to detect partitions instead of the "old" Template:Filename and Template:Filename scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.

UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the Template:Filename file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.

The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):

Recall previous entry

Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit Template:Filename and change the setting of Template:Codeline:

GRUB_DEFAULT=saved

This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to Template:Filename:

GRUB_SAVEDEFAULT=true

Remember to regenerate your configuration file.

Security

If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command Template:Codeline. Enter a password and confirm it. The output will look like this:

Using the command shell

Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in Template:Filename, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.

GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:

sh:grub>

If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:

grub rescue>

The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:

parttool or legacy hide/unhide

If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:

Using the rescue console

See #Using the command shell first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.

The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.

Before starting, the user must know the location of their Template:Filename partition (be it a separate partition, or a subdirectory under their root):

Combining the use of UUID's and basic scripting

If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)

menuentry "Arch Linux 64" {
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07
#Enter the UUID of the partition containing the root partition of your Arch Linux installation.
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a
#(Note: this may be the same as your boot partition)
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above
search --fs-uuid --no-floppy --set=root $uuid_os_root
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot
#Here is the magic. We test to see if the boot and root partitions have the same UUID.
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.
if [ $uuid_grub_boot == $uuid_os_root ] ; then
set grub_boot=$grub_boot/boot
fi
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro
initrd ($grub_boot)/initramfs-linux.img
}

Troubleshooting

Any troubleshooting should be added here.

msdos-style error message

grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.
However, blocklists are UNRELIABLE and its use is discouraged.
grub-setup: error: If you really want blocklists, use --force.

This error may occur when you try installing GRUB2 in a VMware container. Read more about it here. Hopefully a fix will be provided soon.

It also happens when the first partition starts just after the MBR (block 63), without the usual space of 1MB (2048 blocks) before the first partition.

Grub not loaded

In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of

If everything works correctly, the EFI would now automatically load grub.
If the screen only goes black for a second and the next boot option is tried afterwards, according to this post, moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then: