LLI Wiki — My Digital Knowledge Base

Installing Arch Linux with LUKS, Btrfs and Sway

Step-by-step installation of Arch Linux on a UEFI laptop with LUKS2 encryption, Btrfs, a swapfile and the Sway (Wayland) desktop.

Installing Arch Linux on a UEFI laptop with LUKS encryption, a Btrfs file system, a swapfile and the Sway (Wayland) desktop. Belgian AZERTY keyboard layout throughout.

Target configuration

Item Value
Hardware Lenovo ThinkPad T14 Gen 5 AMD (Ryzen 7 PRO 8840U, 32 GB RAM)
Disk /dev/nvme0n1
Boot UEFI, systemd-boot
Encryption LUKS2 on /dev/nvme0n1p2, opened as cryptroot
File system Btrfs with subvolumes
Swap 8 GB swapfile in a dedicated subvolume
Desktop Sway (Wayland), login via greetd + tuigreet
LVM No

Check the disk name before every partitioning command: the internal disk is normally /dev/nvme0n1, not the installation USB key.

1. Preparation from the USB key

# Belgian keyboard in the live environment
loadkeys be-latin1

# Check that the live system booted in UEFI mode
ls /sys/firmware/efi/efivars

# Check connectivity and enable network time
ping -c 3 archlinux.org
timedatectl set-ntp true

# Identify the disk
lsblk -o NAME,SIZE,MODEL,TYPE,MOUNTPOINTS

2. Partitioning and EFI

cfdisk /dev/nvme0n1
Partition Size Type
/dev/nvme0n1p1 1 GB EFI System
/dev/nvme0n1p2 Rest of the disk Linux filesystem

In cfdisk: New, then the size, then Type; Write, type yes, then Quit.

mkfs.fat -F32 /dev/nvme0n1p1

3. LUKS encryption

cryptsetup luksFormat --type luks2 /dev/nvme0n1p2
cryptsetup open /dev/nvme0n1p2 cryptroot

The decrypted volume is then available as /dev/mapper/cryptroot.

4. Btrfs and subvolumes

mkfs.btrfs -L ArchLinux /dev/mapper/cryptroot

mount /dev/mapper/cryptroot /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@log
btrfs subvolume create /mnt/@pkg
btrfs subvolume create /mnt/@snapshots
btrfs subvolume create /mnt/@swap
umount /mnt
Subvolume Mount point
@ /
@home /home
@log /var/log
@pkg /var/cache/pacman/pkg
@snapshots /.snapshots
@swap /swap

5. Mounting the subvolumes

# Root
mount -o noatime,compress=zstd,ssd,space_cache=v2,subvol=@ /dev/mapper/cryptroot /mnt

# Mount points
mkdir -p /mnt/home /mnt/var/log /mnt/var/cache/pacman/pkg /mnt/.snapshots /mnt/swap

mount -o noatime,compress=zstd,ssd,space_cache=v2,subvol=@home /dev/mapper/cryptroot /mnt/home
mount -o noatime,compress=zstd,ssd,space_cache=v2,subvol=@log /dev/mapper/cryptroot /mnt/var/log
mount -o noatime,compress=zstd,ssd,space_cache=v2,subvol=@pkg /dev/mapper/cryptroot /mnt/var/cache/pacman/pkg
mount -o noatime,compress=zstd,ssd,space_cache=v2,subvol=@snapshots /dev/mapper/cryptroot /mnt/.snapshots

# The swap subvolume is not compressed
mount -o noatime,ssd,space_cache=v2,subvol=@swap /dev/mapper/cryptroot /mnt/swap

# EFI
mount --mkdir /dev/nvme0n1p1 /mnt/boot

findmnt -R /mnt

6. 8 GB swapfile

btrfs filesystem mkswapfile --size 8g --uuid clear /mnt/swap/swapfile
swapon /mnt/swap/swapfile
swapon --show

7. Base installation and fstab

pacstrap -K /mnt base linux linux-firmware amd-ucode btrfs-progs cryptsetup sudo nano vim git base-devel man-db man-pages networkmanager fwupd

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

Check that the fstab contains /, /home, /var/log, /var/cache/pacman/pkg, /.snapshots, /swap, /boot and /swap/swapfile. The swap line should look like:

/swap/swapfile none swap defaults 0 0

8. Configuring the installed system

arch-chroot /mnt

Time zone and clock

ln -sf /usr/share/zoneinfo/Europe/Brussels /etc/localtime
hwclock --systohc

Locales

In /etc/locale.gen, uncomment en_US.UTF-8 UTF-8, fr_BE.UTF-8 UTF-8 and fr_FR.UTF-8 UTF-8, then:

locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf

System messages stay in English; the keyboard and time zone are configured separately.

Console keymap (also used for the LUKS passphrase prompt)

echo "KEYMAP=be-latin1" > /etc/vconsole.conf

Host name

echo "arch-laptop" > /etc/hostname

In /etc/hosts:

127.0.0.1       localhost
::1             localhost
192.0.2.10      arch-laptop.localdomain arch-laptop

Passwords and user

passwd
useradd -m -G wheel,audio,video,input,storage -s /bin/bash myuser
passwd myuser
EDITOR=nano visudo

In visudo, uncomment %wheel ALL=(ALL:ALL) ALL.

Initramfs for LUKS

In /etc/mkinitcpio.conf:

HOOKS=(base udev autodetect modconf kms keyboard keymap consolefont block encrypt filesystems fsck)

keyboard and keymap must come before encrypt so the LUKS passphrase can be typed with the Belgian keyboard. Then:

mkinitcpio -P

Warnings about consolefont or missing firmware are not blocking, as long as the initramfs image is generated successfully.

9. systemd-boot

bootctl install
blkid /dev/nvme0n1p2

Use the UUID of /dev/nvme0n1p2 (the encrypted partition), not the one of /dev/mapper/cryptroot.

/boot/loader/entries/arch.conf:

title   Arch Linux
linux   /vmlinuz-linux
initrd  /amd-ucode.img
initrd  /initramfs-linux.img
options cryptdevice=UUID=<UUID_OF_NVME0N1P2>:cryptroot root=/dev/mapper/cryptroot rootflags=subvol=@ rw

/boot/loader/loader.conf:

default arch.conf
timeout 3
console-mode max
editor no

10. Networking and first boot

systemctl enable NetworkManager
exit
swapoff /mnt/swap/swapfile
umount -R /mnt
cryptsetup close cryptroot
reboot

Remove the USB key when the machine restarts. Expected sequence: systemd-boot, Arch Linux, LUKS passphrase, greetd / tuigreet, Sway session.

11. Sway desktop

pacman -S sway swaybg swayidle swaylock waybar foot wofi mako grim slurp wl-clipboard xorg-xwayland
pacman -S thunar file-roller unzip p7zip zip
pacman -S pipewire-pulse pipewire-alsa wireplumber pavucontrol
pacman -S playerctl bluez bluez-utils cups
pacman -S greetd-tuigreet polkit-gnome
systemctl enable bluetooth
systemctl enable cups

greetd configuration in /etc/greetd/config.toml:

[terminal]
vt = 1

[default_session]
command = "tuigreet --time --cmd sway"
user = "greeter"
systemctl enable greetd

User configuration for Sway:

mkdir -p ~/.config/sway
cp /etc/sway/config ~/.config/sway/config

Useful lines to add or check in ~/.config/sway/config:

set $mod Mod4
set $term foot
set $menu wofi --show drun

bindsym $mod+Return exec $term
bindsym $mod+d exec $menu
bindsym $mod+Shift+q kill
bindsym $mod+Shift+c reload

input type:keyboard {
    xkb_layout be
}

exec waybar
exec mako
exec /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

Multiple screens: swaymsg -t get_outputs lists each output's name. To test a scale factor, run swaymsg output eDP-1 scale 1.25, then make it permanent with output eDP-1 scale 1.25 (or 1.5).

12. Checks after installation

nmcli device wifi list
sudo pacman -Syu
lsblk
sudo btrfs subvolume list /
swapon --show
free -h
sudo cryptsetup luksDump /dev/nvme0n1p2
fwupdmgr get-devices
fwupdmgr refresh
fwupdmgr get-updates
sudo fwupdmgr update
sudo systemctl enable --now tlp

Add a second LUKS passphrase with sudo cryptsetup luksAddKey /dev/nvme0n1p2 and keep it outside the machine.

13. Recovery procedure

From the installation USB key:

loadkeys be-latin1
cryptsetup open /dev/nvme0n1p2 cryptroot
mount -o noatime,compress=zstd,ssd,space_cache=v2,subvol=@ /dev/mapper/cryptroot /mnt
mount /dev/nvme0n1p1 /mnt/boot
arch-chroot /mnt

Possible fixes once in the chroot: nano /etc/mkinitcpio.conf then mkinitcpio -P, nano /boot/loader/entries/arch.conf, or bootctl install. To leave:

exit
umount -R /mnt
cryptsetup close cryptroot
reboot

14. Main Sway shortcuts

Shortcut Action
Super + Enter Terminal
Super + D Application menu
Super + Shift + Q Close window
Super + F Full screen
Super + Shift + Space Floating mode
Super + Shift + C Reload Sway
Super + Shift + E Exit Sway
Super + F1 to F5 Switch workspace
Super + Shift + F1 to F5 Move window to a workspace
Super + Ctrl + left / right Focus another screen
Super + Ctrl + Shift + left / right Move window to another screen

Notes

Mastodon LLIMastodon SocialFosstodon