Skip to content

Instantly share code, notes, and snippets.

@DD3Boh
Last active July 12, 2023 17:59
Show Gist options
  • Save DD3Boh/f0e117caa6d7b6aa24c48ff3d9e8d8fe to your computer and use it in GitHub Desktop.
Save DD3Boh/f0e117caa6d7b6aa24c48ff3d9e8d8fe to your computer and use it in GitHub Desktop.
Arch Linux tips and tricks

Arch Linux

Basic command line install

Download the image and liveboot

The images can be found at https://www.archlinux.org/download/

The image can be flashed on a USB with any software (balena etcher works just fine)

Boot the device from USB (UEFI if your computer supports it)

Check the bootmode

Check whether you booted in UEFI mode or not with

# ls /sys/firmware/efi/efivars

If the directory exists you're in UEFI mode, otherwise you're in BIOS

Network(1)

If you're connecting to the network via ethernet, check whether internet is working or not:

# ping archlinux.org

Instead if you're trying to connect to a wifi, do so:

# wifi-menu

Sync the system clock

# timedatectl set-ntp true

Disk partitioning

Check current disks:

# fdisk -l

For the partitioning scheme you can choose if you want to go with MBR or GPT as partition table.

The partition scheme:

BIOS:

MBR:

With MBR as partition table in BIOS mode you need to let some space unallocated before the first partition. The space left by fdisk by default should be enough

/dev/sdX1 mounted to /mnt with partition type "Linux" (root partition, you choose the size)

/dev/sdX2 mounted as swap with partition type "Linux swap" (swap partition, more than 512MiB)

GPT:

With GPT as partition table in BIOS mode instead you need an extra boot partition

/dev/sdX1 mounted to /mnt with partition type "Linux" (root partition, you choose the size)

/dev/sdX2 mounted as swap with partition type "Linux swap" (swap partition, more than 512MiB)

/dev/sdX3 with partition type "BIOS boot" (size of +1M, partition type GUID: 21686148-6449-6E6F-744E-656564454649)

UEFI:

GPT:

With GPT as partition table in UEFI mode, you need an EFI partition with type "EFI system"

/dev/sdX1 mounted to /mnt with partition type "Linux" (root partition, you choose the size)

/dev/sdX2 mounted as swap with partition type "Linux swap" (swap partition, more than 512MiB)

/dev/sdX3 mounted to /mnt/efi with partition type "EFI system partition" (UEFI partition, 260-512MiB, GUID: C12A7328-F81F-11D2-BA4B-00A0C93EC93B)

MBR:

With MBR as partition table in UEFI mode, you need an EFI partition with type "EFI (FAT-12/16/32)"

/dev/sdX1 mounted to /mnt with partition type "Linux" (root partition, you choose the size)

/dev/sdX2 mounted as swap with partition type "Linux swap" (swap partition, more than 512MiB)

/dev/sdX3 mounted to /mnt/efi with partition type "EFI (FAT-12/16/32)" (UEFI partition, 260-512MiB, partition type ID: EF)

To start partitioning the disk you want you can use fdisk:

# fdisk /dev/sdX

Use the help menu that you can get with m to create a new partition table, create partitions like said above and write changes to the disk.

Format the partitions

Format the root partition as ext4:

# mkfs.ext4 /dev/sdX1 Format the swap partition as swap:

# mkswap /dev/sdX2
# swapon /dev/sdX2

If you are in UEFI mode also format the UEFI partition as fat32:

# mkfs.fat -F32 /dev/sdX3

Install the base

Mount the root partition to /mnt:

# mount /dev/sdX1 /mnt

Install essential packages:

# pacstrap /mnt base linux linux-firmware

These are just the most basic packages needed. We will install others later

Generate the fstab

Generate the fstab simply with just one command:

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

Take a look at it to see whether everything is fine, if it isn't just edit the file manually

Chroot

It's time to switch the root folder of the bootable enviroment to the installation root:

# arch-chroot /mnt

From now on you can install packages simply with pacman -S <pkg>

Install secondary packages

Install some other basic packages: # pacman -S sudo nano networkmanager

Time zone and localization

To set the time zone and generate /etc/adjtime:

# ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
# hwclock --systohc

Uncomment wanted locales in /etc/locale.gen

The en_US one is en_US.UTF-8 UTF-8

So regenerate the locales and create locale.conf (the LANG variable needs to be set accordingly):

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

Network (2)

Create the hostname:

# echo myhostname > /etc/hostname

Add the needed entries to hosts:

/etc/hosts:

127.0.0.1	localhost
::1		localhost
127.0.1.1	myhostname.localdomain	myhostname

Change "myhostname" with the desired hostname in the two previous commands

Intramfs

This step is usually not requires since it was already done during the installation of the kernel

To regenerate the intramfs:

# mkinitcpio -P

Set the root password

To set the run password:

# passwd

Creating a new user

This step is crucial since you wouldn't want to keep using the root user for everything

To create a new user:

# useradd -m username

Now you need to set a password to protect the new user:

# passwd username

To get sudo permissions on the recently created user: # usermod -aG sudo username

Now you should be able to get sudo permissions on your new user.

Bootloader installation

To boot into your system after the installation you need a bootloader. The most used and suggested one is grub

Grub installation

Legacy BIOS installation Remember that if you're installing on a disk with GPT and in BIOS mode, you need to create a specific partition for it. Check the "Disk partitioning" section

Firstly install the grub package with pacman as said previously.

Now start the installation:

# grub-install --target=i386-pc /dev/sdX

Change /dev/sdX with the disk where you want to install grub (not the partition)

UEFI installation Firstly install grub and efibootmgr packages with pacman.

Mount the EFI partition to /efi:

# mkdir /efi
# mount /dev/sdX3 /efi

Now start the installation:

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

This command assumes that the system is running as 64bit, if not just replace "x86_64-efi" with "i386-efi".

Grub configuration

It's time to generate all configuration files needed for grub.

You can do so with grub-mkconfig:

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

Multiboot installations For multiboot installation we need to install the package os-prober.

After doing so, we need to mount the partitions containing other systems and re-run grub-mkconfig.

Windows partitions will be discovered automatically by os-prober but the default Linux driver for NTFS may not be enough. If that's the case, install ntfs-3g and remount.

Install sysvcompat

The installation of this package might be needed to boot successfully in some devices and prevent ERROR: root device mounted successfully, but /sbin/init does not exist

The package name is systemd-sysvcompat

Boot into the system

Everything should be set-up perfectly by now.

So, exit the chroot enviroment doing either Ctrl + D or typing exit

Eventually unmount the root partition:

umount -R /mnt

Ultimately type reboot and plug out the USB drive.

Hopefully the system will boot correctly at first trial.

Congratulations, you installed Arch Linux!

First boot

Login

If everything went according to plans, you've just booted into your new system. The first thing you need to do is login into your user with the username and password that you created earlier in the installation.

Network (3)

Now that you booted into your newly installed system, the first thing to get the connection working.

Firstly start NetworkManager:

sudo NetworkManager

Now connect to a network with the command line tool nmcli

Check if the connection is working now:

ping archlinux.org

If everything works fine, enable NetworkManager automatically at boot:

sudo systemctl enable NetworkManager.service

Now it's time for the graphical installation.

Graphical installation

Install xorg

The first thing to do is installing xorg with the package xorg-server.

Warning: DO NOT install xorg or xorg-apps since they contain a lot of unwanted programs

Install GPU drivers

You can install either opensource GPU drivers or proprietary ones (in nvidia case).

Check the complete list of open-source video drivers:

pacman -Ss xf86-video

Open source drivers for AMD/ATI: xf86-video-amdgpu and xf86-video-ati

Open source drivers for Intel: xf86-video-intel

Open source drivers for nvidia: xf86-video-nouveau

Proprietary drivers for nvidia: nvidia (newer) and nvidia-390xx (older).

Installing the display manager

For this installation we'll be using SDDM (Simple Desktop Display Manager).

Installation To install sddm just install the package sddm

After the package has been installed, you need to set sddm to run at boot:

sudo systemctl enable sddm

After this, it's time to install the desired Desktop Enviroment.

I'll continue this guide with a minimal installation of KDE plasma X11.

Plasma desktop minimal installation

Install plasma-desktop

Install the plasma-desktop package containing just the minimal graphical installation of plasma without all of its packages.

Install some basic packages

Start the installation of some packages to implement some features optimally:

  inetutils # Net tools needed for hostname
  plasma-nm # Network configuration inside plasma
  powerdevil # Power management section in plasma (display brightness and power saving)
  plasma-pa # Audio section in plasma
  kscreen # Display section in plasma
  bluedevil # KDE bluetooth interface
  bluez bluez-utils # bluetooth
  kate # plasma file editor
  konsole # plasma terminal
  dolphin # plasma file manager
  firefox # Just a browser to start with
  gwenview # plasma image viewer

Let's also install some fonts:

  noto-fonts
  noto-fonts-cjk
  ttf-dejavu
  ttf-liberation
  ttf-opensans

After having installed these packages, reboot. The system should boot to sddm and after the password input KDE plasma should boot up.

Post install

Install an AUR manager

For the management of packages outside of official repositories we can use an aur manager.

Here we are going to install aurpkg

Download the package:

# git clone --depth=1 https://aur.archlinux.org/aurpkg.git /tmp/aurpkg

Build the package:

# cd /tmp/aurpkg
# makepkg -s

Wait for the build to finish and install the package:

# sudo pacman -U $(ls | grep '.tar.xz') --confirm

Cleanup:

# cd ~
# rm -rf /tmp/aurpkg

Now you can install packages from AUR with aurpkg.

Fix for PGP signatures not verified

During a long usage of Arch Linux, you might end up experiencing errors like this while installing a package:

ERROR: One or more PGP signatures could not be verified!

Most likely any package giving this kind of error will have a validpgpkeys section in its PKGBUILD, containing one or several keys.

What you need to do is simply importing those public keys, that can be retrieved from key servers:

# gpg --recv-keys key-id

  • Change key-id with the desired key found in validpgpkeys

Installing a custom kernel

Here I'm explaining how to build and install a custom kernel with the traditional compilation, not with arch's build system.

  1. Clone the source code

You can clone the desired kernel source code to use as base from your own distro's git, or either download the source from https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/

Clone the desired source code with git and enter the directory with cd

  1. Generating the config file

The best way to get a config file for your custom kernel to be built with is extracting it from your current running kernel:

# zcat /proc/config.gz > .config

To rename your kernel it would be better to rename the CONFIG_LOCALVERSION in the .config file, to prevent any overwriting.

  1. Compilation

To start the compilation it's enough to throw the command make. Though to make things faster it would be better to specify a jobs count according to the CPU cores:

# make -j$(nproc --all)

This will make the compilation clearly a lot faster.

  1. Installation

The kernel installation needs various steps in order to install all the components correctly.

WARNING: All the commands from now on will need to be run with sudo permissions

Firsly we need to install the modules we just built:

# make modules_install

Now it's time to generate the headers and install them:

# make headers_install

After that, installing the actual kernel image follows (this method is for x86_64 only):

# cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linuxXXX

  • To keep a decent consistency for names, it's suggested to name the image file as "vmlinuz-linux" followed by the kernel version. For example for linux-5.4.3 it would be "vmlinuz-linux543".

Now we need to generate the ramdisk file that is needed to load the kernel. For this we're going to use the manual generation method:

# mkinitcpio -k <kernelversion> -g /boot/initramfs-linuxXXX.img

  • : Specifies the version of the kernel to load modules from. A list can be seen in /usr/lib/modules

  • It's better naming the initramfs file consistently with the linux image. For example for linux-5.4.3 it would be "initramfs-linux543.img"

  1. Bootloader configuration

For this part we will be taking in consideration GRUB exclusively.

To configure grub for a new kernel it's simply enough to regenerate the configuration since it should recognize automatically the new kernel:

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

If the kernel got recognized correctly, now it will show up in the advanced menu of grub. If everything is working fine you can eventually change the default boot configuration for grub in order to boot with the new kernel by default.

To do so you need to edit the file /etc/default/grub and change the GRUB_DEFAULT entry. For example if I want to choose the second entry of the "Advanced Configuration" menu, I will need to set it like:

GRUB_DEFAULT="1>1"

After this just regenerate the grub configuration again.

  1. NVIDIA

The default NVIDIA drivers package (nvidia) won't work with custom kernels, just like it won't work with arch's linux-lts either. To have nvidia working with any custom kernel you need to install the package nvidia-dkms that conflicts with nvidia itself, which needs to be uninstalled.

Every time that you update the kernel manually you should re-run dkms so that the nvidia driver gets rebuilt against the new headers:

dkms install nvidia/440.44 -k <kernelversion>

Bluetooth

To get bluetooth up and working on arch linux there are certain things to do.

WARNING: All the following commands need to be run as root

Firstly the basic bluetooth packages have to be installed:

# pacman -S bluez bluez-utils

After this the bluetooth service needs to be enabled via systemctl:

# systemctl enable bluetooth.service

Some other packages are needed to get audio devices working via bluetooth:

# pacman -S pulseaudio pulseaudio-bluetooth pulseaudio-alsa

Then you need to check whether the btusb module is loaded and load it in case it isn't:

# modinfo btusb
# modprobe btusb

The most common utility to connect to bluetooth devices via command line is bluetoothctl.

To load the new settings the computer can either be restarted or you can try with:

# pulseaudio -k # Kill pulseaudio
# pulseaudio --start # Start pulseaudio
# sudo systemctl start bluetooth.service # Start the bluetooth service

Customizing GRUB

To customize GRUB fortunately there is a very useful tool in the community packages of arch linux.

That's grub-customizer which is a fancy software with a nice GUI to change the boot order of grub and such stuff.

Configuring touchpad with libinput

I found it a bit difficult to figure out a way to customize certain things of the touchpad.

Specifically it wasn't easy getting tap-to-click to work in my case, although I archieved the goal at the end of the day.

To do this it's enough editing the file `/usr/share/X11/xorg.conf.d/40-libinput.conf under the touchpad section.

In the section the most useful props are these two:

  • Option "Tapping" "on": tapping a.k.a. tap-to-click
  • Option "ClickMethod" "clickfinger": trackpad no longer has middle and right button areas and instead two-finger click is a context click and three-finger click is a middle click.

Just insert these parameters in the correct section and touchpad tap-to-click should work fine after reloading the X session.

Permanently change sysfs files at boot

To edit files in /sys/, which are recreated from the kernel at each boot, it's enough to use systemd-tmpfiles.

Just create a new file in /usr/lib/tmpfiles.d/ named <whatever>.conf and use the syntax meant for these files:

For example echo 0 > /sys/power/image_size would become:

#    Path                  Mode UID  GID  Age Argument
w    /sys/power/image_size     -    -    -    -   0

Reduce swappiness

On systems with enough RAM, it does more bad than good to have a high value of swappiness since it could reduce the snappiness of the system. For this reason it's better to permanently set a lower value than the defualt of 60.

To do so we're going to create a sysctl.d configuration file to set the swappiness variable: create the file /etc/sysctl.d/99-swappiness.conf with the following content: vm.swappiness=10

The value of swappiness can go from 0 to 200 on new kernels, with 0 being swap getting avoided and 100 being that hardware memory and swap get considered like the same.

Useful things I'd otherwise forget

Systemd-boot

Fix your EFI entries after they get reset

This could happen because of a CMOS reset or other reasons, to reset the entries just:

  • Boot into a live arch linux ISO
  • Use fdisk -l to check the disks
  • Mount the root partition to /mnt and the EFI partition to /mnt/efi
  • Chroot into the partition with arch-chroot /mnt
  • Use bootctl to re-create the entries with bootctl install
  • exit the chroot, unmount the partitions and reboot

Set the last chosen entry as boot entry every time

This is close to unfindable even in arch wiki and documentation, but it's just enough to do:

# bootctl set-default @saved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment