Skip to content

Instantly share code, notes, and snippets.

@onosendi
Last active March 5, 2024 23:22
Show Gist options
  • Save onosendi/5b3bfffe51a2fd213164521c6983abc7 to your computer and use it in GitHub Desktop.
Save onosendi/5b3bfffe51a2fd213164521c6983abc7 to your computer and use it in GitHub Desktop.
Arch linux install: efi, btrfs, systemd boot.

Arch linux install

This is my current Arch linux installation. I created this for myself, so there's not much description.

What I want out of my install:

  • EFI boot partition
  • Btrfs filesystem to take advantage of snapshots
  • Systemd boot loader

Note: If you are not using full disk encryption, replace /dev/mapper/cryptroot with /dev/sdX2 throughout this guide.

Partition disk

Mount Point Partition Partition Type Size
/mnt/boot /dev/sdX1 ESP for UEFI 550 MiB
/mnt /dev/mapper/cryptroot Btrfs Remainder

One-liner

# sgdisk /dev/sdX -o -n 1::+550M -n 2 -t 1:ef00 -t 2:8300

Or

# gdisk /dev/sdX
  1. Press o: create empty partition table
    • Press y then enter
  2. Press n: create new partition.
    • Partition: 1
    • First sector: default
    • Second sector: +550M
    • Partition type: ef00
  3. Press n: create new partition
    • Partition: 2
    • First sector: default
    • Second sector: default
    • Partition type: default
  4. Press w: write table to disk and exit
    • Press y then enter

Create LUKS container (full disk encryption)

# cryptsetup luksFormat --type luks2 /dev/sdX2
# cryptsetup open /dev/sdX2 cryptroot

Format Partitions

# mkfs.fat -F32 /dev/sdX1
# mkfs.btrfs /dev/mapper/cryptroot

Mount the file systems

# mount /dev/mapper/cryptroot /mnt
# btrfs subvolume create /mnt/@
# btrfs subvolume create /mnt/@home
# umount /mnt
# mount -o compress=lzo,space_cache,subvol=@ /dev/mapper/cryptroot /mnt
# mkdir /mnt/{boot,home}
# mount /dev/sdX1 /mnt/boot
# mount -o compress=lzo,space_cache,subvol=@home /dev/mapper/cryptroot /mnt/home

Install essential packages

# pacstrap /mnt base base-devel vim btrfs-progs linux linux-firmware dhcpcd

Configure the system

Fstab

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

Chroot

# arch-chroot /mnt

Time zone

# timedatectl set-ntp true
# ln -sf /usr/share/zoneinfo/America/Phoenix /etc/localtime
# systemctl enable systemd-timesyncd.service --now
# hwclock --systohc

Localization

# echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
# echo LANG=en_US.UTF-8 > /etc/locale.conf
# locale-gen

Network Configuration

Set your hostname

# echo your-hostname > /etc/hostname

Edit your hosts file

/etc/hosts
----------

127.0.0.1  localhost
::1        localhost
127.0.0.1  your-host-name.localdomain your-host-name

List network devices

# ip link

Enable device

Note replace device with the device listed from ip link.

# systemctl enable dhcpcd@device.service

Initramfs

Remove fsck and add btrfs and encrypt to hooks

/etc/mkinitcpio.conf
--------------------
HOOKS=(base ... block btrfs filesystem ... encrypt)

Generate ramdisk

# mkinitcpio -p linux

Pacman

Add multilib

Uncomment the two following lines:

/etc/pacman.conf
----------------
...
[multilib]
Include = /etc/pacman.d/mirrorlist
...

Sync

# pacman -Syy

Users

Set root password

# passwd

Add normal user

# useradd -m -G wheel your-username
# passwd your-username

Give normal user sudo permission

# EDITOR=vim visudo

And uncomment the line:

# %wheel ALL=(ALL) ALL

Swap file

# btrfs subvolume create /.swap
# truncate -s 0 /.swap/swapfile
# chattr +C /.swap/swapfile
# dd if=/dev/zero of=/.swap/swapfile bs=1M count=2048
# chmod 600 /.swap/swapfile
# mkswap /.swap/swapfile

Mount swapfile at boot

/etc/fstab
----------
...
/.swap/swapfile none swap defaults 0 0

Boot loader

Install boot loader

# bootctl --path=/boot install

Install microcode

AMD users
# pacman -S amd-ucode
Intel users
# pacman -S intel-ucode

Create boot entries directory

# mkdir -p /boot/loader/entries

Loader configuration

/boot/loader/loader.conf
------------------------
default arch
timeout 3

Add loader entries

Note: Make sure your *-ucode.img corresponds to the one you installed. If you're not using full disk encryption, omit cryptdevice=....

Default
/boot/loader/entries/arch.conf
-------------------------------
title Arch Linux
linux /vmlinuz-linux
initrd /amd-ucode.img
initrd /initramfs-linux.img
options root=/dev/mapper/cryptroot cryptdevice=/dev/sdX2:cryptroot:allow-discards ro rootfstype=btrfs rootflags=subvol=/@
Fallback
/boot/loader/entries/arch-fallback.conf
---------------------------------------
title Arch Linux (Fallback)
linux /vmlinuz-linux
initrd /amd-ucode.img
initrd /initramfs-linux-fallback.img
options root=/dev/mapper/cryptroot cryptdevice=/dev/sdX2:cryptroot:allow-discards ro rootfstype=btrfs rootflags=subvol=/@

All finished, let's reboot

# exit
# reboot

Post-installation

Snapper

Install Snapper

# pacman -S snapper

Create configuration files

# snapper -c root create-config /

Create initial install snapshot

# snapper -c root create --description "Initial install"

Zsh

Install zsh, with grml configuration

# pacman -S zsh grml-zsh-config

Change shell for root and new user

# chsh -s /usr/bin/zsh
# chsh -s /usr/bin/zsh your-user-name

Log out, and log back in

# exit

X server

Install X server and additional packages

# pacman -S xorg-server xorg-xinit ttf-dejavu polkit rxvt-unicode git

Install open source video drivers

Intel users
# pacman -S xf86-video-intel
AMD users
# pacman -S xf86-video-amdgpu
Nvidia users
# pacman -S xf86-video-nouveau

Gnome-keyring

Install

# pacman -S gnome-keyring

Update pam login

/etc/pam.d/login
----------------
auth
...
auth optional pam_gnome_keyring.so
session
...
session optional pam_gnome_keyring.so auto_start

bspwm (tiling window manager)

Install

# pacman -S bspwm sxhkd dmenu

Create config directories

# mkdir -p ~/.config/bspwm
# mkdir ~/.config/sxhkd

Copy example configs

# cp /usr/share/doc/bspwm/examples/bspwmrc ~/.config/bspwm
# cp /usr/share/doc/bspwm/examples/sxhkdrc ~/.config/sxhkd

Make bspwmrc executable

# chmod +x ~/.config/bspwm/bspwmrc

Execute bspwm when X starts

~/.xinitrc
----------
exec bspwm

Start X when logging in via shell on tty1

Note: Bash users should use .bash_profile instead of .zprofile.

~/.zprofile
-----------
if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
  exec startx > /tmp/xorg.log 2>&1
fi

Log out, log in, voila.

Note: You'll most likely be at a black screen. Here are some basic hotkeys to get started:

  • super+enter spawn a terminal
  • super+space run dmenu
  • $ bspc quit exit your session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment