I’ve been feeling the pull of desktop Linux for a while now.The last time I tried to use Linux as my daily desktopwas almost 10 years ago.It was a pretty big failure.
(Update May 2020: I’ve re-run through this whole process using Linux Mint 19.3 and have updated this blog post with new details. Notably, no need to install pommed, and including the specific voodoo needed for the 2010 MacBook Air from Ask Ubuntu regarding PCI-E bus identifiers). We have a still perfectly usable Late-2010 MacBook Air, but with macOS 10.14 Mojave dropping support for Macs. Straight Installation vs. While there are some computers that come with Linux Mint. Linux is a powerful operating system beloved by coders and capable of breathing life into old Macs. In this feature we look at how to install Linux on a Mac - including how to completely replace.
But after so many years of using,and falling in love with,Linux on the server,I wanted to give it another chance.
So last week I hunkered down and,over the course of a few days,managed to build a functionalLinux environment on my laptop.I took rigorous notesas I struggled and encountered breakthroughs,the results of which you’ll find below.
The steps in this guide will take you froma single-boot OS X install on a Macbook Airto a dual-boot system with OS X and NixOS.Many of the steps apply to installinganother Linux distribution, too,in particular those dealing withdisk encryption (in OS X and Linux)and the requirement for Broadcom drivers.
Other than that,make sure you have any important bits saved somewhere safe,and enjoy the path to Linux below!
There are many, many Linux distributions:distrowatch.com tracks 278 at the moment.Of those 278,you’ve probably heard of some of the major ones:Mint, Ubuntu, Arch, etc.NixOS is not one of the major ones.
So why did I choose it?
I’ve experimented previously withusing the Nix package manager,on which NixOS is built,and found it very interesting and powerful.
I really like the ideaof having a handful of declarativeconfiguration filesfrom which my entire system can be built.It means I can store it in gitand track the history of my configuration,just like with my dotfiles.It also means I can quicklyget up to speed on a new machine.
The ability to easily apply–and later rollback–configurations was also appealing,since I knew it would take a lot of experimentationto get the system working like I wanted.
I’d encourage you to read more aboutNixOS and Nix,especially if you intend to follow the guide below!
The steps below were performedwith the minimal installation CDfor NixOS version 14.12found on the NixOS Download page.
If you’re not using FileVault for full-disk encryption,you can safely skip this step.
If you use FileVault to encrypt your disk,you will not be able to use Disk Utilityto update your disk’s partitions,which will need to be donein a later step.
Open FileVault and disable disk encryption,following the on-screen instructions.After rebooting,re-open FileVault and waitfor the disk to be fully decrypted before continuing.This will probably take a while—for me, about 30 minutes.
Depending on your particular hardware configuration,it may be necessary to use Broadcom’s unfree drivers.You’ll need to follow the instructions belowfor any Apple laptop from the last few years.
The steps that follow are almost certainlynot the quickest or easiest wayto prepare the Broadcom driver for installation.But I had already written most of the stepsfor a future blog post,so it was something I understood how to do.
Attach your USB device,and configure two partitions in Disk Utility:
NIXOS_ISO (600 MB), and
DATA (the rest).Each should be formatted as “MS-DOS (FAT)”.
Eject the drive,but keep it plugged in.
Now in the terminal,we’re going to create a VirtualBox VM running the NixOS livecd.If you’re more comfortable with the VirtualBox GUI,you can do all of the following steps there instead.
You should be able to copy and paste the script below,remembering to set
nixos_livecdto the path of the downloaded iso.
You should now be at a login prompt in a VM window,which you can login to with root and no password.
From the menu bar,select “Devices” and thenthe name of your USB device to attach it.
Now in the VM window,mount the device:
Now we’ll install the driver:
Then we will export the driver and all of its dependencies
Finally,unmount the USB drive and shutdown the VM:
Open “Disk Utility”and change the USB partition name to
Mount the downloaded livecd,and then copy its contents onto the USB device.
Eject the ISO and the USB device.
Open Disk Utility,click on “Macintosh HD”,add new partition,choose size (e.g., half),choose format as free space,apply.
Now reboot the machine,with the USB device inserted,and hold down the Option key.
You should be presented with three choices:“Machintosh HD”, “Recovery”, and “EFI Boot”.Select EFI Boot.
Skip this if you didn’t followthe steps in “Prepare Broadcom driver”.
First,mount the USB device’s
DATA partitionand import the Broadcom driver and dependencies.
Now install the driver:
Finally, load the driver:
We will be creating two new partitionsin the free space we made in the previous step.The first will be 512MB,and be used as our Linux boot partition.The second will use the remaining free spaceand be used for our Linux swap and root partitions.
Make note of the partition numbersassigned to the partitions.You can always find them againby running
fdisk -land reading the device name of the last two entries,whose types should be “EFI Boot” and “Linux Filesystem”.
On OS X,the standard for disk encryption is FileVault.On Linux, it’s LUKS.
We’ll be using a strategy called LVM On LUKS,where the partition we created aboveis an encrypted LUKS partition,on top of which we’ll layer root and swap partitions with LVM.
And then mount them:
You can recover back to this step,by booting into the livecdand running:
You will need a network connectionto complete your NixOS installation.The following commands will update your wireless configurationto recognize your local wireless network.
Within a few seconds,you should be connectedand a command like
ping -c 1 google.comshould be successful.
Start by generating a template configuration:
This will produce two files:
/mnt/etc/nixos/configuration.nix:the system’s configuration file
/mnt/etc/nixos/hardware-configuration.nix:the system’s hardware configuration
If you followed this guide’s Broadcom instructions above,you’ll need to apply an edit to
hardware-configuration.nix.Find the line which starts with
boot.extraModulePackagesand enable the Broadcom kernel moduleby removing the surrounding quotes:
Now we will need to edit
configuration.nixto contain the minimum requirements:
Also, you should ensure that the grub deviceis correct. For me, this was:
Now copy your wireless configuration:
And then install!
If everything goes well,
reboot to boot into your new NixOS system!
When you updated the partition table with
gdisk,the recovery disk partition lost some metadata,and shows up as “EFI Disk” instead of “Recovery”.If you go into Disk Utility,and hit “Repair” on “Macintosh HD”,that will fix this.
Also, don’t forget to re-enable FileVaultif you turned it off earlier!
At this point,you should be able to dual-bootinto a functional, if not particularly useful,NixOS system.
Now starts the fun part,which I’m still going through myself,of exploring Nix, NixOS, and Linuxto build your new environment.I can recommend some resourcesto help you on your way:
man configuration.nix—the same information as above,in your terminal.
language:nixin your searchto turn up other user’s configurations.