ArchLinux installation in VirtualBox

First of all, this tutorial doesn't prevent you from following the ArchWiki - Installation guide, it is not standalone.

Pre-installation#

First basic steps#

For those first steps, I think you are a big boy enough to do them alone.

So you can download the ArchLinux iso, verify its signature, boot the live environment, set the keyboard layout, verify the boot mode, connect to the internet, update the system clock. If you're not confident with those steps check the ArchWiki.

While creating you new virtual machine, you'll need to configure the VM settings in Virtualbox.

If you want to install Arch Linux in EFI mode inside VirtualBox, in the settings of the virtual machine, choose System item from the panel on the left and Motherboard tab from the right panel, and check the checkbox Enable EFI (special OSes only).

In UEFI mode you may experience a black screen, see #Black screen for guest in EFI mode for a workaround.

Partition the disks#

Identify the block device associated to disks with lsblk or fdisk -l.

Now we will use LVM to manage the disk and assume there is only one physical disk.

UEFI is enabled, so I will use a GPT partition type and an EFI system partition (ESP).

So we will have two partitions: one ESP and one partition that will host the LVM container.

# fdisk /dev/sda
g # create GUID Partition Table (GPT)
n # create a new partition (EFI system partition)
1 # partition number
2048 # 1st sector
+550M # last sector
t # change partition type
1 # EFI system
n # create a new partition (LVM)
2 # partition number
<ENTER> # default 1st sector
<ENTER> # default last sector
t # change partition type
2 # select partiton 2
31 # partition type: Linux LVM
p # print the partition table
w # write table to disk and exit

Preparing the logical volumes#

Create a physical volume:

pvcreate /dev/sda2

Create a volume group, adding the previously created physical volume to it:

vgcreate myvg /dev/sda2

Create all your logical volumes on the volume group:

lvcreate -l 100%FREE myvg -n root

Format your filesystems on each logical volume:

mkfs.fat -F32 /dev/sda1
mkfs.ext4 /dev/myvg/root # or /dev/mapper/myvg-root

Mount your filesystems:

mount /dev/myvg/root /mnt
mkdir /mnt/boot/ && mkdir /mnt/efi
mount /dev/sda1 /mnt/efi # mount ESP to /efi outside /boot

Check the partition table: lsblk -f /dev/sda.

Installation#

Select the mirrors#

Again, here it let you select the mirrors.

Install the base packages#

Install the base + some useful packages:

pacstrap /mnt base linux linux-firmware base-devel openssh sudo wget curl neovim lvm2

Fstab#

Generate an fstab file by UUID:

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

Check /mnt/etc/fstab correctness and add /efi /boot none defaults,bind 0 0 to mount the EFI mountpoint at boot since we mounted ESP outside of /boot.

So you should have something similar to:

# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dump> <pass>
# /dev/mapper/myvg-root
UUID=a35deae9-84b3-4039-a70b-fcc9984bbd6c       /               ext4            rw,relatime     0 1

# /dev/sda1
UUID=BED1-3FAD          /efi            vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro       0 2

# bind mount EFI
/efi /boot none defaults,bind 0 0

Chroot#

Change root into the new system:

arch-chroot /mnt

Time zone#

Set the time zone:

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

Run hwclock to generate /etc/adjtime:

hwclock --systohc

Localization#

Uncomment locales in /etc/locale.gen, and generate them with:

locale-gen

As I'm French, for me locales were:

en_US.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8

Set variables in /etc/locale.conf, for example:

LC_ADDRESS=fr_FR.UTF-8
LC_COLLATE=fr_FR.UTF-8
LC_CTYPE=fr_FR.UTF-8
LC_IDENTIFICATION=fr_FR.UTF-8
LC_MONETARY=fr_FR.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_MEASUREMENT=fr_FR.UTF-8
LC_NAME=fr_FR.UTF-8
LC_NUMERIC=fr_FR.UTF-8
LC_PAPER=fr_FR.UTF-8
LC_TELEPHONE=fr_FR.UTF-8
LC_TIME=fr_FR.UTF-8
LANG=fr_FR.UTF-8
LANGUAGE=fr_FR:fr

Set the keyboard layout in /etc/vconsole.conf, for example (for AZERTY default keyboard):

KEYMAP=fr

Network configuration#

Create the hostname file (/etc/hostname):

archway

Add matching entries to /etc/hosts:

127.0.0.1 localhost
::1       localhost

Initramfs#

Configuring mkinitcpio HOOKS in /etc/mkinitcpio.conf:

HOOKS=(base udev autodetect modconf kms keyboard keymap consolefont block lvm2 filesystems fsck)

Recreate the initramfs image:

mkinitcpio -p linux

Mount ESP:

mkdir -p /efi/EFI/
cp -a /boot/vmlinuz-linux /efi/
cp -a /boot/initramfs-* /efi/

Root password#

Easy!

Change root password:

passwd

Boot loader#

I know what you're about to say:

WTF man! Why don't you use GRUB?

Because rEFInd works better for EFI partitions as the name states.

pacman -S refind
refind-install

Warning: Virtualbox will ony see esp/EFI/BOOT/bootx64.efi automatically prior to Virtualbox 6.1 but it's ok nowaday. In that case just run refind-install --usedefault /dev/sda instead.

Then we need to edit /boot/refind_linux.conf:

"Boot with standard options"  "root=/dev/myvg/root rw add_efi_memmap initrd=\initramfs-%v.img"
"Boot to single-user mode"    "root=/dev/myvg/root rw add_efi_memmap initrd=\initramfs-%v.img single"
"Boot with fallback initramfs"  "root=/dev/myvg/root rw add_efi_memmap initrd=\initramfs-%v-fallback.img"
"Boot with minimal options"   "ro root=/dev/mapper/myvg-root"
"Boot to terminal"      "root=/dev/myvg/root rw add_efi_memmap systemd.unit=multi-user.target"

Note: Use backslashes \ for initrd and forward slashes / for other attributes.

Copy /boot/refind_linux.conf to /efi/refind_linux.conf.

And also edit /efi/EFI/refind/refind.conf in order to work with %v in refind_linux.conf:

...
extra_kernel_version_strings linux-zen,linux-lts,linux
...

So this way we have to configure the boot entries only once for multiple kernels.

Do not bind mount the ESP to /boot before using refind-install else it will fail:

mount --bind /efi /boot

Reboot#

You know how to reboot right?

Ok ok, but it's better to quit the chroot and unmount all the partitions first umount -R /mnt.

Post-installation#

In Post-installation the only section specific to a Virtualbox install is about guest additions. For a more complete and up-to-date tutorial, see .

Before we begin#

It could be nice to setup a DHCP client to avoid manual IP configuration.

Enable DHCP client:

systemctl start dhcpcd
systemctl enable dhcpcd

Note: for a server I rather recommand systemd-networkd and systemd-resolved.

Now we have Internet access, let's update the system before installing anything:

pacman -Syu

We'll use a lot this terminal so let's get a fancier zsh shell:

pacman -S zsh zsh-autosuggestions zsh-completions zsh-history-substring-search zsh-syntax-highlighting

System administration#

Users, groups and privilege escalation#

We already installed sudo with pacstrap.

Add a new user and assign sudo privilege

useradd -m -G wheel -s /bin/zsh noraj
passwd noraj
EDITOR=nvim visudo

And uncomment %wheel ALL=(ALL) ALL.

Exit root session and log back as user.

Creating default XDG directories

sudo pacman -S xdg-user-dirs
xdg-user-dirs-update

Package management#

Repositories#

Send stats about packages

sudo pacman -S pkgstats

Arch User Repository#

Install a pacman wrapper for AUR support, for example pikaur, pakku, yay:

sudo pacman -S git && git config --global init.defaultBranch master
cd /tmp
git clone https://aur.archlinux.org/pikaur.git
cd pikaur
makepkg -si

Please, don't install yaourt, check the pacman wrapper ArchWiki page.

Graphical user interface#

Desktop environments#

As we want a true graphical library backed desktop environment (understand a Qt DE as GTK is only the GIMP library), we have barely two choices: KDE or LXQT, but LXQT is very light (nice for a VM but too light for a nice desktop experience).

Install KDE Desktop Environment.

sudo pacman -S plasma-meta
sudo systemctl enable sddm

Configure KDE:

  • System Settings > Startup and Shutdown > Background Services > disable all unneeded services
  • System Settings > Desktop Behavior > Desktop Effects > Disable Translucency that behave bad for dark themes.
  • System Settings > Search > File Search > Deselect "Enable File Search"
  • System Settings > Regional Settings > Set Language and Formats
  • System Settings > Input Devices > Keyboard > Layouts > Configure Layouts

Generate SDDM keyboard layout /etc/X11/xorg.conf.d/00-keyboard.conf:

sudo localectl set-x11-keymap fr

Networking#

If not already installed, install NetworkManager network manager and applets:

sudo pacman -S networkmanager kdeplasma-addons plasma-nm
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager
sudo systemctl disable netctl

Strenght of NetworkManager are: official package for KDE applet, integrated wifi manager, nice integration with KDE.

Drawback of NetworkManger: does not support the use of dhcpcd for IPv6 currently. So you can change for dhclient instead.

If you want to change to dhclient:

sudo pacman -S dhclient # not running as systemd service unlike dhcpcd
sudo systemctl disable dhcpcd
sudo systemctl stop dhcpcd
sudoedit /etc/NetworkManager/conf.d/dhcp-client.conf
[main]
dhcp=dhclient
sudo systemctl restart NetworkManager

Encrypted Wi-Fi passwords by using KDE wallet.

Disallow /etc/resolv.conf overwrite:

sudoedit /etc/NetworkManager/conf.d/dns.conf
[main]
dns=none

VirtualBox#

Install the Guest Additions#

Install virtualbox-guest-utils provided by virtualbox-guest-modules-arch if you plan to keep the default vanilla kernel, else install it from virtualbox-guest-dkms.

sudo pacman -S virtualbox-guest-utils

Load the VirtualBox kernel modules#

sudo systemctl enable vboxservice

General#

Install a VTE (Virtual Terminal Emulator):

sudo pacman -S kitty # qterminal konsole

Install net browsers, Firefox is far more powerful but use GTK where Falkon is using Qt but is far to be complete and fast. But anyway having several browser is always useful.

sudo pacman -S firefox falkon

Install general software:

sudo pacman -S code kate okular dolphin wl-clipboard p7zip unrar kvantum-qt5 openssh ksysguard btop

Install some fonts!

sudo pacman -S ttf-liberation noto-fonts ttf-roboto ttf-anonymous-pro ttf-hack ttf-inconsolata noto-fonts-emoji powerline-fonts adobe-source-code-pro-fonts ttf-fira-mono

Install oh-my-zsh:

pikaur -S oh-my-zsh-git
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc

Install a konsole color scheme, I installed bl1nk.

Aliases for color:

alias diff='diff --color=auto'
alias grep='grep --color=auto'
alias ls='ls --color=auto'
export LESS=-R
man() {
  LESS_TERMCAP_md=$'\e[01;31m' \
  LESS_TERMCAP_me=$'\e[0m' \
  LESS_TERMCAP_se=$'\e[0m' \
  LESS_TERMCAP_so=$'\e[01;44;33m' \
  LESS_TERMCAP_ue=$'\e[0m' \
  LESS_TERMCAP_us=$'\e[01;32m' \
  command man "$@"
}

Color wrappers:

sudo pacman -S grc

KDE Theme

sudo pacman -S papirus-icon-theme

SDDM theme: I installed Sugar Dark for SDDM.

Install a Terminal multiplexers:

sudo pacman -S tmux

Troubleshooting#

System crash/freeze during system update#

If it was during download phase it's probably ok but if it was during the upgrade phase it could be bad especially if it was during the kernel upgrade.

Example: rEFInd doesn't show any boot option because kernel image are not present (crash during kernel upgrade).

Boot on the Arch ISO.

Mount the filesystems:

mount /dev/myvg/root /mnt
mount /dev/sda1 /mnt/efi

Chroot into the filesystem:

arch-chroot /mnt

Remove the locked pacman database:

rm /var/lib/pacman/db.lck

Reinstall the kernel from the cache or download it from a mirror (for kernel issues):

rm -r /var/lib/pacman/local/linux{,-headers}-5.13.9-1
pacman -U /var/cache/pacman/pkg/linux-5.13.13.arch1-1-x86_64.pkg.tar.xz
pacman -U /var/cache/pacman/pkg/linux-headers-5.13.13.arch1-1-x86_64.pkg.tar.xz

Or reinstall all packages if you have other errors:

  1. Reinstall all dependencies
    1. pacman -Qqdn > /tmp/pkglist_deps.txt
    2. pacman --asdeps -S $(< /tmp/pkglist_deps.txt)
  2. Reinstall all explicit packages:
    1. pacman -Qqen > /tmp/pkglist_exp.txt
    2. pacman -S $(< /tmp/pkglist_exp.txt)

Copy kernel images to ESP:

cp -a /boot/vmlinuz-linux /efi/
cp -a /boot/initramfs-linux.img /efi/
cp -a /boot/initramfs-linux-fallback.img /efi/
Share