Installation on Macs could use EFI booting instead of legacy BIOS

Bug #1369187 reported by Jason Heeris
28
This bug affects 5 people
Affects Status Importance Assigned to Milestone
debian-installer (Ubuntu)
Confirmed
Undecided
Unassigned
ubiquity (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I recently installed Ubuntu 14.04.1 LTS (Trusty) on my Mac Mini 6,1 using the server installer. First I tried the "+mac" variant, which gave me a system that booted in legacy BIOS mode, and then then I tried the normal variant, which gave me an unbootable system.

I eventually got the EFI installation working, resulting in an Ubuntu installation that boots directly from the Mac bootloader firmware (ie. no rEFInd/rEFIt). The basic steps are to use an HFS+ filesystem instead of VFAT for the EFI partition, to "bless" the EFI boot image, and to create a couple of files that the Mac bootloader requires.

I wrote the full procedure up as a guide:

http://heeris.id.au/2014/ubuntu-plus-mac-pure-efi-boot/

While my guide only covers single-boot into Ubuntu on a Mac Mini, I hope there's enough detail there to illustrate what's needed for a more general case.

Note that grub-efi-amd64 already does the right thing (except for Debian bug #716927 [1]). The only tool that isn't already in the repos is the mactel-boot utility (aka. hfsbless), which I've made available in my PPA[2] (see also the Github repo[3], which has the Ubuntu packaging metadata in various branches, and is git-buildpackage friendly).

So it should be possible to install Ubuntu in EFI mode on Macs. This would reduce the options presented to a user when downloading the installer, and result in a more consistent experience for users across Windows and Mac.

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=716927#20
[2] https://launchpad.net/~detly/+archive/ubuntu/mactel-utils
[3] https://github.com/detly/mactel-boot

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in debian-installer (Ubuntu):
status: New → Confirmed
Revision history for this message
Bernhard Reiter (ockham-razor) wrote :

Jason,

have you considered submitting your package for inclusion in Debian? (See http://mentors.debian.net/, and links in the 'Getting your package into Debian' section there.) I'd very much appreciate if you did! :-)

--Bernhard

Revision history for this message
Jason Heeris (detly) wrote :

I went through the Debian package submission/mentor process years ago (for RabbitVCS) and would rather not repeat the experience.

I'm happy to keep my packages' metadata up to date with the latest Debian standards, and happy to support what I publish (on Github/PPAs/etc.), and happy to take back changes from Debian maintainers, but I have no desire to subject myself to Debian's package submission purgatory again.

Revision history for this message
Bernhard Reiter (ockham-razor) wrote :

In that case, would you mind me giving it a try? I'm masochist enough to have had a couple of packages added to Debian in the past :-D I would obviously preserve the copyright and licensing of your packaging. My ultimate goal would be to contribute to a better OOTB experience for mactel users, ideally automating your pure EFI boot guide as part of the installer.

Revision history for this message
Jason Heeris (detly) wrote :

I definitely don't mind! Note that the github repo has packaging branches that might be a good starting point. Feel free to email me if you have any problems or feedback.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in ubiquity (Ubuntu):
status: New → Confirmed
Revision history for this message
Jack Howarth (jwhowarth) wrote :
Download full text (3.7 KiB)

I have successfully installed Debian Jessie using the multi-arch netinst iso

https://cdimage.debian.org/debian-cd/current/multi-arch/iso-cd/debian-8.6.0-amd64-i386-netinst.iso

which leverages the new mixed mode support described in https://wiki.debian.org/UEFI

Support for mixed-mode systems: 64-bit system with 32-bit UEFI
Some systems have been released containing 64-bit Intel Atom CPUs (such as the Bay Trail), but unfortunately use 32-bit UEFI firmware with no BIOS compatibility mode. Using the 32-bit UEFI x86 support, an i386 installation should be possible on these machines but it won't make the most of the 64-bit hardware.

Debian Jessie (8.0) was the first Linux distribution to include full support for mixed-mode UEFI installation on these machines. The multi-arch installation media (available in netinst and DVD form) include the UEFI boot loaders necessary for both i386 and amd64 boot. By selecting "64-bit install" from the initial boot menu, debian-installer will install a 64-bit (amd64) version of Debian. The system will automatically detect that the underlying UEFI firmware is 32-bit and will install the appropriate version of grub-efi to work with it.

The resulting Debian Jessie install was transitioned to Ubuntu 16.10 by...

1) replacing the /etc directory with a copy from a fresh Ubuntu 16.10 x86_64 install while retaining copies of the fstab, shadow and passwd files generated by the Debian Jessie installation.
2) Using

apt-get -f update
apt-get clean
for pkg in `dpkg --get-selections | awk '{print $1}' | egrep -v '(dpkg|apt|mysql|mythtv)'` ; do apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" --force-yes install --reinstall $pkg ; done

At this point, the only problem remaining was that the boot selector doesn't detect the Ubuntu installation. I solved this by reformatting the /boot/efi partition as HFS+ with journaling disabled so that Linux could access it for writing. I then used the following script to generate the appropriate boot.ef in /tmp, depending on whether the machine has EFI-32 or EFI-64 firmware, and then installed in /boot/efi/System/Library/CoreServices along side the SystemVersions.plist installed from the current mactel-boot package files and a /boot/efi/mach_kernel file. Lastly the script blesses the newly installed boot.efi.

#!/bin/bash -ex
# update-efi-booter script
pushd /
grub-mkconfig -o /boot/grub/grub.cfg
efi_arch="x86_64"
coreservices_dir="/boot/efi/System/Library/CoreServices/"
boot_efi_dir="/boot/efi/"
mactel_boot_dir="/usr/share/mactel-boot/"
mactel_boot_logo_dir="/usr/share/mactel-boot-logo/"
grep -q "32" /sys/firmware/efi/fw_platform_size && efi_arch="i386"
echo 'Creating boot.efi for '$efi_arch
case "$efi_arch" in
x86_64)
  grub-mkstandalone -o /tmp/boot.efi -d usr/lib/grub/x86_64-efi -O x86_64-efi --compress=xz boot/grub/grub.cfg
  ;;
i386)
  grub-mkstandalone -o /tmp/boot.efi -d usr/lib/grub/i386-efi -O i386-efi --compress=xz boot/grub/grub.cfg
  ;;
esac
echo 'Installing boot.efi for '$efi_arch
mount -t hfsplus -o force,remount,rw $boot_efi_dir && sleep 1
test ! -d $coreservices_dir && install -d $coreservices_dir
install -m 644 /tmp/boot.efi $cores...

Read more...

Revision history for this message
Jack Howarth (jwhowarth) wrote :

I would also strongly suggest that we add code similar to that posted on pastebin for journal_disable.c at http://pastebin.com/7rvxR38d to the mactel-boot package as well as this script so we can add the additional lines...

# make sure HFS+ Journaling is disabled
disable_journal `cat /proc/mounts | grep '/boot/efi' | cut -f1 -d' '`

to the front of the update-efi-booter script to make it even more robust.

Revision history for this message
Jack Howarth (jwhowarth) wrote :

Tested on a fresh install of Ubuntu 16.10 x86_64 by...

gcc -o disable_journal disable_journal.c
chmod ugo+x update-efi-booter
install disable_journal update-efi-booter /usr/local/bin

identify the device that the /boot/efi partition is mounted on, umount it and then use gdisk to delete that partition and create a new one with the code AF00 for HFS+. Write the changes out in gdisk and then execute mkfs.hfsplus on the device to format it. Now change the boot/efi entry in fstab to have 'hfsplus defaults', remount the boot/efi partition and just execute the 'update-efi-booter' script.

Afterwards the /boot/efi subdirectory will contain...
# cd /boot/efi/
# ls -lR .
.:
total 4
-rw-r--r-- 1 root root 34 Dec 16 23:04 mach_kernel
drwxr-xr-x 1 root root 3 Dec 16 23:04 System

./System:
total 0
drwxr-xr-x 1 root root 3 Dec 16 23:04 Library

./System/Library:
total 0
drwxr-xr-x 1 root root 4 Dec 16 23:04 CoreServices

./System/Library/CoreServices:
total 1968
-rw-r--r-- 1 root root 2009088 Dec 16 23:04 boot.efi
-rw-r--r-- 1 root root 380 Dec 16 23:04 SystemVersion.plist

and where the boot.efi is now blessed on a HFS+ filesystem. This allows the option key boot selector on Macs to display the Ubuntu operating system with a customized icon. Thus rEFind is no longer needed to be able to switch between other installed OS releases.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.