Install Arch with full disk encryption, btrfs and EFI
Posted on January 20, 2018 (Last modified on October 23, 2024) • 6 min read • 1,092 wordsUpdates:
I recently had to re-install my beloved Arch Linux. For security I need (and use) full disk encryption. This is a cheatsheet for the whole procedure, because although the Arch Linux Wiki is excellent, it is also huge and sometimes you must pick your stuff together from many pages.
This is what I am doing here π
NOTE: Usually you only have to follow the one subsection I link to!
One after another, we will do the following steps
Use parted
to init the disk and …
Basically,
cryptsetup
command to encrypt the main (big) partition,Cause we want “properly” encrypted swap (you can also encrypt swap using a /dev/random
key every time, but then you will not persist data between reboots and you can’t do things like suspend-to-disk), we need at least two “partitions” “inside” the crypted volume. Sounds like
LVM on LUKS? It does. We already used it π .
cryptsetup luksOpen
before, usually in step 1 in the last section πNOTE: Do not follow the above link down to “prepare the boot partition”, cause they use ext2 and we need FAT32 for EFI boot partitions. Just don’t.
I use the name “secure” for the VG, and I use btrfs cause I am so incredibly elite, and so we don’t need to set a specific size for the /
and /home
“partitions” and can just use btrfs subvolumes, while still being able to wipe the system without the home directories. That’s pretty neat if you need it (I never did, but now I can ;). So that’s the final setup:
/dev/mapper/secure-swap 40 GB, swap
/dev/mapper/secure-system rest, btrfs with 2 subvols: root & home
Of course, Arch has already a wiki page section for that. I did it 3 times in a different way until I found it and had to do it again. So here is my summary.
# CREATE BTRFS & SUBVOLUMES
$ mkfs.btrfs /dev/mapper/secure-system
$ mount /dev/mapper/secure-system /mnt
$ btrfs subvolume create /mnt/@
$ btrfs subvolume create /mnt/@home
$ btrfs subvolume create /mnt/@snapshots
$ umount /mnt
# MOUNT PARTITIONS
$ mount -o subvol=@ /dev/mapper/crypted-system /mnt
$ mkdir -p /mnt/home /mnt/boot
$ mount -o subvol=@home /dev/mapper/crypted-system /mnt/home
$ mount /dev/sda1 /mnt/boot
NOTE: /boot
is not on an encrypted partition π , and the leading “@
” is a convention for subvolumes which should be mounted somewhere. I also don’t use compress=...
Β parameters, cause I don’t need / want transparent compression.
Nowadays nobody uses LAN cables any more. And of course, with Arch you can do it over WiFi as well. This is the short form:
$ iwctl
[iwd] station list
# get the name of your "station" here
[iwd] station wlan0 scan
[iwd] station wlan0 get-networks
# see the list of networks
[iwd] station wlan0 connect NETWORK_NAME
Also useful: IWD docs, connecting to the internet on the arch Wiki.
Then you follow up with the usual installation procedure, but you stop at the “Initramfs” section. Here we will pick up again. In the chroot, this is what is needed and useful. (Yes, we’re installing multiple network managers, Linux “is about choice” …)
pacman -S lvm2 vim \
iwd netctl dialog wpa_supplicant \
networkmanager \
dhcclient \
udev nano zsh sudo iproute2 net-tools \
git
We are using systemd-boot. Or bootctl
, as the binary is called. It should be already installed. The procedure is
also outlined here. We also enable TRIM support, it seems to lessen security, but it raises SSD performance and life time.
pacman -S intel-ucode
.bootctl -path=/boot install
to install systemd-boot.File system ... has wrong type for EFI System Partition
, then you forgot set 1 esp on
on your boot partition in parted during partitioning)Now create/modify the files below.
Remember: /mnt/boot
should be a mounted directory, and since you’re in a chroot this should be /boot
for you.
title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img # ONLY FOR INTEL CPUs!!
initrd /initramfs-linux.img
options luks.uuid=FS_UUID root=/dev/mapper/secure-system rootflags=subvol=@ rd.luks.options=discard
Some hints:
blkid
to get the UUID/dev/sda2
or similar), and not the filesystem within!gpm -m /dev/input/mice -t imps2
; you may have to disable vim’s mouse support using set mouse=
and set ttymouse=
default arch # the file above without .conf extension, can have wildcards!!
timeout 2
editor 0
# Just MODIFY that file, to be precisely this line:
HOOKS=(base systemd autodetect modconf keyboard sd-vconsole block sd-encrypt sd-lvm2 filesystems fsck)
The key idea is to use the “systemd” parameters instead of the “normal” ones. The full list of hooks is of course also available, and the order is important.
Now execute:
mkinitcpio -p linux
If you run into some vmlinuz-linux - file not found
issues, just re-install linux
and intel-ucode
while making sure /boot
is mounted.
We should be done here :) …
… but we’re paranoid:
lvm2
?
(if not - install it and run mkinitcpio
again)iwd
?
(if not - no wifi in the final system)Then you can safely …
$ reboot