Loading...

STORIES

Run Arch Linux on a MacBook

Installing Arch Linux on a MacBook would be relatively easy with the installation guide if it wasn't for Apple's Broadcom wireless network hardware. The Arch Linux Broadcom wireless network driver package is available online, but the proprietary driver software is not included with the installer media, so unless you have a wired connection and an adapter, and you want to install it directly on the MacBook as opposed to simply installing it as a virtual machine, you will not be able to connect to a network to download it during installation.

Here's what I did to get Arch Linux (2020.12.01 release) running on a MacBook Air (2015 model), and how to get it running on any MacBook or machine with a Broadcom wireless network card, or some other proprietary network card, and also how to simply install it as a virtual machine.

Requirements

You will need a PC or a Mac. Then get the following ready:

  • The Arch Linux installer disk image.
  • Etcher: For installing Arch Linux directly on the MacBook; software for writing disk image files to USB drives.
  • VirtualBox: If you do not have a wired connection, or if you would like to simply install Arch Linux as a virtual machine.
  • One or two USB drives: For installing Arch Linux directly on the MacBook; One for the Arch Linux installer disk image and, if you do not have a wired connection, another one for the packages required when doing an offline installation.

Start with a Virtual Machine

If you have a wired connection, and if you would like to install Arch Linux directly on the MacBook and not simply as a virtual machine, skip to the installation.

If you do not have a wired connection you will have to download packages with Arch Linux running in a virtual machine first, for doing an offline installation directly on the MacBook. The packages can be downloaded in the Arch Linux installer environment: There is no need to do an install in the virtual machine for this.

Start VirtualBox and add a virtual machine, setting the memory size and setting up a new virtual hard disk (dynamically sized is fine and 16 GB will do), and remember to go into the machine settings and to increase the number of virtual processors if your system allows for it (under System > Processor) and to enable USB 3 (under Ports > USB).

Start it up and select the downloaded installer disk image to boot from.

If you are simply installing Arch Linux as a virtual machine, skip to creating the system partitions.

Get the Packages for Installing Offline

Connect a USB drive to your machine, and connect it to the Arch Linux virtual machine:

Get the USB drive ready by identifying the device node (line 1), formatting the drive (line 2) and then mounting it (line 3):

fdisk -l
mkfs.ext4 /dev/[device-node-example-sdb1]
mount /dev/[device-node-example-sdb1] /mnt

Generate a list of packages to download using the Arch Linux package manager pacman (line 4), after synchronising the package databases (line 1), installing the wget package (line 2) and clearing existing local packages (line3), and save the list to a file on the USB drive (line 4). The packages include the base system, the Linux kernel, firmware and headers, boot managers, the Nano text editor, manual pages, and networking and wireless packages, including of course the Broadcom wireless network driver package. Then download all the packages to the USB drive (line 5). Verify that about 300 packages were downloaded by getting the file count from the USB drive (line 6), and unmount it (line 7).

pacman -Sy
pacman -S wget
rm -rf /var/lib/pacman/local/*
pacman -Sp --noconfirm base base-devel \
  linux linux-firmware linux-headers \
  grub efibootmgr \
  nano man-db man-pages \
  dhcpcd broadcom-wl broadcom-wl-dkms \
  wireless_tools iw wpa_supplicant iwd > /mnt/package-list.txt
wget -P /mnt/ -nv -i /mnt/package-list.txt
ls -al /mnt | wc -l
umount /mnt

If you are installing Arch Linux directly on the MacBook, you can now disconnect the USB drive from the virtual machine, power off the virtual machine and delete it.

Install Arch Linux

You can install Arch Linux alongside macOS of course, and even alongside macOS and Windows with Boot Camp.

Add a new disk partition with Disk Manager. I started with a 30 GB partition for the system, with 40 GB macOS and 50 GB Windows partitions. The format does not matter at this stage: Just set aside the space.

Flash the downloaded Arch Linux installer disk image to a USB drive with Etcher:

With the USB drive with the Arch Linux installer image on it connected to your machine, restart the MacBook and hold Alt to start up to Startup Manager. Select the USB drive to then boot the Arch Linux install media.

When the Arch Linux installation environment has started up, check the network interfaces:

ip link

You should see a loopback device listed, and with a wired network connection you should also see an ethernet network interface listed.

Create the System Partitions

Partition the disk by listing all disks and running fdisk on the machine's hard drive:

fdisk -l
fdisk /dev/[device-example-sda]

Create three partitions:

p - Display, or "print", all partitions

d - Delete a partition
[created-partition-space-number] - Enter the number for the partition that was created when setting aside space for the new system

n - New partition, the EFI partition (or skip creating a new EFI partition if you decide to add to the existing one, or the boot partition when doing a virtual machine install)
p - Primary partition
<enter> - For the default, 1, if there are no other partitions on the drive, otherwise enter the first next available number
<enter> - Accept the first sector default
+500M - For the size to offset the last sector from the first sector
t - Set the type of partition (or if doing a virtual machine install, skip this and leave the type as a regular Linux partition)
<enter> - For default 1, or this partition number
L - List partition types
uefi - UEFI partition

n - New partition, the swap partition
p - Primary partition
<enter> - For the default, 2, or the next available number
<enter> - Accept the first sector default
+4G - For the size to offset the last sector from the first sector
t - Set the type of partition
<enter> - For default 2, or this partition number
L - List partition types
swap - Swap partition

n - New partition, the root partition
p - Primary partition
<enter> - For the default, 3, or the next available number
<enter> - Accept the first sector default
<enter> - For the default last sector, which will be the last available sector of the remaining space

w - Write changes to the partition table and exit

Format the partitions: The EFI partition formatted as FAT32 (or left as is when using the existing Apple EFI partition, or, when doing a virtual machine install, the boot partition as EXT2), the swap as swap space and the root as EXT4. Label the root partition arch_os:

mkfs.fat -F32 /dev/[efi-partition-device-node-example-sda1]
mkswap /dev/[swap-partition-device-node-example-sda2]
mkfs.ext4 -L arch_os /dev/[root-partition-device-node-example-sda3]

Mount the partitions. The root partition is mounted on the live environment's /mnt mount point, and create a /boot directory for the new system to mount the EFI partition (or boot partition when doing a virtual machine install) on:

mount /dev/[root-partition-device-node-example-sda3] /mnt
swapon /dev/[swap-partition-device-node-example-sda2]
mkdir /mnt/boot
mount /dev/[efi-partition-device-node-example-sda1] /mnt/boot

Install the System

If you do not have a wired connection and are doing an offline install, you have to set up a custom local package repository to install the packages downloaded to the USB drive. If you have a wired connection, or are simply doing a virtual machine install, you should skip to setting up the system and installing the packages.

Find the USB drive device node (line 1), create a directory to mount the USB drive on (line 2) and mount it (line 3), and add the new custom package repository:

fdisk -l
mkdir /mnt0
mount /dev/[device-node-example-sdb1] /mnt0
repo-add /mnt0/custom.db.tar.gz /mnt0/*.pkg.*

Add the custom package repository to the package manager's configuration.

nano /etc/pacman.conf

Scroll down and comment out all the online repositories by adding a # to the front of the line. (Comment out two lines each, the name and the include, for the core, extra and community repositories.) Uncomment the custom repository and set the file path to ///mnt0. Then exit (press Ctrl+X) and save (press y<enter>)

Set up the System and Install the Packages

Now download the initial system files from the internet (if you have a wired connection), or copy these from the newly created custom local repository (if you do not), to the new system partitions, with the pacstrap script, which is similar to the pacman package manager, only it installs packages on a new system instead of the current system:

pacstrap /mnt base linux linux-firmware linux-headers \
  grub efibootmgr \
  nano man-db man-pages \
  dhcpcd broadcom-wl wireless_tools iw wpa_supplicant iwd

Generate the Linux file system table configuration file, and view it to confirm that the device nodes are mounted on the correct mount points:

genfstab /mnt > /mnt/etc/fstab
cat /mnt/etc/fstab

Configure the System

Change the root directory of the current running process (the live environment) to the newly created system's root partition (mounted on the /mnt mount point):

arch-chroot /mnt

Set the system language by editing /etc/locale.gen and uncommenting the line with your locale setting (removing the line's leading # character), for example uncomment the line with en_ZA UTF-8, and running locale-gen and then saving the setting in /etc/locale.conf

nano /etc/locale.gen
locale-gen
echo "LANG=[locale-example-en_ZA].UTF-8" > /etc/locale.conf

Set the time zone by creating a soft link for your region and city in /etc, and then set the hardware clock from the system clock:

ln -sf /usr/share/zoneinfo/[region-example-Africa]/[city-example-Johannesburg] /etc/localtime
hwclock --systohc

Set the machine's hostname:

echo "[hostname-example-arch].host.local" > /etc/hostname

Set the root password:

passwd

Enable the DHCP service, so that a network server can dynamically assign the network configuration when connected to a network. See the Arch Linux wiki for more details about the service manager and system services.

systemctl enable dhcpcd

Configure the Boot Loader

Set up the Grand Unified Boot Loader (GRUB). If you are installing directly on a MacBook, you could skip setting up GRUB if you decide not to use it. If you do decide to use it then the GRUB install command will copy the boot loader to the EFI partition, but Apple's firmware will not yet pick it up. VirtualBox uses the BIOS firmware generally so this is required when doing a virtual machine install.

grub-install --efi-directory=/boot # Just "grub-install /dev/sda" when doing a virtual machine install
grub-mkconfig -o /boot/grub/grub.cfg

If you are simply doing a virtual machine install then the boot loader is now configured and you should skip to verifying the installation.

For the MacBook's firmware to pick up the new system, configure systemd-boot, a UEFI boot loader included with the Arch Linux systemd package. Verify that the system has booted in UEFI mode (line 1) and copy the boot loader to the EFI partition (line 2).

efivar --list
bootctl install

Create the boot loader configuration file:

nano /boot/loader/loader.conf
timeout 15
default arch.conf

If you installed GRUB, create the Arch Linux EFI boot loader entry configuration for starting the system with systemd, with GRUB:

nano /boot/loader/entries/arch-grub.conf
title Arch Linux (GRUB)
efi /EFI/arch/grubx64.efi

Create the Arch Linux EFI boot loader entry configuration for starting the system directly with systemd:

nano /boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root="LABEL=arch_os" rw

Verify the Install

Exit the new system environment back to the live installation environment, unmount everything (all mounted partitions and the USB drive), and reboot the system:

exit
umount -R /mnt
umount /mnt0 # Only if the USB drive was used to install packages
reboot

When the MacBook restarts, hold Alt to start up to Startup Manager, and select the EFI Boot startup disk. Arch Linux should then start up. If this is a virtual machine install then you should remove the Arch Linux disk image from the virtual machine's virtual drive and reset the virtual machine, and Arch Linux should then start up.

Set Up Wireless Networking

To set up wireless networking when installing Arch Linux directly on the MacBook, start by checking the network interfaces. If this is a virtual machine install then you should automatically be connected to the host network so skip to installing a desktop environment.

ip link

You should see a loopback device listed. With a wired network connection you should also see an ethernet network interface listed. With the Broadcom wireless network package now installed you should also see a wireless network interface listed.

Get the name of the wireless network interface (line 1), activate the network interface (line 2) and discover wireless access points (line 3).

iw dev
ip link set [interface-example-wlan0] up
iw dev [interface-example-wlan0] scan

For WPA networks, use the wpa_supplicant package to connect. Configure the package:

nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/run/wpa_supplicant
update_config=1

Start the WPA supplicant service, then start the WPA command line interface and connect to a wireless network:

wpa_supplicant -B -i [interface-example-wlan0] -c /etc/wpa_supplicant/wpa_supplicant.conf
wpa_cli
scan - Scan for available networks
add_network - Returns a network number, e.g. 0
set_network 0 ssid "[wireless-network-id]" - Connect to a wireless network with the specified SSID
set_network 0 psk "[wireless-network-passphrase]" - Set the wireless password
enable_network 0 - Enable the wireless network interface
save_config - Save the network configuration
quit - Exit the WPA command line interface

Install a Destop Environment

Synchronise the package databases with your newly installed system (line 1), install the X Window System and GNOME desktop environment (line 2), enable the GNOME display manager service (line 3), and reboot (line 4):

pacman -Sy
pacman -S xorg xorg-server gnome
systemctl enable gdm.service
reboot

If you are installing directly on the MacBook, remember to hold Alt to start up to Startup Manager, and select the EFI Boot startup disk.

This should boot up a login screen, and after logging in, bring up the GNOME desktop environment.

Opening the Terminal utility app and entering the following command will stop the display manager and drop you back to the terminal. If the terminal is empty then the X Window System is still running in the first terminal, so switch to the second by holding Alt (and the Fn key) and pressing the F2 key, which should bring up an Arch Linux login prompt.

systemctl stop gdm.service

Recommendations and Applications

See the Arch Linux installation recommendations, including user and network security, power management and optimisation.

Also see a list of Arch Linux applications, by category.