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!
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.
From ArchWiki
- 1 General
- 1.1 What is Arch Linux?
- 1.2 Why would I not want to use Arch?
- 1.3 Why would I want to use Arch?
- 1.4 What architectures does Arch support?
- 1.5 Does Arch follow the Linux Foundation’s Filesystem Hierarchy Standard (FHS)?
- 1.6 I am a complete GNU/Linux beginner. Should I use Arch?
- 1.7 Is Arch designed to be used as a server? A desktop? A workstation?
- 1.8 I really like Arch, except the development team needs to implement feature X
- 1.9 When will the new release be made available?
- 1.10 Is Arch Linux a stable distribution? Will I get frequent breakage?
- 1.11 Arch needs more press (i.e. advertisement)
- 1.12 Arch needs more developers
- 2 Installation
- 3 System maintenance
- 4 Package management
- 4.1 I have found an error with package X. What should I do?
- 4.2 Arch packages need to use a unique naming convention. “.pkg.tar.zst” is too long and/or confusing
- 4.3 Pacman needs a library so other applications can easily access package information
- 4.4 Pacman needs feature X!
- 4.5 I just installed Package X. How do I start it?
- 4.6 Why is there only a single version of each shared library in the official repositories?
- 4.7 What if I run a full system upgrade and there will be an update for a shared library, but not for the applications that depend on it?
- 4.8 Is it possible that there is a major kernel update in the repository, and that some of the driver packages have not been updated?
- 4.9 What to do before upgrading?
- 4.10 A package update was released, but pacman says the system is up to date
- 4.11 Upstream project X has released a new version. How long will it take for the Arch package to update to that new version?
- 4.12 If I need an older version of an installed library, can I just symlink to the newer version?
- 5 64-bit
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.
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.
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,
- Avoid blindly following online tutorials and instructions.
- Avoid installing unnecessary packages.
- Avoid assuming that commands will work without understanding what they do.
- Avoid partitioning without understanding the implications.
- Avoid using the root user for regular activities.
- Avoid using AUR packages without understanding the risks.
- Avoid using unsupported or experimental software.
- Avoid using the default kernel if it doesn’t provide the features you need.
- Avoid assuming that the installation will be successful without testing.
- 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.
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.
Now, test you connection with ping,
|
|
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
|
|
Set a password for root,
|
|
Find the IP Address
|
|
From your other computer, connect via SSH (You’ll be prompted for the root password you just set)
|
|
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
,
|
|
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,
|
|
Then run,
|
|
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
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:
|
|
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,
- Partitioning - Legacy BIOS - ArchWiki For installation instruction on BIOS, please check this article,
- Arch Linux Installation Process for a Legacy/BIOS/MBR System #arch-linux · GitHub Also YouTube has quite a few full tutorials available!
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.
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
andzram
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
),
|
|
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
,
|
|
For root partition (/
),
|
|
And finally, if you’ve created swap
then initialize it by,
|
|
Mounting partitions
btrfs root
We need to mount our created partitions into our linux hierarchy. First we need to mount sda3 (root) into /mnt.
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.
If I don’t use separate home partiton?
- @home – Then you have to create this subvolume!
Let’s mount first,
|
|
Then, create required subvolumes,
|
|
Now we see all the sub-volumes we created by using,
|
|
Command | Meaning |
---|---|
su | subvolume |
cr | create |
li | list |
Let us unmount /mnt
and remount all sub volumes.
|
|
Then, mount root with,
|
|
And create directory for other subvolumes,
|
|
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,
|
|
Then we mount the sub volumes.
|
|
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. |
You can also look at these guides if things go wrong, YouTube,
or, blog posts,
EFI
Create a mnt/boot/efi
directory,
|
|
And then mount,
|
|
Home
And also one directory for /home
,
|
|
Swap On
And if you’ve created a swap partition, enable it using,
|
|
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,
|
|
then, let’s install 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,
|
|
archlinux-keyring
Without installing this package, you may face Failed to commit transaction (invalid or corrupted package)
or similar. To avoid, first sync with,
|
|
and then install archlinux-keyring with,
|
|
Essential packages
Use the pacstrap(8) script to install the base package and firmware for common hardware,
|
|
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,
|
|
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,
|
|
entering chroot
Now change root into our system!
|
|
chroot
This section covers some suggested tasks that you may want to after entering chroot.
root password
To set root password
try,
|
|
We’ll need this password later, so try not to forget it!
network
network manager
Install a network manager with,
|
|
and then, enable it with,
|
|
host-name
use a text-editor to set a host name,
|
|
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,
|
|
and append these lines (recommended by Arch Wiki),
|
|
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,
- amd-ucode for AMD processors,
- intel-ucode for Intel processors.
for intel
, my command will be,
|
|
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
,
|
|
and then install grub like,
|
|
Then generate config with,
|
|
Localization
edit your locale.gen
file, like,
|
|
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,
|
|
And, add it to the config file, (remember I told you to note that down? You have to use the first part),
|
|
Here’s a sample (I’m using US English)
|
|
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,
|
|
And, believe it or not, we’ve successfully installed Arch. Now feel free to reboot with,
|
|
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?
arch-chroot
into your root and make sure, a kernel with base is installed and rungrub-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
- Installation guide - ArchWiki
- How to Install Arch Linux in 2022 | It’sFOSS
- Arch Linux Installation Guide For Developers | LunaTrace
- Installing Arch Linux with a BTRFS filesystem | ArcoLinuxD
- Arch Linux with BTRFS Installation (Base) | Tech it Out
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,