Arch Linux on a Macbook Pro Retina

These notes are a supplement to the official manual on the Arch Wiki: Mac. Overall I am very happy with the setup and currently use it as my primary system.

References

The following sites were invaluable when setting up Arch Linux on my MacBook Pro.

Partitioning from Mac OS X

I used diskutility from recover mode (CMD+R when rebooting your mac) to partition the disk. If you use Filevault, make sure Filevault is off before partitioning..

Reboot and press cmd + R to enter recover mode. Select diskutility and find your SSD. I had to first run first aid on the disk as there were some minor corruptions. Next partition the disk by pressing + to create a new partition.

For my first experiment I created a single 46GB partition. This worked fine, but for a good setup you need to seperate the OS from the home folder and have a seperate swap partition for suspend/hibernate. So my second go I create 3 partitions.

swap: 16GB (same as mem) /dev/sda6
root: 15GB               /dev/sda5
home: 100GB              /dev/sda4

Note from the 1st experiment: the manual says to skip partitioning in the installer and only do the formatting from there. This means, I guess, that if you want to have a seperate home partition you need to create it now and not dusing installation. As I created only 1 partition this also means I will not use a swap partition and I ended up using a swapfile.

Boot from USB

Use the ISO to create your own bootable medium, boot from it. I used Etcher to create the bootable USB disk.

View disk partitioning

Use the lsblk command to see the layout of the disks on the machine. In my case /dev/sdb is th USB drive and /dev/sda is the main SSD.

On the main SSD the /dev/sda1 is the ESP used to hold the bootloader.

Installation

Apple Cinema LED

My 27” monitor is working nicely with the console, it just doesn’t show all the lines at the bottom. So much space, but still it fails. At least it immediately mirrored the display using the thunderbolt cable, that makes me happy.

Fontsize

Reading reddit I found a reference to a larger font for high res screens.

setfont sun12x22

Keyboard layout

For me the US keyboard layout as well as the console font are good, could do with a bigger font, but I did not figure out how to do this from the bootable medium. It seems you will need to download a seperate console font for this to work.

Internet connection

I booted using a wired conncetion, it just works out of the box. To start from a wireless you need to do some additional work, it is explained on the wiki.

Time

Using timedatectl to connect to the NTP service went without a hitch, the timezone is set incorrectly though. I used timedatectl to set the timezone to CET.

timedatectl set-timezone CET

Format partitions

The partitions I already created from macOS now need to be formatted.

mkds.ext4 /dev/sda4
mkds.ext4 /dev/sda5
mkswap /dev/sda6
swapon /dev/sda6

The I mounted the disk to /mnt and the ESP boot partition to /mnt/boot.

mount /dev/sda5 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
mkdir /mnt/home
mount /dev/sda4 /mnt/home

Selecting mirrors

Using rankmirrors, lets find the top 6 mirrors that I can use for installation. This takes a little while.

#+beignsrc shell cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist #+endsrc

Remember to update the pacman database using pacman -Syyu after selecting new mirrors. Select n if pacman wants to update stuff. I am unsure if this is actually required for the bootstrap/pacstrap stage.

Install the base system

Use pacstrap to install the basic operating system.

pacstrap /mnt base

I choose to only do the base system for now, to get up and running. After the chroot or the actual reboot into the live system I will add the packages I require such as devel and xorg with gnome 3.

fstab

Generate a new fstab from the mounts.

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

It will find the root partition and the boot partition.

chroot

By running arch-chroot we will activate our installed base system for further configuration.

arch-chroot /mnt

Setup timezone

ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

And sync the hardware clock to our new zone

hwclock --systohc

Locale

I uncommented en_US.UTF-8 UTF-8 in /etc/locale.gen and rand locale-gen. In /etc/locale.conf set this to the default LANG.

Hostname

Create the file /etc/hostname and put your hostname in it. I chose archman as a play on ant-man, to go with my superhero themed machines.

Macbook kernel

Currently (april 2017) there is a bug in the kernel that makes the system not suspend/hibernate well. There is a custom kernel we can use (its like it is 1999 all over again!).

First, enable yaourt, by adding the repo to /etc/pacman.conf

[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch

Install Yaout to perform AUR package management.

pacman -Sy
pacman -S yaourt

Install the build utils and the custom kernel.

pacman -S base-devel
yaourt -S linux-macbook

This will take some time as it will download and compile the patched kernel.

Install bootmanager

First experiment

I tried both rEFInd and Grub, they did not work nicely.

  1. rEFInd

    pacman -S refind-efi efibootmgr
    

    I installed refind-efi and ran refind-install to get a proper bootmanager instead of having to press alt at every boot.

  2. Grub is not useful

    This is the truly exciting part, my first EFI bootmanager thingy. First install the packages

    pacman -S grub efibootmgr
    

    Now we need to install GRUB to /boot.

    grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
    

    Install the intel-ucode.

    pacman -S intel-ucode
    

    Enable the microcode by regenrating the GRUB config file.

    grub-mkconfig -o /boot/grub/grub.cfg
    

Second attempt systemd

Using bootctl you can easily use the systemd bootmanager.

bootctl --path=/boot install

Then change /boot/loader/loader.conf to automatically load our arch config file.

#timeout 3
default arch
timeout 4
editor 0

Next, create a file called /boot/loader/entries/arch.conf to hold the Arch boot configuration. Note that I did install the intel-ucode package as suggested in the manual.

title Arch Linux
linux /vmlinuz-linux-macbook
initrd /intel-ucode.img
initrd /initramfs-linux-macbook.img
options root=/dev/sda5 rw elevator=deadline quiet splash 
	resume=/dev/sda6 nmi_watchdog=0 i915.semaphores=1 
	intel_idle.max_cstate=1

Reboot

exit the shell and return to the USB boot shell. unmount -R /mnt to unmount all disks. Then reboot and pray.

Verify MAC still works

First boot, directly into linux, this was somewhat unexpected. Where did mac go?

Pressing ALT during boot showed th eboot disk and allows booting into Mac again. The setup still works, but GRUB has become the main bootloader and boots into Arch.

Verify we can boot into linux

Restart and just let it run will now boot into linux. I would want a choice between the 2, this is somewhat unexexpected.

Post installation

Use an unprivileged user

Install sudo to allow unprivileged users to perform administrative tasks.

pacman -S sudo

Create unprivileged user in users en wheel group.

useradd -g users -G wheel,input -s /bin/bash arjenw

Lock the root account.

passwd -l root

A graphical user interface

To get the graphics card working the manual suggests to use the xf86-video-intel driver. I found that it causes a lot of tearing/flickering when recording with OBS (Open Broadcast Studio) and my system would freeze up completely from time to time.

The alternative is to ditch the xf86-video-intel driver. Apparently the driver is buggy and it has not been updated in a long time. If you do not set install a driver it will default to the Xorg modesetting DDX driver, which is quite high performant already. So I went with that.

Install Xorg as a base

pacman -S xorg-server

Install gdm gnome gnome-extra

pacman -S gdm gnome gnome-extra

I disabled WayLand in /etc/gdm/custom.conf in order to use OBS (obs-studio).

[daemon]
WaylandEnable=false

Start GDM by default systemctl enable gdm systemctl start gdm

Install and enable NetworkManager to manage the network connections.

pacman -S networkmanager
systemctl enable NetworkManager
systemctl start NetworkManager

Bluetooth

Enable bluetooth, start it. My apple mouse now works in Gnome.

systemctl enable bluetooth
systemctl start bluetooth

Apple Mouse scrolling

Note: with kernel 4.10.10-1-macbook I experienced a lot of lock-ups, these seem to be due to the apple mouse. If it happens to you check the last journal with journalctl --boot -1 to check the last boot logs. Some of the times it will list the crash for hid_magicmouse. I just switched to a plain old wired mouse instead.

I use a bluetooth based Apple Magic Mouse. I quite like it, but the scrolling needs to be fast. By default there is little in the means of setting up scrolling in the GUIs.

The mouse is driven by the hid_magicmouse kernel module which takes several parameters. You can view the parameters by looking at the parameters set in /sys/module/hid_magicmouse/parameters.

emulate_3button      N
emulate_scroll_wheel Y
report_undeciphered  N
scroll_acceleration  Y
scroll_speed         55

I created a modprobe config in =/etc/modprobe.d/magicmouse.conf with the following contents:

options hid_magicmouse scroll-speed=55 scroll-acceleration=1 emulate_3button=0

USB Mouse disconnects/freeze

With the wired mouse I experience a lot of choppy movement, freezing of the cursor. This is due to the rigid powersaving settings that I have deployed with powertop and tlp. Basically it toggles the auto-suspend on the USB ports to be as fast as possible to conserve energy. Very good on its own, but it results in choppy behaviour.

For now I have just toggled the setting using the powertop tool. Run sudo powertop, press TAB to go to the tunables and press enter on the Autosuspend for USB device USB Optical Mouse [USB MOUSE].

For instructions to automatically fix this on boot see this wiki page. When I implement it myself I will update this section further.

Power management

I installed tlp to manage the performance of the laptop when on power and on battery. So far it seems to pull quite a time from a single charge, so I am happy with that.

yaourt -S tlp
sudo systemctl enable tlp
sudo systemctl enable tlp-sleep
sudo tlp start

Upgrading

When you upgrade your software, there’s a certain way you need to do it! Primarily you need to use yaourt to do it:

yaourt -Syua

To refetch and recompile all git software, you need to do:

yaourt -Syua --devel

But beware! If you reinstall your kernel, you need to rebuild it:

sudo mkinitcpio -p linux