Bootloaders: Difference between revisions

From Alpine Linux
m (Add the normal 32-bit EFI file name.)
 
(71 intermediate revisions by 16 users not shown)
Line 1: Line 1:
By default Alpine uses Syslinux as bootloader.
A ''bootloader'' is a computer program that is responsible for booting a computer. In the case where it also provides an interactive menu with multiple boot choices, then it's often called a ''boot manager''. This page shows the basic steps that you need to perform if, for any reason, you want to switch bootloaders or to apply some manual configuration.
This page shows the basic steps you need to perform, if you for any reason want to switch bootloaders or apply some manual configuration.


The following bootloaders are available in Alpine Linux:-


= Installing Syslinux =
* <code>[[#Syslinux|Syslinux]]</code> is the default lightweight bootloader used in Alpine Linux when booting the Alpine Installer ISO.  It is also the bootloader when creating a Live USB/CD/ISOLinux/PXELinux.  Supports the Filesystems: FAT12/16/32
* <code>[[#Extlinux|Extlinux]]</code> is the default lightweight bootloader used in Alpine Linux when Installing the Alpine OS to Disk via BIOS/Legacy Boot.  Supports the Filesystems: EXT2/3/4, BTRFS, XFS<br>
* <code>[[#GRUB|GRUB]]</code> is a standard Linux bootloader used in Alpine Linux when Installing the Alpine OS to Disk via UEFI.
* <code>[[#Limine|Limine]]</code> is a modern, advanced, portable, multiprotocol bootloader and boot manager.
* <code>[[#EFI_Boot_Stub|EFI Boot Stub]]</code> allows for booting Linux directly from a motherboard supporting ''UEFI'' or from another bootloader.
* <code>[[#rEFInd|rEFInd]]</code> is an easy-to-use ''EFI'' boot menu that allows booting different operating systems.<br>
* [[UEFI Secure Boot]] uses {{pkg|systemd-efistub}} or {{pkg|stubbyboot-efistub}}.


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.
A [[#Using a UKI|Unified Kernel Image (UKI)]] is additionally supported, available  for UEFI only. It is a UEFI executable that can be useful in [https://uapi-group.org/specifications/specs/unified_kernel_image/ certain use cases], including secure boot, clouds and containers.


Install the <code>syslinux</code> package:
Note that {{pkg|gummiboot}} is a ''deprecated'' UEFI boot manager that was originally able to leverage UEFI firmware and detect bootable images such as Linux kernels that have an EFI stub on the EFI System Partition (ESP).  The [https://cgit.freedesktop.org/gummiboot/ gummiboot project] was discontinued in 2015 and renamed as {{Pkg|systemd-boot}} for systemd systems and is only available in Alpine Linux in the [[Repositories#Testing|testing repository]].  As it had no runtime dependencies, '''gummiboot''' was appreciated for its simplicity as a lightweight, minimal UEFI boot solution.  Its UEFI stub, {{pkg|gummiboot-efistub}}, was used [[UEFI_Secure_Boot#Generating_Unified_Kernel_Image|to generate a Unified Kernel Images (UKIs)]] e.g. for [[DM-verity]] and Secure Boot, but [[Release_Notes_for_Alpine_3.22.0#Secure_Boot_and_Gummiboot|it has been deprecated since Alpine Linux 3.22]] and is no longer maintained;  it has been replaced by '''systemd-efistub''' (note that the latter package [[UEFI_Secure_Boot#Generating_Unified_Kernel_Image|only supplies EFI stub binaries]] and doesn’t depend on any systemd components).


<pre>apk add syslinux</pre>
== Syslinux ==


If you're using GPT partitions, install the GPT MBR onto the drive you want to install the bootloader on (in this case <code>/dev/sda</code>):
If you want to switch from another bootloader back to ''Syslinux'', or if for some reason you want to install Syslinux manually, then the following steps are required.


<pre>dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/gptmbr.bin of=/dev/sda</pre>
Install the {{pkg|syslinux}} package:


Or if you're using DOS partitions, install the DOS MBR instead:
{{cmd|# apk add syslinux}}


<pre>dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/sda</pre>
If you're using GPT partitions, then install the ''GPT MBR'' onto the drive that you want to install the bootloader on (in this case, {{path|/dev/sda}}):


<!-- See also: http://www.syslinux.org/wiki/index.php?title=Mbr -->
{{cmd|<nowiki># dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/gptmbr.bin of=/dev/sda</nowiki>}}


Next install the required Syslinux binaries. Despite being called <code>extlinux</code>, Syslinux supports booting from FAT12/16/32, NTFS, ext2/3/4, Btrfs, XFS, and UFS/FFS filesystems.
Or, if you're using DOS partitions, then install the ''DOS MBR'' instead:


<pre>extlinux --install /boot</pre>
{{cmd|<nowiki># dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/sda</nowiki>}}
<!-- See also: http://www.syslinux.org/wiki/index.php?title=Mbr -->


The configuration file is located in <code>/boot/extlinux.conf</code>.
Next, install the required Syslinux binaries. Despite being called <code>extlinux</code>, Syslinux supports booting from FAT12/16/32, NTFS, ext2/3/4, [[Btrfs|btrfs]], XFS and UFS/FFS filesystems.
Alpine ships with a script called <code>update-extlinux</code> which automatically (re)generates this file, for example on updates to Syslinux.
The settings for this script can be found in <code>/etc/update-extlinux.conf</code>, including the option to disable automatic overwriting of <code>/boot/extlinux.conf</code>.
You can also place additional menu entries in the <code>/etc/update-extlinux.d/</code> directory, e.g. for dual booting.


{{cmd|# syslinux --install /boot}}


== EFI ==
The configuration file is located in {{path|/boot/syslinux/syslinux.cfg}}.


{{Todo|Work in progress. This should at least get you started.}}
Alpine Linux ships with a script, <code>update-extlinux</code>, that automatically (re)generates this file, for example, on updates to Syslinux. The settings for this script can be found in {{path|/etc/update-extlinux.conf}}, including the option to disable automatic overwriting of {{path|/boot/extlinux.conf}}.


Assuming <code>/mnt</code> is a FAT32 partition of type EF00 and <code>/boot</code> belongs to the rootfs created after running <code>setup-disk</code>:
You can also edit and add additional menu entries in the bootloader configuration file for dual booting multiple os's: {{path|/boot/syslinux/syslinux.cfg}}


<pre>
=== Using EFI with syslinux ===
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/
</pre>


You may need to modify <code>/mnt/EFI/syslinux/syslinux.cfg</code> to change the paths to absolute paths (just add a / in front of the vmlinuz/initramfs entries),
The Alpine Linux installer automatically uses [[#GRUB|GRUB]] if EFI mode is detected. The section below is specifically about using EFI with Syslinux.
or copy the files to <code>/mnt/EFI/syslinux</code> instead (XXX: untested).


= GRUB =
Assuming that {{path|/mnt}} is a FAT32 partition of type EF00 and that {{path|/boot}} belongs to the rootfs created after running <code>setup-disk</code>:


To install GRUB in BIOS mode, (optionally) remove the Syslinux package and install the required GRUB packages:
{{cmd|<nowiki># 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/EFI/syslinux/
# cp /boot/initramfs* /mnt/EFI/syslinux/
</nowiki>}}


<pre>apk del syslinux
You may need to modify {{path|/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 {{path|/mnt/EFI/syslinux}} instead (XXX: untested).
apk add grub grub-bios</pre>


For EFI, install Grub's EFI package instead. Note that <code>/boot</code> has to be an EFI compatible filesystem like FAT32.
In the end, the {{path|/mnt/EFI/syslinux/syslinux.cfg}} file should look like this:


<pre>apk add grub-efi</pre>
{{cat|/mnt/EFI/syslinux/syslinux.cfg|<nowiki>...
DEFAULT menu.c32
PROMPT 0
MENU TITLE Alpine/Linux Boot Menu
MENU HIDDEN
MENU AUTOBOOT Alpine will be booted automatically in # seconds
TIMEOUT 10
LABEL lts
  MENU DEFAULT
  MENU LABEL Linux lts
  LINUX /vmlinuz-lts
  INITRD /initrd-lts
  APPEND root=/dev/sda3 modules=sd-mod,usb-storage,ext4 quiet
</nowiki>}}


Next install the MBR and GRUB binaries to disk for BIOS mode:
Finally, add <code>syslinux</code> to the EFI boot menu.  Assuming that {{path|/dev/sda}} is your hard drive —'''''be careful to check first what is its path on your device and to adjust accordingly''''':


<pre>grub-install /dev/vda</pre>
{{cmd|<nowiki># apk add efibootmgr
# efibootmgr -c -d /dev/sda -p 1 -l \\EFI\\syslinux\\syslinux.efi -L "ALPINE-SYSLINUX"
</nowiki>}}


For EFI mode:
You can now verify that the boot entry has been added:


<pre>grub-install --target=x86_64-efi --efi-directory=/boot</pre>
'''efibootmgr'''
<pre>
BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,0000,0002,...
Boot001* ALPINE-SYSLINUX HD(1,GPT,xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)/FILE(\EFI\syslinux\syslinux.efi)
</pre>


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


<pre>grub-mkconfig -o /boot/grub/grub.cfg</pre>
To install GRUB in BIOS mode, (optionally) remove the Syslinux package and install the required GRUB packages:


This script can be configured via the <code>/etc/default/grub</code> file.
{{cmd|<nowiki># apk del syslinux
See [https://www.gnu.org/software/grub/manual/html_node/Simple-configuration.html] for a list of available options.
# apk add grub grub-bios
</nowiki>}}


= systemd-boot=
For EFI, install GRUB's EFI package instead. Note that {{path|/boot}} has to be an EFI-compatible filesystem, such as FAT32.


{{Todo|Work in progress. This is very short and doesn't cover a lot of the options.}}
{{cmd|# apk add grub-efi efibootmgr}}


Systemd-boot is the simple EFI bootloader part of the systemd project. It is also available in the Alpine Linux testing repository as a standalone component.
Next, install the MBR and GRUB binaries to disk for BIOS mode:


== Installing ==
{{cmd|# grub-install /dev/vda}}


To install the systemd-boot, enable the testing repository, and install the <code>systemd-boot</code> package. Then make sure the boot and EFI partitions are mounted as read-write and install the bootloader with <code>bootctl</code>.
For EFI mode:
 
<pre>
# apk add systemd-boot
# bootctl install
</pre>
 
The <code>bootctl</code> binary also has support for checking if the bootloader is installed.
 
<pre>
# bootctl is-installed
yes
</pre>
 
== Configuring ==


Example configuration files for alpine are available on <code>/usr/share/systemd/bootctl</code> as <code>loader.conf</code> and <code>alpine.conf</code>.
{{cmd|<nowiki># grub-install --target=x86_64-efi --efi-directory=/boot</nowiki>}}


The bootloader (not the boot entries) can be configured via the [https://www.freedesktop.org/software/systemd/man/loader.conf.html# loader.conf] file, an example is available in <code>/usr/share/systemd/bootctl/loader.conf</code>.
Then, add this line to {{path|/etc/default/grub}}:


<pre>
{{cat|/etc/default/grub|<nowiki># GRUB_CMDLINE_LINUX_DEFAULT="quiet rootfstype=ext4 modules=sd-mod,usb-storage,ext4"</nowiki>}}
# cp /usr/share/systemd/bootctl/loader.conf /boot/loader
# vi /boot/loader/loader.conf
</pre>


systemd-boot makes use of configuration files in <code>/boot/loader/entries</code> to list entries for different OSes it can boot into. An example file for Alpine Linux is present on <code>/usr/share/systemd/bootctl/alpine.conf</code>.
GRUB ships with an automatic configuration generator, including some automatic detection of other operating systems installed on the device:


<pre>
{{cmd|# grub-mkconfig -o /boot/grub/grub.cfg}}
# cp /usr/share/systemd/bootctl/alpine.conf /boot/loader/entries
# vi /boot/loader/entries/alpine.conf
</pre>


The example file has a skeleton structure that requires minimal modifications to make them work. You need to modify the example file to fit your oeprating system, among them:
This script can be configured via the {{path|/etc/default/grub}} file.  


* Replace root=UUID=XXXX with the UUID of the root partition.
If the font in the GRUB boot screen appears too small, then [[Fonts#Changing_GRUB_font_and_font_size|change the GRUB font]].
* Replace rootfstype with the filesystem used for the root filesystem.
* Add boot options required/recommended for booting your operating system (E.g: cryptdm=, cryptroot=, modules=, etc).
* (If you don't use the default linux-lts kernel) Replace vmlinuz-lts and initramfs-lts with the ones that are used.
* (If you use an Intel CPU and need Intel microcode) add <code>initrd /intel-ucode.img</code> before the initrd call for the initramfs 


All the options available are documented in the [https://systemd.io/BOOT_LOADER_SPECIFICATION/ systemd boot loader specification] under Technical Details.
Consult [https://www.gnu.org/software/grub/manual/html_node/Simple-configuration.html gnu.org's online manual] for a list of available <code>grub-mkconfig</code> configuration options.


=== Unified Kernel Images ===
== Limine ==


Systemd-boot also accepts unified kernel images, as outlined in their [https://systemd.io/BOOT_LOADER_SPECIFICATION/#type-2-efi-unified-kernel-images document]. They are a combination of various pieces that are usually separate when normally booting, like the kernel, the initramfs and the kernel commandline.
[https://codeberg.org/Limine/Limine Limine] is a modern, advanced, portable, multiprotocol bootloader and boot manager, also used as the reference implementation for the Limine boot protocol. It supports partitioning schemes like MBR, GPT and Unpartitioned media.


To generate a unified kernel image the <code>objcopy</code> binary can be used:
== EFI Boot Stub ==


<pre>
To boot directly from your motherboard's UEFI boot menu, a boot entry needs to be created either with a UEFI shell or with ''efibootmgr''.
# objcopy \
--add-section .osrel="/etc/os-release" --change-section-vma .osrel=0x20000 \
--add-section .cmdline="/proc/cmdline" --change-section-vma .cmdline=0x30000 \
--add-section .linux="$(bootctl -x)/vmlinuz-lts" --change-section-vma .linux=0x40000 \
--add-section .initrd="$(bootctl -x)/initramfs-lts" --change-section-vma .initrd=0x3000000 \
/usr/lib/systemd/boot/efi/linuxx64.efi.stub $(bootctl -p)/EFI/Linux/linux.efi
</pre>
 
Users that also require CPU microcode (like intel-ucode) can also include it by concatenating the CPU microcode .img file before the normal initramfs into a single .img file.
 
<pre>
# cat $(bootctl -x)/cpu_microcode.img $(bootctl -x)/initramfs-lts > /tmp/initramfs-lts
</pre>


Then use that in the .initrd section of the <code>objcopy</code> call.
=== efibootmgr ===


== Listing Information and Status ==
Install {{Pkg|efibootmgr}}:
{{cmd|# apk add efibootmgr}}


<code>bootctl</code> can also list the entries available, which one is default and a wealth of information from them. (Example from Alpine Linux developer Leo, which inculdes an entry and a Unified Kernel Image)
Create a boot entry. It is recommended to do this in a script, as efibootmgr does not allow for editing entries.


<pre>
{{cat|add-bootentry|<nowiki>#!/bin/sh
# bootctl list
Boot Loader Entries:
        title: Alpine Linux
          id: alpine
      source: /boot/loader/entries/alpine.conf
        linux: /vmlinuz-lts
      initrd: /intel-ucode.img
              /initramfs-lts
      options: root=UUID=1437f4dd-7efd-4a4e-8fac-797b548076d1 cryptdm=pool cryptroot=/dev/sda2 modules=ext4,xfs rootfstype=ext4 psi=1 quiet


        title: Alpine Linux edge (default)
params="root=/dev/sdXZ rootfstype=ext4 rw \
          id: alpine-3.12_alpha20200122
  initrd=\intel-ucode.img \
      source: /boot/EFI/Linux/linux.efi
  initrd=\initramfs-lts"
        linux: EFI/Linux/linux.efi
      options: initrd=\intel-ucode.img initrd=\initramfs-lts root=UUID=1437f4dd-7efd-4a4e-8fac-797b548076d1 cryptdm=pool cryptroot=/dev/sda2 modules=ext4,xfs rootfstype=ext4 psi=1 quiet


        title: Reboot Into Firmware Interface
efibootmgr --create --label "Alpine Linux" \
          id: auto-reboot-to-firmware-setup
  --disk /dev/sdX --part Y \
      source: /sys/firmware/efi/efivars/LoaderEntries-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
  --loader /vmlinuz-lts \
</pre>
  --unicode "${params}" \
  --verbose
</nowiki>}}


And it can also list general status of the system, including information on the current bootloader, the system firmware and options (like if Secure Boot is enabled).
Where {{path|/dev/sdXY}} contains the EFI partition and {{path|/dev/sdXZ}} contains the root partition. If you are using {{Pkg|linux-stable}}, then replace <code>lts</code> with <code>stable</code> in the script.


<pre>
{{Tip|If you're modifying EFI records from a running system (e. g. migrating from GRUB), you can populate {{ic|$params}} from {{ic|/proc/cmdline}}. Make sure to append {{ic|initrd}} param if it's missing since GRUB does not add it to the command line.}}
# bootctl status
System:
    Firmware: UEFI 2.40 (American Megatrends 5.11)
  Secure Boot: disabled
  Setup Mode: user


Current Boot Loader:
{{Note| The kernel contains the [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/init/do_mounts.c#n254 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.
      Product: systemd-boot 243
}}
    Features: ✓ Boot counting
              ✓ Menu timeout control
              ✓ One-shot menu timeout control
              ✓ Default entry control
              ✓ One-shot entry control
              ✓ Support for XBOOTLDR partition
              ✓ Support for passing random seed to OS
          ESP: /dev/disk/by-partuuid/00e7649e-bf1f-481b-87cd-7228af8c118f
        File: └─/EFI/systemd/systemd-bootx64.efi


Random Seed:
Optionally, set the newly-created entry as the default:
Passed to OS: yes
System Token: set
      Exists: yes


Available Boot Loaders on ESP:
{{cmd|# efibootmgr -n XXXX}}
          ESP: /boot (/dev/disk/by-partuuid/00e7649e-bf1f-481b-87cd-7228af8c118f)
        File: └─/EFI/systemd/systemd-bootx64.efi (systemd-boot 243)
        File: └─/EFI/BOOT/BOOTX64.EFI (systemd-boot 243)


Boot Loaders Listed in EFI Variables:
Where <code>XXXX</code> is the boot number of the new entry.
        Title: Linux Boot Manager
          ID: 0x0007
      Status: active, boot-order
    Partition: /dev/disk/by-partuuid/00e7649e-bf1f-481b-87cd-7228af8c118f
        File: └─/EFI/systemd/systemd-bootx64.efi


        Title: Alpine
{{Note| The loader and initrd file arguments are relative to the EFI partition. In a default installation, Alpine Linux places these files in {{path|/boot/}}, while EFI is mounted to {{path|/boot/efi/}}. You can either update <code>fstab</code> to mount EFI at {{path|/boot/}}, or manually copy them to {{path|/boot/efi/}}.                                                                                           }}
          ID: 0x0006
      Status: active, boot-order
    Partition: /dev/disk/by-partuuid/00e7649e-bf1f-481b-87cd-7228af8c118f
        File: └─/EFI/EFI/alpine/grubx64.efi


        Title: Windows Boot Manager
== rEFInd ==
          ID: 0x0000
{{Main|rEFInd}}
      Status: active
    Partition: /dev/disk/by-partuuid/fd36bbae-be4f-409a-b1ce-14771e091067
        File: └─/EFI/Microsoft/Boot/bootmgfw.efi


Boot Loader Entries:
[[rEFInd]] provides a graphical boot menu for [[UEFI]] systems.
        $BOOT: /boot (/dev/disk/by-partuuid/00e7649e-bf1f-481b-87cd-7228af8c118f)
== Using a UKI  ==


Default Boot Loader Entry:
'''[https://github.com/uapi-group/specifications/blob/main/specs/unified_kernel_image.md#unified-kernel-image-uki Unified Kernel Image]''' (UKI) is supported in UEFI only. It is possible to boot directly into a UKI. A UKI is a single file that contains the initfs, kernel and cmdline.
        title: Alpine Linux
          id: alpine
      source: /boot/loader/entries/alpine.conf
        linux: /vmlinuz-lts
      initrd: /intel-ucode.img
              /initramfs-lts
      options: root=UUID=1437f4dd-7efd-4a4e-8fac-797b548076d1 cryptdm=pool cryptroot=/dev/sda2 modules=ext4,xfs rootfstype=ext4 psi=1 quiet
</pre>


== Updating ==
The [[UEFI Secure Boot]] page contains the instructions for setting up an a UKI.  While this is typically done in order to ''SecureBoot'', it is perfectly feasible to skip enrolling the custom keys and to leave SecureBoot off.


When the <code>systemd-boot</code> package is updated the bootloader installed needs to be updated as well:
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 {{path|/etc/kernel-hooks.d/secureboot.conf}} :


<pre>
{{cat|/etc/kernel-hooks.d/secureboot.conf|<nowiki># For the stable kernel, install the UKI into the default UEFI path.
# bootctl update
if [ "$1" == "stable" ]; then
</pre>
  output_dir="/efi/EFI/Boot/"
  output_name="bootx64.efi"
fi
</nowiki>}}


== Removing ==
{{Note|  {{path|bootx64.efi}} is only correct for <code>x86_64</code> systems. {{path|bootia32.efi}} is most commonly used on <code>x86</code> (32-bit) systems. For other architectures, the exact name will vary.}}


If for any reason you wish to not use systemd-boot anymore then the <code>bootctl</code> binary also provides a command for easily removing the files that were installed with the install command:
== Troubleshooting ==


<pre>
Since bootloaders are installed only during [[System Disk Mode]], the errors related to them are documented in [[System Disk Mode#Troubleshooting|that page]].
# bootctl remove
# apk del systemd-boot
</pre>


= External Links =
== See also ==
* [https://www.denx.de/wiki/U-Boot/ReleaseCycle U-Boot Release Cycle]
* [[Enable Serial Console on Boot]]
* [https://wiki.archlinux.org/index.php/systemd-boot ArchWiki extensive article on systemd-boot]
* [[Silent boot]]
* [https://wiki.gentoo.org/wiki/Bootloader Gentoo Wiki - Bootloaders]
* [https://wiki.archlinux.org/title/Arch_boot_process#Boot_loader Archwiki - Boot loader]
* [https://wiki.postmarketos.org/wiki/Category:Bootloaders PostmarketOS Wiki - Bootloaders]
* [https://docs.u-boot.org/en/latest/develop/release_cycle.html u-boot.org docs - U-Boot Release Cycle]


[[Category:Installation]]
[[Category:Installation]]
[[Category:Booting]]
[[Category:Booting]]

Latest revision as of 17:32, 18 March 2026

A bootloader is a computer program that is responsible for booting a computer. In the case where it also provides an interactive menu with multiple boot choices, then it's often called a boot manager. This page shows the basic steps that you need to perform if, for any reason, you want to switch bootloaders or to apply some manual configuration.

The following bootloaders are available in Alpine Linux:-

  • Syslinux is the default lightweight bootloader used in Alpine Linux when booting the Alpine Installer ISO. It is also the bootloader when creating a Live USB/CD/ISOLinux/PXELinux. Supports the Filesystems: FAT12/16/32
  • Extlinux is the default lightweight bootloader used in Alpine Linux when Installing the Alpine OS to Disk via BIOS/Legacy Boot. Supports the Filesystems: EXT2/3/4, BTRFS, XFS
  • GRUB is a standard Linux bootloader used in Alpine Linux when Installing the Alpine OS to Disk via UEFI.
  • Limine is a modern, advanced, portable, multiprotocol bootloader and boot manager.
  • EFI Boot Stub allows for booting Linux directly from a motherboard supporting UEFI or from another bootloader.
  • rEFInd is an easy-to-use EFI boot menu that allows booting different operating systems.
  • UEFI Secure Boot uses systemd-efistub or stubbyboot-efistub.

A Unified Kernel Image (UKI) is additionally supported, available for UEFI only. It is a UEFI executable that can be useful in certain use cases, including secure boot, clouds and containers.

Note that gummiboot is a deprecated UEFI boot manager that was originally able to leverage UEFI firmware and detect bootable images such as Linux kernels that have an EFI stub on the EFI System Partition (ESP). The gummiboot project was discontinued in 2015 and renamed as systemd-boot for systemd systems and is only available in Alpine Linux in the testing repository. As it had no runtime dependencies, gummiboot was appreciated for its simplicity as a lightweight, minimal UEFI boot solution. Its UEFI stub, gummiboot-efistub, was used to generate a Unified Kernel Images (UKIs) e.g. for DM-verity and Secure Boot, but it has been deprecated since Alpine Linux 3.22 and is no longer maintained; it has been replaced by systemd-efistub (note that the latter package only supplies EFI stub binaries and doesn’t depend on any systemd components).

Syslinux

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

Install the syslinux package:

# apk add syslinux

If you're using GPT partitions, then install the GPT MBR onto the drive that 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, then 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.

# syslinux --install /boot

The configuration file is located in /boot/syslinux/syslinux.cfg.

Alpine Linux ships with a script, update-extlinux, that 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 edit and add additional menu entries in the bootloader configuration file for dual booting multiple os's: /boot/syslinux/syslinux.cfg

Using EFI with syslinux

The Alpine Linux installer automatically uses GRUB if EFI mode is detected. The section below is specifically about using EFI with Syslinux.

Assuming that /mnt is a FAT32 partition of type EF00 and that /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/EFI/syslinux/ # cp /boot/initramfs* /mnt/EFI/syslinux/

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).

In the end, the /mnt/EFI/syslinux/syslinux.cfg file should look like this:

Contents of /mnt/EFI/syslinux/syslinux.cfg

... DEFAULT menu.c32 PROMPT 0 MENU TITLE Alpine/Linux Boot Menu MENU HIDDEN MENU AUTOBOOT Alpine will be booted automatically in # seconds TIMEOUT 10 LABEL lts MENU DEFAULT MENU LABEL Linux lts LINUX /vmlinuz-lts INITRD /initrd-lts APPEND root=/dev/sda3 modules=sd-mod,usb-storage,ext4 quiet

Finally, add syslinux to the EFI boot menu. Assuming that /dev/sda is your hard drive —be careful to check first what is its path on your device and to adjust accordingly:

# apk add efibootmgr # efibootmgr -c -d /dev/sda -p 1 -l \\EFI\\syslinux\\syslinux.efi -L "ALPINE-SYSLINUX"

You can now verify that the boot entry has been added:

efibootmgr

BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,0000,0002,...
Boot001* ALPINE-SYSLINUX HD(1,GPT,xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)/FILE(\EFI\syslinux\syslinux.efi)

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, such as FAT32.

# apk add grub-efi efibootmgr

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

# grub-install /dev/vda

For EFI mode:

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

Then, add this line to /etc/default/grub:

Contents of /etc/default/grub

# GRUB_CMDLINE_LINUX_DEFAULT="quiet rootfstype=ext4 modules=sd-mod,usb-storage,ext4"

GRUB ships with an automatic configuration 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.

If the font in the GRUB boot screen appears too small, then change the GRUB font.

Consult gnu.org's online manual for a list of available grub-mkconfig configuration options.

Limine

Limine is a modern, advanced, portable, multiprotocol bootloader and boot manager, also used as the reference implementation for the Limine boot protocol. It supports partitioning schemes like MBR, GPT and Unpartitioned media.

EFI Boot Stub

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

efibootmgr

Install efibootmgr:

# apk add efibootmgr

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

Contents of add-bootentry

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

Where /dev/sdXY contains the EFI partition and /dev/sdXZ contains the root partition. If you are using linux-stable, then replace lts with stable in the script.

Tip: If you're modifying EFI records from a running system (e. g. migrating from GRUB), you can populate $params from /proc/cmdline. Make sure to append initrd param if it's missing since GRUB does not add it to the command line.
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:

# efibootmgr -n XXXX

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 Linux 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/.

rEFInd

rEFInd provides a graphical boot menu for UEFI systems.

Using a UKI

Unified Kernel Image (UKI) is supported in UEFI only. It is possible to boot directly into a UKI. A UKI is a single file that contains the initfs, kernel and cmdline.

The UEFI Secure Boot page contains the instructions for setting up an a UKI. While this is typically done in order to SecureBoot, it is perfectly feasible to skip enrolling the custom keys and to leave SecureBoot off.

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 :

Contents of /etc/kernel-hooks.d/secureboot.conf

# For the stable kernel, install the UKI into the default UEFI path. if [ "$1" == "stable" ]; then output_dir="/efi/EFI/Boot/" output_name="bootx64.efi" fi
Note: bootx64.efi is only correct for x86_64 systems. bootia32.efi is most commonly used on x86 (32-bit) systems. For other architectures, the exact name will vary.

Troubleshooting

Since bootloaders are installed only during System Disk Mode, the errors related to them are documented in that page.

See also