Articles | Contact

Arch installation with btrfs and systemd-boot

This post contains notes by me when installing Arch linux. The installation was made using the official Arch install guide. Other installation guides was used for particular installation steps and is then referenced.

P. Preparations

P1. Create installation media

Download latest arch iso and write it to a USB drive with the dd-c command.

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdX status=progress oflag=sync

P2. Optional: Disable Windows Fast Startup

The Fast Startup function can break the EFI boot partition and should be disabled. If you are installing Windows before it can be a good idea to increase the size of the EFI partition.

E. Installation environment setup

The setup of the installation environment will not affect the installed system.

E1. Boot live environment

Boot and select Arch Linux archiso x86_64 UEFI CD.

E2. Optional: Set a bigger font if you have a high resolution display

setfont sun12x22

E3. Optional: Change keymap

In my case to a Swedish keyboard mapping

loadkeys sv-latin1

E4. Check the network connection

A working network connection is necessary to download packages for install or to login with SSH to manage the installation.

ping -c 3

E5. Login with SSH

To install by logging into the install environment over SSH has advantages as it is simple to paste commands or run scripts. To login the root password has to be set with the passwd command and the SSH deamon has to be started with systemctl start sshd. In /etc/ssh/sshd_config root login must be aloved with PermitRootLogin yes, which is the default setting in the Arch Live. Then login with SSH from the remote computer.

#host computer
systemctl start sshd
#remote computer
ssh root@installip

E6. Verify the boot mode

If installing on a UEFI system, you can verify that the /sys/firmware/efi/efivars directory isn't empty.

ls /sys/firmware/efi/efivars
efivar -l

E7. Update the system clock

timedatectl set-ntp true

D. Disk setup

Now the installation starts, and now changes will start to affect the system. In the disk setup partitions will be setup and formatted with desired file systems.

D1. Inspect disks and current partions

The fidsk, gdisk and lsblk commands can be used to list information about disk and partitions.

# Useful commands
cat /proc/partitions
ls /dev/[s|x|v]d*
fdisk -l
gdisk -l /dev/sda
ls /dev | grep ‘^[s|v|x][v|d]’$*

D2. Partioning

GPT-mode partioning can be made interactively with gdisk, or with the user friendlier interface cgdisk. Non-interactively command partitioning can be made with sgdisk. Remember to set the correct partition type for e.g. boot, root, swap etc, and consider an EFI system partition. If you are to install a dual-boot system alongside windows 10 you need to consider how to deal with the boot partition. After paritioning partprobe is executed, a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.

I am setting up two paritions. One for the EFI esp, and one with BTRFS where I later will create subvolumes.

# Using sgdisk for BTRFS with subvolumes
sgdisk -Z /dev/sda # Zap (destroy) the GPT and MBR data structures. Do not use if you want to keep existing partitions.
sgdisk -n 0:0:+512M -t 0:ef00 -c 0:"boot" /dev/sda # Creates a boot partitioning.
sgdisk -n 0:0:+140GiB -t 0:8300 -c 0:"root" /dev/sda # Creates Linux partition.
sgdisk -p /dev/sda # Prints the partition tables.
partprobe /dev/sda # Updates the running linux kernel about partition tables.

D3. Format partitions

UEFI partitions needs to be formated with a FAT 32 file system. If using btrfs subvolumes those are created after formating.

mkfs.fat -F32 /dev/sda1
mkfs.btrfs /dev/sda2
#BTRFS subvolumes
mount /dev/sda2 /mnt
btrfs subvolume create /mnt/@root
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@var
btrfs subvolume create /mnt/@snapshots
umount /mnt

S. System setup and configuration

S1. Mount partitions

# BTRFS mounts
mount -o $SSD_MOUNTS,subvol=@root /dev/sda2 /mnt
mkdir -p /mnt/{boot,home,var,.snapshots}
mount -o $SSD_MOUNTS,nosuid,subvol=@home /dev/sda2 /mnt/home
mount -o $SSD_MOUNTS,subvol=@var /dev/sda2 /mnt/var
mount -o $SSD_MOUNTS,subvol=@snapshots /dev/sda2 /mnt/.snapshots
mount -o $EFI_MOUNTS /dev/sda1 /mnt/boot

S2. Install Arch base system

Installation is made with the pacstrap command. base is the necessary package for installing arch. base-devel is a package group that includes tools needed for building (compiling and linking). For user space utilities install the btrfs-progs package, which is not part of the base group, and is required for basic operations. It is not necessary for a basic install, and many users don't need to install it. It can be a part of the basic install, or installed later.

pacstrap /mnt base base-devel btrfs-progs

Install might be faster selecting fast mirrors. After backing up the mirror list with cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak, close mirrors can be selected with

awk -F: '/Sweden/ && $0 != "" { getline; print $0}' /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist.sweden

The rankmirrors script can find fast mirrors

rankmirrors -n 4 /etc/pacman.d/mirrorlist.sweden > /etc/pacman.d/mirrorlist

S3. Generate fstab file

Generate a fstab file based on mounted partitions

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

S4. Optional: Append tmpfs to the fstab file

echo -e "tmpfs /tmp tmpfs rw,nodev,nosuid 0 0\n\ntmpfs /dev/shm tmpfs rw,nodev,nosuid,noexec 0 0" >> /mnt/etc/fstab

echo -e "tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0" >> /mnt/etc/fstab

S4. Change system root to the created file structure

arch-chroot /mnt

S5. Configure your system time zone

ln -sf /usr/share/zoneinfo/Europe/Stockholm /etc/localtime

S6. Configure hardware clock to use UTC

Check that the hardware clock is the UTC with timedatectl.

hwclock --systohc

S7. Configure the system languages

echo -e "en_US.UTF-8 UTF-8\nen_GB.UTF-8 UTF-8\nsv_SE.UTF-8 UTF-8" >> /etc/locale.gen

S8. Generate the system languages layout


S9. Set language variable in locale configuration

echo LANG=en_US.UTF-8 >> /etc/locale.conf

Optional: Set the locale for all processes run from the current shell environment.

export LANG=en_US.UTF-8

S10. Make default keyboard Swedish

echo KEYMAP=sv-latin1 > /etc/vconsole.conf

S11. Name the system

echo $HSTNME > /etc/hostname
cat /etc/hostname

S12. Local network

Setup the local network settings in /etc/hosts, replacing myhostname. localhost
::1 localhost myhostname.localdomain myhostname

Echo command to do this

echo -e " localhost\n::1 localhost\n127.0.1.1 $HSTNME.localdomain $HSTNME" > /etc/hosts
cat /etc/hosts

S13. Set root password


S14. Create user

Move to post install guide

Bootloader: systemd-boot

S15. Optional: Backup Windows boot partition

Before making further changes to the EFI paritioning it can be backed up.

S16. Install systemd-boot bootloader

Install bootloader to the boot partition.

bootctl --path=/boot install

S17. Optional: Install intel microcode

The micro code fixes or handles erratas in the CPU.

pacman -Syy intel-ucode

S18. Optional: Install additional kernels

Possibly move this to post-install. Install additional kernels.

pacman -S linux-lts linux-zen

S18. Create bootloader entry

The bootloader will use loader entries with settings when booting. The entries are stored in files as esp/loader/entries/*.conf. It will tell what kernel to boot and pass settings to the kernel, as where the system root is located. Any microcode should be loaded at the row before the kernel. If additional kernels were installed they need to have their own entries.

#Example of an entry
title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options root=UUID=$ROOTUUID rootfstype=ext4

The UUID can be used to reference the root partitioning and can be retrieved with the blkid command.

blkid -o value -s UUID /dev/sda2

Below this command is used in echo to create two entries, one that loads micro code and one that don't.

echo -e "title Arch Linux\nlinux /vmlinuz-linux\ninitrd /intel-ucode.img\ninitrd /initramfs-linux.img\noptions root=UUID=$(blkid -o value -s UUID /dev/sda5) rw rootfstype=btrfs rootflags=subvol=@root" > /boot/loader/entries/arch.conf

echo -e "title Arch Linux No Microcode\nlinux /vmlinuz-linux\ninitrd /initramfs-linux.img\noptions root=UUID=$(blkid -o value -s UUID /dev/sda5) rw rootfstype=btrfs rootflags=subvol=@root" > /boot/loader/entries/archnomicro.conf

Maybe the add_efi_memmap option could be added, but is supposedly deprcated.

S17. Update the bootloader to default to the entry above.

vi /boot/loader/loader.conf

echo -e "default  arch\ntimeout  4" > /boot/loader/loader.conf
cat /boot/loader/loader.conf

Bootloader Grub

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

S18. Reboot

exit # To exit back to the live system
umount -R /mnt # Unmount the installed system
reboot # Reboot the system

Error 1962

The install above went smooth with no serious error. But on reboot the computer promts Error 1962: No operating system found. Press any key to repeat boot sequence. The computer is a Lenovo M91p, and when googling the error it seems to be a Lenovo related problem.

Many forum threads suggest this to be a problem with the SATA cable but the same cable starts just alright when I boot with another disk with Ubuntu installed.

I also tried to reset the BIOS and to remove the motherboard battery if a remaining system setting from previous boots caused the problem.

Add boot option to EFI

]# findmnt /boot/
/boot  /dev/sda1 vfat   rw,nosuid,nodev,noexec,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro,discard
efibootmgr --create --disk /dev/sda --part 1 --loader /EFI/systemd/systemd-bootx64.efi --label "systemd-boot" --verbose
efibootmgr --create --disk /dev/sda --part 1 --loader EFI/BOOT/BOOTX64.EFI --label "systemd-boot 2" --verbose

Install GRUB

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


Techmints guide to install Arch on UEFI Machines , Mattias Lundgergs Guide and Fhacks.

Is root running this script ? THIS CHECK SHOULD ALWAYS BE THE FIRST CODE THAT'S EXECUTED. if [ "id -u" -ne 0 ] then echo -e "\n\nRun this script as root!\n\n" exit -1 fi

if [ -f "$file" ]
    echo "$file found."
    echo "$file not found."