Bootloaders: Difference between revisions

From Alpine Linux
(always write GRUB uppercase)
(→‎Syslinux: commented out efi section)
 
(12 intermediate revisions by 3 users not shown)
Line 2: Line 2:
This page shows the basic steps you need to perform, if you for any reason want to switch bootloaders or 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.


* <code>[[#Syslinux|Syslinux]]</code> is the default light-weight bootloader used in Alpine.<br>
* <code>[[#rEFInd|rEFInd]]</code> is an easy to use EFI boot menu that allows booting different operating systems.<br>
* <code>[[#GRUB|GRUB]]</code> is a standard linux boot loader.<br>
* <code>[[#EFI_Boot_Stub|EFI Boot Stub]]</code> allows booting linux directly from a motherboard supporting UEFI or another bootloader.<br>
* Gummiboot can be used for [[UEFI Secure Boot]].


<code>[[#rEFInd|rEFInd]]</code> is an easy to use EFI boot menu that allows booting different operating systems.<br>
= rEFInd =
<code>[[#Syslinux|Syslinux]]</code> is the default light-weight bootloader used in Alpine.<br>
<code>[[#GRUB|GRUB]]</code> is a standard linux boot loader.<br>
<code>[[#EFI_Boot_Stub|EFI Boot Stub]]</code> allows booting linux directly from a motherboard supporting UEFI or another bootloader.<br>


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


As of now, {{pkg|refind}}  is available in the [[Repositories#Testing|testing]] repository. It can be safely installed in alpine by following the [[Repositories#Using_testing_repository|guidelines]] or it may be installed in other dual/multi-booted linux distribution.


= rEFInd =
The below command installs the alpine-linux refind package:
{{cmd|# apk add refind@testing }} 


For (U)EFI systems, the {{pkg|refind}} package can provide a graphical EFI boot menu that allows to boot operating systems that are found on the available partitions.
The below command installs refind to the EFI partition
{{cmd| # refind-install --alldrivers}}  


If <code>refind</code> is not yet available in the used alpine release, it may be installed in another dual/multi-booted linux distribution.
The <code>--alldrivers</code> 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.


For example, with a Debian based distribution, it can be installed to the EFI partition like this:
For a Debian based distribution, it can be installed to the EFI partition like this:
   
   
{{cmd|<nowiki># apt install refind            # installs the debian package
{{cmd|<nowiki># apt install refind            # installs the debian package
# refind-install --alldrivers    # installs refind to the EFI partition
# refind-install --alldrivers    # installs refind to the EFI partition
</nowiki>}}
</nowiki>}}
(The <code>--alldrivers</code> 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 {{path|/media/sdXY}} it can be done like this (at time of writing):
And a first (default) boot menu line needs to be configured with Alpine's default boot parameters. Assuming the bootable partition is mounted at {{path|/media/sdXY}} it can be done like this (at time of writing):
Line 29: Line 33:
{{Note|At the time of writing, it was still needed to use backslashes in the .conf file.<br>
{{Note|At the time of writing, it was still needed to use backslashes in the .conf file.<br>
The path in the config file needs to be relative to the partition that the kernel resides on. If {{path|/boot}} resides on its own separate partition, then <code>\boot</code> needs to be removed from the paths.}}
The path in the config file needs to be relative to the partition that the kernel resides on. If {{path|/boot}} resides on its own separate partition, then <code>\boot</code> needs to be removed from the paths.}}
There is also a second config file, '''refind.conf''' which is located inside the EFI partition. This file has to be edited manually, but it does not get affected by btrfs snapshot rollbacks.
The config file is self-explanatory.  The author's  [https://www.rodsbooks.com/refind/configfile.html website] is also extremely rich in information.
For [[btrfs]] filesystem, the necessary boot entry for Alpine Linux is as follows:
{{Cat|/boot/efi/EFI/refind/refind.conf|
<nowiki>menuentry "Alpine Linux" {
    icon    /EFI/refind/icons/os_alpine.png
    volume  BTRFSVOL
    loader  @alpine/boot/vmlinuz-lts
    initrd  @alpine/boot/initramfs-lts
    options  "root=UUID=823a3283-30a7-4fef-b50b-8a2230c71b5b rw rootflags=subvol=@alpine rootfstype=btrfs"
    # PARTUUID not working for alpine
}
</nowiki>
}}
For default alpine [[Installation#System_Disk_Mode|sys]] mode installation, the complete file content of refind.conf necessary to [[Dualbooting|dual boot]] Alpine Linux and windows is as follows:
{{Cat|/boot/efi/EFI/refind/refind.conf|
<nowiki>
timeout 20
resolution 1920 1080
use_graphics_for windows,linux
menuentry "Windows" {
  loader /EFI/Microsoft/Boot/bootmgfw.efi
  icon /EFI/refind/icons/os_win.png
}
menuentry "Alpine Linux" {
    icon    /EFI/refind/icons/os_alpine.png
    volume  ROOT
    loader  /boot/vmlinuz-lts
    initrd  /boot/initramfs-lts
    options  "root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw"
</nowiki>
}}
The  {{pkg|refind}} utility currently does not have Alpine Linux icon file. You can place this [[Media:Os alpine.png| icon]] in /boot/efi/EFI/refind/icons/ folder.
{{Tip|If the above configuration is working perfectly,there is no need for {{pkg|grub}} and can be safely removed.}}


= Syslinux =
= Syslinux =
Line 54: Line 101:
The configuration file is located in {{path|/boot/extlinux.conf}}.
The configuration file is located in {{path|/boot/extlinux.conf}}.
Alpine ships with a script called <code>update-extlinux</code> which automatically (re)generates this file, for example on updates to Syslinux.
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 {{path|/etc/update-extlinux.conf}}, including the option to disable automatic overwriting of {{path|/boot/extlinux.conf</code>.
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}}.
You can also place additional menu entries in the {{path|/etc/update-extlinux.d/}} directory, e.g. for dual booting.
You can also place additional menu entries in the {{path|/etc/update-extlinux.d/}} directory, e.g. for dual booting.


 
<!--
The below section is commented as other options like grub and refind handle efi. Also the material looks quite dated.
=== EFI ===
=== EFI ===


Line 104: Line 152:
Boot001* ALPINE-SYSLINUX HD(1,GPT,xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)/FILE(\EFI\syslinux\syslinux.efi)
Boot001* ALPINE-SYSLINUX HD(1,GPT,xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)/FILE(\EFI\syslinux\syslinux.efi)
</pre>
</pre>
--->


= GRUB =
= GRUB =

Latest revision as of 17:11, 8 September 2024

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

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

rEFInd

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.

As of now, refind is available in the testing repository. It can be safely installed in alpine by following the guidelines or it may be installed in other dual/multi-booted linux distribution.

The below command installs the alpine-linux refind package:

# apk add refind@testing

The below command installs refind to the EFI partition

# refind-install --alldrivers

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.

For 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

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

Note: At the time of writing, it was still needed to use backslashes in the .conf file.
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.

There is also a second config file, refind.conf which is located inside the EFI partition. This file has to be edited manually, but it does not get affected by btrfs snapshot rollbacks. The config file is self-explanatory. The author's website is also extremely rich in information.

For btrfs filesystem, the necessary boot entry for Alpine Linux is as follows:

Contents of /boot/efi/EFI/refind/refind.conf

menuentry "Alpine Linux" { icon /EFI/refind/icons/os_alpine.png volume BTRFSVOL loader @alpine/boot/vmlinuz-lts initrd @alpine/boot/initramfs-lts options "root=UUID=823a3283-30a7-4fef-b50b-8a2230c71b5b rw rootflags=subvol=@alpine rootfstype=btrfs" # PARTUUID not working for alpine }

For default alpine sys mode installation, the complete file content of refind.conf necessary to dual boot Alpine Linux and windows is as follows:

Contents of /boot/efi/EFI/refind/refind.conf

timeout 20 resolution 1920 1080 use_graphics_for windows,linux menuentry "Windows" { loader /EFI/Microsoft/Boot/bootmgfw.efi icon /EFI/refind/icons/os_win.png } menuentry "Alpine Linux" { icon /EFI/refind/icons/os_alpine.png volume ROOT loader /boot/vmlinuz-lts initrd /boot/initramfs-lts options "root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw" }

The refind utility currently does not have Alpine Linux icon file. You can place this icon in /boot/efi/EFI/refind/icons/ folder.

Tip: If the above configuration is working perfectly,there is no need for grub and can be safely removed.

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:

# apk add syslinux

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.

# extlinux --install /boot

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.


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.

# 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 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

Install efibootmgr:

# apk add efibootmgr

Create a boot entry. It's recommended to do this in a script, as efibootmgr does not allow 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-edge, replace lts with edge in the script

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

Contents of /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.

See also