JustToThePoint English Website Version
JustToThePoint en español
JustToThePoint in Thai

Installing Arch from Scratch

Talk is cheap, show me the code, Linux Torvald.

This is Linux world. In silent nights you can hear the Windows machines rebooting.

Arch Linux is an independently developed, free and open-source, rolling release distribution. It is a minimalist, lightweight, and bleeding edge distribution that targets advanced users.

Installing Arch is challenging and time consuming. However, you end up with a system you understand very well and set up the way you want. Arch Linux challenges you to build your PC’s operating system yourself. Talk is cheap, show me the code, Linux Torvald.

Talk is cheap, show me the code, Linux Torvald.

Installing Arch remotely

It is sometimes a good idea and convenient to install ArchLinux using SSH.


# Set up the keyboard layout: loadkeys es
echo "KEYMAP=es" >> /etc/vconsole.conf

Previously, you should verify boot mode (UEFI). Maybe, you are either sitting on old hardware or you have UEFI disabled in the BIOS: ls /sys/firmware/efi/efivars

You can install Arch Linux on a virtual machine by using VirtualBox, but you must enable EFI in the virtual machine settings. To enable support for UEFI on VirtualBox, navigate through Settings, System, and tick the checkbox that says Enable EFI (special OSes only).

Besides, check your Internet connection: ping -s 5 justtothepoint.com

If it does not work: ip link shows your network device configuration and this is the output in my machine:

lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

enp5s0: mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 7c:10:c9:42:f2:b7 brd ff:ff:ff:ff:ff:ff 3: wlo1: mtu 1500 qdisc noqueue state DOWN mode DORMANT group default qlen 1000 link/ether 82:1f:72:58:c2:1a brd ff:ff:ff:ff:ff:ff permaddr 14:85:7f:b9:6f:b8 altname wlp0s20f3

You may want to try to bring up the interface (ip link set dev interface up), e.g., ip link set dev enp5s0 up. Next, run dhcpd to provide DHCP service to your machine: dhcpcd enp5s0. Finally, check your Internet connection again: ping -s 5 justtothepoint.com

# Set up your timezone. 
timedatectl set-timezone Europe/Madrid
# Enable and start network time synchronization. 
sudo timedatectl set-ntp true

NTP stands for Network Time Protocol. It is used to synchronize computers clocks automatically over the Internet and help ensure that all system clocks in servers and networking equipment use accurate time.

# Set the hardware clock to the local system clock.
sudo hwclock --systohc

Partitioning and Formatting

Safety isn’t expensive, it’s priceless.

Partitioning is difficult and inherently dangerous. Please backup your data before this operation.

There are many ways to partition a disk. sgdisk is a command-line utility for manipulating partition tables under Linux. Let’s start by partitioning our Virtual Machine’s drive (/dev/sda1):

# Wipe out the partition table (it deletes all GPT and MBR entries and creates a new GPT -GUID Partition Table-) and any data on it! 
[email protected]:~$ sgdisk --za-all /dev/sda 
sgdisk -og /dev/sda # It creates a fresh GPT disk. 
# Let's create four partitions.
sgdisk -n 1:2048:+1M -c 1:"BIOS Boot Partition" -t 1:ef02 /dev/sda 
sgdisk -n 2:0:+40G -c 2:"Linux /" -t 2:8304 /dev/sda
sgdisk -n 3:0:+2G -c 3:"[SWAP]" -t 3:8200 /dev/sda
sgdisk -n 4:0:0 -c 4:"Linux /home" -t 4:8302 /dev/sda
# Let's format the partitions.
mkfs.vfat /dev/nvme0n1p1 
mkfs.vfat /dev/sda1
mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda4
mkswap /dev/sda3 # It sets up a Linux swap on the third partition.
swapon /dev/sda3 # It enables it for swapping.
# Let's mount the root, home, and the EFI boot file systems.
mount /dev/sda2 /mnt 
mkdir -p /mnt/{boot/efi,home}
mount /dev/sda1 /mnt/boot/efi
mount /dev/sda4 /mnt/home

Let’s work in our main machine (In GNU/Linux, the first NVMe-SSD is called /dev/nvme0n1) with a bash script.

# The order lsblk lists all block-level devices available on your system.

# Wipe out the partition table (it deletes all GPT and MBR entries and creates a new GPT -GUID Partition Table-) and any data on it! 
sgdisk --zap-all $disk

# Let's partition the drive.
sgdisk -og $disk # Convert an MBR (Master Boot Record) or BSD disklabel disk to a GPT disk. 

We are creating four partitions: sgdisk -n,

  1. ‐‐new partition_number:starting sector:ending sector. Partitions locations can be enter in either absolute or relative form. Relative values are specified by preceding the number with a plus or minus sign.
  2. -c change the name of the partition, e.g., from 1 to BIOS Boot Partition
  3. -type code, e.g., ef02 is “BIOS boot partition”, 8304 is “Linux x86-64 root”, 8200 is “Linux swap”, and 8302 is Linux (/home)
  4. device file name ($disk)

It creates the following partitions: /boot/efi -1M-, / (root) -30G-, swap -2G-, and /home -the remaining disk space.

sgdisk -n 1:2048:+1M    -c 1:"BIOS Boot Partition"  -t 1:ef02 $disk  
sgdisk -n 2:0:+30G      -c 2:"Linux /"              -t 2:8304 $disk  
sgdisk -n 3:0:+2G       -c 3:"[SWAP]"               -t 3:8200 $disk  
sgdisk -n 4:0:0         -c 4:"Linux /home"          -t 4:8302 $disk 

# Format the partitions. mkfs stands for “make file system.” 
mkfs.vfat /dev/nvme0n1p1
mkfs.ext4 /dev/nvme0n1p2
mkfs.ext4 /dev/nvme0n1p4
# mkswap sets up a Linux swap area on the third partition of our disk. 
mkswap  /dev/nvme0n1p3
# swapon enables it for swapping.
swapon  /dev/nvme0n1p3

# Mount the root, home, and the EFI boot filesystems.
mount /dev/nvme0n1p2 /mnt
mkdir -p /mnt/{boot/efi,home}
mount /dev/nvme0n1p1 /mnt/boot/efi
mount /dev/nvme0n1p4 /mnt/home

Let’s install Arch Linux

The archlinux-keyring package contains the latest keys.

pacman -Sy archlinux-keyring

Pacstrap is designed to create a new system installation from scratch. Let’s install Arch Linux:

pacstrap /mnt base base-devel linux-lts linux-firmware git vim intel-ucode base-devel linux-lts-headers

Let’s Generate /etc/fstab. genfstab generates the /etc/fstab file by autodetecting all the current mounts below a given mountpoint (/mnt)

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

This is my /etc/fstab:

UUID=70b8e993-17b3-4991-af26-c2a96290425f / ext4 rw,relatime 0 1 
# UUID is an identifier used in partitions to uniquely identify partitions in GNU/Linux. 
UUID=9619-B821 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2
UUID=98213662-0927-49fc-8768-d870d9de3870 /home ext4 defaults,rw,nofail,noatime 0 0 
UUID=2fcbaaa5-3f66-4e85-b98b-c94f29d80f6f none swap defaults 0 0

Next, we enter or switch to the new system.

arch-chroot /mnt /bin/bash

Set the timezone and update the system clock:

ln -sf /usr/share/zoneinfo/Europe/Madrid /etc/localtime
# Set the hardware clock to the current system time (systohc stands for “system to hardware clock").
hwclock --systohc --utc

Set up the locale, i.e., the language, numbering, date, and currency formats for your system.

sed --in-place=.bak 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen

sed ‐‐in-place edits text on the file /etc/locale.gen. The syntax of the s (substitute) command is ‘s/regexp/replacement/flags’.

A regular expression is a sequence of characters that forms a search pattern. Metacharacters are characters with a special meaning, e.g, ^ stands for “starts with”, so we are searching for #en_US.UTF-8 UTF-8 and replacing it by en_US.UTF-8 UTF-8 (UTF-8 American/English locale), and therefore, we remove the comment and set the American/English locale in our system.

locale-gen is a program that reads the file /etc/locale.gen and generates localisation files.

# The /etc/locale.conf file defines system-wide locale settings.
echo "LANG=en_US.UTF-8" >> /etc/locale.conf

# Set up the keyboard layout: loadkeys es
echo "KEYMAP=es" >> /etc/vconsole.conf

# Network configuration. 
echo "myarch" >> /etc/hostname # It sets the hostname as myarch.
echo " localhost" >> /etc/hosts # /etc/hosts translates hostnames to IP-addresses.
echo "::1       localhost" >> /etc/hosts
echo " myarch.localdomain arch" >> /etc/hosts

/etc/hosts translates hostnames to IP-addresses and it was extensively used for all computers connected to the internet before DNS was created.

The idea is simple, a file with an address and a host name for each line. Nowadays, the name resolution is defined in /etc/nsswitch.conf. It usually contains this entry, hosts: file dns. It means: first try in /etc/hosts, and if it fails, try DNS.

echo "Setting root password"

# Create a new sudo (Super User Do) user and let's avoid typing his password constantly
read -r -p "Enter a new user name:" username
# Create a new user and add him or her to the wheel group.
useradd -m -G wheel -s /bin/bash $username 
passwd $username

Being a member of the wheel group allows you to run any command via “sudo”, but only if you uncomment the appropriate line in /etc/sudoers.

If you don’t want to use a bash script, replace the last two lines by the following ones: useradd -m -G wheel -s /bin/bash yourUser, passwd yourUser

# Members of the wheel group are automatically granted sudo privileges: %wheel ALL=(ALL). 
# NOPASSWD: ALL means that the system requires no password when these members invoke the sudo command (that's just for convenience purposes, but it is not safe).
echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
echo 'Defaults insults' >> /etc/sudoers # Sudo insults you if you enter an incorrect password. Obviously, this step is super important for the whole installation.
echo 'Defaults:USER_NAME !authenticate' >> /etc/sudoers #  It disables asking for a password for user USER_NAME (not safe).
# Install the boot manager, the network manager, xdg-utils, and PulseAudio
pacman -Sy grub efibootmgr networkmanager network-manager-applet dialog wpa_supplicant linux-headers xdg-utils xdg-user-dirs pulseaudio alsa-utils pavucontrol
PulseAudio is a sound server intended to run as a proxy between your applications and your hardware devices. PulseAudio Volume Control (pavucontrol) is a simple GTK based volume control tool (“mixer”) for the PulseAudio sound server.

xdg-utils is a set of tools that allows applications to easily integrate with different desktop environments. xdg-user-dirs is a tool to help manage “well known” user directories like the desktop folder and the music folder.

Installing Grub using grub-install

Grub is one of the most common booloader for GNU/Linux distributions. It allows you to choose between different operating systems, if there is more than one on your system.

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

grub-install’s arguments:
‐‐ efi-directory=/boot/efi = It specifies where the EFI System is mounted.
‐‐ bootloader-id=GRUB = It is the bootloader identifier.
‐‐ target=x86_64-efi = It installs GRUB for x86_64 systems.

If it does not work, you may want to try: grub-install ‐‐target=x86_64-efi ‐‐efi-directory=/boot/efi ‐‐bootloader-id=GRUB ‐‐no-nvram ‐‐removable ‐‐force

After the installation, the configuration file /boot/grub/grub.cfg needs to be generated by using grub-mkconfig:

grub-mkconfig -o /boot/grub/grub.cfg 

# Start the service NetworkManager. It manages your network devices and connections: Ethernet, Wifi, etc. It attempts to keep your network connectivity active all the time.
systemctl enable NetworkManager

# Exit the new system, unmount the partitions, and reboot.
umount -R /mnt
echo All Done. Type "reboot" to enjoy!

If you want to set the GRUB’s time to zero: sudo vim /etc/default/grub: GRUB_TIMEOUT=0


Processor manufacturers release stability and security updates to the processor microcode. These updates provide bug fixes that can be critical to the stability of your system”, Microcode, Arch Wiki.

To update your CPU microcode on Arch Linux, install the following packages: sudo pacman -Syy intel-ucode (Intel processors)/sudo pacman -Syy aamd-ucode (AMD processors). sudo grub-mkconfig will automatically detect the microcode update and configure GRUB appropriately.

After installing the microcode package or set the GRUB’s time to zero, regenerate the GRUB config by running sudo grub-mkconfig -o /boot/grub/grub.cfg

Bitcoin donation

JustToThePoint Copyright © 2011 - 2022 Anawim. ALL RIGHTS RESERVED. Bilingual e-books, articles, and videos to help your child and your entire family succeed, develop a healthy lifestyle, and have a lot of fun.

This website uses cookies to improve your navigation experience.
By continuing, you are consenting to our use of cookies, in accordance with our Cookies Policy and Website Terms and Conditions of use.