How I have installed Arch Linux through trial and error

EDIT: This article was written when I was not aware of the importance of software freedom. Please note that Arch "Linux" is not 100% free software. You should consider using GNU/Linux distros that are completely free as in freedom.

Ever since a few years ago, the idea of having a try on Arch Linux has been in my mind. Unfortunately, never have I successfully installed this tiny but beginner-unfriendly distribution of Linux before. Each time when I thought I was ready for another try on the installation, I failed, just for the lifelong and complex installation progress.

Just a few days ago this idea came to my mind again. Yes, it is not a beginner-friendly operating system, but I don't think I'm a beginner anymore as I was years ago.

Again, I opened in my browser 7 step-by-step tutorials and 4 YouTube videos. I didn't read the official docs because I knew I wouldn't understand that abstruse writing.

After 4 hours of switching between black and white screens, I have finally managed to install Arch Linux. Epic.

Here I am writing down how exactly I was just working on the installation, in order to prevent me from spending another 4 hours on the same silly thing in the future.

Now let's assume you have entered the live system, the following things are just what you are going to do.

Connecting to the internet

As I have an Ethernet connection that works automatically after plugging in the cable, no more configuration is needed in this part. But if you are working with other types of connections, make sure to read the docs and learn how you should get connected.

Updating the system clock

After connecting to the internet, ensure the system clock is accurate:

# timedatectl set-ntp true

Partitioning, formatting and mounting

To be sure about which device of disks to start partitioning, run:

# fdisk -l

and the result would be like

Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 sectors
Disk model:  ...
Units: ...
Sector size (logical/physical): ...
I/O size (logical/physical): ...

Disk /dev/loop0: 604.05 MiB, 633393152 bytes, 1237096 sectors
Units: ...
Sector size (logical/physical): ...
I/O size (logical/physical): ...

This indicates I'll modify the partition tables of /dev/sda with

# cfdisk /dev/sda

With GPT selected as label type, here is how I partition the disk:

Partition

Now /dev/sda1 is for EFI, /dev/sda2 for swap and /dev/sda3 for the root. Format and mount them with the lines below:

# mkfs.vfat /dev/sda1
# mkswap /dev/sda2
# mkfs.ext4 /dev/sda3

# swapon /dev/sda2
# mount /dev/sda3 /mnt
# mkdir -p /mnt/boot/efi
# mount /dev/sda1 /mnt/boot/efi

Installing essential packages

Install the base package, Linux kernel, firmware for common hardware, etc:

# pacstrap /mnt base linux linux-firmware nano sudo

Configuring the system

Generate an fstab file which tells the system how partitions are mounted:

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

Change root into the new system rather than the live system of the ISO file:

# arch-chroot /mnt

Set the current time zone and update the hardware clock (here I am using Asia/Shanghai):

# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# hwclock --systohc

Edit the localization file with

# nano /etc/locale.gen

and uncomment #en_US.UTF-8 UTF-8 by removing the # before it.

Then, generate the locales and set the LANG variable by running:

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

Set the host name that identifies the machine (mine is Peaksol):

# echo "Peaksol" > /etc/hostname

Edit the hosts file with

# nano /etc/hosts

and add the following lines (be sure to change the host names to yours accordingly):

127.0.0.1   localhost
::1     localhost
127.0.1.1   Peaksol.localdomain Peaksol

Install dhcpcd for internet connection:

# pacman -S dhcpcd
# systemctl enable dhcpcd

Set the root password of the system:

# passwd

Create a user and set its password (replace peaksol with your name):

# useradd -mG wheel peaksol
# passwd peaksol

Edit the sudoers file with

# EDITOR=nano visudo

and uncomment # %wheel ALL=(ALL) ALL by removing the # before it.

Install grub and its optional dependencies:

# pacman -S grub efibootmgr dosfstools
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ArchLinux
# grub-mkconfig -o /boot/grub/grub.cfg

Lastly, end the installation with

# exit
# umount -a
# reboot

Conclusion

Peace. I know I still have a lot to do after installation, but that's a story for another day.