Installing Arch Linux with Btrfs and systemd-boot

Posted on Sep 14, 2021

A while ago I described an installation of Arch Linux with Btrfs, systemd-boot and LUKS. Normally, I use an encrypted system for laptops only. For desktop computers I have a simpler setup without LUKS but with a swap partition. This post describes how to install such a system.

It’s almost the same installation that is described in this video1 (German).

Using SSH

Again, I recommend to do the installation as far as possible from a second computer via SSH as described here since that’s much more convenient.

Partitioning

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 for partition number, first sector and partition type - enter a relative size for the last sector making sure to leave sufficient space for the swap partition):

Command (? for help): n

Create a swap partition (adopt the default values for partition number, first sector and last sector - enter 8200 as partition type):

Command (? for help): n

Check the partitions:

Command (? for help): p

Write the new partitions to disk if everything’s OK:

Command (? for help): w

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:

# mkfs.btrfs -L ROOT /dev/sda2

Format the swap partition and give it the label SWAP - you can choose any other label name:

# mkswap -L SWAP /dev/sda3

Activate swap:

# swapon /dev/sda3

Create and Mount Subvolumes

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

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

Mount the subvolumes:

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

Mount the EFI partition

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

Base System and /etc/fstab

Install Arch Linux (adjust this list to your needs - in this example the long term support kernel will be installed, if you prefer the “normal” kernel, just remove the -lts from the subsequent commands):

# pacstrap /mnt linux-lts 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.domain.org>	<hostname>
127.0.0.1	<YOUR-HOSTNAME>.localdomain	<YOUR-HOSTNAME>
::1		localhost.localdomain	localhost

Set root password:

# passwd

Initramfs

Recreate initramfs:

# mkinitcpio -p linux-lts

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-lts
initrd /intel-ucode.img
initrd /initramfs-linux-lts.img
options root=LABEL=ROOT rootflags=subvol=@ rw

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!

References

comments powered by Disqus
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License