ArchLinux Tutorial, Part 1: Basic ArchLinux Installation
This post is the first in a series of three posts on installing and configuring Archlinux with I3 Windows Manager on a hardware machine.
Part -1 Basic ArchLinux Installation
Part -2 X Window System and I3 Installation
Part 3: I3 Configuration and Operation
Introduction
I have been an ArchLinux user for the past 10+ years and was running ArchLinux on all my desktops and laptops. The last time I deployed Arch on my desktop was almost six years ago, and I never reinstalled it since my first installation on a brand new (at that time) HW. The system is up-to-date with the latest kernel and apps.
uname -r
4.20.6-arch1–1-ARCH
All these years, I was running XFCE and, I am happy with a very light desktop manager. Recently, I felt I needed a change for my desktop environment and decided to try something new. Besides, after all these years of experimentation in installing and uninstalling software packages, my system started to feel sluggish and slow in a few instances.
So I decided it was time to do a clean install and, in the process, to try a new GUI. I decided to try I3, as I was looking at it for some time but didn’t find time until now to look into in more detail.
Download Archlinux ISO
ISO for Archlinux can be downloaded from Arch Linux Downloads. Select the closest mirror to you. The latest image at this date of writing is 2019.01.01, contains Linux Kernel 4.20, and is only 602.0 MB in size.
Once the image was downloaded you can write on a CD-ROM (if you still have one) or a USB stick.
Pre-installation checks
The current set up assumes you have EFI-enabled BIOS.
Once booted from a CD or USB stick, verify that the installation supports EFI.
ls -la /sys/firmware/efi
Verify that there is available disk space.
Note that we assume we are installing on a /dev/sda disk; your disk name may be different, so pay close attention.
dmesg | grep sda && \
lsblk
Initial pre-installation configuration
You can install Arch from local media CD/USB stick, but my recommendation is to use online installation with the latest updated packages. For this, we will need to configure MirrorList for the Archlinux to use during installation.
nano /etc/pacman.d/mirrorlist
- Manual mirrorlist configuration
Un-comment mirrors located crossest to you
nano /etc/pacman.d/mirrorlist
- Generate a Mirrorlist by specifying the type of the mirror and location.
Visit the Mirrorlist generator in the web browser on another computer and generate a Mirrorlist. Here’s an example of the generated Mirrorlists that are near my location.
Server = https://sgp.mirror.pkgbuild.com/$repo/os/$arch
Server = http://mirror.nus.edu.sg/archlinux/$repo/os/$arch
Server = http://mirror.0x.sg/archlinux/$repo/os/$arch
Server = https://mirror.0x.sg/archlinux/$repo/os/$arch
Partition disk
We will use two partitions: one partition for EFI 512 Mb, and one partition for the rest of the data.
We can partition in a more granular way depending on the requirements. For simplicity’s sake, we use the minimum required for the two partitions.
Partition EFI
gdisk /dev/sda
Clear partitions table
This will remove all existing partitions
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y
Create EFI partition
Command (? for help): n
Partition number (1–128, default 1):
First sector (34–268435422, default = 2048) or {+-}size{KMGTP}:
Last sector (2048–268435422, default = 268435422) or {+-}size{KMGTP}: +512M
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to ‘EFI System’
Partition root
Command (? for help): n
Partition number (2–128, default 2):
First sector (34–268435422, default = 1050624) or {+-}size{KMGTP}:
Last sector (1050624–268435422, default = 268435422) or {+-}size{KMGTP}:
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to ‘Linux filesystem’
- verify partition table before write
Command (? for help): p
Disk /dev/sda: 268435456 sectors, 128.0 GiB
Model: Virtual Disk
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 7A0873FE-EA25–4CC1–8543–1559F4861C2B
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 268435422
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB EF00 EFI System
2 1050624 268435422 127.5 GiB 8300 Linux filesystem
- Write changes to the disk
Command (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.
Format partitions
- Format EFI partition
512 MB EFMI partition we created previously will need to be formatted on OLD FAT32
mkfs.fat -F32 /dev/sda1
- Format Root partition
For simplicity sake we will format in EXT4 but you can always decide to use any other type of partition supported by Linux Ex. XFS, BTRFS etc.
mkfs.ext4 /dev/sda2
Mount partition
mount /dev/sda2 /mnt && \
mkdir /mnt/boot && \
mount /dev/sda1 /mnt/boot
Archlinux installation
1st will need to update the system clock
timedatectl set-ntp true
Once have time sync up we can proceed to install Archlinux
We will install base OS and base development packages and OpenSSH to allow us to ssh into the box
pacstrap /mnt base base-devel openssh
The final step is to generate a fstab file that will include partition information.
genfstab -U /mnt >> /mnt/etc/fstab
Before we reboot into newly installed OS will need to add few configuration changes and install and configure boot loader.
A Base configuration of the newly installed Archlinux
- Chroot into newly installed Archlinux
arch-chroot /mnt
Boot loader
- Configure bootctl loader
We will need to configure boot menu for the boot loader
bootctl install && \
echo “default arch” > /boot/loader/loader.conf && \
echo “timeout 3” >> /boot/loader/loader.conf && \
echo “editor 0” >> /boot/loader/loader.confcat /boot/loader/loader.confdefault arch
timeout 3
editor 0
In addition to the above information provided we will need to configure an entry for Arch Linux to boot from selected partition.
- find /dev/sda2 root partition UUID
blkid -s PARTUUID -o value /dev/sda2
Note down PARTUUID nr Ex. 2caa8dfe-ac06–4f64-b719–2991249a52c4
- Add PARTUUID to /boot/loader/entries/arch.conf
nano /boot/loader/entries/arch.conftitle Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=PARTUUID=af06626c-51a5–4e99–8e09–2eaf3ee90959 rw
Optional if you have other OS install you can be added as well to boot loader
title Windows
efi /EFI/Microsoft/Boot/bootmgfw.efi
Install boot loader
bootctl install && \
bootctl update && \
bootctl list && \
bootctl
Archlinux base configuration
- Generate locale
mv /etc/locale.gen /etc/locale.gen.bak && \
echo “en_US.UTF-8 UTF-8” >> /etc/locale.gen && \
echo “LANG=en_US.UTF-8” > /etc/locale.conf && \
cat /etc/locale.gen && \
cat /etc/locale.conf && \
locale-gen
- Check locale
locale -a && \
localedef — list-archive && \
locale
- Configure time zone
I am based in Singapore you may need to select the correct time zone by listing the content of the /usr/share/zoneinfo/
ln -sf /usr/share/zoneinfo/Asia/Singapore /etc/localtime && \
ls -la /etc/localtime && \
hwclock — systohc
- Enable ssh and DHCP services to start during the boot
systemctl enable sshd.service && \
systemctl enable dhcpcd
Final steps are to change root password that will allow us to login post restart
passwd
- Exit chroot environment
exit
- Un-mount partitions
umount /mnt/boot && \
umount /mnt
- Reboot system
reboot
If all went well you should be able to login into the Archlinux shell.
We not yet done with all our configuration
Post installation configuration
- Set hostname
In below case I name my box as arch, you free to name as you wish
hostnamectl status && \
hostnamectl set-hostname arch && \
hostnamectl status
- Set locale
localectl list-locales && \
localectl set-locale LANG=en_US.UTF-8
Network configuration
1st will need to find our network interfaces
ip a show && \
ip route show
- Use static ip Ex. your Ip can be different ip a show
In below case my network interface name is enp3s0f0 you may have a different name for your network interface
nano /etc/systemd/network/20-wired.network[Match]
Name=enp3s0f0[Network]
Address=192.168.1.10/24
Gateway=192.168.1.1
- Used dynamically allocated IP
nano /etc/systemd/network/20-wired.network[Match]
Name=enp3s0f0[Network]
DHCP=ipv4
- Configure DNS service
In below case we will use systemd resolvd service
grep “DNS=” /etc/systemd/resolved.conf && \
sudo sed -i -e ‘s/#DNS=/DNS=8.8.8.8 8.8.4.4/g’ /etc/systemd/resolved.conf && \
grep “DNS=” /etc/systemd/resolved.confcat /etc/systemd/resolved.conf[Resolve]
DNS=8.8.8.8 8.8.4.4
we are using Google DNS that have SLA of 100% you can use other DNS ip entry Ex. DNS=1.1.1.1 1.0.0.1
Restart and reconfigure network services
systemctl enable systemd-networkd && \
systemctl enable systemd-resolved && \
systemctl start systemd-networkd && \
systemctl start systemd-resolved && \
systemctl stop dhcpcd && \
systemctl disable dhcpcd && \
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf && \
ls -la /etc/resolv.conf && \
resolvectl status
- Check resolver configuration
cat /etc/resolv.conf && \
cat /run/systemd/resolve/resolv.conf
- Add time sync systemd service
timedatectl set-ntp true && \
timedatectl status
- Add an entry into the hosts file
cat /etc/hosts && \
echo “127.0.0.1 localhost.localdomain localhost” >> /etc/hosts && \
echo “::1 localhost.localdomain localhost” >> /etc/hosts && \
echo “127.0.0.1 arch.localdomain arch” >> /etc/hosts && \
cat /etc/hosts127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.0.1 arch.localdomain arch
Install useful linux tools
pacman -Syyuu && \
pacman -S p7zip python unzip pygmentize docker vim htop git jq rsync tmux bash-completion keychain mlocate wget words lsof which go pciutils lshw pacman-contrib reflector
- Update latest and newest mirror
Arch Linux uses a list of the mirror where all packages are synchronized using pacman -Syyuu.
The file that keeps all mirrors is located in /etc/pacman.d/mirrorlist, is a good idea to configure mirrorlist file with mirror fastest and closer to you. We will use the reflector tool that will configure the file automatically.
reflector — verbose — latest 200 — number 5 — sort rate — save /etc/pacman.d/mirrorlist
- Start docker daemon
systemctl enable docker && \
systemctl start docker
Create new user and group
Is not a good idea to run as user, the best practice is to configure a separate user that can be used as default and root user only in case you may need to configure system files.
groupadd -r autologin && \
useradd -m -g users -G wheel,storage,power,docker,autologin,audio -s /bin/bash your_user_name && \
passwd your_user_name
Add sudo access to the user
visudo%wheel ALL=(ALL) NOPASSWD: ALL
- Login into newly created user
su - your_user_name
Install AUR package manager
Users of the Archlinux can use packages maintained by the community called AUR. In order to use AUR, we need a tool similar to pacman to allow us to install packages from AUR.
Few AUR installers are available and I during the years I used few “yaourt, packer etc” Recently I switched to yay that so far works very nice without any issues.
Installing YAY
mkdir sources && \
cd sources && \
git clone https://aur.archlinux.org/yay.git && \
cd yay && \
makepkg -si && \
yay - editmenu - nodiffmenu - save
Optimizing system for faster compilation of the source based packages
grep “COMPRESSXZ=(xz” /etc/makepkg.conf && \
grep “#MAKEFLAGS=\”-j” /etc/makepkg.conf && \
sudo sed -i ‘s/COMPRESSXZ=(xz -c -z -)/COMPRESSXZ=(xz -c -T 8 -z -)/g’ /etc/makepkg.conf && \
sudo sed -i ‘s/#MAKEFLAGS=”-j2"/MAKEFLAGS=”-j9"/g’ /etc/makepkg.conf
grep “COMPRESSXZ=(xz” /etc/makepkg.conf && \
grep “#MAKEFLAGS=\”-j” /etc/makepkg.conf
In the “COMPRESSXZ=(xz -c -T 8 -z -)” -T 8 represent the number of CPU cores and you can find the correct number by running “lscpu | grep “CPU(s):” | grep -v NUMA”
Optional add nice color to pacman output
The final touch is to add some color to the package manager
grep “Color” /etc/pacman.conf && \
sudo sed -i -e ‘s/#Color/Color/g’ /etc/pacman.conf && \
grep “Color” /etc/pacman.conf
In the next article, we will install and configure X window and i3 Desktop manager