Efi linux boot loader

Создание загрузочной системы EFI⚓︎

Отключите secure boot ! На данный момент эта технология не поддерживается. Чтобы настроить процесс загрузки с помощью GRUB для UEFI, необходимо отключить её в интерфейсе конфигурации прошивки. Прочтите документацию, предоставленную производителем вашей системы, чтобы узнать, как это сделать.

Убедитесь, что вы не пропустили раздел по настройке ядра, для поддержки EFI.

Поиск, или создание системного раздела EFI⚓︎

В системе на основе EFI загрузчики устанавливаются в специальный раздел FAT32, называемый системным разделом EFI (ESP). Если ваша система поддерживает EFI и предустановлен дистрибутив Linux и (или) Windows, скорее всего, ESP уже создан. Посмотрите все разделы на вашем жёстком диске (замените sda на нужное устройство):

Столбец ESP type должен быть EFI System .

 Устр-во начало Конец Секторы Размер Тип /dev/sda1 4096 618495 614400 300M EFI /dev/sda2 618496 268430084 267811589 127,7G Файловая система Linux 

Если система или жёсткий диск новые, или если вы впервые устанавливаете ОС, загружаемую через UEFI , ESP может не существовать. В этом случае создайте новый раздел, создайте на нем файловую систему vfat и установите тип раздела EFI system .

Некоторые (старые) реализации UEFI могут требовать, чтобы ESP был первым разделом на диске.

Создайте точку монтирования для ESP и смонтируйте ее (замените sda1 на соответствующий ESP ):

 mkdir -pv /boot/efi && mount -v -t vfat /dev/sda1 /boot/efi 

Добавьте запись для ESP в /etc/fstab , чтобы он автоматически монтировался во время загрузки системы:

 cat >> /etc/fstab  /dev/sda1 /boot/efi vfat defaults 0 1 EOF 

Монтирование EFI Variable File System⚓︎

Для установки GRUB на UEFI необходимо смонтировать файловую систему EFI Variable, efivarfs . Если она еще не была смонтирована ранее, выполните команду:

 mountpoint /sys/firmware/efi/efivars || mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars 

Добавьте запись для efivarfs в /etc/fstab , чтобы она автоматически монтировалась во время загрузки системы:

 cat >> /etc/fstab  efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 0 EOF 

Если система не загружается с UEFI, каталог /sys/firmware/efi будет отсутствовать. В этом случае вы должны загрузить систему в режиме UEFI с аварийным загрузочным диском.

Настройка⚓︎

В системах на основе UEFI GRUB работает устанавливая приложение EFI (особый вид исполняемого файла) в /boot/efi/EFI/[id sizes/grubx64.efi , где /boot/efi — точка монтирования ESP , а [id] заменяется идентификатором, указанным в командной строке grub-install . GRUB создаст запись в переменных EFI , содержащую путь EFI/[id]/grubx64.efi , чтобы прошивка EFI могла найти grubx64.efi и загрузить его.

grubx64.efi очень легкий (136 Кб), поэтому он не будет занимать много места в ESP. Типичный размер ESP составляет 100 Мб (для диспетчера загрузки Windows, который использует около 50 Мб в ESP). Как только grubx64.efi загружен прошивкой, он загрузит модули GRUB в загрузочный раздел. Расположение по умолчанию — /boot/grub .

Установите файлы GRUB в /boot/efi/EFI/LFS/grubx64.efi и /boot/grub . Затем настройте загрузочную запись в переменных EFI:

 grub-install --bootloader-id=LIN --recheck 

Если установка прошла успешно, вывод должен быть:

 Installing for x86_64-efi platform. Installation finished. No error reported. 

Запустите efibootmgr , чтобы ещё раз проверить конфигурацию загрузки EFI.

 BootCurrent: 0000 Timeout: 1 seconds BootOrder: 0005,0000,0002,0001,0003,0004 Boot0000* ARCH Boot0001* UEFI:CD/DVD Drive Boot0002* Windows Boot Manager Boot0003* UEFI:Removable Device Boot0004* UEFI:Network Device Boot0005* LIN 

Обратите внимание, что 0005 является первым в BootOrder , а Boot0005 — это LIN . Это означает, что при следующей загрузке системы будет использоваться версия GRUB , установленная в LIN .

Создание файла конфигурации GRUB⚓︎

Создайте /boot/grub/grub.cfg для настройки меню загрузки GRUB:

 cat > /boot/grub/grub.cfg  # Begin /boot/grub/grub.cfg set default=0 set timeout=5 insmod part_gpt insmod ext2 set root=(hd0,2) if loadfont /boot/grub/fonts/unicode.pf2; then set gfxmode=auto insmod all_video terminal_output gfxterm fi menuentry "GNU/Linux, Linux 5.10.17-lfs-10.1"  linux /boot/vmlinuz root=/dev/sda2 ro > menuentry "Firmware Setup"  fwsetup > EOF 

(hd0,2) , sda2 следует заменить в соответствии с вашей конфигурацией.

Для GRUB файлы используются относительно раздела. Если вы использовали отдельный раздел /boot , удалите /boot из указанных выше путей (к ядру и к unicode.pf2). Вам также нужно будет изменить строку корневого раздела, чтобы она указывала на загрузочный раздел.

Загрузка вместе с Windows⚓︎

Добавьте запись в файл конфигурации grub.cfg :

 cat >> /boot/grub/grub.cfg  # Begin Windows addition menuentry "Windows 10"  insmod fat insmod chain set root=(hd0,1) chainloader /EFI/Microsoft/Boot/bootmgfw.efi > EOF 

(hd0,1) следует заменить назначенным GRUB именем для ESP. Директива chainloader может использоваться, чтобы указать GRUB запустить другой исполняемый файл EFI, в данном случае диспетчер загрузки Windows. вы можете поместить больше используемых инструментов в исполняемом формате EFI (например, оболочку EFI) в ESP и создать для них записи GRUB.

Источник

Bootloaders

This page shows the basic steps you need to perform, if you for any reason want to switch bootloaders or apply some manual configuration.

rEFInd is an easy to use EFI boot menu that allows booting different operating systems.
Syslinux is the default light-weight bootloader used in Alpine.
Grub is a standard linux boot loader.
EFI Boot Stub allows booting linux directly from a motherboard supporting UEFI or another bootloader.

rEFIind

For (U)EFI systems, the refind package can provide a graphical EFI boot menu that allows to boot operating systems that are found on the available partitions.

If refind is not yet available in the used alpine release, it may be installed in another dual/multi-booted linux distribution.

For example, with a Debian based distribution, it can be installed to the EFI partition like this:

apt install refind # installs the debian package refind-install --alldrivers # installs refind to the EFI partition

(The —alldrivers option includes all filesystem drivers instead of only the one needed to load the currently running kernel, to allow finding and booting operating systems from more partitions.)

And a first (default) boot menu line needs to be configured with Alpine’s default boot parameters. Assuming the bootable partition is mounted at /media/sdXY it can be done like this (at time of writing):

echo '"Alpine" "modules=loop,squashfs,sd-mod,usb-storage quiet initrd=\boot\intel-ucode.img initrd=\boot\amd-ucode.img initrd=\boot\initramfs-lts"' > /media/sdXY/boot/refind_linux.conf
  1. At the time of writing, it was still needed to use backslashes in the .conf file.
  2. The path in the config file needs to be relative to the partition that the kernel resides on. If /boot resides on its own separate partition, then \boot needs to be removed from the paths.

Installing Syslinux

If you want to switch from another bootloader back to Syslinux, or if you for some reason want to install Syslinux manually, the following steps are required.

Install the syslinux package:

If you’re using GPT partitions, install the GPT MBR onto the drive you want to install the bootloader on (in this case /dev/sda ):

dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/gptmbr.bin of=/dev/sda

Or if you’re using DOS partitions, install the DOS MBR instead:

dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/sda

Next install the required Syslinux binaries. Despite being called extlinux , Syslinux supports booting from FAT12/16/32, NTFS, ext2/3/4, btrfs, XFS, and UFS/FFS filesystems.

The configuration file is located in /boot/extlinux.conf . Alpine ships with a script called update-extlinux which automatically (re)generates this file, for example on updates to Syslinux. The settings for this script can be found in /etc/update-extlinux.conf , including the option to disable automatic overwriting of /boot/extlinux.conf . You can also place additional menu entries in the /etc/update-extlinux.d/ directory, e.g. for dual booting.

EFI

Assuming /mnt is a FAT32 partition of type EF00 and /boot belongs to the rootfs created after running setup-disk :

mkdir -p /mnt/EFI/syslinux cp /usr/share/syslinux/efi64/* /mnt/EFI/syslinux/ cp /boot/extlinux.conf /mnt/EFI/syslinux/syslinux.cfg cp /boot/vmlinuz* /mnt/ cp /boot/initramfs* /mnt/

You may need to modify /mnt/EFI/syslinux/syslinux.cfg to change the paths to absolute paths (just add a / in front of the vmlinuz/initramfs entries), or copy the files to /mnt/EFI/syslinux instead (XXX: untested).

GRUB

To install GRUB in BIOS mode, (optionally) remove the Syslinux package and install the required GRUB packages:

apk del syslinux apk add grub grub-bios

For EFI, install Grub’s EFI package instead. Note that /boot has to be an EFI compatible filesystem like FAT32.

Next install the MBR and GRUB binaries to disk for BIOS mode:

grub-install --target=x86_64-efi --efi-directory=/boot

GRUB ships with an automatic config generator, including some automatic detection of other operating systems installed on the device:

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

This script can be configured via the /etc/default/grub file. See [1] for a list of available options.

EFI Boot Stub

To boot directly from your motherboard’s UEFI boot menu, a boot entry needs to be created with either a UEFI shell or efibootmgr.

efibootmgr

Create a boot entry. It’s recommended to do this in a script, as efibootmgr does not allow editing entries.

#!/bin/sh params="root=/dev/sdXZ rw \ initrd=\intel-ucode.img \ initrd=\initramfs-lts" efibootmgr --create --label "Alpine Linux" \ --disk /dev/sdX --part Y \ --loader /vmlinuz-lts \ --unicode "$" \ --verbose

Where /dev/sdXY contains the EFI partition and /dev/sdXZ contains the root partition. If you are using Note:

The kernel contains the exhaustive list of ways to specify the block device. For a more robust boot entry, it is recommended to use a persistent name such as the PARTUUID.

Optionally, set the newly created entry as the default:

Where XXXX is the boot number of the new entry.

Note: The loader and initrd file arguments are relative to the EFI partition. In a default installation, alpine places these files in /boot/ , while EFI is mounted to /boot/efi/ . You can either update fstab to mount EFI at /boot/ , or manually copy them to /boot/efi/ .

Using a UKI (UEFI only)

It is possible to boot directly into a Unified Kernel Image (UKI). A UKI is a single file which contains the initfs, kernel and cmdline. While this is typically done in order to enable SecureBoot, it is perfectly feasible to skip enrolling the custom keys and leave SecureBoot off.

The page UEFI Secure Boot contains the instructions for setting an a UKI. Additionally, it is possible to install the UKI in the default fallback path used by most UEFI implementations. By installing the UKI into this path, the system will automatically boot into it if no other entries are defined. This can be automated as part of the kernel hook by adding the following to /etc/kernel-hooks.d/secureboot.conf

# For the edge kernel, install the UKI into the default UEFI path. if [ "$1" == "edge" ]; then output_dir="/efi/EFI/Boot/" output_name="bootx64.efi" fi

bootx64.efi is only correct for x86_64 systems. For other architectures the exact name will vary.

Источник

Читайте также:  Pdf viewers for linux
Оцените статью
Adblock
detector