rEFInd & Linux kernel EFISTUB booting at Apple hardware, how to implement it?
Here follows a somewhat simpler way to implement a EFISTUB and bare Linux kernel booting from rEFInd.
More recent (K)Ubuntu versions includes a not much noticed EFI boot option called safe graphics. Behind this stands the more or less known nomodeset
GRUB parameter. In older times this option mostly resulted in booting to a CLI command prompt, no graphical UI (X-Server) was available. However under an EFI environment that option enables the booting of X with basic "UEFI resolutions". These seems to be defined along the UEFI GOP (Graphics Output Protocol) specification. (https://wiki.osdev.org/GOP) To some degree the working principle of the safe graphics option corresponds to the "Microsoft Basic Display Driver" in newer Windows versions.
Long speak short, this nice little option enables a minimal X "emergency booting" also on very restricted "vBIOS not exposed in EFI" systems. :-) Well I have not tested this at an iMac11,2, but I can confirm that this works GREAT at an iMac11,1 which contains a Radeon HD 4850 GPU.
Whatever, this awesome option has the potential to again simplify the topic described here. The installation steps will look as follow:
-
Prepare the desired partitioning layout under Mac OS. As mentioned, in my case this would be: sda1 (EFI ESP), sda2 (Macintosh HD), sda3 (Apple Recovery HD), sda4 (Linux HD) Note, the Recovery Partition is not visible in the Apple disk utility.
-
Install now Ubuntu, select the EFI (safe graphics) option, target partition is sda4 aka the "Linux HD". (Also in this case no additional boot, swap or data partition is used.) Please consider, the steps 1 to 3 mentioned below should be carried out before a reboot is made.
-
After K(U)buntu is installed, install rEFInd directly from the CD/DVD. This option is avaiable in newer rEFInd builds. Download the corresponding image from the official website, burn it to a CD/DVD, boot from it and chose the "install" option.
Note, if someone needs to install just the bare Linux kernel booting, the following steps can be skipped (for the moment). Please check first the section "Optional further steps".
Because (K)Ubuntu is running in EFI mode, we can config the additional EFI related booting stuff directly without any additional steps. The example here uses the regular EFI path syntax.
The following steps describe how a regular EFISTUB booting from the stock Apple EFI firmware is established.
-
When Ubuntu is completely installed, the efi esp partition should be present and mounted at
/boot/efi
. (As mentioned, this is because Ubuntu is running in EFI mode.) -
Create a new file
sudo nano /etc/kernel/postinst.d/zz-update-efistub
with the following contents:#!/bin/sh rm /boot/efi/EFI/ubuntu/* cp /boot/vmlinuz /boot/vmlinuz.efi cp /boot/vmlinuz* /boot/initrd.img /boot/efi/EFI/ubuntu/ rm /boot/efi/EFI/ubuntu/vmlinuz.old
This hook will sync the ESP kernel-related files to those at the root partition. Make it executable with:
sudo chmod +x /etc/kernel/postinst.d/zz-update-efistub sudo /etc/kernel/postinst.d/zz-update-efistub
The
vmlinuz.efi
kernel loader is needed at older Apple EFI firmware versions. On those the normalvmlinuz
file is not recognized as bootable. -
Because Linux is running in EFI mode, the regular EFISTUB boot entry can be established now.
sudo efibootmgr -c -d /dev/sda -p 1 -L "Ubuntu (efistub)" -l /EFI/ubuntu/vmlinuz.efi -u "root=/dev/sda4 rw initrd=/EFI/ubuntu/initrd.img quiet splash"
Also here, the syntax is correct for this example. Otherwise the arguments
-d
and-p
must be changed according to the used partition layout. The EFI ESP is/dev/sda1
while theroot=
partition issda4
.
As a final (optional) step it would make sense to completely remove GRUB and Shim. Update: Unfortunately these two packages are installed again and again automatically by (K)Ubuntu. If you really want to get rid of them, then it is necessary to blacklist the GRUB and Shim packages manually. The following command would uninstall these two packages including the corresponding config:
sudo apt remove --purge grub-common
sudo apt remove --purge shim
Congrats, the regular EFISTUB kernel booting (including rEFInd) is now fully configured!
To verify the boot order enter sudo efibootmgr -v
at the CLI. The "Ubuntu (efistub)" is in my case entry "Boot0002". It should be set as the first one, before any other. This can be done at the CLI for example with sudo efibootmgr -o 0002,0000,0001
. But be aware, Mac OS sometimes defaults the boot order again back to itself. So the most save option is to install rEFInd permanently as already described. This will by-pass all generic Apple EFI and GRUB boot principles. As an emergency boot option, a rEFInd CD or USB flash drive can be additionally used if the installed rEFInd fails.
Take a reboot and check if everything works as expected. :-D
Optional further steps, only necessary on restricted "vBIOS not exposed in EFI" systems:
To establish a bare Linux kernel booting directly from rEFInd, the following command is required. It is very important to understand that this requires an ongoing manual adjustment because the kernel and kernel name changes with every kernel update. So check first out which kernel version is present! ;-)
sudo cp /boot/vmlinuz-5.4.0-72-generic /boot/vmlinuz-5.4.0-72-generic.efi
In some situations it may be necessary to delete the previously generated vmlinuz.efi
file. But I recommend to try it first out without deleting it.
sudo rm /boot/vmlinuz.efi
As the last step it is recommended to install the rEFInd PPA. This will automatically update rEFInd to the newest release. Regarding (K)Ubuntu this can be done quite easy through the official rEFInd PPA from Roderick W. Smith:
sudo apt-add-repository ppa:rodsmith/refind
sudo apt-get update
sudo apt-get install refind
Alternatively it is also possible to skip this step and boot rEFInd always from CD.
That's it! Reboot the Mac and choose in rEFInd the Linux kernel (with the efi extension). K(u)buntu should now boot fine also on systems which doesn't expose the vBIOS under EFI.
And by the way, an auto-mount entry (of the esp partition) in fstab isn't required. This is already configured because (K)Ubuntu was installed from the beginning in EFI mode.