Ubuntu Linux Now Runs On Apple M1 Silicon Macs, What To Expect And How To Prepare
Arm offers an array of licenses to its architecture that range from processor licenses, in which a chip vendor can whole hog plug modules of Arm CPU cores into a chip, to the more abstracted architecture license, which is what Apple uses to develop custom Arm64 CPUs for its own devices. Being an architecture licensee, Apple is beholden to nobody in the way that its chips implement the ISA and boot an operating system. According to Corellium, those implementation differences are what made it a bit more difficult to get running Ubuntu. In a series of tweets, Corellium's Chief Technical Officer Chris Wade recently showed off Ubuntu running on an Apple M1-powered Mac mini, so we felt compelled to explore it a little ourselves as well.
Booting Ubuntu On The Apple M1 BeastieThe Macintosh operating system, which itself finds its roots in NeXTSTEP system developed by Steve Jobs' other computer company, NeXT. It's based on the Mach microkernel, not GNU Linux, and has its own method for booting a system. NeXTSTEP and macOS both use Mach-O executable files, which is just a different format of executable from a WinPE executable that Windows uses on UEFI platforms, or the binary files that Arm-based Linux tends to use. Anybody who's ever built a Hackintosh and had a boot problem probably had nightmares about "mach-o has a bad magic number" while trying to install the OS.
Corellium says that Arm-based Linux distributions have more or less settled on a format to get the system running which is nothing like Apple's Mach-O boot loader on macOS. On Intel-based Macs, the UEFI BIOS and Boot Camp worked together to form a wrapper to get other operating systems running. On Apple Silicon, that wrapper layer is gone. Mach-O is a published and open format, though, so as Corellium notes in its blog post, it was possible to get the port going. The development team started with a Raspberry Pi 4 image and made the changes required to get the system to boot from an external drive.
Apple, being free to implement various Arm features any way it sees fit, also deviated from the de facto standards set out by other Arm PC vendors in the way additional CPU cores are brought online. Most Arm PCs rely on the firmware to make a PSCI call using additional data tables stored within the firmware itself. On M1 silicon, this is done through a memory-mapped IO register. Apple documents its behavior by publishing the Darwin source on GitHub so it was all discoverable. Still, Corellium had to get CPU cores to talk to one another, which required diving into Apple's proprietary interrupt controller. In newer SoCs like the M1, Apple has registers to store inter-processor interrupts, so once the OS could deal with them, all eight cores of the M1 CPU could come online.
Enabling Ubuntu's Human Interface On The M1Just getting Ubuntu to boot isn't enough to make for a usable system. There's still input to deal with. Apple provides a pretty limited set of options: the Thunderbolt 4 controller, Apple's own USB 3.0 interface and Bluetooth. Apple's USB controller serves the Type-A ports on the Apple M1 Mac mini along with providing USB connectivity to the Type-C ports on all M1 systems. On Windows PCs, Bluetooth is typically implemented over USB, even when it's built into a laptop (which can be seen by viewing Devices By Connection in Device Manager on Windows 10). Apple uses PCI Express for its Bluetooth controller, which means it's nothing like anything that's come before it and therefore no drivers exist.
Limited to Thunderbolt 4 and USB connectivity, Corellium chose the xHCI USB 3.0 controller in the M1. Apple happens to use hardware that has its own Linux drivers already, so it was a simple choice for Corellium to make, although it had custom firmware that needed to be worked around. In the end after a few days of tinkering, the development team was able to connect a keyboard, mouse, and flash drive to the USB 3.0 Type-A ports in a Mac mini and boot Ubuntu Linux.
Experiencing Linux On The M1 MacAdventurous M1 Mac owners can check out Ubuntu for themselves on M1 hardware if they like. There are some caveats, however. Apple still hasn't published any data on the M1's GPU, so everything is drawn via software without any acceleration from the GPU. That means it can be pretty sluggish in certain situations. This isn't an issue when using a virtual machine like the latest Parallels Technology Preview, which uses a shim to translate guest OS draw calls to their native macOS equivalents. Without macOS as a host, Ubuntu has to talk to the bare hardware, and there's just not enough documentation to do that right now.
When Corellium initially published its blog post, onboard Ethernet wasn't working. However, late Thursday, Corellium posted additional work to its Github repository that got PCI Express and the Broadcom Ethernet chip in the M1 Mac mini working. Any USB Ethernet dongle that has Linux drivers should work on the MacBook Air and Pro, but wireless networking is not presently functional. Outside of graphics acceleration and wireless networking, however, the system should be pretty functional. Hopefully this won't be too limited for long, however, as Corellium intends to upstream its work to mainline Arm Ubuntu.
If the caveats haven't scared you away, Corellium's blog post ends with a tutorial. It mostly involves flashing a modified Raspberry Pi Ubuntu image to a flash drive and booting from that. Macs have all sorts of protections to prevent unauthorized boot devices, so you'll have to dive into the recovery options to turn off the T2's external boot locks and install a custom kernel via a scripted command. And then, finally, the system will boot until Ubuntu. To get back to macOS, simply enter another terminal command, power down, and remove the flash drive before starting the system again. So yeah, happy hacking!