Skip to content

Not Just How, But Why: Arch Linux Install Guide

Published: at 03:30 AM
|
ArchLinux

This guide will walk you through creating partitions, formatting them, mounting the system, and installing a basic Linux system using pacstrap.

This tutorial assumes you’re using UEFI boot and are installing Arch Linux.

1. Boot from a USB (UEFI)

Create a bootable USB drive with UEFI support and boot into the live environment.

Make a bootable USB drive with UEFI support and boot the system on that. If you are using Unix based system you can make a bootable device via following command. But if you are using Windows you can make a bootable device via Rufus. Please consider to select GTP partition table with UEFI target system.

What is EFI?

sudo dd status=progress if=<archlinux-image-address> of=<device-address> bs=4M

boot

2. Identify Your Disk

Run the following command to list all block devices:

lsblk

lsblk

3. Partition the Disk

In my case the sda is the block that I want to do some partitioning which about 40GB. So I apply with regard to the size of my partition. To do so run the following command:

cfdisk

cfdisk is a curses-based program for partitioning any block device.

By running this command you might be asked to select a partition table. Choose gpt when prompted for the partition table.

partition table

What is a Partition Table?

By selecting free space and hitting New on the non-partitioned size set the new block sizes for our new linux system. For our basic installation we need the following partitions:

cfdisk

-> 200MB EFI system for boot
-> 1GB   swap (optional)
-> 18GB  /
-> 21GB  /home

These block sizes for / and /home are set according to my needs in this tutorial. You can set higher values for you use case. For example at least 40GB of disk space is required to be set for / dir.

Then we can optionally set label for each partition to help the bootloader identify the partition purpose by hitting Type when each of these blocks is selected.

What is Linux Directory Structure?

For the EFI partition set its label to EFI System:

EFI System

What is /boot/efi?

And for Linux swap:

Linux Swap

What is Swap?

For the other two partition leave it to be Linux filesystem.

After creating all partitions, select Write, type yes, and exit.

4. Format the Partitions

Format each partition by running the following commands.

mkfs.fat -F 32 /dev/sda1
mkswap /dev/sda2
mkfs -t ext4 /dev/sda3
mkfs -t ext4 /dev/sda4

What is Linux Filesystem?

5. Mount the Partitions

Now that the partitions are ready we can go on by installing the OS. For doing that first we need to mount these partitions into the system. By running:

mount /dev/sda3 /mnt

Since the mounted partitions are empty, we need to create the required directories to mount nested other disks into nested directories.

mkdir -p /mnt/boot/efi
mkdir /mnt/home

Now we mount the rest of disks:

mount /dev/sda1 /mnt/boot/efi
mount /dev/sda4 /mnt/home
swapon /dev/sda2

Mount Disks

6. Install the Base System

Now the system is ready for OS installation. To install the essential packages:

What is OS Installation?

pacman -Syy
pacman-key --init
pacman-key --populate
pacstrap -K /mnt base linux linux-firmware sudo nano

pacstrap is a tool to create a new system installation from scratch.

pacstrap

The -K flag initializes a new pacman keyring, instead of using the hosts keyring, for people who are using unofficial mirrors within their chroot and want to import their keys from the host can omit this flag.

7. Generate fstab

Now the base system is installed. We need to tell the bootloader how to load each of the disks by running the following command.

What is Bootloader?

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

What is fstab?

Now we are done. We can go into the newly installed operating system and do the rest of configurations.

8. Chroot into the New System

arch-chroot /mnt

chroot

What is chroot?

9. Set Locale and Timezone

first we need to generate locales:

nano /etc/locale.gen

Uncomment your preferred locales. For example en_US.UTF8 and fa_IR.UTF8

To generate the locales run:

locale-gen

locale

What is locale?

To set the correct timezone:

ln -sf /usr/share/zoneinfo/Asia/Tehran /etc/localtime

To set clock:

hwclock --systohc

10. Set Hostname and Hosts

set hostname:

echo "seraj-pc" > /etc/hostname

set /etc/hosts:

echo "127.0.0.1    localhost" >> /etc/hosts

”>>” appends string to end of file while ”>” overwrites the string to whole file

11. Create a New User

useradd -m -G wheel,power,storage,audio,video -s /bin/bash seraj

Now set a password for root and the defined user:

passwd # change password for root user
passwd seraj # change password for defined user

12. Make wheel group sudoer:

By Using nano edit /etc/sudoers

nano /etc/sudoers

Uncomment wheel group:

# %wheel ALL=(ALL:ALL) ALL
%wheel ALL=(ALL:ALL) ALL

Save and exit

What is sudo?

Since our defined user is added to wheel group then we have sudo privilege.

13. Install GRUB Bootloader

pacman -S grub efibootmgr
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

What is Bootloader?

14. Install Network Packages

pacman -S dhcpcd networkmanager resolvconf

Run the following commands to run these services on system boot:

systemctl enable dhcpcd
systemctl enable NetworkManager
systemctl enable systemd-resolved

What is systemctl?

15. Final Steps

exit # exits from chroot
umount /mnt/home
umount /mnt/boot/efi
umount /mnt

16. Reboot

reboot

If you see something like the following image after reboot and login then you have successfully installed ArchLinux.

terminal login

17. Install a desktop environment:

I prefer to use KDE.

sudo pacman -Sy plasma-desktop plasma-nm konsole sddm

KDE Installation

Once installed by running the following command:

sudo systemctl enable --now sddm

You should see the login page: sddm

After login: KDE