posts-go/posts/2022-12-25-archlinux.md

11 KiB

Install Arch Linux

Install Arch Linux is thing I always want to do for my laptop/PC since I had my laptop in ninth grade.

This is not a guide for everyone, this is just save for myself in a future and for anyone who want to walk in my shoes.

Installation guide

Pre-installation

Check disks carefully:

lsblk

USB flash installation medium

Verify the boot mode

Check UEFI mode:

cat /sys/firmware/efi/fw_platform_size
# 64 or 32 is UEFI
# File not found is BIOS

Connect to the internet

For wifi, use iwd.

Partition the disks

GPT fdisk:

cgdisk /dev/sdx

UEFI/GPT layout:

Mount point Partition Partition type Suggested size gdisk code
/mnt/efi /dev/efi_system_partition EFI System Partition 512 MiB EF00
/mnt/boot /dev/extended_boot_loader_partition Extended Boot Loader Partition (XBOOTLDR) 1 GiB EA00
/mnt /dev/root_partition Root Partition 8300

Why not /boot/efi? See Lennart Poettering comment.

BIOS/GPT layout:

Mount point Partition Partition type Suggested size gdisk code
BIOS boot partition 1 MiB EF02
/mnt /dev/root_partition Root Partition 8300

LVM (optional):

# Create physical volumes
pvcreate /dev/sdaX

# Create volume groups
vgcreate RootGroup /dev/sdaX /dev/sdaY

# Create logical volumes
lvcreate -l +100%FREE RootGroup -n rootvol

Format:

# efi
mkfs.fat -F32 /dev/efi_system_partition

# boot
mkfs.fat -F32 /dev/extended_boot_loader_partition

# root
mkfs.ext4 -L ROOT /dev/root_partition

# root with btrfs (optional)
mkfs.btrfs -L ROOT /dev/root_partition

# root on lvm (optional)
mkfs.ext4 /dev/RootGroup/rootvol

Mount:

# root
mount /dev/root_partition /mnt

# root with btrfs (optional)
mount -o compress=zstd /dev/root_partition /mnt

# root on lvm (optional)
mount /dev/RootGroup/rootvol /mnt

# efi
mount --mkdir /dev/efi_system_partition /mnt/efi

# boot
mount --mkdir /dev/extended_boot_loader_partition /mnt/boot

Installation

Please check Mirrors if you have slow Internet.

pacstrap -K /mnt base linux linux-firmware

# AMD (optional)
pacstrap -K /mnt amd-ucode

# Intel (optional)
pacstrap -K /mnt intel-ucode

# Btrfs (optional)
pacstrap -K /mnt btrfs-progs

# LVM (optional)
pacstrap -K /mnt lvm2

# zsh (optional)
pacstrap -K /mnt zsh

# Text editor
pacstrap -K /mnt neovim

Configure

fstab

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

Chroot

arch-chroot /mnt

Time zone

# Change Region/City to your location
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime

hwclock --systohc

Localization:

Edit /etc/locale.gen then uncomment # en_US.UTF-8 UTF-8 by removing # at the beginning.

Generate locales:

locale-gen

Edit /etc/locale.conf:

LANG=en_US.UTF-8

Network configuration

Edit /etc/hostname:

myhostname

Initramfs

Edit /etc/mkinitcpio.conf:

# https://wiki.archlinux.org/title/mkinitcpio#Common_hooks
# Replace udev with systemd
#
# LVM (optional)
# https://wiki.archlinux.org/title/Install_Arch_Linux_on_LVM#Adding_mkinitcpio_hooks
# Add lvm2 between block and filesystems
#
HOOKS=(base systemd ... block lvm2 filesystems)
mkinitcpio -P

Root password

passwd

NetworkManager

pacman -Syu networkmanager dhcpcd iwd
systemctl enable NetworkManager.service
systemctl enable systemd-resolved.service

Edit /etc/NetworkManager/conf.d/wifi_backend.conf:

[device]
wifi.backend=iwd

Edit /etc/NetworkManager/conf.d/wifi_rand_mac.conf:

[device-mac-randomization]
wifi.scan-rand-mac-address=yes
 
[connection-mac-randomization]
ethernet.cloned-mac-address=stable
wifi.cloned-mac-address=stable

Bluetooth

pacman -Syu bluez
systemctl enable bluetooth.service

Clock

Use systemd-timesyncd

timedatectl set-ntp true

timedatectl status

Boot loader

Use systemd-boot

Install using XBOOTLDR:

bootctl --esp-path=/efi --boot-path=/boot install

systemctl enable systemd-boot-update.service

Label partition

Edit /efi/loader/loader.conf:

default	archlinux.conf
timeout 4
editor no
console-mode max

Edit /boot/loader/entries/archlinux.conf:

title Arch Linux
linux /vmlinuz-linux

# Intel (optional)
initrd /intel-ucode.img

# AMD (optional)
initrd /amd-ucode.img

initrd /initramfs-linux.img

# Kernel parameters (optional)
#
# Acer Nitro AN515-45
# https://wiki.archlinux.org/title/backlight#Kernel_command-line_options
# acpi_backlight=vendor
#
# NVIDIA
# https://wiki.archlinux.org/title/NVIDIA#DRM_kernel_mode_setting
# nvidia-drm.modeset=1
#
options root="LABEL=ROOT" rw quiet loglevel=3 nowatchdog module_blacklist=iTCO_wdt,sp5100_tco ipv6.disable=1 init_on_alloc=1 init_on_free=1 page_alloc.shuffle=1

General recommendations

Always remember to check dependencies when install packages.

System administration

Sudo:

pacman -Syu sudo

EDITOR=nvim visudo
# Uncomment group wheel by removing % at the beginning of %wheel ...

# Add user if don't want to use systemd-homed
useradd -m -G wheel -c "The Joker" joker

# Or using zsh (optional)
useradd -m -G wheel -s /usr/bin/zsh -c "The Joker" joker

# Set password
passwd joker
systemctl enable systemd-homed.service

homectl create joker --real-name="The Joker" --member-of=wheel

# Using zsh (optional)
homectl update joker --shell=/usr/bin/zsh

Note: Can not run homectl when install Arch Linux. Should run on the first boot.

Desktop Environment

Install Xorg:

pacman -Syu xorg-server

# Remember to install GPU driver

KDE

See KDE Distributions/Packaging Recommendations

pacman -Syu plasma-desktop

# Login manager
pacman -Syu sddm

Worth trying

List of applications

pacman

Uncomment in /etc/pacman.conf:

# Misc options
Color
ParallelDownloads
systemctl enable paccache.timer

Pipewire

pacman -Syu pipewire wireplumber \
	pipewire-alsa pipewire-pulse \
	gst-plugin-pipewire pipewire-v4l2

See Advanced Linux Sound Architecture

pacman -Syu sof-firmware

Flatpak

pacman -Syu flatpak

Improving performance

Edit /etc/systemd/journald.conf.d/00-journal-size.conf then restart:

[Journal]
SystemMaxUse=50M

Edit /etc/systemd/coredump.conf.d/custom.conf then restart:

[Coredump]
Storage=none
ProcessSizeMax=0

Enable ext4 fast commit:

tune2fs -O fast_commit /dev/partition

Periodic TRIM:

systemctl enable fstrim.timer

Edit /etc/sysctl.d/99-sysctl.conf:

# Enable TCP Fast Open
net.ipv4.tcp_fastopen = 3

kernel.split_lock_mitigate = 0

Security

# Kernel parameters

Hardware dependent

Experiment

Do it at your own risk!!!

Maintenance

See pacman/Tips and tricks

sudo pacman -Syu

In the end

This guide is updated regularly I promise.