Getting started with Arch Linux

Last updated on 2022-04-11 Tagged under  #arch   #linux   #luks 

Arch Linux is a community developed, x86-64 GNU/Linux distribution based on a rolling-release model.

Rolling-release is a very different model from my longtime favourite Linux distro Debian, which roughly every two years makes a new stable release with packages locked to a specific version, receiving only security patches and bugfixes until the next release. Debian strives for stability by minimizing change, which might bring in system breaking surprises. Its an excellent Linux for servers.

Arch is not like that. The idea is the system will receive a continuous, incremental stream of updates to the latest stable versions of software. Below is my walk-through of the excellent installation guide and the choices I make along the way to create a basic encrypted Arch environment.

My setup

1. Install

1.1 Prepare USB install media

Download and verify checksums for archlinux-RELEASE_VERSION-x86_64.iso.

Prepare a USB flash drive as an installer using one of these two methods:

Method #1: Ventoy

I now use Ventoy to create a multiboot installer. Simply copy archlinux-RELEASE_VERSION-x86_64.iso to the USB drive, reboot, and the auto-generated menu lists all the disk images available to boot.

See: Create a multiboot USB installer with Ventoy

Method #2: dd

Write the installer to an unmounted USB storage device using the dd command as root.


Example: Under Linux, if a USB device appears as sdx1, then write the installer to sdx (remove partition number) ...

sudo dd if=archlinux-RELEASE_VERSION-x86_64.iso of=/dev/sdx bs=4M status=progress oflag=sync

1.2 Boot installer

Insert USB installer in target device and boot. Installer auto-logins as root.

1.2.1 Optional: Continue install from another Linux system via SSH

Enable SSH on the target device ...

systemctl start sshd.service

Set password for root ...


Look up IP address ...

ip a

Now, from the other system, ssh into the Arch installer ...

ssh root@ip.address.of.arch-installer

1.3 Keyboard layout

Default console keymap is us. List available layouts ...

localectl list-keymaps

Optional: Load a preferred keymap (example: colemak) ...

loadkeys colemak

1.4 Verify boot mode

If UEFI mode is enabled on an UEFI motherboard, Archiso will boot Arch Linux accordingly via systemd-boot.

Verify by listing contents of efivars ...

ls /sys/firmware/efi/efivars

If the directory does not exist, the system is booted in BIOS mode.

Note: If the target device has been manufactured within the last decade, chances are its a UEFI-capable device. All my current devices use UEFI boot mode and this HOWTO is based on UEFI. Some of the instructions below - drive partitioning and GRUB setup in particular - will need to be modified if using BIOS mode. Check out the Arch Wiki for details.

1.5 Connect to internet

Ethernet: auto-configured.

Wireless: see wireless network configuration and iwd.

1.6 Update system clock

timedatectl set-ntp true
timedatectl status

1.7 Set disk for install

Identify the internal storage device where Arch Linux will be installed by running lsblk -f.

Set a disk variable for use in installation commands.

Example: In this HOWTO I'm installing to my internal storage device identified as nvme0n1 ...

export disk="/dev/nvme0n1"

1.8 Delete old partition scheme

wipefs -af $disk
sgdisk --zap-all --clear $disk

1.8.1 Optional: Zero out disk

Wipe disk by using dd command to fill space with data from /dev/zero ...

dd if=/dev/zero of=${disk} bs=4096 status=progress

1.9 Partition disk

Use sgdisk to create partitions.

List partition type codes ...

sgdisk --list-types

Layout for a single SSD with a GPT partition table that contains two partitions:

sgdisk -n 0:0:+1GiB -t 0:ef00 -c 0:esp $disk
sgdisk -n 0:0:0 -t 0:8309 -c 0:luks $disk

Print the new partition table...

sgdisk -p $disk

In lieu of using a swapfile or dedicated swap partition as system swap memory, after the install is complete and I've rebooted into my new Arch environment I create a swap device in RAM.

See: Managing partitions with sgdisk

1.10 Encrypt linux partition

If the disk variable created earlier was set as a nvme-type storage device (as it was in this HOWTO), then the LUKS partition will be ${disk}p2. Otherwise, it will be ${disk}2 (drop the p).

Initialize the LUKS-encrypted partition (partition #2) ...

cryptsetup --type luks2 -y -v luksFormat ${disk}p2

1.11 Logical Volume Manager (LVM)

Open the LUKS device mapped to cryptdev ...

cryptsetup open ${disk}p2 cryptdev

Create physical volume...

pvcreate /dev/mapper/cryptdev

Create volume group vg ...

vgcreate vg /dev/mapper/cryptdev

1.12 LV containers

1.12.1 Root LV

If $disk is <= 128GB, I create a single root LV container and assign it 90% of free space ...

lvcreate -l +90%FREE vg -n root

1.12.2 Root + home LVs

Otherwise, I create separate root and home LVs. Its a more flexible arrangement, and makes any re-install or parallel install of a Linux OS easier (while leaving user files untouched).

Create an LV container for root and assign 30G of disk space ...

lvcreate -L 30G vg -n root

Create an LV container for home and assign +90% of free space ...

lvcreate -l +90%FREE vg -n home

View modifications ...


1.13 Format partitions

ESP partition (partition #1) is formatted with the vfat filesystem, and the Linux LVs use ext4 ...

mkfs.vfat -F32 -n ESP ${disk}p1
mkfs.ext4 /dev/vg/root

If separate home LV was created ...

mkfs.ext4 /dev/vg/home

1.14 Mount file systems

mount /dev/vg/root /mnt
mkdir /mnt/boot
mount /dev/disk/by-label/ESP /mnt/boot

Again, if separate home exists ...

mkdir /mnt/home
mount /dev/vg/home /mnt/home

1.15 Select package mirrors

Synchronize package databases ...

pacman -Syy

Generate a new mirror selection using reflector.

Example: Verbosely select the 5 most recently synchronized HTTPS mirrors located in either Canada or Germany, sort them by download speed, and overwrite mirrorlist ...

reflector --verbose --protocol https --latest 5 --sort rate --country Canada --country Germany --save /etc/pacman.d/mirrorlist

1.16 Install base system

Select an appropriate microcode package to load updates and security fixes from processor vendors.

View cpuinfo ...

grep vendor_id /proc/cpuinfo

Depending on the processor, set microcode for Intel ...

export microcode="intel-ucode"

... or for AMD ...

export microcode="amd-ucode"

Install the base system ...

pacstrap /mnt base base-devel ${microcode} linux linux-firmware bash-completion cryptsetup htop lvm2 man-db neovim networkmanager openssh pacman-contrib pkgfile reflector sudo terminus-font tmux

1.17 Fstab

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

1.18 Chroot

Chroot into the base system to configure ...

arch-chroot /mnt /bin/bash

1.19 Timezone

Set desired timezone (example: America/Toronto) and update the system clock ...

ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
hwclock --systohc

1.20 Hostname

Assign a hostname (example: foobox) ...

echo "foobox" > /etc/hostname

Add matching entries to /etc/hosts ...

cat > /etc/hosts <<EOF	localhost
::1         localhost	foobox.localdomain foobox

1.21 Locale

Set locale (example: en_CA.UTF-8) ...

export locale="en_CA.UTF-8"
sed -i "s/^#\(${locale}\)/\1/" /etc/locale.gen
echo "LANG=${locale}" > /etc/locale.conf

1.22 Font and keymap

Set a console font (example: terminus ter-224n) ...

echo "FONT=ter-v22n" > /etc/vconsole.conf

Set a keyboard layout choice (example: colemak) ...

echo "KEYMAP=colemak" >> /etc/vconsole.conf

1.23 Editor

Set a system-wide default editor (example: neovim) ...

echo "EDITOR=nvim" > /etc/environment && echo "VISUAL=nvim" >> /etc/environment

1.24 Root password

Assign password to root ...


1.25 Add user

Create a user account (example: foo) with superuser privileges ...

useradd -m -G wheel -s /bin/bash foo
passwd foo

Activate wheel group access for sudo ...

sed -i "s/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/" /etc/sudoers

1.26 NetworkManager

Enable NetworkManager to start at boot ...

systemctl enable NetworkManager

Wired network connection is activated by default. Run nmtui in the console and choose Activate a connection to setup a wireless connection.

1.27 SSH

Enable sshd server ...

systemctl enable sshd.service

After the install is complete and system has rebooted, secure remote access using SSH keys.

1.28 Mkinitcpio

Set necessary HOOKS in /etc/mkinitcpio.conf ...

HOOKS=(base systemd keyboard autodetect sd-vconsole modconf block sd-encrypt lvm2 filesystems fsck)

Order of the hooks matters:

Recreate the initramfs image ...

mkinitcpio -P

1.29 Boot loader: systemd-boot

Install ...

bootctl --esp-path=/boot install

Create /boot/loader/loader.conf ...

cat > /boot/loader/loader.conf <<EOF
default arch.conf
timeout 3
console-mode max
editor yes

Determine the UUID of the encrypted partition ...

blkid -s UUID -o value ${disk}p2

This string of characters is used in the boot entry created in the next step.

Create /boot/loader/entries/arch.conf:

title Arch
linux /vmlinuz-linux
initrd /intel-ucode.img (or /amd-ucode.img for AMD CPU)
initrd /initramfs-linux.img
options root=/dev/vg/root rw

List boot loader entries ...

bootctl list

1.30 Reboot and login

Exit chroot and reboot ...

umount -R /mnt

Systemd-boot prompts for the LUKS passphrase to unlock the system.

Then ... Voila!

archlinux login:

2. After the install

2.1 Check for errors

Failed systemd services ...

systemctl --failed

High priority errors in the systemd journal ...

journalctl -p 3 -xb

2.2 Update systemd-boot

Create ...

$ sudo mkdir /etc/pacman.d/hooks

Automatically update the boot manager whenever a new version of systemd-boot is reinstalled by creating /etc/pacman.d/hooks/100-systemd-boot.hook ...

Type = Package
Operation = Upgrade
Target = systemd

Description = Updating systemd-boot
When = PostTransaction
Exec = /usr/bin/bootctl update

2.3 Linux LTS kernel

Install the LTS kernel in Arch Linux

2.4 Fallback boot entries

Every time a kernel is installed or upgraded, mkinitcpio creates two initial ramdisk images: 1. A default image as per instructions in /etc/mkinitcpio.conf and /etc/mkinitcpio.d; 2. A fallback image that includes a whole range of modules built-in and bootable on most systems.

Create boot entries for these fallback images by copying /boot/loader/entries/arch.conf to /boot/loader/entries/arch-fallback.conf.

Modify the copied arch-fallback.conf with fallback settings ...

title Arch fallback


initrd /initramfs-linux-fallback.img

2.5 SSD

Periodic TRIM optimizes performance on SSD storage.

Enable a weekly task that discards unused blocks on the drive ...

$ sudo systemctl enable fstrim.timer

2.6 Desktop

Many choices! Install a full-featured desktop such as GNOME, or put together a custom desktop built around a lightweight window manager. I like Openbox.

2.7 Arch news

Keep up-to-date with the latest news from the Arch development team by subscribing to arch-announce or the news feed:

Welcome to Arch!

Thanks for reading! Read other posts?

» Later: Use zram for swap

« Earlier: Debian-after-install