2017-02-09 © 2017 Barnet Wagman


Installing Arch Linux on a MacBook Air

Step-By-Step Instructions

Among its other virtues, Arch Linux has particularly good documentation, and that certainly includes the Mac ArchWiki, which is the best description of installing Linux on a Mac that I've found.

Even so, installing Arch Linux on a MacBook takes a bit of work and involves making a number of choices.  The first time I did it, I found myself jumping back in forth among various websites to find the information I needed.  To ease the pain a bit, I'm posting a step by step description of how I installed Arch Linux on a MacBook Air.  This is no substitute for the Mac ArchWiki, but perhaps seeing a complete example will help.

Notation:indicates an action that is specific to a Mac or MacBook (as opposed to actions required for installing Arch Linux on any hardware).

The target system:

Computer MacBook Air (13-inch, Early 2015)
RAM 8 GB
Drive 256 GB SDD
OS X
El Capitan 10.11.5



Step-By-Step Instructions

Prerequisites
Use OS X to prepare the system for Arch Linux
Install the Arch base system
Add a user and some basic services
Install basic graphics and audio
Add touchpad and keyboard support
Add WIFI support
Install power management
Install and configure Openbox


Prerequisites

A blank USB stick, at least 1GB, for the Arch Linux iso.  Optionally, a second one to hold a bootable OS X installer.

◉ A connection to the internet via ethernet  - not wireless.

◉ A  USB to ethernet adaptor - the Arch Linux iso does not have the driver for the macbook's wireless chip.

Use OS X to prepare the system for Arch Linux

◉  (Optional) Create a bootable OS X installer

As a precaution, you may want to have a bootable OS X installer on a USB stick.  If the system gets completely screwed up, you'll want to be able to reinstall OS X.  This can usually be done using the recovery partition that Apple installs on its systems.  However, if this partition gets damaged, you'll need the bootable installer to reinstall OS X.

See this page (or others) for instructions on how to put a bootable installer on a USB stick.  The USB drive will probably need to be formatted for OS X.  To boot off this drive, start the MacBook holding down the alt key.

◉  Update OS X

The Mac ArchWiki strongly recommends keeping OS X so that you can get firmware updates.  Update OS X before proceeding.

◉ Resize the OS X partition

To free up space for the Linux system, use the OS X Disk Utility to shrink the OS X partition.

In Disk Utility, select the drive (e.g. "APPLE SDD SM0256G Media") not the partition (e.g. "Machintosh HD") within it.
Select "Partition" (one of the commands at the top of the window).

Resize the partition.

E.g. On my 256 GB ssd,  the OS X system was using ~ 36.7 GB.   OS X itself uses 15-20 GB.  I shrunk the partition to 64 GB.  After resizing, the disk partitions were
Macintosh HD 64.65 GB
Untitled 185.64 GB

◉ Install the rEFInd boot manager

This is a 'platform-neutral' boot manager that seems the be the preferred one for Arch Linux on a Mac.   As of El Capitan, installation has been complicated by Apple's introduction of System Integrity Protection (SIP).  The installation process in the 'regular' rEFInd documentation no longer works.  Installing on a system with SIP is described in The rEFInd Boot Manager: rEFInd and System Integrity Protection.

There are several ways of circumventing SIP.  "Using Recovery Mode" is approach recommended by rEFInd's author.  It does not entail disabling SIP.

Download and unzip refind-bin-0.10.3.zip.

Reboot into Recovery Mode: Command-R at chime.

In recovery mode, select Utilities -> Terminal from the top menu bar.

Change directory to the unzipped rEFInd dir, i.e. the directory that was created when you unzipped refind-bin-0.10.3.zip

In this directory, run the script ./refind-install.  Note that the script will warn you that SIP is enabled.  Because we are in recovery mode, it isn't.  Answer 'yes' to proceed.

Install Arch base (minimal) system

 Create the iso image

Download archlinux-2016.05.01-dual.iso from an Arch Linux mirror (e.g. http://mirror.rackspace.com/archlinux/iso/2016.05.01/ ).

Write the iso image to a usb flash drive.  USB Flash Installation Media has instructions for writing this iso image to usb (in Linux, OS x etc.).

◉ Connect one USB port to an internet connection (e.g. router, modem).

Note that a wireless connection will not do.  Wifi support will be added later - see Add WIFI below.

Boot from the iso image

Reboot the system with the Arch Linux iso image USB inserted.

The rEFind manager page appears first.  It displays available boot options, including OS X and OS X recovery mode. By default rEFInd boots into OS X after a delay.  Hit an arrow key to stop the countdown and choose something else.  Note that in this screen you must use the arrow keys to navigate.  The touchpad will not work.

rEFInd will find several things on that drive (in addition to all the OS X stuff on the ssd).  Choose "Boot EFI\boot\loader.efi from ARCHISO_EFI".

A text Arch Linux menu will appear: choose the first option "Arch Linux archiso x86_64 UEFI CD".  The system will boot to Arch Linux on the usb drive.

Set the clock to use ntp

timedatectl set-ntp true

To test, type timedatectl status, which will show 'Network time on', 'NTP synchronized', among other things.

◉  Setup the Linux partitions: EFI boot and root

Use fdisk -l (or another Linux utility) to identify the storage devices on your system. There should be two devices, the ssd drive and the usb drive.  The former will have several partitions including "EFI System", "Apple Core Storage", "Apple boot", ...  This is the one we will be working on.  On my system, it was /dev/sdc.

I use the simplest possible partitioning scheme: a boot partition and a root partition.  Of course you can use other schemes if you prefer.

 I used cgdisk to do the partitioning (but there are other equally good disk utilities).  To partition with cgdisk:

Launch cgdisk with the ssd device (e.g. /dev/sdc) as an argument.  cgdisk is an interactive program.  It will show the partitions on the drive.

Delete the "Untitled: partition.  This is the partition created with OS X Disk Utility to hold Arch Linux.

Create a new partition, the boot partition.  Assign it a name such as 'boot'.

For first sector, specify +128M.  This leaves space after the OS X partitions; OS X likes that.

Boot partition size is 512M, type ef00

Create another new partition, the root partition, using the remaining space. Assign it a name such as 'root'.

Format the partitions

Use lsblk or fdisk -l to identify the dev names of the boot partition and root partition.  Note that if the system's been rebooted, the letters may have change.  E.g. my ssd initially showed up as /dev/sdc, but after rebooting it was /dev/sda. The boot partition was /dev/sda4 and the root partition was /dev/sda5.

Format the root partition
       mkfs.ext4 /dev/sda5

◉  Format the boot partition
        mkfs.ext4 /dev/sda4

Mount the root and boot partitions

mount /dev/sda5 /mnt
mkdir -p /mnt/boot
mount /dev/sda4 /mnt/boot

Modify the pacman mirrorlist

Edit /etc/pacman.d/mirrorlist (vi is available): move the server you want to try first to the top.   E.g. move the U.S. servers to the top if you are in U.S.  Note that while we've just 'edited' the file in ram, it will be copied to our ssd.

Install the base system packages

The base system is installed using pacstrap During installation of the base system using pacman, there are options re package to be installed.  You can select 'all' (the default) at each prompt.

pacstrap -i /mnt base base-devel

Create fstab

genfstab -U /mnt >> /mnt/etc/fstab

chroot

arch-chroot /mnt /bin/bash

This will put things in the right places (in /mnt) without adding /mnt to all the paths.  The /bin/bash argument gives us bash instead of zsh.

Set the locale

Edit /etc/locale.gen uncommenting en_US.UTF-8 UTF-8 if you are in the U.S. or the appropriate line if you're not. Then run
 
locale-gen

Create (using vi or some other editor) /etc/locale.conf.  For U.S. users, it should contain

LANG=en_US.UTF-8

Set the timezone and 'time skew'

Run

tzselect

To make this permanent for a particular user, add a timezone specification to the user's .profile, for example TZ='America/Los_Angeles'; export TZ for the west coast of the U.S.

ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
hwclock --systohc
--utc

Install and configure a boot loader (UEFI/GPT)

bootctl install

Note that the MacBookPro11,x ArchWiki states that "You may need to install intel-ucode ..." I didn't do this and it doesn't appear to be necessary for my hardware.

Modify /boot/loader/loader.conf.  Based on the Arch Linux systemd-boot wiki (not the sample file), this should contain
timeout 4
default arch
editor 0

Use ls -l /dev/disk/by-partuuid to find the partuuids for disk partitions.

Use the partuuid for the root (not the boot) partition to create /boot/loader/entries/arch.conf.  Note that this file was not created automatically.  It should contain (at a minimum)
title        Arch Linux
linux    /vmlinuz-linux
initrd   /initramfs-linux.img
options root=PARTUUID=<the partuuid for the root files system partition> rootfstype=ext4 add_efi_memmap

Set the hostname

Put a hostname of your choice in /etc/hostname,
Edit /etc/hosts. Add your hostname to the localhost lines.

Set the root password

passwd

Setup network connection by enabling dhcpd

Use ls /sys/class/net to determine the ethernet device name.  It is enp3s0.
systemctl enable dhcpcd@enp3s0.service

Shutdown and reboot

exit # This gets us out of the chroot environment.
umount -R /mnt
reboot

◉ When you reboot, you'll have a choice of
Arch Linux
EFI Default Booter
OS X

The "EFI Default Booter" justs gives you a choice of Arch Linux and OS X.

Choose "Arch Linux". You'll get a login prompt: use root to login.



We now have a functioning, bootable Arch Linux system with one user (root) and the base and base-devel packages.  It has no graphics yet.



Add a user and some basic services

Add a user with a password

useradd -m -G wheel -s /bin/bash someu
passwd someu

Note that we put the user in group wheel to support building AUR packages, among other things.

  ssh server

pacman -S openssh

Edit /etc/ssh/sshd_config to allow password login, root login, and limiting login to moi and root.

systemctl enable sshd
systemctl start sshd

ntp

pacman -S ntp

Network manager

systemctl enable NetworkManager.service

Add Basic graphics and audio

X11 graphics

Install the following packages using pacman -S

xf86-video-intel
xorg-server with defaults choices of libs
xorg-server-utils
xorg-apps

The xorg* packages constitute the basic X11 graphics system.

◉ Add the Intel video driver

Use lspci to determine your graphics 'card'.  (In my case, it's an Intel Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller.)

For systems with an Intel graphics chip, it is important to add the Intel specific drivers.  While graphics will sometimes work without them, some applications (e.g. libreoffice) will crash if they haven't been installed.  To determine your graphics chip:

lspci | grep VGA

which on my MacBook Air yields

00:02.0 VGA compatible controller: Intel Corporation Broadwell-U Integrated Graphics (rev 09)

Install the Intel driver, which is available in an official Arch Linux package:  xf86-video-intel

Fonts

While the xorg packages provide usable fonts, font appearance was substantially improved by using Infinality. I had a little trouble getting the Infinality packages.  As of 6/2016, there is an infinality meta-package that works and is available from an unofficial repository.  To use it, add the following to /etc/pacman.conf

[infinality-bundle]
Server = http://bohoomil.com/repo/$arch

then import and sign the key

pacman-key -r 962DDE58
pacman-key --lsign-key 962DDE58
refresh the package database
pacman -Syy
and install the meta-package
pacman -Ss infinality-bundle

Note that pacman will ask which of a set of packages you want installed - install all of them.  It will also ask you if you want to replace conflicting packages - answer yes.

Audio

pacman -S alsa-utils

Display Manager

There are many of these.  One simple one that works without problems is gdm:

pacman -S gdm
systemctl enable gdm.service

Remember that once a display manager is enable, the system will boot to it, rather than to a text shell.  Of course gdm won't get us anywhere until a window manager like OpenBox or a desktop is installed (described below). 

If necessary, virtual terminals are always available.  On an Apple keyboard, use fn-cntrl-option-F<3,4,...> to get a virtual terminal.

Add touchpad and keyboard support

◉  Install xf86-input-synaptics

The official Arch Linux package xf86-input-synaptics gives good functionality.  Note that a two fingered vertical move simulates the mouse wheel very nicely.

◉ Change the keyboard layout

The default US keyboard layout gives '<>' from the '~`' key.  To fix it temporarily

echo 0 > /sys/module/hid_apple/parameters/iso_layout
The permanent fix is

Edit /etc/modprobe.d/hid_apple.conf and add
options hid_apple iso_layout=0
then run, as root,
mkinitcpio -p linux

See the Arch Linux Apple Keyboard wiki for this and other keyboard fixes if needed.

◉ Set keyboard backlight brightness

By default, the keyboard backlight is off.  It can be reset (e.g. to 128) by

echo 128 > /sys/class/leds/smc::kbd_backlight/brightness

The max brightness is 255. 

Note: The above command can only be run by the root.  For a less crude approach, see the Keyboard Backlight section of the Arch Linux Macbook wiki.

Also note that the directory /sys/class/leds/smc::kbd_backlight is a link to /sys/devices/platform/applesmc.768/leds/smc::kbd_backlight

I use a trivial shell script to change the brightness:
# kbb
# Set keyboard backlight brightness.
# Range is [0,255]

echo $1 >> /sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness

echo "Set keyboard brightness to " $1

Add WIFI support

◉ Adding WIFI support is not inherently MacBook specific. But many systems, WIFI hardware will be detected at boot time and the correct driver will be automatically loaded.  This is not case for a MacBook; the following procedure is needed.

Identify the wifi chip using

lspci -vnn -d 14e4:
I have a Broadcom BCM4360 14e4:43a0

The Wi-Fi section of the MacBook ArchWiki has information about finding the correct driver for various chips.   Note that there is a separate ArchWiki BroadCom wireless page.

I used the broadcom-wl-dkms AUR package.  Note that the first time I installed it, I ran into dependency problems.  After a few misadventures, the follow sequence got it installed and working properly:

pacman -Syu # i.e. update everything

Install two official packages:
linux-headers
dkms
Install the AUR package broadcom-wl-dkms

Restart the NetworkManager service:
systemctl restart NetworkManager

To easily manage wifi connections, I use the nm-applet.   It's best to add this after graphics is installed:  see  nm-applet (below).

Note/Warning: After an update of the system (pacman -Syu), the wifi connection no longer worked.  It was necessary to update the broadcom driver (as described above) and to restart the NetworkManager.   This may be because broadcom-wl-dkms depends on two official packages, which may have been updated.  fter the broadcom driver was broken, the internet was still accessible using a hardwired network connection (via one of the usb ports).

Add Power Management

◉ Install the official Arch Linux package: tlp and enable and disable relevant services:

systemctl disable systemd-rfkill.service
systemctl enable tlp.service
systemctl enable tlp-sleep.service

I use cbatticon to monitor power.  That gets installed after the window manager (see below)

◉ Disable systemd suspend when lid is closed

By default, systemd handles some acpi events, including the lid closing event.  When the lid is closed, the screen is dimmed and system is suspended correctly.  When the lid is re-opened, the system is awoken successfully, but the screen stays dark.   I haven't figured out how to fix this, but we can disable the suspend altogether.   To do so, edit

/etc/systemd/logind.conf

and set

HandleLidSwitch=ignore

Install and Configure OpenBox

Installation

This section describes installing OpenBox and some supporting packages from a text shell.  After OpenBox is up and running, we'll do a little configuration and add more packages.

FYI there's nothing special about OpenBox re a MacBook.  Other window managers or desktops would probably work just as well.

Install OpenBox and related packages. 

These are official packages that can be installed with pacman -S

openbox
openbox-themes
compton
compton is a compositor.  Without it, most apps (including firefox) have extremely delayed typing echo.

Copy default config files to the non-root user's .config directory

cp -R /etc/xdg/openbox ~<user name>/.config/

Add packages for configuring OpenBox

The following (official) packages are useful for configuring OpenBox.  Add them now (with pacman), so that they'll be  available the first time you run OpenBox:

obmenu
menumaker
obconf

Enable compton

When OpenBox launches, it runs the commands in ~<username>/.config/openbox/autostart
The compton compositor need to be explicitly run, so create a minimal autostart file now, containing the line

compton -b &

Add some applications need for working in OpenBox

OpenBox is a display manager, not a desktop, so it provides no applications.  To avoid some inconvience, install a few basic applications now. The following are all available as official packages and can be installed with pacman:

lxterminal (or some other terminal emulator)
thunar (or some other filemanager)
firefox (do not choose the 10-bit option)
gedit (or some other editor)

Create the OpenBox menu

The default OpenBox menu doesn't have much, and won't include lxterminal.  Use mmaker to create menu.xml.  mmake scans for executables and seems to find nearly everything.  Note that it overwrites the menu file  ~<user name>/.config/openbox/menu.xml.

We use mmaker just to build the initial menu file. Later we'll edit this file by hand.  To build a menu.xml

mmaker -vf OpenBox3

◉ Setup power monitoring

To monitor power, install the official package: cbatticon and put
cbatticon &
in ~<username>/.config/openbox/autostart
<hr size="1" color="#9d1d1e"> <br>



The next time the system is booted, the display manager gdm will get launched and OpenBox will be one of the options.  It should really be the only one, but because of the way window managers and desktops are detected, other options may be in the list.


Configuration and supporting packages

Reboot

◉ You'll have three choices:
Arch Linux
EFI Default Loader
OS X

Choosing 'Arch Linux' will boot to the display manager (GDM);
Choose OpenBox from the display manager and login as a (non-root) user.  Right-clicking opens the OpenBox menu which will contain lxterminal (somewhere).  Launch lxterminal

Add packages that support OpenBox

These can be added with pacman, except as noted.

tint2 # taskbar
hsetroot # AUR package. Sets the desktop color
volumeicon
libnotify # Supports messages from some services
network-manager-applet
xfce4-notifyd  # Needed by network-manager-applet
gnome-icon-theme # Needed by network-manager-applet

FYI OpenBox's configuration files are in ~<username>/.config/openbox.

Changes to OpenBox configuration are not automatically applied. In most cases openbox --reconfigure (which is in the OpenBox menu) will do it, but for some things restarting OpenBox is necessary.

Edit autostart.xml, the file OpenBox runs when it starts

Edit ~<user name>/.config/openbox/autostart.xml.  This file contains commands that get executed when OpenBox starts.  The file contains

compton -b &
hsetroot -solid '#F0F0F0' & 
volumeicon &

#F0F0F0 is a very light gray.

Edit ~<user name>/.config/openbox/rc.xml to changes some key bindings

To get the volume keys working add the following at the end of the keyboard section, as a <keybind> item:
<keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <command>amixer set Master 10%+</command>
      </action>
 </keybind>
 <keybind key="XF86AudioLowerVolume">
     <action name="Execute">
        <command>amixer set Master 10%-</command>
      </action>
  </keybind>
  <keybind key="XF86AudioMute">
      <action name="Execute">
        <command>amixer set Master toggle</command>
      </action>
  </keybind>
To use cntrl-arrow keys to change desktops, add the following to the <keyboard> section):
<keybind key="C-Right">   <action name="DesktopRight"><wrap>yes</wrap></action></keybind>
<keybind key="C-Left">    <action name="DesktopLeft"><wrap>yes</wrap></action></keybind>
◉ On the MacBook, I did not disable changing workspaces with the 'mousewheel', which in the touchpad is two fingers moved vertically.  This works very nicely.

nm-applet

To manage wifi connections, I use the nm-applet.    Install the following official packages

network-manager-applet
xfce4-notifyd  # Needed by network-manager-applet
gnome-icon-theme # Needed by network-manager-applet
nm-applet needs to be launched explicitly.  Put
nm-applet &

in ~<username>/.config/openbox/autostart



Comments? © 2017 Barnet Wagman