Bootloaders: Difference between revisions
Prabuanand (talk | contribs) (→Syslinux: commented out efi section) |
Prabuanand (talk | contribs) m (removed words to add clarity and added more example from https://www.rodsbooks.com/refind/linux.html) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A bootloader, is a computer program that is responsible for booting a computer. If it also provides an interactive menu with multiple boot choices then it's often called a boot manager. 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. | |||
* <code>[[#Syslinux|Syslinux]]</code> is the default light-weight bootloader used in Alpine.<br> | * <code>[[#Syslinux|Syslinux]]</code> is the default light-weight bootloader used in Alpine.<br> | ||
Line 8: | Line 9: | ||
* Gummiboot can be used for [[UEFI Secure Boot]]. | * Gummiboot can be used for [[UEFI Secure Boot]]. | ||
= rEFInd = | == rEFInd == | ||
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. | 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 by following the [[Repositories#Using_testing_repository|guidelines]]. | ||
The below command installs the alpine-linux rEFInd package: | |||
The below command installs the alpine-linux | |||
{{cmd|# apk add refind@testing }} | {{cmd|# apk add refind@testing }} | ||
rEFInd's refind-install script creates a sample file {{Path|/boot/refind_linux.conf}}. | |||
{{cmd| # refind-install | {{cmd| # refind-install}} | ||
<!-- | |||
For 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: | ||
Line 27: | Line 25: | ||
# refind-install --alldrivers # installs refind to the EFI partition | # refind-install --alldrivers # installs refind to the EFI partition | ||
</nowiki>}} | </nowiki>}} | ||
--> | |||
The above steps should be sufficient for most cases to start using rEFInd as boot loader. | |||
A sample {{Path|/boot/refind_linux.conf}} from rEFInd website for a system with ext4 filesystem is given below: | |||
{{Cat|/boot/refind_linux.conf|<nowiki>"Boot with standard options" "ro root=UUID=084f544a-7559-4d4b-938a-b920f59edc7e splash=silent quiet showopts " | |||
"Boot to single-user mode" "ro root=UUID=084f544a-7559-4d4b-938a-b920f59edc7e splash=silent quiet showopts single" | |||
"Boot with minimal options" "ro root=UUID=084f544a-7559-4d4b-938a-b920f59edc7e" | |||
# This line is a comment</nowiki>}} | |||
This sample file defines three entries: | |||
* The first entry uses options derived from the contents of {{Path|/proc/cmdline}} when the script was run, unless the script was run from an emergency system, in which case refind-install tries to translate from options in {{Path|/etc/default/grub}}. | |||
* The second entry provides the same boot options as the first, but adds single, which causes most distributions to boot into a single-user maintenance mode. | |||
* The final entry subtracts most options from the list, leaving only ro root=rootfs, where rootfs is the identified root (/) filesystem. This option may not be bootable on some systems that need unusual options, but if it does boot, it will normally do so with verbose startup messages, which can be helpful when debugging boot problems. | |||
Given below is a sample {{Path|/boot/refind_linux.conf}} created automatically by rEFInd for a system with [[Btrfs]] filesystem whose layout is given further below as <Code>blkid</Code> output: | |||
{{Cat|/boot/refind_linux.conf|<nowiki>"Boot with standard options" "root=LABEL=_SYS0_ modules=sd-mod,usb-storage,btrfs rootflags=subvol=@ resume=LABEL=_SWAP_ ro quiet" | |||
"Boot to single-user mode" "root=LABEL=_SYS0_ modules=sd-mod,usb-storage,btrfs rootflags=subvol=@ resume=LABEL=_SWAP_ ro quiet single" | |||
"Boot with minimal options" "ro root=UUID=aafbf6b0-7d54-4222-a3dd-a8f45c0ac607"</nowiki>}} | |||
Output of <Code>blkid</Code> from [[Busybox]] is given below. | |||
<Pre> | |||
/dev/sda4: LABEL="_SWAP_" UUID="33899521-599f-458e-9bfe-f4b59254eb7c" TYPE="swap" | |||
/dev/sda3: LABEL="_SYS0_" UUID="aafbf6b0-7d54-4222-a3dd-a8f45c0ac607" TYPE="btrfs" | |||
/dev/sda1: LABEL="_BOOT_" UUID="6771-DB5C" TYPE="vfat" | |||
</Pre> | |||
The single-user mode and minimal options does not work in Alpine Linux for [[Btrfs]] filesystem as per user u/Xerotras in https://redd.it/1hbog74 | |||
{{Note|The {{pkg|refind}} utility currently does not have Alpine Linux icon file. You can place this [[Media:Os alpine.png| icon file]] in {{Path|/boot/efi/EFI/refind/icons/}} or {{Path|/boot/EFI/refind/icons/}} folder.}} | |||
Proceed to [[#Manual configuration|Manual configuration]] only if rebooting did not result in rEFInd appearing as boot loader. | |||
=== Manual configuration === | |||
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 34: | Line 63: | ||
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. | There is also a second config file, '''refind.conf''' which is located inside the EFI partition. The config file is self-explanatory and has to be manually edited. Refer [https://www.rodsbooks.com/refind/configfile.html refind website] for additional information. | ||
The config file is self-explanatory. | |||
The below instructions assume esp partition is mounted as shown:{{cat|/etc/fstab|<nowiki>... | |||
UUID=ABCD-1234 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro 0 2 | |||
...</nowiki>}} | |||
If your setup is different from above, adjust the path in below files accordingly. | |||
For default alpine [[Installation#System_Disk_Mode|sys]] mode installation, a sample refind.conf to [[Dualbooting|dual boot]] Alpine Linux and windows will be: {{Cat|/boot/efi/EFI/refind/refind.conf|<nowiki>timeout 20 | |||
For default alpine [[Installation#System_Disk_Mode|sys]] mode installation, | |||
{{Cat|/boot/efi/EFI/refind/refind.conf| | |||
<nowiki> | |||
timeout 20 | |||
resolution 1920 1080 | resolution 1920 1080 | ||
use_graphics_for windows,linux | use_graphics_for windows,linux | ||
Line 69: | Line 84: | ||
initrd /boot/initramfs-lts | initrd /boot/initramfs-lts | ||
options "root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw" | options "root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw" | ||
} | } </nowiki> }} | ||
</nowiki> | |||
If you use [[btrfs]] filesystem, for the above {{Path|/etc/fstab}} setup, 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> | |||
}} | }} | ||
{{Tip|If the above configuration is working perfectly,there is no need for other bootloaders and they can be safely removed.}} | |||
== Syslinux == | |||
= 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. | 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. | ||
Line 99: | Line 124: | ||
{{cmd|# extlinux --install /boot}} | {{cmd|# extlinux --install /boot}} | ||
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 | |||
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}}. | Alpine ships with a script <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}}. | ||
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. | ||
=== Using EFI with syslinux === | |||
=== EFI === | |||
Alpine Linux installer automatically uses [[#GRUB|Grub]], if EFI mode is detected. The below section is specifically about using EFI with syslinux: | |||
Assuming {{path|/mnt}} is a FAT32 partition of type EF00 and {{path|/boot}} belongs to the rootfs created after running <code>setup-disk</code>: | Assuming {{path|/mnt}} is a FAT32 partition of type EF00 and {{path|/boot}} belongs to the rootfs created after running <code>setup-disk</code>: | ||
Line 152: | Line 176: | ||
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 == | ||
To install GRUB in BIOS mode, (optionally) remove the Syslinux package and install the required GRUB packages: | To install GRUB in BIOS mode, (optionally) remove the Syslinux package and install the required GRUB packages: | ||
Line 184: | Line 207: | ||
See [https://www.gnu.org/software/grub/manual/html_node/Simple-configuration.html] for a list of available options. | See [https://www.gnu.org/software/grub/manual/html_node/Simple-configuration.html] for a list of available options. | ||
= EFI Boot Stub = | == EFI Boot Stub == | ||
To boot directly from your motherboard's UEFI boot menu, a boot entry needs | To boot directly from your motherboard's UEFI boot menu, a boot entry needs | ||
to be created with either a UEFI shell or ''efibootmgr''. | to be created with either a UEFI shell or ''efibootmgr''. | ||
== efibootmgr == | === efibootmgr === | ||
Install efibootmgr: | Install efibootmgr: | ||
Line 225: | Line 248: | ||
The loader and initrd file arguments are relative to the EFI partition. In a default installation, alpine places these files in {{path|/boot/}}, while EFI is mounted to {{path|/boot/efi/}}. You can either update fstab to mount EFI at {{path|/boot/}}, or manually copy them to {{path|/boot/efi/}}. }} | The loader and initrd file arguments are relative to the EFI partition. In a default installation, alpine places these files in {{path|/boot/}}, while EFI is mounted to {{path|/boot/efi/}}. You can either update fstab to mount EFI at {{path|/boot/}}, or manually copy them to {{path|/boot/efi/}}. }} | ||
= Using a UKI | == 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 which contains the initfs, kernel and cmdline. While this is typically done in order to enable [https://en.wikipedia.org/wiki/UEFI 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 {{path|/etc/kernel-hooks.d/secureboot.conf}} | 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 {{path|/etc/kernel-hooks.d/secureboot.conf}} |
Latest revision as of 09:02, 30 December 2024
A bootloader, is a computer program that is responsible for booting a computer. If it also provides an interactive menu with multiple boot choices then it's often called a boot manager. 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.
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 by following the guidelines.
The below command installs the alpine-linux rEFInd package:
# apk add refind@testing
rEFInd's refind-install script creates a sample file /boot/refind_linux.conf.
# refind-install
The above steps should be sufficient for most cases to start using rEFInd as boot loader. A sample /boot/refind_linux.conf from rEFInd website for a system with ext4 filesystem is given below:
Contents of /boot/refind_linux.conf
This sample file defines three entries:
- The first entry uses options derived from the contents of /proc/cmdline when the script was run, unless the script was run from an emergency system, in which case refind-install tries to translate from options in /etc/default/grub.
- The second entry provides the same boot options as the first, but adds single, which causes most distributions to boot into a single-user maintenance mode.
- The final entry subtracts most options from the list, leaving only ro root=rootfs, where rootfs is the identified root (/) filesystem. This option may not be bootable on some systems that need unusual options, but if it does boot, it will normally do so with verbose startup messages, which can be helpful when debugging boot problems.
Given below is a sample /boot/refind_linux.conf created automatically by rEFInd for a system with Btrfs filesystem whose layout is given further below as blkid
output:
Contents of /boot/refind_linux.conf
Output of blkid
from Busybox is given below.
/dev/sda4: LABEL="_SWAP_" UUID="33899521-599f-458e-9bfe-f4b59254eb7c" TYPE="swap" /dev/sda3: LABEL="_SYS0_" UUID="aafbf6b0-7d54-4222-a3dd-a8f45c0ac607" TYPE="btrfs" /dev/sda1: LABEL="_BOOT_" UUID="6771-DB5C" TYPE="vfat"
The single-user mode and minimal options does not work in Alpine Linux for Btrfs filesystem as per user u/Xerotras in https://redd.it/1hbog74
Proceed to Manual configuration only if rebooting did not result in rEFInd appearing as boot loader.
Manual configuration
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
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. The config file is self-explanatory and has to be manually edited. Refer refind website for additional information.
The below instructions assume esp partition is mounted as shown:
Contents of /etc/fstab
If your setup is different from above, adjust the path in below files accordingly.
For default alpine sys mode installation, a sample refind.conf to dual boot Alpine Linux and windows will be:
Contents of /boot/efi/EFI/refind/refind.conf
If you use btrfs filesystem, for the above /etc/fstab setup, the necessary boot entry for Alpine Linux is as follows:
Contents of /boot/efi/EFI/refind/refind.conf
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 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.
Using EFI with syslinux
Alpine Linux installer automatically uses Grub, if EFI mode is detected. The below section is specifically about using EFI with syslinux:
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/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).
At the end, the file /mnt/EFI/syslinux/syslinux.cfg should look like this:
Contents of /mnt/EFI/syslinux/syslinux.cfg
And finally, add syslinux to EFI boot menu (assuming /dev/sda is your hard drive)
# 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 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 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
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
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.
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 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
bootx64.efi is only correct for x86_64
systems. For other architectures the exact name will vary.