Contents

Archlinux minimal Install with btrfs


Arch Linux Installation Guide

Introduction

If you don’t know about Arch Linux, and willing to learn, then check this post,

In this guide I’ll be installing Arch Linux with BTRFS. And in a separate article I’ll show you the way to a minimal KDE plasma desktop along with some extended possibilities. If you’re reading this I can assume you are already familiar with archwiki - a great place to learn about Arch Linux!

Tip
This post will be long and may be hard to navigate without TOS (table of contents). So please use table of contents. On desktop it’s placed on the right side and mobile device users can access it from the very top of the post.

Why Arch?

If you don’t have much idea about different distros, maybe you can read this article. Also you’ll find a lot of guys in YouTube for this purpose (to explain you why you need arch). If you’ve much free time to tinker with your system and you are in need of a full time job with no salary, welcome to the arena! I’ll highly recommend you to try Arch Linux.

F.A.Q.'s

From ArchWiki

Why BTRFS?

You might be familiar with computer storage formats like ntfs, fat32 or exfat. BTRFS (better F S ) is just like that with copy-on-write principal.

Snapshots

As Arch Linux is a rolling model, often called bleeding edge, system will be updated a lot and a lot of things can break or repair on each update.

With btrfs you can take snapshots within seconds and it’ll use less resource due to it’s copy-on-write principal. And what’s more you can also recover to a previous snap within a few seconds (just a simple restart),

Boot from snapshots

And the most interesting thing is that you can add your btrfs snapshot entry to GRUB bootloader. You can use pacman hook to trigger snapshot backup before any system update and an another script to add those backup as GRUB entry.

So if something goes wrong, you can go to previous condition right from your bootloader! I’ll show the way to achieve this on the next part (post installation).

Compression

BTRFS can compress your data as you write to save storage and it’ll be helpful on the long road. Also there are some cons. Read more here.

Tip

If you want to learn more about BTRFS then maybe a search through the web or, our favourite arch wiki is here,

Prerequisite

To install Arch Linux, indeed the best way to learn is Arch Wiki. But, the official guide will be little tough to understand to follow especially if you want to install on a btrfs file system or maybe a different kernel. This is why I won’t be explaining everything in details and my guide is specifically for intermediate users.

Danger

If your intention is blindly copy paste commands from this guide or Arch wiki without understanding anything, things may not work the way you want. So I highly recommend you to install any other distro. You can try,

  • Manjaro Linux - for complete newbies to learn things around and recommended for stability.
  • EndeavourOS - it’s more like graphical arch installer and highly recommended!

And keep these things in mind,

  1. Avoid blindly following online tutorials and instructions.
  2. Avoid installing unnecessary packages.
  3. Avoid assuming that commands will work without understanding what they do.
  4. Avoid partitioning without understanding the implications.
  5. Avoid using the root user for regular activities.
  6. Avoid using AUR packages without understanding the risks.
  7. Avoid using unsupported or experimental software.
  8. Avoid using the default kernel if it doesn’t provide the features you need.
  9. Avoid assuming that the installation will be successful without testing.
  10. Avoid reinstalling the system without backing up your data first.

Pre-Installation

ISO

You can grab it from official download page. To achieve better download speed you can try a local mirror. Scroll down a bit in the download page.

Example

For example, my country is Bangladesh and I’ve a mirror available. I can achieve better broadband speed from this mirror!

It’s always recommended to select the latest version. File name is like,

  • archlinux-2022.12.01-x86_64.iso

Installation medium

You can use a USB flash drive or, an optical disc or a network with PXE for installation. Now USB drives are more better choice and I’ll recommend you to try ventoy available for almost every desktop platform. Take a backup of your drives data first and then launch ventoy. You can install ventoy on a drive, and later just copy the ISO to your drive. Specialty of ventoy is that you can put multiple ISO to make a multi-boot bootable USB and what’s more, you can also store data (anything) on that USB.

[OPTIONAL] You can also verify your ISO. Try this guide for that purpose,

Booting into live ISO

First, go to bios/ uefi setting. Different motherboard has different keybindings. You can search through web to learn more. Finally you have to point your first boot to the bootable USB or disk.

Extended guide in Arch Wiki,

Preparation

As for preparation, we’ll make sure we have an active internet connection and set our keyboard’s layout and time zone [optional]. I’ll install minimal KDE plasma desktop and I can manage my time zone and keyboard’s layout later using GUI. If you’re using a differnet layout than English, you may want to check,

Internet

If you’re using Ethernet cable, internet connection should work out of the box. As for WiFi users, connect using iwctl. And for mobile broadband users, try with the mmcli utility.

Troubleshooting
For wireless and WWAN, make sure the card is not blocked with rfkill

Now, test you connection with ping,

1
ping 1.1.1.1

Tip: Ctrl + c to stop a process

Summery,

utility achievement
iwctl WiFi
mmcli mobile broadband
ping check/ verify network

Remote Installation (SSH)

If you want to let your friend install Arch on your PC, he can easily do it securely if both if your’e under the same local network,

Start SSH

1
systemctl start sshd.service

Set a password for root,

1
passwd

Find the IP Address

1
ip address

From your other computer, connect via SSH (You’ll be prompted for the root password you just set)

1
ssh "root@<IP-OF-THE-FIRST-PC>

Remote Installation (Internet)

But if your friend is on the other part of the planet or not on the same network, you can use internet protocol for this.

First, sync your packages and install tmate,

1
pacman -Sy tmate

And, run, tmate and give your friend the access key!

If you get any error, first sync with, pacman -Sy

and then install archlinux-keyring with, pacman -S archlinux-keyring

later you can update archinstall, pacman -S tmate

ArchInstall

Since 2021-04-01, Arch has a guided installer again. See archinstall for details. You can easily install Arch with the help of this script and avoid the rest of this post but if you want to extend your possibilities and configure everything with your own hand then I’ll recommend the manual way.

For easily install, first get the latest package,

1
pacman -Sy archinstall

Then run,

1
archinstall

If you get any error, first sync with, pacman -Sy

and then install archlinux-keyring with, pacman -S archlinux-keyring

later you can update archinstall, pacman -S archinstall

Tip
If you’re going for archinstall, then I would highly recommend you to install EndeavourOS. And if you want to install arch to show up, then while installing endeavouros select the online method and from the package choice list deselect endevouros corresponding packages and cofigs! Then it’ll install pure arch! Besides you’ll find arch GUI installers in the sourceforge.

Partitioning

You can list you drives along with partitions using lsblk or fdisk -l. You may find something like, sda, sdb, etc. Here sda and sdb are two different drive/ disk. You’ll also notice their partitions (if they exist). If you need to change a partition table or create or remove or resize partitions there are several tools. I’ll recommend to use cfdisk. And to check disks and partitions size, try df -H.

Summery,

command achievement
lsblk list drives along with existing partitions
fdisk -l same as above with more information
df -H list partitions size
cfdisk manage partitons
parted third party to manage partitions (Gparted CLI)

Layouts

It’s recommended to get a basic concepts of disk partitions at first. Try the following post for understanding,

Checking UEFI/ BIOS

To verify the boot mode, list the efivars directory:

1
ls /sys/firmware/efi/efivars

If the command shows the directory without error, then the system is booted in UEFI mode. If the directory does not exist, the system may be booted in BIOS (or CSM) mode. If the system did not boot in the mode you desired, refer to your motherboard’s manual.

BIOS with MBR

Check this link for an example layout,

UEFI

Most of the modern system supports UEFI (even BIOS can have it! Please check your BIOS first) and so I’ll continue my guide in UEFI only. You can go with the layout from Arch Wiki,

Our layout

I’ll be using 4 partition. A separate home partition. It’ll allow me to keep the home partition even if I reinstall or change distro.

Fun fact

Once I downloaded the same file (using firefox) in 3 differnent Linux distro (like, 10% here, 70% there and rest in another distro). It was possible because of same home partition. But things may go ugly if you install a distro with different desktop manager, such as, plasma or gnome or, a distro with different package (like firefox 89 and firefox 108)

Layout, (let our disk be sda)

Mount point partition suggested size partiton type
/boot/efi sda1 At least 300 MiB EFI system partiton
/ sda2 More than 10 GiB Linux x86-64
/home sda3 More than 3 GiB Linux x86-64
[SWAP] sda4 Twice the size of RAM Linux swap
sda5 Windows NTFS

We have an extra partition, right? We’ll think about it later! So whatever we do won’t effect this one. Think it as a data partiton.

F.A.Q.'s

Why I arranged in this way?

  • Well, it really doesn’t matter. You can arrange in whatever way you want. I put swap at the end because in future it can allow me to resize home and swap! Some upstream suggest to put it at the beginning if you’re using HDD as this part has little more read/ write rate.

Why swap?

  • Read here . You don’t have to use swap partition if you want. In fact there is systemd-swap and zram concept. So feel free to avoid if you know what you’re doing!

Why swap is twice the size of RAM?

  • It’ll help you if you hibernate your system. Most probably, you may never need to use more than 8 GiB for swap! If you don’t need hibernate then equal the size of RAM is more than enough.

I have a large amount of RAM, can I avoid swap?

  • Sure! In fact you should. Besides even if you’ve 1 GB ram you can avoid swap. Swap can be also created later as a swapfile!

Why swap partiton?

  • Well, if you dual boot linux, won’t it be more easy to share the same space instead of using two separate swapfile?

Formatting partitions

First of all, if you are coming from an another distro and want to keep the same home partition along with users, then avoid formatting home partition.

For home partition (/home),

1
mkfs.ext4 /dev/sda3

And you don’t need to format /boot/efi either! In fact it can destroy other boot-loaders if you’re trying to dual boot.

For /boot/efi,

1
mkfs.fat -F 32 /dev/sda1

For root partition (/),

1
mkfs.btrfs /dev/sda2

And finally, if you’ve created swap then initialize it by,

1
mkswap /dev/sda4

Mounting partitions

btrfs root

We need to mount our created partitions into our linux hierarchy. First we need to mount sda3 (root) into /mnt.

Tip
If your root partition is exfat then simply try, mount /dev/_root_partition_ /mnt and avoid this section.

We create subvolumes to better organize our data and to exclude them from btrfs snapshots.

  • @ – This is the main root subvolume /.
  • @log – Contains logs, temp. files, caches, games, etc.
  • @pkg – Contains all the pacman packages
  • @var - Contains logs, temp. files, caches, games, etc.
  • @opt - Contains third party products
  • @tmp – Contains certain temporory files and caches
  • @srv - This directory contains site-specific data that is served by this system.
F.A.Q.'s

If I don’t use separate home partiton?

  • @home – Then you have to create this subvolume!

Let’s mount first,

1
mount /dev/sda2 /mnt

Then, create required subvolumes,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
btrfs su cr /mnt/@

btrfs su cr /mnt/@root

btrfs su cr /mnt/@srv

btrfs su cr /mnt/@log

btrfs su cr /mnt/@cache

btrfs su cr /mnt/@tmp

Now we see all the sub-volumes we created by using,

1
btrfs su li /mnt
Command Meaning
su subvolume
cr create
li list

Let us unmount /mnt and remount all sub volumes.

1
2
3
cd /

umount /mnt

Then, mount root with,

1
mount -o defaults,noatime,compress=zstd,commit=120,subvol=@ /dev/sda2 /mnt

And create directory for other subvolumes,

1
2
3
4
5
6
7
8
9
mkdir  /mnt/root

mkdir  /mnt/srv

mkdir -p /mnt/var/log

mkdir -p /mnt/var/cache/

mkdir /mnt/tmp

Or, you can do with a one line,

1
 mkdir -p /mnt/{root,srv,var/log,var/cache,tmp}

Then, you can check your work with,

1
lsblk

Then we mount the sub volumes.

1
2
3
4
5
6
7
8
9
mount -o defaults,noatime,compress=zstd,commit=120,subvol=@root /dev/sda2 /mnt/root

mount -o defaults,noatime,compress=zstd,commit=120,subvol=@tmp /dev/sda2 /mnt/tmp

mount -o defaults,noatime,compress=zstd,commit=120,subvol=@srv /dev/sda2 /mnt/srv

mount -o defaults,noatime,compress=zstd,commit=120,subvol=@log /dev/sda2 /mnt/var/log

mount -o defaults,noatime,compress=zstd,commit=120,subvol=@cache /dev/sda2 /mnt/var/cache
Btrfs options meaning,
Option Meaning
noatime No access time. Improves system performace by not writing time when the file was accessed
commit Periodic interval (in sec) in which data is synchronized to permanent storage.
compress Choosing the algorithm for compress. I have set zstd as it has good compression level and speed.
subvol Choosing the subvol to mount.
Other guides

You can also look at these guides if things go wrong, YouTube,

or, blog posts,

EFI

Create a mnt/boot/efi directory,

1
mkdir -p /mnt/boot/efi

And then mount,

1
mount /dev/sda1 /mnt/boot/efi

Home

And also one directory for /home,

1
mount --mkdir /dev/sda3 /mnt/home

Swap On

And if you’ve created a swap partition, enable it using,

1
swapon /dev/sda4

Now we also have a data partition with ntfs file system and we can mount it to /mnt/any-name, but I’ll do it later. (GUI available)

Selecting mirror

By default in the live boot, arch will generate 20 mirrors in your mirrorlist file, sorted by download speed. But you can achieve better internet speed by using your local mirror or by using reflector.

Reflector

With reflector you can easily set a mirror. To do that, first let’s make sure our package list is with sync with server by,

1
pacman -Sy

then, let’s install reflector,

1
pacman -S reflector

then, you can use reflector to generate a mirrolist. Here’s an example,

My country is Bangladesh so I can display my available local mirrors in this way,

1
reflector -c BD

and, I can save this list to my mirrorlist in this way,

1
reflector -c BD --save /etc/pacman.d/mirrorlist

Manually

We can use a text editor to edit the mirrorlist and set our desired mirrors also. To do that, you can use nano or vim text editor or install any CLI-based text editor if you need. And there’s an online arch mirror list generator,

Simply edit the mirrorlist file, like,

1
nano /etc/pacman.d/mirrorlist

archlinux-keyring

Without installing this package, you may face Failed to commit transaction (invalid or corrupted package) or similar. To avoid, first sync with,

1
pacman -Sy

and then install archlinux-keyring with,

1
pacman -S archlinux-keyring

Essential packages

Use the pacstrap(8) script to install the base package and firmware for common hardware,

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

And, then you can also install the linux kernel like, but I’ll be installing linux-zen kernel. It’s your choice. For installing linux-zen my command will be,

1
pacstrap  /mnt linux-zen

For vanilla-linux kernel, try,

1
pacstrap  /mnt linux

System configuration

fstab

When you start your system it’ll help Arch to determine mount points which we set manually. To generate it, use,

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

entering chroot

Now change root into our system!

1
arch-chroot /mnt

chroot

This section covers some suggested tasks that you may want to after entering chroot.

root password

To set root password try,

1
passwd

We’ll need this password later, so try not to forget it!

network

network manager

Install a network manager with,

1
pacman -S networkmanager

and then, enable it with,

1
systemctl enable NetworkManager.service

host-name

use a text-editor to set a host name,

1
nano /etc/hostname

In the text file, put any name and save it!

hosts

[OPTIONAL] I’ll be editing my hosts later. Because with hosts you can even do ad-blocking, malicious site blocking or adult site blocking. I’ll add it in the post installation part. For now you can safely avoid this part.

But if you want to allow resolving the local host-name, edit,

1
nano /etc/hosts

and append these lines (recommended by Arch Wiki),

1
2
3
127.0.0.1        localhost
::1              localhost
127.0.1.1        _myhostname_

replace myhostname with your actual host-name, you set before!

Microcode

To acquire updated microcode, depending on the processor, install one of the following packages,

for intel, my command will be,

1
pacman -S intel-ucode

Do this before the next step to make sure it’s starting with bootloader.

Bootloader

This step is different for UEFI and non-UEFI systems. For EFI, inside the arch-chroot, install grub and efibootmgr,

1
pacman -S grub efibootmgr

and then install grub like,

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

Then generate config with,

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

Localization

edit your locale.gen file, like,

1
nano /etc/locale.gen

Then search for your desired locale, write it down (take note) ,and un-comment it (remove the # from the beginning of a line). In nano text editor you can use ctrl + w to search. Then press, ctrl + o to save, followed by an enter and then ctrl + x to exit.

Later, generate your config by running,

1
locale-gen

And, add it to the config file, (remember I told you to note that down? You have to use the first part),

1
nano /etc/locale.conf

Here’s a sample (I’m using US English)

1
LANG=en_US.UTF-8

Additional steps

Now you can do some additional configuration if you want, like setting up timezone, initial services etc. I will be installing KDE plasma and I can do all of those from plasma’s setting so I’ll avoid those. But if you want you can do it. Here are some references,

Wrapping up

Reboot

After configuring from inside of arch-chroot you can leave arch-chroot by using,

1
exit

And, believe it or not, we’ve successfully installed Arch. Now feel free to reboot with,

1
reboot

What to expect?

If you reboot/ restart then you will first notice a GRUB bootloader which will wait 5 seconds for you, or you can just select your kernel and hit enter. Later you’ll be greeted with a CLI login prompt where you can login as root (username = ‘root’)! Remember the password from this part? Use it to login.

Why that GRUB and black and white terminal?

  • No need to worry, we’ll both hide that GRUB 5 seconds and black and white login prompt in the next part.

Stucked in GRUB? If it’s grub-rescue shell, then move on to the next section.

Grub rescue?

Most probably, you have grub, but forgot grub-mkconfig? Try the following sequence of commands,

1. ls

The ls command lists all the available partitions and devices. Use this command to identify the partition containing your Linux root file system.

1
grub rescue> ls

If you don’t know which partition, do use it like, ls (hd0,msdos1)

2. set

The set command displays the current values of Grub environment variables. This information can help you identify the correct partition and configuration settings.

1
grub rescue> set

3. set prefix

To set the correct partition containing the Grub modules, use the set prefix command followed by the partition path.

1
grub rescue> set prefix=(hd0,msdos1)/boot/grub

Replace (hd0,msdos1) with the appropriate partition identifier.

If you are running btrfs file system, you may need to use something like, set prefix=(hd0,msdos1)/@/boot/grub. Check the set in the step 2 for accurate prefix template (if available).

4. set root

Similar to the prefix, you need to set the root partition using the set root command.

1
grub rescue> set root=(hd0,msdos1)

5. insmod

The insmod command is used to load Grub modules, such as normal and linux. Start by loading the normal module:

1
grub rescue> insmod normal

6. normal

After loading the normal module, execute the normal command to exit the Grub rescue mode and return to the standard Grub menu.

1
grub rescue> normal

7. boot

If you’ve manually set up the boot parameters using Grub commands, use the boot command to boot the system.

1
grub rescue> boot

Remember: You must load the required modules and set the boot parameters correctly before using the boot command. Above section is referenced from this site.

Alternative way

If trying to get into the OS via grub-rescue didn’t work then, try the following,

  • arch-chroot into your root and make sure, a kernel with base is installed and run grub-mkconfig again.
  • Unmount and reboot

Forgot root password?

  • Boot into live ISO
  • Mount the root partiton
  • arch-chroot into root
  • Use the passwd command to set the new password (you will not be prompted for an old one).
  • Unmount and reboot

References

What’s next?

Now you can install any desktop environment or any window manager with your favorite softwares! If you want I can pick you up right from where you’re now with my next post,