Installing Arch Linux on a Macbook Pro (mid-2009) (and a Thinkpad T470)

Initial Install

Installation process follows that outlined in Arch Installation Guide, with the following additions/exceptions.

Boot Arch install ISO CD by holding ALT key on poweron. Select EFI boot (other choice is Windows which gives MBR boot). Be prepared to wait for a few minutes until Arch starts.

Using the mac-uk keyboard map i.e. loadkeys mac-uk kills the keyboard. No character prints what is inscribed on the key. This has been reported a couple of times, but there seems to be no reaction/fix available. I suspect this keymap is not for the Macbook Pro.

Best option for UK/International Macbook Pro keyboard seems to be to use the US keyboard layout.

The only keys not mapped correctly are (1) the section (§) key, which produces the grave character (`), (2) the grave key, which generates < and >, and (3) the £ key (shift 3), which generates a #.

I suggest a fix for this later.

Contents of /etc/vconsole.conf:

  # Closest match for Macbook Pro keyboard in console mode
  KEYMAP=us

Decided to use btrfs (for a change).

Originally had /usr as a separate partition. This caused grub to fail to find /sbin/init on reboot. There is a way of supporting a /usr partition by configuration in mkinitcpio (see /etcv/mkinitcpio.conf, HOOKS), but I decided to go with the flow and just have a bigger root partition, forgetting /usr. Here's the autogenerated /etc/fstab.

  # Static information about the filesystems.
  # See fstab(5) for details.

  # <file system> <dir> <type> <options> <dump> <pass>
  # /dev/sda3
  UUID=893ad534-7875-4723-be91-1f9d36e6e20b       /               btrfs           rw,relatime,ssd,space_cache,subvolid=5,subvol=/ 0 0

  # /dev/sda1
  UUID=0299-F54F          /boot/efi       vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro       0 2

  # /dev/sda4
  UUID=a7843e2d-b3fc-4054-b7e1-411143f1fdf4       /var            btrfs           rw,relatime,ssd,space_cache,subvolid=5,subvol=/ 0 0

  # /dev/sda5
  /dev/sda5               /tmp            btrfs           rw,relatime,ssd,space_cache,subvolid=5,subvol=/ 0 0

  # /dev/sda6
  UUID=6174874f-47b2-4769-89ff-ccbc4f4505b7       /home           btrfs           rw,relatime,ssd,space_cache,subvolid=5,subvol=/ 0 0

  # /dev/sda2
  UUID=d58ddbd7-6d69-4062-8553-7e25841c5d5d       none            swap            defaults       0 0

Partition sizing

Device Mount Point Size
/dev/sda1 EFI System 256MB
/dev/sda2 Swap 8GB
/dev/sda3 Root 30GB
/dev/sda4 var 10GB
/dev/sda5 tmp 2GB
/dev/sda6 home 172GB (the rest)

Initial set of packages

When using pacstrap, add the following packages, in addition to base, linux and linux-firmware:

  grub efibootmgr mg btrfs-progs man-db man-pages texinfo iwd binutils
  fakeroot b43-fwcutter wget iwd

NB b42-fwcutter, binutils and fakeroot are required to build the Wifi Broadcom firmware. See below.

After using arch-chroot to the /mnt directory, and following the install guide, the next step can be performed.

Setting up grub

First, install grub on the boot partition:

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

Then create the grub configuration file:

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

You can reboot now, or carry on with the next steps and then reboot.

Enabling Macbook Broadcom WiFi

The firmware for the Macbook Broadcom adapter can be downloaded from here. Use the "Download snapshot" on the left-hand menu.

This will download b42-firmware.tar.gz. Untar and cd into the resulting directory. Then issue the command:

  makepkg

If that works (it will download the firmware), the generated package can then be installed with:

  pacman -U b43-firmware-6.30.163.46-1-any.pkg.tar.zst

By the way, there's more Arch Linux Mac stuff

systemd network setup

First, enable the daemons:

  systemctl enable systemd-networkd
  systemctl enable systemd-resolved

Then, create the configuration files.

Configuration

/etc/systemd/network/20-wired.network

  [Match]
  Name=enp0s10

  [Network]
  DHCP=yes

  [DHCP]
  RouteMetric=10
  UseDomains=yes

/etc/systemd/network/25-wireless.network

  [Match]
  Name=wlan0

  [Network]
  DHCP=yes

  [DHCP]
  RouteMetric=20
  UseDomains=yes

Now the configuration files exist, start the daemons.

  systemctl start systemd-networkd
  systemctl start systemd-resolved

This setup causes a DHCP IP address to be assigned to each network adapter. See below for a different way of handling the two adapters with bonding.

Setup Wifi with iwd

  systemctl enable iwd
  systemctl start iwd

Control / set-up wireless with iwctl.

  # iwctl
  [iwd]# station wlan0 connect <station_id>

If this doesn't work, scan for networks first:

  [iwd]# station wlan0 scan

Note, this will not work if wlan0 is part of a bond (see below).

Keyboard led lights

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

Useful ip commands

  ip addr   # shows interfaces with address
  ip link   # shows network adapters
  ip link set 'device' [up | down]

Setting up X

  # pacman -S lxde xorg xorg-xinit
  # Allow non-root users to run startx
  # chmod 4755 /usr/bin/startx
  $ echo "exec startlxde" >~/.initrc

Wallpapers

  pacman -S archlinux-wallpaper

Images are installed in /usr/share/backgrounds/archlinux.

NFS Client

Need to install nfs-utils.

The first mount after boot takes an age (maybe systemd related?):

  [mark@albino:~]$ doas mount -t nfs opal:/home/mark /mnt
  Created symlink /run/systemd/system/remote-fs.target.wants/rpc-statd.service → /usr/lib/systemd/system/rpc-statd.service.

Subsequent mounts were fast.

After much investigation, to little effect, the slowdown was caused by:

  systectl start rpc-statd

invoked when the mount command is issued. This took about 60 seconds to complete. Starting /usr/sbin/rpc-statd manually was fast, as was a subsquent mount command. I could not figure out the real problem, but added an [Install] section to the /usr/lib/systemd/system/rpc-statd.service file:

  [Install]
  Wantedby=multi-user.target

and then enabled with

  # systemctl daemon-reload

This meant I could start rpc-statd.service at boot time. Doing this doesn't cause any boot delay, as far as I can tell.

After some more investigation, the rpc-statd hang was actually caused by sm-notify (/usr/lib/systemd/system/rpc-statd-notify.service), which is required by the rpc-statd.service. The sm-notify hang occurs when the wired ethernet is disconnected. If the Match name in 20-wired.network is changed to something that will not match, the hang does not occur. Caused by systemd-networkd trying to get a DHCP address on the wired network?

Running a bonded network (slaves wired and wireless) still has an approx 90s delay in mounting NFS.

If the wired ethernet is connected at boot, no delay in mounting.

The kludge I used above (making rpc-statd run at boot time) didn't help with a BOND.

Found this thread on askubuntu forum. The answer is to edit /usr/lib/systemd/system/systemd-networkd-wait-online.service, remove the existing ExecStart= line and replace it with the following lines:

  ExecStart=
  ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --ignore enp0s10

where enp0s10 is the wired ethernet interface. This causes wait-online to succeed, irrespective of the state of the wired adapter.

Could also try the --any switch (which waits until at least one interface is online). This works and has the advantage of not needing the interface name.

The use of a bond is a bit academic. If the laptop is mobile and must connect to other wifi points, then much manual editting is required. Easier just to leave unbonded and use the wireless adapter all the time.

Sound

For sound, install alsa-utils, pulseaudio, and pulseaudio-alsa. Lxmusic doesn't want to play mp3 files (they disappear as soon as you open them in lxaudio), so installed audacious. That works fine.

Turns out lxmusic needs pacman -S libmad to play mp3 files.

Updating Arch packages

pacman -Syu: updates package list and upgrades all packages.

Aka pacman --sync --refresh --sysupgrade.

For a list of installed packages:

pacman -Qett.

Aka packman --query --explicit --unrequired --unrequired

Final package list

  alsa-utils 1.2.4-2
  archlinux-wallpaper 1.6.1-1
  audacious 4.1-3
  b43-firmware 6.30.163.46-1
  b43-fwcutter 019-3
  base 2-2
  binutils 2.36.1-2
  btrfs-progs 5.11.1-1
  efibootmgr 17-2
  emacs 27.2-1
  fakeroot 1.25.3-2
  firefox 88.0.1-1
  gcc 10.2.0-6
  gpicview 0.2.5-6
  grub 2:2.04-10
  iwd 1.14-1
  libmad 0.15.1b-9
  linux 5.12.1.arch1-1
  linux-firmware 20210426.fa0efef-1
  lxappearance 0.6.3-4
  lxappearance-obconf 0.2.3-3
  lxde-common 0.99.2-3
  lxde-icon-theme 0.5.1-5
  lxdm 0.5.3-7
  lxhotkey 0.1.1-1
  lxinput 0.3.5-3
  lxlauncher 0.2.5-4
  lxmusic 0.4.7-5
  lxpanel 0.10.1-1
  lxrandr 0.3.2-2
  lxsession 1:0.5.5-1
  lxtask 0.1.10-1
  lxterminal 0.4.0-1
  make 4.3-3
  man-db 2.9.4-1
  man-pages 5.11-1
  mg 20210314-1
  nfs-utils 2.5.3-1
  ntfs-3g 2017.3.23-5
  openbox 3.6.1-7
  opendoas 6.8.1-3
  openssh 8.6p1-1
  pcmanfm 1.3.2-1
  pulseaudio 14.2-3
  pulseaudio-alsa 1:1.2.2-2
  rpcbind 1.2.5-3
  rsync 3.2.3-3
  strace 5.12-1
  texinfo 6.7-3
  wget 1.21.1-1
  xf86-video-vesa 2.5.0-1
  xorg-bdftopcf 1.1-2
  xorg-docs 1.7.1-3
  xorg-font-util 1.3.2-2
  xorg-fonts-100dpi 1.0.3-7
  xorg-fonts-75dpi 1.0.3-7
  xorg-iceauth 1.0.8-2
  xorg-mkfontscale 1.2.1-2
  xorg-server-devel 1.20.11-1
  xorg-server-xephyr 1.20.11-1
  xorg-server-xnest 1.20.11-1
  xorg-server-xvfb 1.20.11-1
  xorg-sessreg 1.1.2-2
  xorg-smproxy 1.0.6-3
  xorg-x11perf 1.6.1-2
  xorg-xauth 1.1-2
  xorg-xbacklight 1.2.3-2
  xorg-xcmsdb 1.0.5-3
  xorg-xcursorgen 1.0.7-2
  xorg-xdpyinfo 1.3.2-4
  xorg-xdriinfo 1.0.6-2
  xorg-xev 1.2.4-1
  xorg-xgamma 1.0.6-3
  xorg-xhost 1.0.8-2
  xorg-xinit 1.4.1-3
  xorg-xinput 1.6.3-2
  xorg-xkbevd 1.1.4-3
  xorg-xkbutils 1.0.4-4
  xorg-xkill 1.0.5-2
  xorg-xlsatoms 1.1.3-2
  xorg-xlsclients 1.1.4-2
  xorg-xmodmap 1.0.10-2
  xorg-xpr 1.0.5-2
  xorg-xprop 1.2.5-1
  xorg-xrdb 1.2.0-2
  xorg-xrefresh 1.0.6-2
  xorg-xset 1.2.4-2
  xorg-xsetroot 1.1.2-2
  xorg-xvinfo 1.1.4-2
  xorg-xwayland 21.1.1-1
  xorg-xwd 1.0.7-2
  xorg-xwininfo 1.1.5-2
  xorg-xwud 1.0.5-2
  xscreensaver 6.00-2

Macbook Pro keyboard on console

To overcome the missing/transposed keys, I had to create a new keyboard map file, based on the us.map file. Files are in this location: /usr/share/kbd/keymaps/i386/qwerty. The following changes were made:

  [mark&albino:~]$ diff -u us.map uk-macbook-pro.map
  --- us.map      2021-05-15 14:44:08.311357071 +0100
  +++ uk-macbook-pro.map  2021-05-15 14:45:32.094363649 +0100
  && -1,4 +1,4 &&
  -# us.map
  +# uk-macbook-pro.map
   keymaps 0-2,4-6,8-9,12
   alt_is_meta
   include "qwerty-layout"
  && -10,8 +10,9 &&
   keycode   1 = Escape
   keycode   2 = one              exclam
   keycode   3 = two              at               at               nul              nul
  -keycode   4 = three            numbersign
  +keycode   4 = three            sterling
          control keycode   4 = Escape
  +       altgr keycode     4 = numbersign
   keycode   5 = four             dollar           dollar           Control_backslash
   keycode   6 = five             percent
          control keycode   6 = Control_bracketright
  && -50,5 +51,7 &&
   keycode  57 = space
          control keycode  57 = nul
   keycode  58 = Caps_Lock
  -keycode  86 = less             greater          bar
  +keycode  41 = section  plusminus
  +keycode  86 = grave tilde
   keycode  97 = Control

Note the map file has to be gzipped before placing in the keymaps directory.

Macbook Pro keyboard under X11

My first attempt (after much research) at getting the keyboard working properly (i.e. what is printed is the same as the key is labelled) led to this configuration file (/etc/X11/xorg.conf.d/00-keyboard.conf):

  Section "InputClass"
        Identifier "Generic Keyboard"
        MatchIsKeyboard "on"
        Driver  "kbd"
        Option  "CoreKeyboard"
        Option  "XkbRules"      "xorg"
        Option  "XkbLayout"     "gb"
        Option  "XkbModel"      "pc105"
        Option  "XkbVariant"    "mac"
        Option  "XkbOptions"    "lv3:rwin_switch"
  EndSection

I believe the lv3:rwin_switch option emits the #hash; symbol when the AltGR key (right-hand Alt alt key) is pressed with the 3 key.

Everything seemed to work except the section and grave keys were switched. I could find no options (e.g. Option XkbOptions "apple:badmap") which would fix this. Then I found (even worse) the arrow keys weren't being recognised.

Yet more research ...

Testing combinations keyboard setup is made easier by using setxkbmap. For example, this is the closest I could get to matching the keyboard:

  setxkbmap -layout gb -variant mac

This xorg configuration is correct, apart from the § and grave (`) keys being swapped. This can be fixed by modifing /usr/share/X11/xkb/symbols/gb:

  [mark@albino:/usr/share/X11/xkb/symbols]$ diff -u gb~ gb
  --- gb~ 2021-05-14 19:55:48.024452514 +0100
  +++ gb  2021-05-15 14:22:28.911999295 +0100
  && -188,8 +188,8 &&

       key <AE02> { [ 2,              at,         EuroSign    ]       };
       key <AE03> { [ 3,        sterling,       numbersign    ]       };
  -    key <LSGT> { [ section,       plusminus ]    };
  -    key <TLDE> { [ grave,      asciitilde ]    };
  +    key <TLDE> { [ section,       plusminus ]    };
  +    key <LSGT> { [ grave,      asciitilde ]    };

       include "level3(ralt_switch)"
       include "level3(enter_switch)"

This vital change was found from this article.

Then I could create an X11 keyboard configuration file using localectl:

  doas localectl set-x11-keymap gb "" mac

This produces a /etc/X11/xorg.conf.d/00-keyboard.conf with the following contents:

  # Written by systemd-localed(8), read by systemd-localed and Xorg. It's
  # probably wise not to edit this file manually. Use localectl(1) to
  # instruct systemd-localed to update it.
  Section "InputClass"
          Identifier "system-keyboard"
          MatchIsKeyboard "on"
          Option "XkbLayout" "gb"
          Option "XkbVariant" "mac"
  EndSection

LX Terminal - Dracula colour scheme settings

This is a manual exercise; create a custom Palette, selecting the appropriate Dracula colour for each of the standard LXTerminal colours. Once configured, the setup is in ~/.config/lxde/lxterminal/lx-terminal.conf. This can be copied into a new configuration, if necessary.

Issues

The one remaining problem is that on rsync'ing large datasets, the rsync process stalls after a period of time. Test case is copying around 60GB of mp3 files.

What's the cause? Could be the ethernet driver, the use of bonding, btrfs ... Hard to say.

First start: forcedeth. Possible fix has been implemented, but not yet tested. Added these options to /etc/modprobe.d/forcedeth.conf:

  options forcedeth msix=0 msx=0

Modifications for a Thinkpad T470

Networking

  /etc/systemd/network/20-wired.network

  [Match]
  Name = enp0s31f6

  [Network]
  DHCP=yes

  [DHCP]
  RouteMetric=10

Keyboard led lights

On the Thinkpad T470, the FN-Space combination works to control the led brightness.

Keyboard settings

/etc/X11/xorg.conf.d/00-keyboard.conf:

  Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "gb"
        Option "XkbModel" "pc105"
  EndSection

For Thinkpad T470 console keyboard, enter the following into /etc/vconsole.conf:

  KEYMAP=uk

Screen brightness

Set via ACPI:

  # echo 1515 /sys/class/backlight/intel_backlight/brightness

T470 Wireless - Intel Dual Band Wireless AC 8260

Stalls a lot. Placed these options in /etc/modprobe.d/iwlwifi.conf:

  options iwlwifi power_save=0
  options iwlmvm power_scheme=0
  options iwlwifi 11n_disable=1 swcrypto=1

These options turn off power saving, use of 11n and software crypto (I think). Much more stable now.