Skip to content

Instantly share code, notes, and snippets.

@f4str
Last active December 31, 2022 04:26
Show Gist options
  • Select an option

  • Save f4str/0e00c26ef92039c7d2ea37ef96f4f81b to your computer and use it in GitHub Desktop.

Select an option

Save f4str/0e00c26ef92039c7d2ea37ef96f4f81b to your computer and use it in GitHub Desktop.
Guide to install Arch Linux

Arch Linux Installation Guide

Guide to install Arch Linux on an EFI system. Uses the following features:

  • Btrfs with @, @home, @cache, @log, and @swap subvolumes
  • Swapfile
  • Snapshots using Timeshift
  • GRUB bootloader with bootable snapshots
  • GNOME desktop environment
  • GDM display manager

NOTE: This guide is mainly for educational purposes. For a practical Arch Linux installation, use EndeavourOS as it performs most of these steps automatically.

Step 1: Sync and Setup Mirrors

Enable network time sync.

timedatectl set-ntp true

Sync with the Arch servers and install reflector.

pacman -Sy reflector rsync

Backup the previous mirror list. Then use reflector to save the fastest pacman mirrors. Use your county name. This is mostly likely US. This will take some time.

cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
reflector -c US -l 200 -f 6 --sort rate --connection-timeout 1 --download-timeout 1 --verbose --save /etc/pacman.d/mirrorlist

Edit the pacman configuration to enable parallel downloads and color.

vim /etc/pacman.conf
- #ParallelDownloads
- #Color
+ ParallelDownloads
+ Color

Step 2: Disk Partitioning

List your current disks.

lsblk -p

Choose the disk you want to erase, format, and install Arch Linux on. This is typically /dev/sda, /dev/nvme0n1, or /dev/vda. Run sgdisk to wipe the disk and then gdisk to start partitioning.

sgdisk -Z /dev/vda
gdisk /dev/vda

Creating each partition in gdisk is 3 steps. Choose the partition start, choose the partition size, and choose the partition type.

EFI Partition

Type n and hit enter to create a new partition. Hit enter to leave the defaults for the partition start. Type +512M and hit enter to create a 512MB size partition (this can be smaller but 512MB is recommended for Windows dual booting). Type ef00 and hit enter to choose EFI partition type.

Root Partition

Type n and hit enter to create a new partition. Hit enter to leave the defaults for the partition start. Hit enter to use the remainder of the disk. Hit enter to choose the default partition type.

Type w and hit enter to write and save the partitioning.

Step 3: Disk Formatting

List your current disks partitions.

lsblk -p

Remember the device names for the EFI and root partitions. This is typically as follows.

Type EFI Partition Root Partition
SATA Disks /dev/sda1 /dev/sda2
NVMe Disks /dev/nvme0n1p1 /dev/nvme0n1p2
Virtual Machines /dev/vda1 /dev/vda2

The instructions will use /dev/vda, but use what is specific to your machine.

Format the EFI partition as FAT32.

mkfs.vfat -F32 /dev/vda1

Format the root partition as btrfs.

mkfs.btrfs /dev/vda2

Verify everything mounted correctly using lsblk.

Step 4: Mounting and Btrfs Subvolumes

Mount the root partition onto /mnt.

mount /dev/vda2 /mnt

Subvolumes

Create btrfs subvolumes for @, @home, @cache, @log, and @swap.

btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@cache
btrfs subvolume create /mnt/@log
btrfs subvolume create /mnt/@swap

Umount the root partition

umount /mnt

Choose the Btrfs optimization options you want. The following are recommended: noatime,compress=zstd:1,space_cache=v2. If running on an SSD, also use ssd. If running on an HDD, also use autodefrag. Mount the root partition using these optimization options.

mount -o noatime,compress=zstd:1,space_cache=v2,ssd,subvol=@ /dev/vda2 /mnt

Create directories for the EFI partition, recovery partition, and each of the subvolumes.

mkdir -p /mnt/{boot/efi,recovery,home,var,swap}

Mount each of the subvolumes except swap using the same options to the corresponding directories.

mount -o noatime,compress=zstd:1,space_cache=v2,ssd,subvol=@home /dev/vda2 /mnt/home
mount -o noatime,compress=zstd:1,space_cache=v2,ssd,subvol=@cache /dev/vda2 /mnt/var/cache
mount -o noatime,compress=zstd:1,space_cache=v2,ssd,subvol=@log /dev/vda2 /mnt/var/log

Mount the EFI partition onto the /boot/efi directory.

mount /dev/vda1 /mnt/boot/efi

Verify everything is mounted correctly using lsblk.

Swapfile

Mount the swap subvolume to the /swap directory with only the noatime and ssd optimization options.

mount -o noatime,ssd,subvol=@swap /dev/vda2 /mnt/swap

Disable copy-on-write for the @swap subvolume.

sudo chattr -R +C /mnt/swap

Create the swapfile, disable copy-on-write, disable compression, and allocate it to 4GB.

touch /mnt/swap/swapfile
chattr +C /mnt/swap/swapfile
btrfs property set /mnt/swap/swapfile compression none
dd if=/dev/zero of=/mnt/swap/swapfile bs=1M count=4096 status=progress

Set permissions, format the swapfile, and activate it.

chmod 600 /mnt/swap/swapfile
mkswap /mnt/swap/swapfile
swapon /mnt/swap/swapfile

Verify everything is mounted correctly using lsblk.

Step 5: Installing Arch Base

Use pacstrap to install the base packages. If you have an Intel CPU, use intel-ucode. If you have an AMD CPU, use amd-ucode. This will take some time.

pacstrap /mnt base linux linux-firmware sudo vim nano git intel-ucode btrfs-progs

Create the file system table.

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

Enter the installed system.

arch-chroot /mnt

Edit the file system table for the swap subvolume. Remove all Btrfs flags except rw, noatime, subvolid, and subvol flags.

vim /etc/fstab
- rw,noatime,compress=zstd:1,ssd,space_cache=v2,subvolid=261,subvol=/@swap
+ rw,noatime,subvolid=261,subvol=/@swap

Step 6: Configuring Locales

Enable network time sync.

timedatectl set-ntp true

Set your timezone. If you are in the United States East Coast, it is America/New_York.

timedatectl set-timezone America/New_York

Sync the hardware clock.

hwclock --systohc

Edit the locale gen to enable United States English UTF-8.

vim /etc/locale.gen
- #en_US.UTF-8 UTF-8
+ en_US.UTF-8 UTF-8

Regenerate the locale file.

locale-gen

Set the locale language, time, and keyboard.

localectl set-locale LANG="en_US.UTF-8"
localectl set-locale LC_TIME="en_US.UTF-8"
localectl set-keymap us

Set the hostname.

vim /etc/hostname
+ arch

Set the host.

vim /etc/hosts
+ 127.0.0.1   localhost
+ ::1         localhost
+ 127.0.1.1   arch.localdomain   arch

Step 7: Installing Arch System

Installing Packages

Edit the pacman configuration to enable parallel downloads and color.

vim /etc/pacman.conf
- #ParallelDownloads
- #Color
+ ParallelDownloads
+ Color

Sync to the Arch servers and update packages.

pacman -Syu

Install the necessary Arch packages. This will take some time.

# basic packages
pacman -S base-devel linux-headers reflector rsync bash-completion
# bootloader
pacman -S grub grub-customizer efibootmgr os-prober
# network
pacman -S networkmanager network-manager-applet dialog wpa_supplicant 
# network utilities
pacman -S inetutils avahi bind openssh firewalld
# audio
pacman -S pipewire pipewire-alsa pipewire-pulse pipewire-jack alsa-utils
# file systems
pacman -S dosfstools exfatprogs e2fsprogs ntfs-3g nfs-utils gvfs gvfs-smb mtools
# desktop utilities
pacman -S xdg-user-dirs xdg-utils
# bluetooth
pacman -S bluez bluez-utils
# power management
pacman -S acpi acpi_call acpid tlp
# fonts
pacman -S awesome-terminal-fonts noto-fonts-emoji powerline-fonts terminus-font
# printer
pacman -S cups

Enable Services

Enable the services on system startup.

systemctl enable NetworkManager
systemctl enable sshd
systemctl enable avahi-daemon
systemctl enable reflector.timer
systemctl enable firewalld
systemctl enable acpid
systemctl enable fstrim.timer # only on SSD
systemctl enable bluetooth # optional bluetooth
systemctl enable tlp # only on laptops
systemctl enable cups # optional printer

Enabling Btrfs

Edit the mkinit config to enable Btrfs.

vim /etc/mkinitcpio.conf
- MODULES=()
+ MODULES=(btrfs)

Regenerate the ramdisk init environment.

mkinitcpio -p linux

Installing the Bootloader

Install the GRUB bootloader.

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB

Edit the GRUB configs to fix the resolution and enable OS prober.

vim /etc/default/grub
- #GRUB_GFXMODE=auto
- #GRUB_DISABLE_OS_PROBER=false
+ GRUB_GFXMODE=1920x1080,auto
+ GRUB_DISABLE_OS_PROBER=false

Generate the GRUB config.

grub-mkconfig -o /boot/grub/grub.cfg

Step 8: Creating a User

Create the user account and update the password. Replace user with the username.

useradd -mG wheel user
passwd user

Edit the sudoers to enable sudo access for the user.

EDITOR=vim visudo
- #%wheel ALL=(ALL) ALL
+ %wheel ALL=(ALL) ALL

Disable root.

passwd -l root

The system is now installed. Exit out of the chroot environment, umount all disks, remove the live ISO, and reboot.

exit
umount -a
reboot now

Boot through GRUB and log in to the command line interface.

Step 9: Installing GNOME Desktop Environment

Install the necessary display drivers.

# Intel
sudo pacman -S xf86-video-intel mesa vulkan-intel
# AMD
sudo pacman -S xf86-video-amdgpu mesa vulkan-radeon
# Nvidia
sudo pacman -S nvidia nvidia-utils

Install all Xorg packages.

sudo pacman -S xorg

Install the GDM display manager and GNOME desktop environment. This will take some time.

sudo pacman -S gdm gnome gnome-extra

Enable GDM for the login manager.

sudo systemctl enable gdm

Reboot the system and login.

sudo reboot now

Step 10: Btrfs Snapshots

Timeshift

Download and install an AUR helper. The recommended ones are yay and paru.

cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Install Timeshift from the AUR.

yay -S timeshift

Launch Timeshift and select the backup frequency. It is recommended to enable daily, weekly, and monthly snapshots.

(Optional) Install the timeshift-autosnap package to automatically create snapshots when using the package manager.

yay -S timeshift-autosnap

GRUB btrfs

Install grub-btrfs.

sudo pacman -S grub-btrfs

Edit the grub-brtfs config to use Timeshift instead of Snapper.

sudo EDITOR=vim systemctl edit --full grub-btrfsd
- ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots
+ ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto

Enable the grub-btrfs daemon.

sudo systemctl enable --now grub-btrfsd

Create a new snapshot in Timeshift and reboot. This should now automatically appear in the GRUB menu as a bootable snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment