crazy content for mankind, great stuff for nerds

31 May 2020

Installing Arch Linux with Btrfs, systemd-boot and LUKS

My preferred Arch Linux setup is with Btrfs, systemd-boot (which requires UEFI) and - at least when installing a laptop - LUKS. Not least for myself, to make the installation easier the next time, I thought that it’s a good idea to document the steps.

Using SSH

If you have another PC, it’s convenient to do the installation from this PC via SSH because then you can have browser windows with installations guides open in parallel and easily copy and paste commands. To do so, boot the PC that you want to install from the Arch Linux ISO.

Enable SSH:

# systemctl enabale sshd.service --now

Set a password for root:

# passwd

Look up the IP address of the PC:

# ip addr show

Now, on the second PC, call into the first PC via SSH:

# ssh root@<IP-OF-THE-FIRST-PC>

and continue with the installation.


For the rest of this post, we assume that we install Arch Linux on /dev/sda. Adjust the steps for your setup if necessary.

# gdisk /dev/sda

Create new partition table:

Command (? for help): o

Create an EFI partition (choose size 550M and hex code EF00):

Command (? for help): n

Create a root partition (adopt the default values):

Command (? for help): n

Write the new partitions to disk:

Command (? for help): w


Create an encrypted container for the root file system (you need to define a passphrase):

# cryptsetup luksFormat /dev/sda2

Open the container (“luks” is just a placeholder, you can use a name of your choice, but remember to adopt the subsequent steps of the guide accordingly):

# cryptsetup open /dev/sda2 luks

File System Creation

Format the EFI partition with FAT32 and give it the label EFI - you can choose any other label name:

# mkfs.vfat -F32 -n EFI /dev/sda1

Format the root partition with Btrfs and give it the label ROOT - you can choose any other label name. If you didn’t open the LUKS container under the name “luks” you must adjust the command accordingly:

# mkfs.btrfs -L ROOT /dev/mapper/luks

Create and Mount Subvolumes

Create subvolumes for root, home, the package cache, snapshots and the entire Btrfs file system:

# mount /dev/mapper/luks /mnt
# btrfs sub create /mnt/@
# btrfs sub create /mnt/@home
# btrfs sub create /mnt/@pkg
# btrfs sub create /mnt/@snapshots
# btrfs sub create /mnt/@btrfs
# umount /mnt

Mount the subvolumes:

# mount -o noatime,nodiratime,compress=zstd,space_cache,ssd,subvol=@ /dev/mapper/luks /mnt
# mkdir -p /mnt/{boot,home,var/cache/pacman/pkg,.snapshots,btrfs}
# mount -o noatime,nodiratime,compress=zstd,space_cache,ssd,subvol=@home /dev/mapper/luks /mnt/home
# mount -o noatime,nodiratime,compress=zstd,space_cache,ssd,subvol=@pkg /dev/mapper/luks /mnt/var/cache/pacman/pkg
# mount -o noatime,nodiratime,compress=zstd,space_cache,ssd,subvol=@snapshots /dev/mapper/luks /mnt/.snapshots
# mount -o noatime,nodiratime,compress=zstd,space_cache,ssd,subvolid=5 /dev/mapper/luks /mnt/btrfs

Mount the EFI partition

# mkdir /mnt/boot
# mount /dev/sda1 /mnt/boot

Base System and /etc/fstab

Install Arch Linux with (adjust this list to your needs):

# pacstrap /mnt linux base base-devel btrfs-progs intel-ucode nano

Generate /etc/fstab:

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

System Configuration

Since I want a German system the following steps are according to that. Adjust them to your needs.

chroot into the new system:

# arch-chroot /mnt/

Set host name:

# echo <YOUR-HOSTNAME> > /etc/hostname

Set locale:

# echo LANG=de_DE.UTF-8 > /etc/locale.conf

Uncomment the following rows of /etc/locale.gen:

#de_DE.UTF-8 UTF-8
#de_DE ISO-8859-1
#de_DE@euro ISO-8859-15

Generate locale:

# locale-gen

Set keyboard layout and font:

# echo KEYMAP=de-latin1 > /etc/vconsole.conf
# echo FONT=lat9w-16 >> /etc/vconsole.conf

Set time zone:

# ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime

Define hosts in /etc/hosts:

#<ip-address>	<>	<hostname>	<YOUR-HOSTNAME>.localdomain	<YOUR-HOSTNAME>
::1		localhost.localdomain	localhost

Set root password:

# passwd


Configure the creation of initramfs by editing /etc/mkinitcpio.conf. Change the line HOOKS=... to:

HOOKS="base keyboard udev autodetect modconf block keymap encrypt btrfs filesystems"

Recreate initramfs:

# mkinitcpio -p linux

Boot Manager

Install systemd-boot:

# bootctl --path=/boot install

Create file /boot/loader/entries/arch.conf and fill it with:

title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options cryptdevice=UUID=<UUID-OF-ROOT-PARTITION>:luks:allow-discards root=/dev/mapper/luks rootflags=subvol=@ rd.luks.options=discard rw

The UUID of the root partition can be determined via:

# blkid -s UUID -o value /dev/sda2

Edit file /boot/loader/loader.conf and fill it with:

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

Final Steps

Exit chroot, unmount partitions and reboot:

# exit
# umount -R /mnt
# reboot

Have fun with your system!


[1] Arch My Way 1 | Grundsystem installieren (German)

[2] Arch Linux - UEFI, systemd-boot, LUKS, and btrfs

[3] Arch Linux Wiki: systemd-boot

comments powered by Disqus