Fog

From wikinotes

Archlinux on a macbook. Named after Dean Fog.

TODO:

these install instructions don't belong here.
I need a section for archlinux variant installs like archlinux-arm, and this alt-kernel

t2linux install docs https://wiki.t2linux.org/distributions/arch/installation/
t2linux wifi docs https://wiki.t2linux.org/guides/wifi/
t2linux pacman repo https://github.com/Redecorating/archlinux-t2-packages
arch install https://wiki.archlinux.org/title/Installation_guide#Set_the_console_keyboard_layout
systemd boot https://wiki.archlinux.org/title/Systemd-boot

Install Media

Download install media

raw (out of date) https://dl.t2linux.org/archlinux/iso/index.html
w/ wifi drivers https://github.com/t2linux/archiso-t2/releases
diskutil list
diskutil unmountDisk /dev/disk2
dd if=path/to/archlinux-version-x86_64.iso of=/dev/rdisk2 bs=1m

Partition Setup

You can't change the partition scheme from outside of macos unfortunately.

- macbook, start bootcamp (preinstalled)
  - drag slider for size (deletes apfs snapshots?)

- disk utility
  - create a partition (any format) for your linux install

- restart, holding cmd+r
  - Utilities > Startup Security Utility:
    - [x] No Security
    - [x] Allow booting from external media

- restart, holding opt
  - you don't need to connect to wifi in bootloader
  - boot from EFI

Base Install

NOTE:

Use the wifi-enabled ISO, spoke with devs and wired kernel is outdated

(archiso) wlan setup

iwctl
 device list
 station wlan0 scan
 station wlan0 get-networks
 station wlan0 connect ${SSID}

ping archlinux.org

(archiso) format && baseinstall

timedatectl set-ntp true

pacman -Sy
# pacman-key --refresh-keys

fdisk -l                  # find disk/partition
mkfs.ext4 /dev/nvme0n1p3  # format partition as ext4

mount /dev/nvme0n1p3 /mnt            # your install
mkdir -p /mnt/boot/efi
mount /dev/nvme0n1p1 /mnt/boot/efi   # reuse macbook's EFI paritition

# if necesary, copy/modify /etc/pacman.conf to /mnt/pacman.conf
# and use: `pacstrap -C /mnt/pacman.conf`
pacstrap /mnt \
  base base-devel                           `# base packages/build-tools` \
  linux-t2 linux-t2-headers linux-t2-docs   `# t2-kernel` \
  efivar efibootmgr dosfstools              `# tools to manage efi` \
  linux-firmware dkms \
  apple-bcm-wifi-firmware \
  iwd networkmanager netstat-nat net-tools \
  neovim git openssh man-db

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

(chroot) Add t2linux repo

cat << EOF >> /etc/pacman.conf
[mbp]
Server = https://dl.t2linux.org/archlinux/$repo/$arch
EOF

pacman -Syy

(chroot) Base Settings

ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
hwclock --systohc
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
echo "fog" > /etc/hostname
mkinitcpio -P  # confirm kernel/initramfs in /boot/efi
passwd

(chroot) Bootloader

cat << EOF > /boot/efi/loader/loader.conf
default archlinux
timeout 1
EOF

# find PARTUUID of 'archlinux' install partition
# (not EFI partition, not UUID)
blkid

cat << EOF > /boot/efi/loader/entries/archlinux.conf
title Arch Linux
linux vmlinuz-linux-t2
initrd initramfs-linux-t2.img
# no quotes around PARTUUID
options intel_iommu=on iommu=pt pcie_ports=compat root=PARTUUID=${PARTUUID} rw
EOF

bootctl --path=/boot/efi --no-variables install

systemctl mask systemd-boot-system-token

# remount efivars as read-only (or kernel panic)
# USE EITHER: (1 works for me)
#    echo efivarfs /sys/firmware/efi/efivars efivarfs ro,remount,nofail 0 0 >> /etc/fstab
# OR
#    add 'efi=noruntime' to options in '/boot/efi/loader/entries/archlinux.conf'

Reboot

- exit && reboot
- hold 'option' while booting to choose boot
- after selection, wait for timeout (choosing with enter seems to fail)

Debugging Boot Issues

# from archiso, specify the journal of your chroot
journalctl --directory=/var/log/journal

unable to mount /boot/efi unknown filesystem vfat

do you have an old kernel in /boot/efi?
try copying initramfs/kernel from /boot to /boot/efi.

this may only work with old kernel though ...

Post Install

Wifi Drivers

Boot into macos

curl -#O https://wiki.t2linux.org/tools/wifi.sh
chmod +x wifi.sh
./wifi.sh

Boot into linux

sudo umount /dev/nvme0n1p1
sudo mkdir /tmp/apple-wifi-efi
sudo mount /dev/nvme0n1p1 /tmp/apple-wifi-efi
bash /tmp/apple-wifi-efi/wifi.sh
sudo reboot

Now verify output of wifi driver is error-free.

sudo journalctl -k --grep=brcmfmac  # check for errors
ip link                             # check for wlan0

Now you can test a connection

systemctl start iwd
iwctl
> station wlan0 scan
> station wlan0 get-networks
> station wlan0 connect ${SSID}

Finally, use NetworkManager (for wireguard, routing) with iwd as backend

cat << EOF > /etc/NetworkManager/NetworkManager.conf
[device]
wifi.backend=iwd
EOF

sudo systemctl enable --now iwd
sudo systemctl restart NetworkManager

route               # confirm routing table present
ping archlinux.org  # test

CPU fan

Install and configure mbpfan,
monitor effectiveness with lm_sensors.

GPU

lscpi -nn | grep VGA  # find gpu

pacman -S xf86-video-ati    # oss
# or
pacman -S xf86-video-amdgpu # proprietary

Heat/Power Optimization

Without optimizations, this laptop idles at 60-80*C in linux (where I would normally expect ~30*C)
These are some power optimizations that may help.

NOTE:

within this hardware, I found disabling intel_pstate to give full control to cpupower.service much more effective at reducing heat.

current configuration

  • tlp.service + tlp-rdw (defaults)
  • thermald.service (defaults)
  • cpupower.service (defaults)
  • mpbfan.service (lower threshold for fan)

TODO:

apparently some people have had better results with auto-cpufreq. I'll have to try it.

monitoring some usage stats

sudo i7z
watch eval 'sensors | head -n 10'
watch eval 'cpupower frequency-info | grep "current CPU"'

TODO:

determine good settings

# find warnings with tlp (ex: warning: systemd-rfkill.service is not masked, to correct this...)
sudo tlp-stat -s

# correct warnings
sudo systemctl mask systemd-rfkill.service
sudo systemctl mask systemd-rfkill.socket

Trackpad

pacman -S xf86-input-synaptics
reboot # for driver to be used

# test it out if you like
synclient AccelFactor=0.05  # smaller movements travel further

make permanent

# /etc/X11/xorg.conf.d/70-synaptics.conf

Section "InputClass"
  Identifier "touchpad"
  Driver "synaptics"
  MatchIsTouchpad "on"

  # moving mouse-pointer
  Option "AccelFactor" "0.01"
  Option "MinSpeed" "1.2"
  Option "MaxSpeed" "2.5"

  # scroll momentum speed
  Option "VertScrollDelta" "250"
EndSection

Function Keys

TODO:

  • default to function keys
  • multimedia keys don't work
  • following suspend/resume, touchbar doesn't work at all

mkinitcpio hooks

On updates, kernel/initramfs must be copied to /boot/efi for system to boot.

TODO:

mkinitcpio hook?

Disable Boot Sound

# MacOs
System Preferences:
  Sound:
    - [ ] Play Sound on Startup

Default Boot

NOTE:

Since I can't write to EFI, I'm not sure I can default to linux.
Bootcamp appears to support this if you have completed a windows install, which I haven't.

NOTE:

Try omitting --no-variables from the bootctl command on archiso. If that installs an entry, we're all good.

Choosing default Disk

- boot macos
- apple-menu > system preferences:
  - startup disk

Choosing default EFI bootloader

# show installed bootloaders
#
#  BootOrder: 0080,0000  # boot priority
#  Boot0080:  Mac OS X   # macos boot entry
#  Boot0000:  Foo        # foo boot entry
efibootmgr

efibootmgr -o 0000,0080  # change boot priority

Audio

TODO