https://wiki.archlinux.org/api.php?action=feedcontributions&user=Fil0&feedformat=atomArchWiki - User contributions [en]2024-03-29T00:20:35ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=GRUB&diff=172867GRUB2011-12-09T17:45:28Z<p>Fil0: Useful info added to "Background image" & others minor changes in "4.4 Visual Configuration".</p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ 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 [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
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.<br />
<br />
== Preface ==<br />
<br />
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.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB Legacy users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* 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).<br />
<br />
* 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, {{ic|/dev/sda1}} would be referred to as {{ic|(hd0,msdos1)}} (for MBR) or {{ic|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
=== Preliminary Requirements for GRUB2 ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== [[GPT]] specific instructions =====<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). 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 of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk 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 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 cgdisk or {{ic|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{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 BIOS is selected as bootloader).}}<br />
<br />
===== [[MBR]] aka msdos partitioning specific instructions =====<br />
<br />
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 to 2 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).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
==== UEFI systems ====<br />
<br />
===== Create and Mount the UEFI SYSTEM PARTITION =====<br />
<br />
Follow [[Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux]] for instructions on creating a UEFI SYSTEM PARTITION. Then mount the UEFI SYSTEM PARTITION at {{ic|/boot/efi}}. It should be FAT32 formatted and should be >=200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{ic|/boot/efi}} in the below instructions with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
<br />
Create a <UEFI_SYSTEM_PARTITION>/efi directory if it does not exist:<br />
<br />
# mkdir -p /boot/efi/efi<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{ic|/etc/resolv.conf}} 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:<br />
# cp /etc/resolv.conf /tmp/install/etc/resolv.conf<br />
* If you run into network issues in the pacman update step below, you may have needed to install the net-tools package.<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{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.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# mount -t proc /proc /mnt/proc/<br />
# mount -t sysfs /sys /mnt/sys/<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* 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):<br />
# pacman -Syy<br />
* 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.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== Make a backup of your precious data =====<br />
<br />
In general, a grub installation should run smoothly . Sometimes it could mess up your system. You're strongly advised to make a backup before installing grub2-bios.<br />
<br />
* copy grub modules and configuration<br />
<br />
# cp -a /boot/grub /path/to/backup/<br />
<br />
* backup the MBR and GRUB-Legacy stage 1.5<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/first-sectors bs=512 count=63<br />
<br />
Replace /dev/sdaX with you disk path (mostly /dev/sda).<br />
<br />
{{Note|This command backs up the partition table too. Be careful while restoring if you've changed your partition setup in the meantime}}<br />
<br />
To backup only the MBR boot code use:<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/mbr-boot-code bs=440 count=1<br />
<br />
You could now lightly remove {{ic|/boot/grub}} with:<br />
<br />
# rm -rf /boot/grub<br />
<br />
and follow the instructions below. You know that if things get nasty, you could reboot your system thanks to an installation media and:<br />
<br />
* move old grub-legacy or grub2 files out of the way<br />
<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
<br />
* copy grub back to /boot<br />
<br />
# cp -a /path/to/backup/grub /boot/<br />
<br />
* replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
<br />
# dd if=/path/to/backup/first-sectors of=/dev/sdX bs=512 count=63<br />
<br />
{{Note|This command also restores the partition table. Be careful.}}<br />
<br />
To restore only the MBR boot code use:<br />
<br />
# dd if=/path/to/backup/mbr-boot-code of=/dev/sdX bs=440 count=1<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Pkg|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option {{ic|--no-floppy}}. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions:<br />
<br />
# modprobe dm-mod<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{ic|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{ic|/boot/grub}} directory, generate the {{ic|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run:<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --debug /dev/sda<br />
<br />
where {{ic|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{ic|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{ic|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occurring). Otherwise you get an error like this:<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force --debug /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{ic|--force}} option to allow usage of blocklists and should not use {{ic|1=--grub-setup=/bin/true}} (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{ic|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{ic|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{ic|/boot/grub/core.img}} file and the prefix dir {{ic|/boot/grub}} . The sector locations of {{ic|core.img}} may change whenever the filesystem 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 .<br />
<br />
The workaround for this is to set the immutable flag on {{ic|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{ic|core.img}} file in the disk is not altered. The immutable flag on {{ic|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{ic|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{ic|/boot/grub}} directory and generate a {{ic|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add {{ic|1=--grub-setup=/bin/true}} to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck --debug /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== Generate GRUB2 BIOS Config file =====<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
If {{ic|grub-mkconfig}} fails, convert your {{ic|/boot/grub/menu.lst}} file to {{ic|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{hc|/boot/grub/menu.lst|<nowiki><br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
{{hc|/boot/grub/grub.cfg|<nowiki><br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
</nowiki>}}<br />
<br />
If you forgot to create a GRUB2 {{ic|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{ic|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{ic|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{ic|bootmgr}} exists at {{ic|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{ic|/etc/grub.d/40_custom}} and regenerate grub.cfg with grub-mkconfig as explained above to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode:<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{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.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option {{ic|--no-floppy}}. For more details search this option in the article.}}<br />
<br />
{{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.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Run grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Install to UEFI SYSTEM PARTITION ======<br />
<br />
{{Note|The below commands assume you are using {{ic|grub2-efi-x86_64}} (for {{ic|grub2-efi-i386}} replace {{ic|x86_64}} with {{ic|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck --debug<br />
<br />
The {{ic|grub_efi_x86_64-install}} automatically generates a {{ic|grub.efi}} while setting up the {{ic|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{ic|/dev/sda}}) at the end of the {{ic|grub_efi_x86_64-install}} 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.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{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. This is true only for efivars kernel module and efibootmgr step. The other steps (ie. upto setting up <UEFISYS>/efi/grub/grub.{efi,cfg} ) can be done even in BIOS/Legacy boot mode.}}<br />
<br />
{{Warning|Using {{ic|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs (see chapter regarding Apple systems}}<br />
<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{ic|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{ic|efibootmgr}} and if it is able to access UEFI Runtime Services. {{ic|efibootmgr}} 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 {{ic|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{ic|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
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:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{ic|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
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.<br />
<br />
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.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{ic|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{ic|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{ic|/boot/efi/efi/grub/grub.efi}} can be split up as {{ic|/boot/efi}} and {{ic|/efi/grub/grub.efi}}, which translates to {{ic|(/dev/sda)}} -> partition 1 -> {{ic|\\EFI\\grub\\grub.efi}}. <br />
<br />
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 {{ic|\\EFI\\grub\\grub.efi}} or {{ic|\\efi\\grub\\grub.efi}} 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 {{ic|\EFI\grub\grub.efi}} is passed to {{ic|efibootmgr}}.<br />
<br />
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 [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grubx64.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grubx64.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grubx64.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
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).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
Use bless command from within Mac OS X to set {{ic|grub.efi}} as the default boot option. You can also boot from the Mac OS X install disc and launch a Terminal there if you only have Linux installed. In the Terminal, create a directory and mount the EFI System Partition:<br />
<br />
# cd /Volumes<br />
# mkdir efi<br />
# mount -t msdos /dev/disk0s1 /Volumes/efi<br />
<br />
Then run bless on {{ic|grub.efi}} and on the EFI partition to set them as the default boot options.<br />
<br />
# bless --folder=/Volumes/efi --file=/Volumes/efi/efi/grub/grub.efi --setBoot<br />
# bless --mount=/Volumes/efi --file=/Volumes/efi/efi/grub/grub.efi --setBoot<br />
<br />
More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{ic|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{ic|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{ic|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{ic|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{ic|grub.cfg}} file should exist in the same directory as {{ic|grub.efi}} or {{ic|grub_custom.efi}}.<br />
<br />
The {{ic|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{ic|/boot/efi/efi/grub}} directory by copying all the files in {{ic|/usr/lib/grub/x86_64-efi}} to {{ic|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{ic|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{ic|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{ic|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{ic|bootmgfw.efi}} exists at {{ic|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{ic|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode:<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
{{bc|<nowiki><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</nowiki>}}<br />
<br />
The {{ic|1=--with-platform=pc}} generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
{{bc|<nowiki><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</nowiki>}}<br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
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 {{ic|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
You can also choose to automatically generate or manually edit {{ic|grub.cfg}}.<br />
<br />
{{Note|If using UEFI {{ic|grub.cfg}} must be placed alongside {{ic|grub.efl}} on the UEFI system partition. The easiest way is to copy the configuration file created below from {{ic|/boot/grub/grub.cfg}} to {{ic|/boot/efi/EFI/grub}} where {{ic|/boot/efi}} is the mounted UEFI partition. }}<br />
<br />
=== Automatically generating using grub-mkconfig (Recommended) ===<br />
<br />
The GRUB2 {{ic|menu.1st}} equivalent configuration files are {{ic|/etc/default/grub}} and {{ic|/etc/grub.d/*}}. grub-mkconfig uses these files to generate {{ic|grub.cfg}}. By default the script outputs to stdout. To generate a {{ic|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
{{ic|/etc/grub.d/10_linux}} is set to automatically add menu items for Arch linux that work out of the box, to any generated configuration. Other operating systems may need to be added manually by editing {{ic|/etc/grub.d/40_custom}}<br />
<br />
=== Manually creating grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{ic|(hdX,Y)}} is the partition {{ic|Y}} on disk {{ic|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{ic|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{ic|1=set timeout=M}} is the time {{ic|M}} to wait in seconds for a user selection before default is booted<br />
* {{ic|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{ic|title}}<br />
* {{ic|1=set root=(hdX,Y)}} 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 ({{ic|/}})<br />
<br />
An example configuration:<br />
<br />
{{hc<br />
|/boot/grub/grub.cfg<br />
|<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{ic|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{ic|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{ic|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{ic|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{ic|map}} and is now done with {{ic|drivemap}}. Assume grub is on {{ic|hd0}} and windows on {{ic|hd2}}, you need to add the following after {{ic|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{ic|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{ic|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{ic|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
{{Note|If this example does not work for you try to replace {{ic|1=gfxmode="1024x768x32"}} by {{ic|1=vbemode="0x105"}}. Remember to replace the specified resolution with one suitable for your screen.}}<br />
{{Note|To show all the modes you can use {{ic|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{ic|1=vbeinfo}} command.}}<br />
<br />
If this method does not work for you, the deprecated {{ic|1=vga=}} method will still work. Just<br />
add it next to the {{ic|1="GRUB_CMDLINE_LINUX_DEFAULT="}} line in {{ic|/etc/default/grub}}<br />
for eg: {{ic|1="GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"}} will give you a {{ic|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{ic|640×480}}, {{ic|800×600}}, {{ic|1024×768}}, {{ic|1280×1024}}, {{ic|1600×1200}}<br />
<br />
====Background image and bitmap fonts====<br />
<br />
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 {{ic|unicode.pf2}}, or, as only ascii characters under the name {{ic|ascii.pf2}}. <br />
<br />
Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware.<br />
<br />
Make sure you have set up the proper [https://wiki.archlinux.org/index.php/GRUB2#Setting_the_framebuffer_resolution framebuffer resolution].<br />
<br />
Edit {{ic|/etc/default/grub}} like this:<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
{{Note|If you have installed Grub on a separate partition, {{ic|/boot/grub/archlinux.tga}} becomes {{ic|/grub/archlinux.tga}}.}}<br />
<br />
To generate the changes and add the information into grub.cfg, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If adding the splash image was successful, the user will see "Found background image..." in the terminal as the command is executed. <br />
If this phrase is not seen, the image information was probably not incorporated into the grub.cfg file.<br />
<br />
If the image is not displayed, check:<br />
* The path and the filename in /etc/default/grub are correct.<br />
* The image is of the proper size and format (tga, png, 8-bit jpg).<br />
* The image was saved in the RGB mode, and is not indexed.<br />
* The console mode is not enabled in /etc/default/grub.<br />
* The command grub-mkconfig must be executed to place the background image information into the /boot/grub/grub.cfg file.<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{ic|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
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.<br />
<br />
Edit {{ic|/etc/default/grub}} 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:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{ic|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{ic|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{ic|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{ic|/dev/sd*}} and {{ic|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
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 {{ic|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
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):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{ic|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{ic|--label}} option to {{ic|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
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 {{ic|/etc/default/grub}} and change the setting of {{ic|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{ic|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Note that manually added menu items, eg Windows in {{ic|/etc/grub.d/40_custom}}, will need {{ic|savedefault}} added. Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
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 {{ic|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
{{bc|<nowiki><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</nowiki>}}Then, add the following to {{ic|/etc/grub.d/00_header}}:<br />
{{bc|<nowiki>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</nowiki>}}<br />
where <password> is the string generated by {{ic|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{ic|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
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 {{ic|/boot/grub}}, 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.<br />
<br />
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:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
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:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
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:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
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.<br />
<br />
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.<br />
<br />
Before starting, the user must know the location of their {{ic|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{ic|/boot}} from the path, (i.e. type {{ic|1=set prefix=(hdX,Y)/grub}} and {{ic|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{ic|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{ic|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
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.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{ic|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{ic|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{ic|/boot/grub/}} in case of BIOS systems and {{ic|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{ic|/usr/share/grub/unicode.pf2}} does not exist, install {{Pkg|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{ic|grub.cfg}} 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:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{ic|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 drops to shell ===<br />
<br />
If grub loads but drop you into the rescue shell with no errors, it may be because of a missing or misplaced {{ic|grub.cfg}}. For UEFI, {{ic|grub.cfg}} must be copied into the UEFI system partition alongside grub.efi ({{ic|/boot/efi/EFI/grub}})<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 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:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Fil0