Install Arch Linux on UEFI with LVM, LUKS, GRUB and XFCE
Encrypted Arch Linux install (LVM, LUKS, GRUB, XFCE) and GRUB repair after a firmware update.
This guide covers installing Arch Linux on UEFI with LVM, LUKS encryption and GRUB, and repairing the bootloader after a firmware update.
Repairing GRUB after a firmware update
The system stopped booting after a firmware update through fwupdmgr:
fwupdmgr get-updates
fwupdmgr refresh
fwupdmgr update
Fix: boot an Arch live USB, mount the installed system and reinstall GRUB.
loadkeys be-latin1
fdisk -l
mkdir /mnt/arch
mount -t auto /dev/sda3 /mnt/arch
arch-chroot /mnt/arch
mount -t auto /dev/sda1 /boot/EFI
grub-install --target=x86_64-efi --bootloader-id=grub_uefi --recheck
exit
reboot
Note: /dev/sda3 (root) and /dev/sda1 (EFI partition) are examples; check them with fdisk -l.
Preparation
Disable Secure Boot in the BIOS to boot from USB, then check that the machine boots in UEFI mode.
loadkeys fr
setfont Lat2-Terminus16
# if this directory exists, the system booted in UEFI mode
ls /sys/firmware/efi/efivars
Network
ip addr show
ping -c 2 example.com
Wi-Fi with iwctl:
[iwd]# device list
[iwd]# station device scan
[iwd]# station device get-networks
[iwd]# station device connect SSID
Refresh the mirror list with reflector (sorted by speed, HTTPS):
pacman -Syy
pacman -S reflector
reflector --verbose --country 'France' -l 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
lsblk
Partitioning
Wipe the disk (slow), then create a GPT table with cgdisk or gdisk:
shred -v -n 1 /dev/sda
cgdisk /dev/sda
| Partition | Type | Size | Hex code |
|---|---|---|---|
| /dev/sda1 | EFI System | 512 MB | ef00 |
| /dev/sda2 | LVM | 100% of the rest | 8e00 |
mkfs.fat -F32 /dev/sda1
LVM
pvcreate --dataalignment 4M /dev/sda2
vgcreate vglvm /dev/sda2
lvcreate -L 30G -n root vglvm
lvcreate -L 16G -n swap vglvm
lvcreate -L 4G -n tmp vglvm
lvcreate -l 100%FREE -n home vglvm
Check the volumes with pvdisplay, vgdisplay or fdisk -l.
LUKS encryption of the root volume
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 /dev/vglvm/root
cryptsetup luksOpen /dev/vglvm/root root
Format and mount
mkfs.ext4 /dev/mapper/root
mount /dev/mapper/root /mnt
mkfs.vfat -F32 /dev/sda1
mkdir /mnt/boot && mount /dev/sda1 /mnt/boot
lsblk -l
Base system
pacstrap /mnt linux base base-devel pacman-contrib linux-firmware ntp sudo lvm2 cryptsetup vim nano git man-db man-pages openssh zip p7zip unzip tar htop rsync tmux bash-completion wget pciutils lshw syslog-ng reflector iwd
# add intel-ucode or amd-ucode depending on the CPU
Generate fstab:
genfstab -L /mnt >> /mnt/etc/fstab
nano /mnt/etc/fstab
/dev/mapper/root / ext4 defaults,noatime 0 1
/dev/sda1 /boot vfat defaults,noatime 0 2
#/dev/mapper/home /home ext4 rw,noatime 0 2
#/dev/mapper/tmp /tmp tmpfs nodev,nosuid 0 0
#/dev/mapper/swap none swap sw 0 0
Enable the commented lines once /home, /tmp and swap are encrypted (see below). Example /etc/crypttab:
# home /dev/vglvm/home /etc/luks-keys/home
# swap /dev/vglvm/swap /dev/urandom swap,cipher=aes-xts-plain64:whirlpool,size=512,hash=sha512
# tmp /dev/vglvm/tmp /dev/urandom tmp,cipher=aes-xts-plain64,size=256
Configuration inside the chroot
arch-chroot /mnt /bin/bash
passwd
nano /etc/hostname
nano /etc/locale.gen # uncomment en_US.UTF-8 UTF-8 and fr_FR.UTF-8 UTF-8
locale-gen
/etc/locale.conf:
LANG="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
/etc/vconsole.conf (AZERTY keyboard):
KEYMAP=fr-pc
Time zone and NTP:
export LANG=fr_FR.UTF-8
timedatectl set-timezone Europe/Paris
# or: ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
timedatectl set-ntp true
hwclock --systohc
Network services:
# desktop
pacman -S networkmanager
systemctl enable NetworkManager
# server
systemctl enable systemd-networkd.service
# Wi-Fi and SSH
systemctl enable iwd
systemctl enable sshd.service
Periodic TRIM:
pacman -S util-linux
systemctl enable fstrim.timer
initramfs
In /etc/mkinitcpio.conf, the encrypt and lvm2 hooks are required, before filesystems:
HOOKS=(base udev autodetect keyboard keymap consolefont modconf block encrypt lvm2 resume filesystems fsck)
mkinitcpio -p linux
GRUB
pacman -S grub efibootmgr
mkdir -p /boot/efi
mount -t vfat /dev/sda1 /boot/efi
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
In /etc/default/grub, point to the encrypted root partition:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/vglvm/root:root"
GRUB_ENABLE_CRYPTODISK=y
grub-mkconfig -o /boot/grub/grub.cfg
exit
umount -R /mnt
reboot
After the reboot, the LUKS passphrase is requested once. If something goes wrong, boot the live USB again and open the container with cryptsetup luksOpen /dev/vglvm/root root.
Swap, user and sudo
mkswap /dev/vglvm/swap && swapon /dev/vglvm/swap
useradd -m -G wheel user01
passwd user01
export EDITOR=vim
visudo # uncomment: %wheel ALL=(ALL) ALL
Encrypting /home
Create a key file on the root partition (the folder can be renamed, update crypttab accordingly):
mkdir -m 700 /etc/luks-keys
dd if=/dev/random of=/etc/luks-keys/home bs=1 count=256
cryptsetup luksFormat -c aes-xts-plain64 -s 512 /dev/vglvm/home /etc/luks-keys/home
cryptsetup luksOpen --allow-discards -d /etc/luks-keys/home /dev/vglvm/home home
mkfs.ext4 /dev/mapper/home
tune2fs -m 0 /dev/mapper/home # reclaims the 5% reserved space
mkfs.ext4 /dev/vglvm/tmp && mount /dev/vglvm/tmp /tmp
Then enable /home and swap in crypttab and fstab, reboot and check with lsblk -f.
Post-installation
pacman -Syu
pacman-key --init
Install the yay AUR helper:
mkdir sources && cd sources
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
Audio, graphics drivers and X server:
sudo pacman -S pulseaudio pulseaudio-alsa
speaker-test -c 2
alsactl store
sudo pacman -S mesa xf86-input-libinput xorg-xinit xorg-twm xorg-xclock
Keyboard layout under Xorg, file /etc/X11/xorg.conf.d/10-evdev.conf:
Section "InputClass"
Identifier "evdev keyboard catchall"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
Option "XkbLayout" "fr"
Driver "evdev"
EndSection
XFCE desktop
sudo pacman -S xfce4 xfce4-goodies lightdm-gtk-greeter-settings gtk-xfce-engine
sudo systemctl enable lightdm
In /etc/lightdm/lightdm.conf: greeter-session = lightdm-gtk-greeter. To start with startx:
echo "exec startxfce4" > ~/.xinitrc
With NetworkManager, disable dhcpcd to avoid conflicts:
sudo pacman -S network-manager-applet
sudo systemctl disable dhcpcd.service
sudo systemctl enable NetworkManager.service
sudo systemctl start NetworkManager.service
Firewall
sudo ufw enable
sudo ufw logging on
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw reload
Notes
- Disk names (
sda1,sda2,sda3) and volume names are examples to adapt. - The original note had two GRUB command-line variants: with LVM (above) and without LVM (
cryptdevice=/dev/sda2:root root=/dev/mapper/root). - User, machine and host names were replaced with generic values.