This post is part of the ArchLinux Chronoscope series.

Thoughts on laptop configurations for ArchLinux in 2023, with btrfs and sway

Warning

This post is a little less complete than most, it has been dated to roughly the correct time chronologically.

Background

I split this post from the previous one, to make each more self contained. Since the installation media has more features one might perhaps use gparted for resizing disks, use the GUI for managing networks, etc. Personally I generally allocate a chunk from whatever other OS is present in gparted, and format it as unformatted. This is so I can use encrypted BTRFS subvolumes1.

Input variants with sway

Instead of setting up a configuration, I typically use:

1swaymsg input type:keyboard xkb_variant colemak
2swaymsg input type:keyboard xkb_layout us

Setup Encryption

1cryptsetup luksFormat /dev/nvme0n1p5
2cryptsetup open /dev/nvme0n1p5 luks
3mkfs.btrfs -L ROOT /dev/mapper/luks

BTRFS Layout

The logic behind the flat btrfs layout is to separate things which should remain untouched during rollbacks of the system. I use a variant of a layout from this issue (more on layouts here and here):

 1mount /dev/mapper/luks /mnt
 2# Root
 3btrfs sub create /mnt/@ # /
 4# Needs additional setup
 5btrfs sub create /mnt/@swap
 6# Manage each home separately
 7btrfs sub create /mnt/@home # /home
 8btrfs sub create /mnt/@pkg # /var/cache/pacman/pkg
 9btrfs sub create /mnt/@.snapshots
10# VMs shouldn't be rolled back
11btrfs sub create /mnt/@VMs # /var/lib/libvirt/images
12btrfs sub create /mnt/@containers # for docker
13# Log files should be consistent
14btrfs sub create /mnt/@log # /var/log
15# Often has licensed software
16btrfs sub create /mnt/@opt # /opt
17btrfs sub create /mnt/@usr_local # /usr/local
18umount /mnt

These can then be mounted with reasonable defaults (detailed here):

 1mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@ /dev/mapper/luks /mnt
 2mkdir -p /mnt/btrfs # To mount the btrfs root: https://unix.stackexchange.com/q/367123/246530
 3mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvolid=5 /dev/mapper/luks /mnt/btrfs
 4# Mount the other subvolumes
 5mkdir -p /mnt/{boot,home,var/cache/pacman/pkg,.snapshots,var/lib/libvirt/images,var/log,opt,usr/local}
 6mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@home /dev/mapper/luks /mnt/home
 7mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@pkg /dev/mapper/luks /mnt/var/cache/pacman/pkg
 8mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@VMs /dev/mapper/luks /mnt/var/lib/libvirt/images
 9mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@log /dev/mapper/luks /mnt/var/log
10mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@opt /dev/mapper/luks /mnt/opt
11mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@usr_local /dev/mapper/luks /mnt/usr/local
12mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=@.snapshots /dev/mapper/luks /mnt/.snapshots

We also need to mount the EFI partition:

1mount -o rw,relatime,fmask=0022,dmask=0022,iocharset=ascii,shortname=mixed /dev/nvme0n1p1 /mnt/boot

Switch to sddm with weston for a better display manager

Handling swap

To get the physical offset, as noted on the ArchWiki we can use btrfs inspect-internal2.

1cd /mnt/btrfs/@swap
2truncate -s 0 ./swapfile
3chattr +C ./swapfile
4btrfs property set ./compression none
5dd if=/dev/zero of=./swapfile bs=1M count=<FILE-SIZE-IN-MiB> status=progress
6chmod 600 ./swapfile
7mkswap ./swapfile
8swapon ./swapfile
9cd -

System setup

I like the live USB packages, so I tend to use the ./offlineInst.sh instead of pacstrap. Some additional configuration is needed:

 1arch-chroot /mnt
 2# Set the hostname
 3echo <HOSTNAME> > /etc/hostname
 4# Locale is set already to C.UTF-8
 5# Setup timezone
 6ln -sf /usr/share/zoneinfo/<WHATEVER> /etc/localtime
 7
 8# Hosts should be updated
 9# cat /etc/hosts
10# #<ip> <hostname.domain.org> <hostname>
11# 127.0.0.1 <HOSTNAME>.localdomain <HOSTNAME>
12# ::1 localhost.localdomain localhost

Finally, a password needs to be setup for the root user with passwd. It is generally a good idea to make a new user too:

1useradd -m username -s /bin/zsh
2passwd username
3usermod -aG wheel username # for sudo

Some other (optional) colemak steps: ,#+begin_src bash echo KEYMAP=colemak > /etc/vconsole.conf #+end_src

Cleaning up archiso

Some cruft is copied over if the offlineInst.sh script is used. We will need to:

  • Remove the local repository from /etc/pacman.conf
  • Remove the preset archiso for mkinitcpio (by deleting /etc/mkinitcpio.d/linux.preset)

We also need to remove the user:

1userdel hzlinarch
2rm -rf /home/hzlinarch

Some other things to be deleted (should be updated in the script):

1sudo rm -rf /var/lib/pacman/local/mkinitcpio-archiso-*
2sudo rm -rf /usr/lib/initcpio/hooks/archiso*
3sudo rm -rf /usr/share/doc/mkinitcpio-archiso

Kernel setup

The initramfs hooks need to be modified for swap and to recognize btrfs (also to remove all the archiso hooks):

1# /etc/mkinitcpio.conf
2HOOKS=(base keyboard udev kms autodetect modconf block keymap encrypt btrfs filesystems resume)

Additionally, the kernel will need to be recompiled (at the very least). Since I was using the nitrous variant, this time I recompiled with mperformance in the PKGBUILD and this meant modifying the rtl88xxau kernel driver a bit as it passes -mhard-float and clang will fail with unused arguments.

Setup notes

With the skeletal system setup, I needed only to add my customizations. Namely:

  • All clang source builds
  • SDDM display management

Nix

My dotfiles expect nix for a variety of additional reasons. With sddm however, the default installation adds all nixbld users to the login screen. To prevent this, it is best to set the MaximumUid, for example in /etc/sddm.conf.d/08_nix_uid.conf:

1[Users]
2MaximumUid=30000

Wayland notes

  • caja isn’t compatible with wayland out of the box (but my favorite thunar is)
  • Thanks to a very old archive-manager (file-roller) bug, there aren’t any really good native options for compression
    • peazip works as a native file and archive manager though
  • kdialog turned out to be really useful for handling issues with Chromium browsers
    • Wasn’t able to print or attach files or anything otherwise

Laptop Tweaks

Mostly garnered from the Archwiki Laptop page. I generally setup /etc/systemd/{logind,sleep}.conf with defaults from my older etckeeper configuration.

  • Fingerprints worked natively with fprintd and a polkit (I used lxpolkit)
  • For keyring management gnome-keyring is fine (with wl-clipboard)

Conclusions

At this point, my notes came to an abrupt end. Presumably this meant I was able to cobble together the rest of the system using the pointers there.


  1. Based on the setup described here↩︎

  2. This is derived from this post, which in turn references the ArchWiki for BTRFS and swap↩︎


Series info

ArchLinux Chronoscope series

  1. Revisiting Wayland for ArchLinux
  2. Customizing ArchLinux Installation Media
  3. Laptop setup notes btrfs subvolumes <-- You are here!