Skip to content

Instantly share code, notes, and snippets.

@kmikko
Last active March 10, 2024 02:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kmikko/9b179ce51d5063b6b09f070aa1f0d67c to your computer and use it in GitHub Desktop.
Save kmikko/9b179ce51d5063b6b09f070aa1f0d67c to your computer and use it in GitHub Desktop.
Arch Linux installation guide with LVM on LUKS

Arch Linux Installation Guide

Create bootable USB

Download Arch Linux iso file: https://www.archlinux.org/download/

Plug and identify your USB flash drive

lsblk

Unmount if necessary

umount /run/media/<user>/<uuid>

Create bootable USB

sudo dd if=archlinux-2017.03.01-dual.iso of=/dev/sdX status=progress bs=4M && sync

Installation

Prepare

Load proper keyboard layout

loadkeys fi

Connect to Wi-Fi

wifi-menu

Test connection

ping -c 3 google.com

Partition disk

Identify devices

lsblk | grep -v "rom\|loop\|airoot"

Creates 2 partitions, one EFI System Partition and one ext4 partition for LUKS

parted /dev/sda
mklabel gpt
mkpart ESP fat32 1MiB 513MiB
set1 boot on
mkpart primary ext4 513MiB 100%
quit

Verify partitions

lsblk /dev/sda

Set EFI partition to use FAT32 file system

mkfs.vfat -F32 /dev/sda1

Setup encryption using LUKS

cryptsetup -c aes-xts-plain64 -y --use-random luksFormat /dev/sda2
cryptsetup luksOpen /dev/sda2 luks

Create encrypted partitions

Creates 3 partitions; 16GB swap, 128GB /home and rest for /root.

pvcreate /dev/mapper/luks
vgcreate vg0 /dev/mapper/luks
lvcreate --size 16G vg0 --name swap
lvcreate --size 128G vg0 --name home
lvcreate -l 100%FREE vg0 --name root

Create file systems on encrypted partitions

mkswap /dev/mapper/vg0-swap
mkfs.ext4 /dev/mapper/vg0-home
mkfs.ext4 /dev/mapper/vg0-root

Mount partitions

swapon /dev/mapper/vg0-swap
mount /dev/mapper/vg0-root /mnt
mkdir /mnt/home
mount /dev/mapper/vg0-home /mnt/home
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

Install base system

pacstrap /mnt base base-devel

Generate fstab file

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

Edit fstab and change all relatime values on non-boot partitions to noatime to reduce SSD wear

Change root into the new system:

arch-chroot /mnt

Set locale

Uncomment line: en_US.UTF-8 UTF-8

nano /etc/locale.gen

Generate locale

locale-gen

Set LANG variable

echo LANG=en_US.UTF-8 > /etc/locale.conf
export LANG=en_US.UTF-8

Set timezone

ln -s /usr/share/zoneinfo/Europe/Helsinki /etc/localtime

Set HW clock to UTC

hwclock --systohc --utc

Set hostname

echo <hostname> > /etc/hostname

Set root password

passwd

Setup Wi-Fi

pacman -S iw wpa_supplicant dialog

Add non-root user

useradd -m -G wheel -s /bin/bash <username>
passwd <username>

Allow members of group wheel sudo access

Uncomment following line from /etc/sudoers

%wheel      ALL=(ALL) ALL

Configure mkinitcpio

Edit /etc/mkinitcpio.conf Add ext4 to MODULES

MODULES="ext4

Add encrypt and lvm2 to HOOKS before filesystems

HOOKS="base udev autodetect modconf block keymap encrypt lvm2 filesystems keyboard fsck"

Regenerate initrd image

mkinitcpio -p linux

Install and configure a bootloader

pacman -S grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub_uefi --recheck

Edit /etc/default/grub

GRUB_CMDLINE_LINUX="cryptdevice=/dev/sda2:luks:allow-discards"

Generate main configuration file

grub-mkconfig -o /boot/grub/grub.cfg
efibootmgr -c -g -d /dev/sda -p 1 -w -L "Arch Linux (GRUB)" -l /EFI/grub_uefi/grubx64.efi

Unmount all partitions

exit
umount -R /mnt
swapoff -a

Reboot and pray

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