Difference between revisions of "Handbook:AMD64/Blocks/Bootloader"

From Gentoo Wiki
Jump to:navigation Jump to:search
(Add instructions for GRUB-2 + UEFI as efibootmgr is not the recommended way for new users)
Line 13: Line 13:
  
 
<!--T:5-->
 
<!--T:5-->
For {{#show: Handbook:{{ROOTPAGENAME}}|? architecture}}, we document how to configure either [[#Default: Using GRUB2|GRUB2]] or [[#Alternative: Using LILO|LILO]] for BIOS based systems, and [[#Alternative: Using efibootmgr|efibootmgr]] for UEFI systems.
+
For {{#show: Handbook:{{ROOTPAGENAME}}|? architecture}}, we document how to configure either [[#Default: Using GRUB2|GRUB2]] or [[#Alternative: Using LILO|LILO]] for BIOS based systems, and [[#Default: Using GRUB2|GRUB2]] or [[#Alternative: Using efibootmgr|efibootmgr]] for UEFI systems.
  
 
== Default: Using GRUB2 == <!--T:6-->
 
== Default: Using GRUB2 == <!--T:6-->
Line 26: Line 26:
  
 
<!--T:10-->
 
<!--T:10-->
 +
==== Using BIOS ====
 
{{Emerge|sys-boot/grub}}
 
{{Emerge|sys-boot/grub}}
 +
 +
==== Using UEFI ====
 +
UEFI users will need to add GRUB_PLATFORMS="efi-64" to make.conf first.
 +
 +
{{RootCmd|1=echo GRUB_PLATFORMS="efi-64" >> /etc/portage/make.conf}}
 +
{{Emerge|sys-boot/grub}}
 +
  
 
<!--T:11-->
 
<!--T:11-->
Line 36: Line 44:
 
Next, install the necessary GRUB2 files in {{Path|/boot/grub/}}. Assuming the first disk (the one where the system boots from) is {{Path|/dev/sda}}, the following command will do this:
 
Next, install the necessary GRUB2 files in {{Path|/boot/grub/}}. Assuming the first disk (the one where the system boots from) is {{Path|/dev/sda}}, the following command will do this:
  
 +
==== Using BIOS ====
 
<!--T:14-->
 
<!--T:14-->
 
{{RootCmd|grub2-install /dev/sda}}
 
{{RootCmd|grub2-install /dev/sda}}
  
 +
==== Using UEFI ====
 +
{{RootCmd|1=grub2-install --target=x86_64-efi --efi-directory=/boot}}
 +
{{Note|Modify the efi-directory setting to the root of the vfat EFI System Partition if you did not format /boot as vfat.}}
 +
 +
==== Generating a configuration file ====
 
<!--T:15-->
 
<!--T:15-->
 
Next, we can generate the GRUB2 configuration based on the user configuration specified in the {{Path|/etc/default/grub}} file and {{Path|/etc/grub.d}} scripts. In most cases, no configuration is needed by users as GRUB2 will automatically detect which kernel to boot (the highest one available in {{Path|/boot/}}) and what the root file system is.
 
Next, we can generate the GRUB2 configuration based on the user configuration specified in the {{Path|/etc/default/grub}} file and {{Path|/etc/grub.d}} scripts. In most cases, no configuration is needed by users as GRUB2 will automatically detect which kernel to boot (the highest one available in {{Path|/boot/}}) and what the root file system is.

Revision as of 12:57, 10 September 2015


Selecting a boot loader

With the Linux kernel configured, system tools installed and configuration files edited, it is time to install the last important piece of a Linux installation: the boot loader.

The boot loader is responsible for firing up the Linux kernel upon boot - without it, the system would not know how to proceed when the power button has been pressed.

For amd64, we document how to configure either GRUB2 or LILO for BIOS based systems, and GRUB2 or efibootmgr for UEFI systems.

Default: Using GRUB2

Previously, Gentoo Linux used what is now called GRUB Legacy as the recommended boot loader. As the name implies, the older GRUB package is no longer actively maintained and has been superseded by GRUB2. For more information about the legacy GRUB, please refer to its GRUB article on the Gentoo Wiki.

Installing GRUB2

GRUB2 is provided through the sys-boot/grub package.

Using BIOS

root #emerge --ask sys-boot/grub

Using UEFI

UEFI users will need to add GRUB_PLATFORMS="efi-64" to make.conf first.

root #echo GRUB_PLATFORMS="efi-64" >> /etc/portage/make.conf
root #emerge --ask sys-boot/grub


The GRUB2 software is now installed on the system, but not activated yet.

Configuring GRUB2

Next, install the necessary GRUB2 files in /boot/grub/. Assuming the first disk (the one where the system boots from) is /dev/sda, the following command will do this:

Using BIOS

root #grub2-install /dev/sda

Using UEFI

root #grub2-install --target=x86_64-efi --efi-directory=/boot
Note
Modify the efi-directory setting to the root of the vfat EFI System Partition if you did not format /boot as vfat.

Generating a configuration file

Next, we can generate the GRUB2 configuration based on the user configuration specified in the /etc/default/grub file and /etc/grub.d scripts. In most cases, no configuration is needed by users as GRUB2 will automatically detect which kernel to boot (the highest one available in /boot/) and what the root file system is.

To generate the final GRUB2 configuration, run the grub2-mkconfig command:

root #grub2-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-6.6.21-gentoo
Found initrd image: /boot/initramfs-genkernel-amd64-6.6.21-gentoo
done

The output of the command must mention that at least one Linux image is found, as those are needed to boot the system. If an initramfs is used or genkernel was used to build the kernel, the correct initrd image should be detected as well. If this is not the case, go to /boot/ and check the contents using the ls command. If the files are indeed missing, go back to the kernel configuration and installation instructions.

Alternative: Using LILO

Installing LILO

LILO, the LInuxLOader, is the tried and true workhorse of Linux boot loaders. However, it lacks some features that GRUB has. The reason why LILO is still used is that, on some systems, GRUB doesn't work and LILO does. Of course, it is also used because some people know LILO and want to stick with it. Either way, Gentoo supports both.

Installing LILO is a breeze; just use emerge.

root #emerge --ask sys-boot/lilo

Configuring LILO

To configure LILO, first create /etc/lilo.conf:

root #nano -w /etc/lilo.conf

In the configuration file, sections are used to refer to the bootable kernel. Make sure that the kernel files (with kernel version) and initramfs files are known, as they need to be referred to in this configuration file.

Note
If the root filesystem is JFS, add an append="ro" line after each boot item since JFS needs to replay its log before it allows read-write mounting.
FILE /etc/lilo.confExample LILO configuration
'"`UNIQ--pre-00000002-QINU`"'
Note
If a different partitioning scheme and/or kernel image is used, adjust accordingly.

If an initramfs is necessary, then change the configuration by referring to this initramfs file and telling the initramfs where the real root device is at:

FILE /etc/lilo.confAdding initramfs information to a boot entry
'"`UNIQ--pre-00000005-QINU`"'

If additional options need to be passed to the kernel, use an append statement. For instance, to add the video statement to enable framebuffer:

FILE /etc/lilo.confAdding video parameter to the boot options
'"`UNIQ--pre-00000008-QINU`"'

Users that used genkernel should know that their kernels use the same boot options as is used for the installation CD. For instance, if SCSI device support needs to be enabled, add doscsi as kernel option.

Now save the file and exit.

To finish up, run /sbin/lilo so LILO can apply the /etc/lilo.conf settings to the system (i.e. install itself on the disk). Keep in mind that /sbin/lilo needs to be executed every time a new kernel is installed or a change has been made to the lilo.conf file.

root #/sbin/lilo

Alternative: Using efibootmgr

On UEFI based systems, the boot loader itself is the UEFI firmware of the system. Such systems do not need additional boot loaders to help boot the system, although EFI-based bootloaders do exist to extend the functionality of UEFI systems during boot.

The sys-boot/efibootmgr application is not a boot loader, but a tool to interact with the UEFI firmware and update its settings, so that the Linux kernel that was previously installed can be booted with additional options (if necessary), or to allow multiple boot entries. This interaction is done through the EFI variables (hence the need for the support of EFI vars in the past).

Note
efibootmgr is not a requirement to boot from an UEFI system. The Linux kernel itself can (and will) be booted immediately, and additional boot options can be made part of the Linux kernel itself (there is a kernel configuration that allows the user to specify the boot parameters). Even an initramfs can be made part of the kernel itself.

First install the software:

root #emerge --ask sys-boot/efibootmgr

Next, tell the UEFI firmware that a boot entry called "Gentoo" is to be created, which has the freshly installed Linux kernel booted:

root #efibootmgr --create --disk /dev/sda --part 2 --label "Gentoo" --loader "\efi\boot\bootx64.efi"

If an initial ram file system (initramfs) is used, add the proper boot option to it:

root #efibootmgr -c -d /dev/sda -p 2 -L "Gentoo" -l "\efi\boot\bootx64.efi" initrd='\initramfs-genkernel-amd64-6.6.21-gentoo'
Note
The use of \ as directory separator is mandatory when using EFI definitions.

With these changes done, when the system reboots, a boot entry called "Gentoo" will be available.