Arch Linux Installation Guide

A full guide to help you install a fresh Arch Linux distribution on your computer.

If you have heard about static blog website engines, you should known hexo.

1. Prepare Installation Media

For Chinese users, download iso image file from Tsinghua mirror.

It is highly recommended to validate the GPG signature of the file. Whether you are downloading the image from archlinux official site or a mirror site, there should be a .sig GPG signature file alongside the image .iso. Download that signature file as well. Check the integrity of the image by

1
gpg --verify archlinux-ver-x86_64.iso.sig archlinux-ver-x86_64.iso

where ver should be replaced by the actual version of archlinux downloaded.

Burn the image into a removable media (USB driver, hard drive, etc.). There are a bunch of softwares to burn image, you could use Etcher Balena which is the one recommended by the Ubuntu installation.

The media contains a copy of so called “live system”. You would plug in the installation media and boot into this live system. The live system does not support secure boot, so turn off secure boot in the BIOS settings.

Go to BIOS menu, for Levono Xiaoxin Pro 14 2023, it’s by pressing F2 in the first few seconds of startup. Configure the boot sequence to make the installation media the very first one. Press F10 to exit BIOS and boot into the live system.

2. Live System Settings

It should take just a few minutes to copy the live system files into RAM. After that you are presented by a zsh shell of the live system. The live system has already preinstalled many softwares, tools and services to ease your installation process. But remember that nothing will be copied from the live system to the target system you would use in the future. You would be able to install necessary things before booting the target system shortly, though.

First, check your keyboard layout. The default layout for US. If yours is not, set by

loadkeys delatin1.

Pick a suitable font for the terminal. For HiDPI monitors, the largest font available

setfont ter-132b

Check the system is 64-bit

cat /sys/firmware/efi/fw_platform_size

should give you 64.

Next, connect to the internet. I am working on a laptop without a place to LAN cable, so I’m gonna demonstrate how to connect to wireless networks (WiFi).

ip link to print the network interface. If it’s not up

ip link set wlan0 up

Your network interface may not have exactly the same name as wlan0.

If that failed, it’s most likely that rfkill has block the device.

rfkill unblock wlan0

The we shall use iwctl to connect to a hotspot. Type iwctl to enter an interactive session. Then these commands can help you connect to your home WiFi. Replace <wifiname> with the actual name.

  • device list to show available hotspots
  • device <device> set-property Powered on if it’s not powered on
  • station wlan0 scan (wlan0 is the device name in the previous step)
  • station wlan0 get-networks prints a list of hotspot names
  • station wlan0 connect <wifiname>

Then quit the session and ping archlinux.org to check network is indeed connected.

Run timedatectl to verfiy the system clock is syncronized. The live system has systemd-timesyncd service enabled by default, and the clock will be synced as soon as an active internet connection is made.

To install a copy of Arch Linux on our machine, we need to partition and format the disk (HDDs and SSDs). Depending on your hardware and needs, you will need three partions, or more:

  1. A UEFI boot partition
  2. A swap memory partion (optional)
  3. The linux filesystem that’s going to hold the OS and your files

Partition

Let’s write the partition table with fdisk

Other disk format tools are available in the live system, simply pick one you feel comfortable with.

Type fdisk -l to print a list of the current partition tables of all the drives on the computer. Check them, if the partition table (probably from your previous operating system) is already good, you can skip this step.

fdisk /dev/nvme0n1 to enter an interactive session. On my laptop there is only one solid state drive (SSD) named nvme0n1, replace that with the actual name of your drive.

  1. g to erase the partition table and start with a fresh one.
  2. n to create a new partition, use +500M, +4G to specify the sector size. For the UEFI sector, no less than 500M is enough. I designated a 4G sector for the swap memory. The rest of the disk (about 470 gigabytes) is left for the Linux Filesystem.
  3. t to change the partition we’ve just created, pick UEFI/SWAP/Linux Filesystem
  4. repeat step 2 and step 3 to create all partitions you like.

During the fdisk session, nothing will be flushed to the disk until you explicitly send w to write and exit.

Important note: I picked ‘Linux filesystem’ for the type of the third sector (the main filesystem) . However, that is not mandatory. If you would like some advance features such as dynamic volume resizing in a dual-boot settings. You could opt for LVM (Logical Volume Manager) instead, which involves some additional settings and twists. Since I am going to install Arch Linux as the only operating system on the computer, I chose the vanilla type.

Formatting

Then we’re ready to format the partitions we’ve just made

Format the boot sector as FAT32
mkfs.fat -F 32 /dev/nvme0n1p1

Initialize the swap region
mkswap /dev/nvme0n1p2

Format the main filesystem as EXT-4
mkfs.ext4 /dev/nvme0n1p3

Mount

Mount the disk sectors to their Linux pathes

1
2
3
mount /dev/nvme0n1p3 /mnt
mount /dev/nvme0n1p1 /mnt/boot
swapon /dev/nvme0n1p2 # activate the swap

Notice the /mnt prefix here. We prefix everything with /mnt because we will chroot into that later, and the new system makes /mnt his root /.

Install the Linux kernel and drivers

Hooray! We’ve done a lot to prepare the disk for the fresh system, and we’ve come to the exciting step to install the KERNEL. Any Linux distribution (including Arch) is built on top of a common Linux kernel, which sits at the heart of the system to provide the most vital functionalities.

vim /etc/pacman.d/mirrorlist
Add the folling line to the very first
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch

You may pick other mirror sites which give you the best bandwidth. The official wiki has a section that summarizes available sites all over the world.

pacstrap -K /mnt base linux linux-firmware base-devel

base is a minimal toolset for Arch. linux is the linux kernel. linux-firmware provdies hardware drivers. base-devel, a set of tools to build Arch Linux packages, is optional but recommended to install before we boot into the new system.

You could add more packages to the end of the command as long as you wish, such as vim or neofetch, etc. You also have a chance to use pacman to install packages shortly.

3. Dive Into The New System

Create the fstab file by
genfstab -U /mnt >> /mnt/etc/fstab

Check the file cat /mnt/etc/fstab to verify the partitions are good.

Finally, chroot into the new system.

1
arch-chroot /mnt

Now the previous /mnt directory is the new root /.

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime sets the local timezone.

hwclock --systohc generates /etc/adjtime. systohc means setting the Hardware Clock to the current System Time.

vim /etc/locale.gen, uncomment line en_US.UTF-8 UTF-8. You could uncomment more locales such as zh_CN.GBK if needed. You can also do that after rebooting later.

If you haven’t install vim or other editors, you could use nano or pacman -S vim

Generate the locales by locale-gen.

vim /etc/locale.conf set the content to LANG=en_US.UTF-8.

vim /etc/hostname pick a nice hostname.

Network Checking

That’s quite a lot of work. The new system is nearly set up and ready for a reboot. But there is a very important thing to check for before rebooting: the network. Keep in mind archlinux is a quite slim distribution, it barely includes anything in a fresh copy. The live disk includes many tools, but they won’t be available after rebooting. The iwctl we used before is only available on the live system. Nothing (actually one thing for exception, the mirrorlist file we editted before) will be copied from the live system to the new system.

Therefore, if you haven’t install any network management tools, and you reboot right now, also unfortunately you are with a wireless connection (a wired connection probably works out-of-the-box), then you are in trouble. You could find yourself in dead lock that you can’t connect to the internet and pacman can’t install more packages for you, including network managers.

For a complete list of network managers available and their pros and cons, check out wiki.

Typically speaking, you have two major choices: networkmanager or netctl. Installing either of them should do. I strongly suggest not installing or enabling both of them. If you enable networkmanager by systemctl enable NetworkManager, you will see some weird errors when you use netctl to enable a network profile later.

Option 1: networkmanager

pacman -S networkmanager

Option 2: netctl, with a few optional dependencies

pacman -S netctl wpa_supplicant dhcpcd dialog

  • wpa_supplicant for wireless networking support
  • dhcpcd for DHCP support
  • dialog for menu based wifi assistant wifi-menu

Both networkmanager and netctl provide a set of command line interface and a TUI client for managing network profiles.

Optionally, install wireless_tools for some utility tools to monitor wireless connections

pacman -S wireless_tools

It’s a good idea to install more packages via pacman at this point, consider stuff like

  • sof-firmware if you have an intel sound card
  • man-db for extra man pages
  • an editor like vim or nvim

Create accounts

Set root user password by passwd.

It’s strongly recommended to create non-priviledge users and use them for daily work, rather than using the root user. You may create user by

useradd -m <username>

passwd <username> to set his password.

To make him sudoers, type visudo to edit the sudoer file. Add a line under the root line

<username> ALL=(ALL)ALL>

Install a Boot Loader (GRUB)

pacman -S grub efibootmgr os-prober

vim /etc/default/grub uncomment the last line, GRUB_DISABLE_OS_PROBER.

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

Generate GRUB config file grub-mkconfig -o /boot/grub/grub.cfg

exit to leave the chroot shell and reboot to restart the machine.

After seeing the GRUB interface you should be logged on into the new system.

4. Post Installation Configuration

Enable and start systemd-resolved service for DNS, otherwise you might encounter errors using netctl to connect to the internet.

If you installed dialog before, you can type wifi-menu to get into a graphical UI to pick WiFi hotspot to connect to.

Other topics include

  • Install a terminal emulator like Alacritty
  • Install a desktop environment (DE) like Hyprland or KDE
  • Install an AUR helper like yay
  • Install a login manager like sddm or gdm
  • Install a status bar / dock like waybar
  • Install a Chinese font like adobe-source-han-sans-cn-fonts
  • Install a file manager like dolphin
  • Install necessary drivers to control volume, bluetooth, backlight, etc.
  • Other interesting stuff like rofi, swaylock, swww, wlogout, etc.

To list explicitly installed packages (pacman and AUR included), run pacman -Qe

Note this command list all packages installed by pacman and AUR packages. To list only AUR packages, run pacman -Qem.

Maintaining a list like this helps to easily clone standard packages on different machines.

The new system does not have systemd-timesyncd enabled. It’s a good idea to enable that as early as possible after you login, to avoid the clock of the new system to be off. Run

1
2
systemctl enable systemd-timesyncd
systemctl start systemd-timesyncd

Then timedatectl to verify “System Clock Synchronized”.

5. System Glitch Recovery

For sure, Arch Linux users love to run pacman -Syu to update all packages. This updates everything, including the boot manager grub, if you use that. It is possible that the upgrade will break your grub configuration, resulting in failure to enter GRUB when you boot. The computer normally prompts you to choose a different boot option as it can’t find grub to start with.

The solution is simple. You basically repeat part of the installation process above to reinstall grub.

  1. Plug in the installation media (live system)
  2. Mount all the partitions as they should
  3. arch-chroot into YOUR system (the broken one)
  4. Run grub-install and grub-mkconfig in the same way, reboot

References

  1. Official Wiki
  2. Bilibili Video
  3. Arch Linux: Full Installation Guide