GRUB
Related articles
- Arch boot process
- Boot loaders
- Master Boot Record
- GUID Partition Table
- Unified Extensible Firmware Interface
- GRUB Legacy
- GRUB/EFI examples
- GRUB/Tips and tricks
GRUB — not to be confused with GRUB Legacy — is the next generation of the GRand Unified Bootloader. GRUB is derived from PUPA which was a research project to develop the next generation of what is now GRUB Legacy. GRUB has been rewritten from scratch to clean up everything and provide modularity and portability [1].
Contents
- 1 Preface
- 2 BIOS systems
- 2.1 GUID Partition Table (GPT) specific instructions
- 2.2 Master Boot Record (MBR) specific instructions
- 2.3 Installation
- 2.3.1 Install boot files
- 2.3.1.1 Install to disk
- 2.3.1.2 Install to external USB stick
- 2.3.1.3 Install to partition or partitionless disk
- 2.3.1.4 Generate core.img alone
- 2.3.1 Install boot files
- 3 UEFI systems
- 3.1 Check if you have GPT and an ESP
- 3.2 Create an ESP
- 3.3 Installation
- 3.4 Further reading
- 3.4.1 Alternative install method
- 3.4.2 UEFI firmware workaround
- 3.4.3 Create a GRUB entry in the firmware boot manager
- 3.4.4 GRUB standalone
- 3.4.5 Technical information
- 4 Generate the main configuration file
- 5 Configuration
- 5.1 Additional arguments
- 5.2 Dual-booting
- 5.2.1 Automatically generating using /etc/grub.d/40_custom and grub-mkconfig
- 5.2.1.1 GNU/Linux menu entry
- 5.2.1.2 FreeBSD menu entry
- 5.2.1.2.1 Loading the kernel directly
- 5.2.1.2.2 Chainloading the embedded boot record
- 5.2.1.2.3 Running the traditional BSD 2nd stage loader
- 5.2.1.3 Windows XP menu entry
- 5.2.1.4 Windows installed in UEFI-GPT Mode menu entry
- 5.2.1.5 "Shutdown" menu entry
- 5.2.1.6 "Restart" menu entry
- 5.2.1.7 Windows installed in BIOS-MBR mode
- 5.2.2 With Windows via EasyBCD and NeoGRUB
- 5.2.3 parttool for hide/unhide
- 5.2.1 Automatically generating using /etc/grub.d/40_custom and grub-mkconfig
- 5.3 LVM
- 5.4 RAID
- 5.5 Multiple entries
- 5.6 Encryption
- 5.6.1 Root partition
- 5.6.2 Boot partition
- 6 Using the command shell
- 6.1 Pager support
- 6.2 Using the command shell environment to boot operating systems
- 6.2.1 Chainloading a partition
- 6.2.2 Chainloading a disk/drive
- 6.2.3 Chainloading Windows/Linux installed in UEFI mode
- 6.2.4 Normal loading
- 6.3 Using the rescue console
- 7 Troubleshooting
- 7.1 Intel BIOS not booting GPT
- 7.1.1 MBR
- 7.1.2 EFI path
- 7.2 Enable debug messages
- 7.3 "No suitable mode found" error
- 7.4 msdos-style error message
- 7.5 UEFI
- 7.5.1 Common installation errors
- 7.5.2 Drop to rescue shell
- 7.5.3 GRUB UEFI not loaded
- 7.6 Invalid signature
- 7.7 Boot freezes
- 7.8 Arch not found from other OS
- 7.9 Warning when installing in chroot
- 7.10 GRUB loads slowly
- 7.11 error: unknown filesystem
- 7.12 grub-reboot not resetting
- 7.13 Old BTRFS prevents installation
- 7.1 Intel BIOS not booting GPT
- 8 See also
Preface
- A 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.
- The name GRUB officially refers to version 2 of the software, see [2]. If you are looking for the article on the legacy version, see GRUB Legacy.
- GRUB supports Btrfs as root (without a separate
/boot
file system) compressed with either zlib or LZO- GRUB currently (Sep 2015) supports booting from Btrfs RAID 0/1/10, but not RAID 5/6. You may use mdadm for RAID 5/6, which is supported by GRUB.
- GRUB does not support F2FS as root so you will need a separate
/boot
with a supported file system.
BIOS systems
GUID Partition Table (GPT) specific instructions
On a BIOS/GPT configuration a BIOS boot partition is required. GRUB embeds its core.img
into this partition.
Create a mebibyte partition (+1M
with fdisk
or gdisk
) on the disk with no file system and type BIOS boot (BIOS boot in fdisk, ef02
in gdisk, bios_grub
in parted
). This partition can be in any position order but has to be on the first 2 TiB of the disk. This partition needs to be created before GRUB installation. When the partition is ready, install the bootloader as per the instructions below.
The post-GPT gap can also be used as the BIOS boot partition though it will be out of GPT alignment specification. Since the partition will not be regularly accessed performance issues can be disregarded (though some disk utilities will display a warning about it). In fdisk
or gdisk
create a new partition starting at sector 34 and spanning to 2047 and set the type. To have the viewable partitions begin at the base consider adding this partition last.
Master Boot Record (MBR) specific instructions
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the first partition) in many MBR (or 'msdos' disklabel) partitioned systems is 31 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding GRUB's core.img
(FS#24103). It is advisable to use a partitioning tool that supports 1 MiB partition alignment to obtain this space as well as to satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img
).
Installation
Install the grub package. It will replace grub-legacyAUR, where already installed.
Install boot files
There are 4 ways to install GRUB boot files in BIOS booting:
- Install to disk (recommended)
- Install to external USB stick (for recovery)
- Install to partition or partitionless disk (not recommended)
- Generate core.img alone (safest method, but requires another BIOS bootloader like Syslinux to be installed to chainload
/boot/grub/i386-pc/core.img
)
Install to disk
The following commands will:
- Set up GRUB in the 440-byte Master Boot Record boot code region
- Populate the
/boot/grub
directory - Generate the
/boot/grub/i386-pc/core.img
file - Embed it in the 31 KiB (minimum size - varies depending on partition alignment) post-MBR gap in case of MBR partitioned disk
- In the case of a GPT partitioned disk it will embed it in the BIOS Boot Partition , denoted by
bios_grub
flag in parted and EF02 type code in gdisk
# grub-install --recheck --target=i386-pc /dev/sdx # grub-mkconfig -o /boot/grub/grub.cfg
If you use LVM for your /boot
, you can install GRUB on multiple physical disks.
Install to external USB stick
Assume your USB stick's first partition is FAT32 and its partition is /dev/sdy1
# mkdir -p /mnt/usb ; mount /dev/sdy1 /mnt/usb # grub-install --target=i386-pc --recheck --debug --boot-directory=/mnt/usb/boot /dev/sdy # grub-mkconfig -o /mnt/usb/boot/grub/grub.cfg
# optional, backup config files of grub.cfg # mkdir -p /mnt/usb/etc/default # cp /etc/default/grub /mnt/usb/etc/default # cp -a /etc/grub.d /mnt/usb/etc
# sync; umount /mnt/usb
Install to partition or partitionless disk
To set up grub to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sdaX
as the /boot
partition):
# chattr -i /boot/grub/i386-pc/core.img # grub-install --target=i386-pc --recheck --debug --force /dev/sdaX # chattr +i /boot/grub/i386-pc/core.img
You need to use the --force
option to allow usage of blocklists and should not use --grub-setup=/bin/true
(which is similar to simply generating core.img
).
grub-install
will give out warnings like which should give you the idea of what might go wrong with this approach:
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea. /sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.
Without --force
you may get the below error and grub-setup
will not setup its boot code in the partition boot sector:
/sbin/grub-setup: error: will not proceed with blocklists
With --force
you should get:
Installation finished. No error reported.
The reason why grub-setup
does not by default allow this is because in case of partition or a partitionless disk is that GRUB relies on embedded blocklists in the partition bootsector to locate the /boot/grub/i386-pc/core.img
file and the prefix directory /boot/grub
. The sector locations of core.img
may change whenever the file system in the partition is being altered (files copied, deleted etc.). For more info, see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915.
The workaround for this is to set the immutable flag on /boot/grub/i386-pc/core.img
(using chattr
command as mentioned above) so that the sector locations of the core.img
file in the disk is not altered. The immutable flag on /boot/grub/i386-pc/core.img
needs to be set only if GRUB is installed to a partition boot sector or a partitionless disk, not in case of installation to MBR or simple generation of core.img
without embedding any bootsector (mentioned above).
Unfortunately, the grub.cfg
file that is created will not contain the proper UUID in order to boot, even if it reports no errors. see https://bbs.archlinux.org/viewtopic.php?pid=1294604#p1294604.
In order to fix this issue the following commands:
# mount /dev/sdxY /mnt #Your root partition. # mount /dev/sdxZ /mnt/boot #Your boot partition (if you have one). # arch-chroot /mnt # pacman -S linux # grub-mkconfig -o /boot/grub/grub.cfg
Generate core.img alone
To populate the /boot/grub
directory and generate a /boot/grub/i386-pc/core.img
file without embedding any GRUB bootsector code in the MBR, post-MBR region, or the partition bootsector, add --grub-setup=/bin/true
to grub-install
:
# grub-install --target=i386-pc --grub-setup=/bin/true --recheck --debug /dev/sda
You can then chainload GRUB's core.img
from GRUB Legacy or syslinux as a Linux kernel or as a multiboot kernel (see also Syslinux#Chainloading).
UEFI systems
Check if you have GPT and an ESP
An EFI System Partition (ESP) is needed on every disc you want to boot using EFI. GPT is not strictly necessary, but it is highly recommended and is the only method currently supported in this article. If you are installing Arch Linux on an EFI-capable computer with an already-working operating system, like Windows 8 for example, it is very likely that you already have an ESP. To check for GPT and for an ESP, use parted
as root to print the partition table of the disk you want to boot from. (We are calling it /dev/sda
.)
# parted /dev/sda print
For GPT, you are looking for "Partition Table: GPT". For EFI, you are looking for a small (512 MiB or less) partition with a vfat file system and the boot flag enabled. On it, there should be a directory named "EFI". If these criteria are met, this is your ESP. Make note of the partition number. You will need to know which one it is, so you can mount it later on while installing GRUB to it.
Create an ESP
If you do not have an ESP, you will need to create one. See UEFI#EFI System Partition
Installation
This section assumes you are installing GRUB for x86_64 systems (x86_64-efi). For i686 systems, replace x86_64-efi
with i386-efi
where appropriate.
Make sure you are in a bash shell. For example, when booting from the Arch ISO:
# arch-chroot /mnt /bin/bash
Install the packages grub and efibootmgr. GRUB is the bootloader, efibootmgr creates bootable .efi
stub entries used by the GRUB installation script.
The following steps install the GRUB UEFI application to $esp/EFI/grub
, install its modules to /boot/grub/x86_64-efi
, and place the bootable grubx64.efi
stub in $esp/EFI/grub
.
First, tell GRUB to use UEFI, set the boot directory and set the bootloader ID. Change $esp
to your efi partition (usually /boot
):
# grub-install --target=x86_64-efi --efi-directory=$esp --bootloader-id=grub --recheck
The --bootloader-id
is what appears in the boot options to identity the GRUB EFI boot option; make sure this is something you will recognize later. The install will create a directory of the same name under $esp/EFI/
where the EFI binary bootloader will be placed.
After the above install finished the main GRUB directory is located at /boot/grub/
.
Remember to #Generate the main configuration file after finalizing further setup dependant #Configuration.
See UEFI troubleshooting in case of problems.
Further reading
Below is other relevant information regarding installing Arch via UEFI
Alternative install method
Usually, GRUB keeps all files, including configuration files, in /boot
, regardless of where the EFI System Partition is mounted.
If you want to keep these files inside the EFI System Partition itself, add --boot-directory=$esp
to the grub-install command:
# grub-install --target=x86_64-efi --efi-directory=$esp --bootloader-id=grub --boot-directory=$esp --recheck --debug
This puts all GRUB files in $esp/grub
, instead of in /boot/grub
. When using this method, make sure you have grub-mkconfig put the configuration file in same place:
# grub-mkconfig -o $esp/grub/grub.cfg
Configuration is otherwise the same.
UEFI firmware workaround
Some UEFI firmware requires that the bootable .efi
stub have a specific name and be placed in a specific location: $esp/EFI/boot/bootx64.efi
(where $esp
is the UEFI partition mountpoint). Failure to do so in such instances will result in an unbootable installation. Fortunately, this will not cause any problems with other firmware that does not require this.
To do so, first create the necessary directory, and then copy across the grub .efi
stub, renaming it in the process:
# mkdir $esp/EFI/boot # cp $esp/EFI/grub_uefi/grubx64.efi $esp/EFI/boot/bootx64.efi
Create a GRUB entry in the firmware boot manager
grub-install
automatically tries to create a menu entry in the boot manager. If it does not, then see UEFI#efibootmgr for instructions to use efibootmgr
to create a menu entry. However, the problem is likely to be that you have not booted your CD/USB in UEFI mode, as in UEFI#Create UEFI bootable USB from ISO.
GRUB standalone
This section assumes you are creating a standalone GRUB for x86_64 systems (x86_64-efi). For i686 systems, replace x86_64-efi
with i386-efi
where appropriate.
It is possible to create a grubx64_standalone.efi
application which has all the modules embedded in a tar archive within the UEFI application, thus removing the need for having a separate directory populated with all of the GRUB UEFI modules and other related files. This is done using the grub-mkstandalone
command (included in grub) as follows:
# echo 'configfile ${cmdpath}/grub.cfg' > /tmp/grub.cfg # grub-mkstandalone -d /usr/lib/grub/x86_64-efi/ -O x86_64-efi --modules="part_gpt part_msdos" --fonts="unicode" --locales="en@quot" --themes="" -o "$esp/EFI/grub/grubx64_standalone.efi" "boot/grub/grub.cfg=/tmp/grub.cfg" -v
Then copy the GRUB config file to $esp/EFI/grub/grub.cfg
and create a UEFI Boot Manager entry for $esp/EFI/grub/grubx64_standalone.efi
using efibootmgr.
Technical information
The GRUB EFI file always expects its config file to be at ${prefix}/grub.cfg
. However in the standalone GRUB EFI file, the ${prefix}
is located inside a tar archive and embedded inside the standalone GRUB EFI file itself (inside the GRUB environment, it is denoted by "(memdisk)"
, without quotes). This tar archive contains all the files that would be stored normally at /boot/grub
in case of a normal GRUB EFI install.
Due to this embedding of /boot/grub
contents inside the standalone image itself, it does not rely on actual (external) /boot/grub
for anything. Thus in case of standalone GRUB EFI file ${prefix}==(memdisk)/boot/grub
and the standalone GRUB EFI file reads expects the config file to be at ${prefix}/grub.cfg==(memdisk)/boot/grub/grub.cfg
.
Hence to make sure the standalone GRUB EFI file reads the external grub.cfg
located in the same directory as the EFI file (inside the GRUB environment, it is denoted by ${cmdpath}
), we create a simple /tmp/grub.cfg
which instructs GRUB to use ${cmdpath}/grub.cfg
as its config (configfile ${cmdpath}/grub.cfg
command in (memdisk)/boot/grub/grub.cfg
). We then instruct grub-mkstandalone to copy this /tmp/grub.cfg
file to ${prefix}/grub.cfg
(which is actually (memdisk)/boot/grub/grub.cfg
) using the option "boot/grub/grub.cfg=/tmp/grub.cfg"
.
This way, the standalone GRUB EFI file and actual grub.cfg
can be stored in any directory inside the EFI System Partition (as long as they are in the same directory), thus making them portable.
Generate the main configuration file
After the installation, the main configuration file grub.cfg
needs to be generated. The generation process can be influenced by a variety of options in /etc/default/grub
and scripts in /etc/grub.d/
; see #Configuration.
If you have not done additional configuration, the automatic generation will determine the root filesystem of the system to boot for the configuration file. For that to succeed it is important that the system is either booted or chrooted into.
Use the grub-mkconfig tool to generate grub.cfg
:
# grub-mkconfig -o /boot/grub/grub.cfg
By default the generation scripts automatically add menu entries for Arch Linux to any generated configuration. See #Dual-booting for configuration with other systems.
Configuration
This section only covers editing the /etc/default/grub
configuration file. See GRUB/Tips and tricks for more information.
Remember to always #Generate the main configuration file after making changes to /etc/default/grub
.
Additional arguments
To pass custom additional arguments to the Linux image, you can set the GRUB_CMDLINE_LINUX
+ GRUB_CMDLINE_LINUX_DEFAULT
variables in /etc/default/grub
. The two are appended to each other and passed to kernel when generating regular boot entries. For the recovery boot entry, only GRUB_CMDLINE_LINUX
is used in the generation.
It is not necessary to use both, but can be useful. For example, you could use GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sdaX quiet"
where sdaX
is your swap partition to enable resume after hibernation. This would generate a recovery boot entry without the resume and without quiet suppressing kernel messages during a boot from that menu entry. Though, the other (regular) menu entries would have them as options.
By default grub-mkconfig determines the UUID of the root filesystem for the configuration. To disable this, uncomment GRUB_DISABLE_LINUX_UUID=true
.
For generating the GRUB recovery entry you also have to comment out #GRUB_DISABLE_RECOVERY=true
in /etc/default/grub
.
You can also use GRUB_CMDLINE_LINUX="resume=UUID=uuid-of-swap-partition"
See Kernel parameters for more info.
Dual-booting
Automatically generating using /etc/grub.d/40_custom and grub-mkconfig
The best way to add other ent