Skip Navigation

GRUB Notes

Sometimes it is necessary to install GRUB manually. While the Alpine Linux installation script has improved as of release 3.17, there are still some cases that it cannot handle properly. Notes for x86_64 (the standard architecture used for most physical and virtual machines) and AArch64 (for emulating ARM CPUs in QEMU) are included below, followed by links to resources for customizing the GRUB bootloader menu.

Page Contents

x86_64

If you are using UEFI mode, it is necessary to use the GRUB bootloader. Automatic installation of GRUB might fail, although this is less likely as of Alpine Linux 3.17. Should a failure occur, run the following commands in the installer environment. Do not reboot until you have a working bootloader, or you’ll just be stuck in an installation loop.

For fully encrypted installations, edit the GRUB configuration at /mnt/etc/default/grub before running the following commands. See the LVM on LUKS wiki entry for the necessary configuration.

mkdir -p /mnt/dev
mkdir -p /mnt/proc
mkdir -p /mnt/sys
mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
chroot /mnt
grub-install --target=x86_64-efi --bootloader-id=grub --efi-directory=/boot/efi --removable
grub-mkconfig -o /boot/grub/grub.cfg
exit
umount -l /mnt/dev
umount -l /mnt/proc
umount -l /mnt/sys

The –removable flag makes the bootloader location more compatible with a wider variety of motherboards.

AArch64

Installing GRUB in UEFI mode on AArch64 is a bit challenging. First, the Alpine Linux installer doesn’t properly install GRUB automatically. Second, there is an issue accessing the EFI variables from Linux within the AArch64 environment, so it is necessary to add a boot entry for grub using the EFI Shell.

Once the setup-disk step finishes, run the following commands:

mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
chroot /mnt
grub-install --target=arm64-efi --bootloader-id=grub --efi-directory=/boot/efi --removable --no-nvram
grub-mkconfig -o /boot/grub/grub.cfg
exit
umount -l /mnt/dev
umount -l /mnt/proc
umount -l /mnt/sys
poweroff

The –removable flag puts the bootloader in a default location, while the –no-nvram flag skips any attempts to set the boot order. We have to configure the boot order manually using the UEFI shell. To perform this step, first edit your shell script, batch file, or PowerShell script as follows:

  1. Remove the -drive argument that specifies the Alpine Linux ISO file, as we no longer need it.
  2. Change the -device virtio-vga argument to -device ramfb instead. This adjustment will enable us to access the TianoCore boot menu when the virtual machine is first started.

Boot the virtual machine with the modified configuration. Immediately press the Esc key at the TianoCore splash screen to enter the UEFI setup application. If you miss this keypress, use the Machine…Reset option in the QEMU window to reboot and try again.

At the TianoCore main menu (Figure 1), use the down arrow to navigate to the Boot Manager. Press the Enter key.

TianoCore main menu

Figure 1: TianoCore UEFI setup main menu.

In the Boot Manager menu (Figure 2), navigate to the EFI Internal Shell by using the down arrow. Press Enter to start the EFI shell application.

TianoCore Boot Manager menu

Figure 2: TianoCore Boot Manager menu. Note that you will not have a GRUB entry at first. Pick the EFI Internal Shell entry using the keyboard.

Let the EFI shell run the startup.nsh script, as shown in Figure 3.

EFI shell

Figure 3: The UEFI Interactive Shell application.

Run the following commands in the EFI shell:

fs0:
bcfg boot add 0 EFI\BOOT\BOOTAA64.EFI "GRUB"
reset

When the virtual machine reboots, you should briefly see the GRUB menu in the ramfb display device. The screen will then switch to a blinking cursor for a bit (boot messages will be in the serial console device). Once the boot process finishes, a login screen will appear in the rambfb and serial devices.

Customizing the GRUB Menu

The following resources should be helpful for customizing the GRUB menu:

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.