Setting Up Arch Linux on Asus A15



Published December 17, 2020

Introduction

For future projects we will dig more into video, so I felt the need for a laptop with a bit more graphics power. I was also curious about AMD processors, so when a very good offer came along for an ASUS A15 at my local computer store, I pounced.

These are my notes for setting up Arch Linux on the machine.

The aim of this write-up is to go from Windows laptop to a fully functional Arch multimedia machine with all my tools ready. For good measure I throw in a bit about dotfile management and how to keep things in sync between multiple machines. It will be a long ride, but hopefully a useful one. Please note that most of this information is not specific to the Asus laptops, but can be applied to pretty much any Windows laptop.

First Impressions

The laptop is 15.6 inches across, and weighs 2.3 kg, which sounds like a lot, but I found it a bit lighter than expected, considering how big the thing is. Pushing the start button launches a light show that I will promptly disable as soon as I get Linux on the machine.

It was a shocking experience to have Cortana start chatting to me, being so accustomed to the austere world of terminals and command line tools. It is not an experience I will miss.

Getting through the whole windows setup was, as expected, a painful experience involving giving up your email address, trying to backtrack when it turned out the keyboard wasn’t UK English after all, ultimately rebooting when that didn’t work out, all the time accompanied by chirpy, corporate nonsense. All of which just reinforced my dislike of that particular OS. And all of that just to be able to pull down the latest firmware upgrades.

And somebody said it was hard to install Arch…

Firmware Upgrades

It’s always a good idea to have the latest and greatest firmware updates, which is why I didn’t immediately nuke the Windows disk.

Launch the MyASUS application. Skip the McAfee junk, and do the long and windy dance to get to the upgrade. Turns out I did it all for nothing, as it seems there are no new updates. Lucky me.

Instead I ran hardware diagnostics, just to feel like it was worth it. This resulted in an incredibly loud fan noise for a little while and (apparently) green light.

In order to run Linux on the machine, you need to disable Secure Boot. I followed this guide

The steps were:

  • Hold shift while clicking Restart on the Power icon.
  • Select Troubleshoot > Advanced Options > UEFI Firmware Settings
  • Click Restart
  • The BIOS utility that pops up is Hollywood hacker worthy.
  • Click on Advance Mode > Security
  • Switch Secure Boot Control to Disabled
  • Save & Exit
  • Enjoy another keyboard light show

Keyboard Backlight

Turned off the keyboard backlight in Windows and set it to Static. This got rid of the light-show, but not the backlight. Back in Linux I could turn it off completely by running

echo 0 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness

Replace SSD

The A15 shipped with a 512 GB SSD, which should be plenty for most applications, but not if you work with video. So I invested in a 1TB SSD. This has the additional benefit that I can keep the original disk around in case I need to go back into Windows-land for critical firmware updates.

I followed this guide to open the back cover, using a Philips screwdriver and a guitar pick.

Once inside it was relatively straightforward to swap the SSD and add an extra 8GB of RAM, bringing the total up to 16GB.

Installing Arch Linux

After the initial procedures it was now time to install the actual OS, following the canonical Installation Guide. Please note that the Arch installation guide is always the most up to date. The information in this blog will most likely be out of date in a year or even earlier.

Creating the Installation Medium

Download the installation image, either as a torrent or as a direct download, as described here

Follow this guide to create a bootable USB stick. I chose the dd path. For the love of everything you hold dear make sure you dd to the correct disk, which you can find out by running lsblk. It will probably be /dev/sdb or some such. Also make sure you have no precious data on this disk, because it will be irrevocably lost after running this command.

On my system I ran:

sudo dd bs=4M if=~/Downloads/archlinux-2020.11.01-x86_64.iso of=/dev/sdb status=progress oflag=sync

Pop the stick into the ASUS, and you should (eventually) be presented with a list of options for boot. Hit enter, and watch in awe as you are taken into the wonderful world of the console.

Interestingly enough, the light show still continued on the keyboard. I am almost starting to enjoy it.

Connect an ethernet cable to the appropriate hole and run

ping -c 3 archlinux.org

If all is good you should be online.

Set system time:

timedatectl set-ntp true

Partition the Disk

I followed this guide.

Creating the EFI partition run

fdisk /dev/nvme0n1

Then, when prompted, type this in order:

n
p
1
2048
+512M
t
ef

Staying in fdisk, create the main partition. I use a swap file, so there is no need for a separate swap partition. Hit n and keep accepting the defaults until partition 2 has been created.

Finally, type w to write the partitions to disk. Run lsblk to verify. Your nvme0n1 should now contain nvme0n1p1and nvme0n1p2.

Encrypt the Disk

It is generally a good idea to encrypt your data in case your laptop gets stolen or otherwise compromised. Follow this guide to do so.

Steps:

cryptsetup luksFormat /dev/nvme0n1p2
cryptsetup open --type luks /dev/nvme0n1p2 cryptroot

Create filesystems:

mkfs.fat -F32 /dev/nvme0n1p1
mkfs.ext4 /dev/mapper/cryptroot

Mount them:

mount -t ext4 /dev/mapper/cryptroot /mnt
mkdir -p /mnt/boot
mount -t ext4 /dev/nvme0n1p1 /mnt/boot

Housekeeping

Install the basics:

pacstrap -i /mnt base base-devel

Generate fstab:

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

Chroot into the system:

arch-chroot /mnt

Install a few necessary tools:

pacman -S neovim linux linux-headers amd-ucode kbd alacritty

Make the font a bit bigger, so that you can see what you’re doing:

setfont ter-128n

Edit locale:

nvim /etc/locale.gen

Comment out your region, then generate locale:

locale-gen

Install bootloader. I prefer the lightness of systemd-boot to the monstrosities of grub. However, if you are dual-booting you may have to use another tool. On my old MacBook I used rEFInd and was happy with this.

bootctl install

Create a bootloader entry at /boot/loader/entries/arch.conf for the vanilla kernel

title Arch Linux
linux /vmlinuz-linux
initrd /amd-ucode.img
initrd /initramfs-linux.img
options cryptdevice=UUID=<device uuid>:cryptroot root=/dev/mapper/cryptroot rw

Additionally, edit /boot/loader/loader.conf to look like this

default arch.conf
timeout 3

Edit fstab to look something like this

# <device>                                <dir> <type> <options> <dump> <fsck>
UUID=CBB6-24F2                            /boot vfat   defaults  0      2
UUID=0a3407de-014b-458b-b5c1-848e92a327a3 /     ext4   defaults  0      1

Pro tip: run :r! lsblk -no NAME,UUID in nvim while editing fstab. This way you get all the UUIDs right there, and you can just yank and put them wherever you need them. Don’t forget to delete them afterwards, though, otherwise you’ll have a hard time booting. Another note: the UUID for / is the one listed as cryptroot.

Edit /etc/mkinitcpio.conf to enable encrypt hook. The HOOKS line should look like this:

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

Network Setup

Create hostname file at /etc/hostname

myhostname

Edit /etc/hosts

127.0.0.1	localhost
::1		    localhost
127.0.1.1	myhostname.localdomain	myhostname

The latest and greatest of network management is systemd-networkd.

Create the network config files, /etc/systemd/network/20-wired.network and /etc/systemd/network/25-wireless.network

[Match]
Name=enp2s0

[Network]
DHCP=yes

[DHCP]
RouteMetric=10

for the ethernet connection, and

[Match]
Name=wlp2s0

[Network]
DHCP=yes

[DHCP]
RouteMetric=20

for the wireless.

Install iwd:

sudo pacman -S iwd

Start the services

systemctl enable --now systemd-networkd.service systemd-resolved.service iwd.service

Recreate initramfs, just in case:

mkinitcpio -p

Set root password:

passwd

Add user and set password:

useradd -m -G tty,audio,video,wheel -s /usr/bin/zsh <username>
passwd <username>

Install sudo (side-note: Arch is such a bare-bones distro that even sudo is considered optional):

pacman -S sudo

Edit the sudoers file:

EDITOR=nvim visudo

Always edit this file with visudo, otherwise all kinds of horrible things can and will happen to you!

Uncomment the line that says:

# %wheel ALL=(ALL) ALL

by removing the #.

Dotfiles Management

Right around this time I need to digress a bit from the purity of the Arch install procedure and talk about dotfiles, i.e. the configuration files any Arch user inevitably builds after years of customization.

One way of dealing with dotfiles is to copy them over manually from whichever location they are in. A better way is to have git handle it for you by way of the dotbot script.

Create a dotfiles repo on your hard drive, mv all dotfiles you want to keep track of to this repo, and run these commands inside the repo:

git init
git submodule add https://github.com/anishathalye/dotbot
cp dotbot/tools/git-submodule/install .
$EDITOR install.conf.yaml

You can make your life even easier by installing the dotbot-yay plugin:

git submodule add https://github.com/alexwh/dotbot-yay
$EDITOR install

Modify the install script like this:

"${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASEDIR}" -c "${CONFIG}" \
  --plugin-dir "${BASEDIR}/dotbot-yay" "${@}"

The install.conf.yaml file should look something like this:

- defaults:
    link:
      relink: true

- clean: ['~']

- link:
    $HOME/.config/nvim : nvim/
    $HOME/.bashrc: bashrc
    $HOME/.zshrc: zshrc

-yay:
    - neovim
    - alacritty
    etc....

Note that you can also link directories. Huge time-saver.

Add files and commit them to the repository.

git add .
git commit -m "initial commit"

Create a remote git{ea,lab,hub} repository and push from your local repo to this one. This makes it possible to do a simple:

git clone
cd dotfiles
./install

and all your dotfiles should be linked into the right locations and yay will start its job of restoring your system (if you already have an Arch install, that is…)

Next, on the ASUS, make sure you have git and python installed.

pacman -S git python

Log out from the root account:

exit

Log into your new user account:

cd into your user’s home directory (NOT root…) and pull the dotfiles repo.

git clone --recurse-submodules https://address/of/your/git/repo.git

You also need to create the default config directory:

mkdir ~/.config

Install an AUR helper:

mkdir build && cd build
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

cd into the dotfiles repo and change the final line of the install script to be:

"${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASEDIR}" -c "${CONFIG}" \
  --plugin-dir "${BASEDIR}/dotbot-yay" "${@}"

before typing

./install

This will take a long time, depending on how many packages you have listed. Relax, read a book, take a walk, stare at the scrolling text… However, be aware that you might have to re-type your password occasionally, so don’t go too far away.

Configuring the System

Create Swapfile

The days when you had to create a swap partition are over. These days you can simply create a swap-file instead. Much nicer.

As root:

dd if=/dev/zero of=/swapfile bs=1M count=8032 status=progress
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

Finally, edit /etc/fstab to automount:

/swapfile none swap defaults 0 0

Get Graphic

This is the time of our journey to get a graphical environment up and running. The A15 comes with a discrete NVIDIA GPU, which is not yet supported by the open-source Noveau drivers, so you need to install the proprietary nvidia-dkms drivers. The dkms packages are kernel-agnostic and will be rebuilt on every kernel upgrade. Handy for when you want to run a custom kernel, which, if you work with audio, you almost certainly will want to do.

Another unfortunate side effect of the lack of nouveau support is that I will not be able to use my favorite wayland window manager sway. So I installed i3 instead, sway’s immediate xorg-based precursor. Or so I believed. It turns out that this is, indeed, possible if you launch sway with the flag sway --my-next-gpu-wont-be-nvidia. However, I still prefer to have sway AND i3 installed, as there are some things that don’t work yet on Wayland, like for example screen mirroring. My favorite wave editor Audacity is also a bit iffy on wayland, so I tend to keep tty1 open for sway and ttty2 for i3.

EDIT on 29 December 2020: after a series of brutal crashes I realized that there are good reasons for the sway folks to discourage using their server with nvidia’s proprietary drivers. So I crawled back to Xorg.

sudo pacman -S xorg xorg-xinit i3-wm nvidia-dkms sway

Reboot to allow nvidia-dkms to do its thing. After logging in as your username, you can start i3 by running startx i3. Make this somewhat more permanent by editing ~/.xinitrc to look something like this:

#!/bin/sh

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

exec i3

This lets you start i3 from the console by running startx. If you want to start i3 automatically on login, you can put something like this in your login shell configuration:

if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  exec startx
fi

However, I find it easier to troubleshoot without autostart. More information on the xorg startup can be found here.

Screen Flickering

One bug was driving me crazy: after a while I would get a constant flicker emanating from the lower left corner of the screen. The workaround for this (for now) is to flip the monitor refresh rate to 60 hz and back to the default 144 hz. To make this process less painful, I created a script called resetMonitor.sh and put it in my $PATH:

exec --no-startup-id xrandr --output eDP-1 --mode 1920x1080 --rate 60.00 &&\
exec --no-startup-id xrandr --output eDP-1 --mode 1920x1080 --rate 144.00 &

Whenever I get a bit of flicker, I run this script and it solves the problem for a while. Pretty f**king far from ideal, but it’s a lot better than the alternative.

SSH

In order to access the A15 from other computers over ssh:

sudo systemctl enable --now sshd.service

Power Management

In order to be able to suspend, reboot and shut down the computer as a regular user, you need to install the polkit package:

sudo pacman -S polkit

I use tuned to set the CPUs powerstate and a bunch of other stuff I don’t want to know about.

yay -S tuned
sudo systemctl enable --now tuned.service
sudo tuned-adm profile latency-performance

To save battery power when on the road, I use this udev rule: /etc/udev/rules.d/99-powerprofile_switch.rules


# Rule for when switching to battery
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0" RUN+="/usr/bin/tuned-adm profile laptop-battery-powersave"
# Rule for when switching to AC
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1" RUN+="/usr/bin/tuned-adm profile latency-performance"

Syncing between Computers

I recently started using Syncthing to keep my two laptops in sync with each other, and so far the experience has been very good. Install:

sudo pacman -S syncthing

Then follow this guide to get started, with the additional Arch-specific stuff outlined in the wiki

Firewall

Uncomplicated Firewall works very well for my modest requirements.

pacman -S ufw
sudo ufw enable

Uncomplicated indeed. If I need to open a port to have a conversation between an external controller and SuperCollider over the local network, I simply run

sudo ufw allow 57120

Sound

The world of Linux audio is intricate and confusing, even for experienced users. There is some hope now that this will improve with the advent of pipewire, but this is not quite ready for showtime yet, so in the meantime we all have to navigate the treacherous depths of ALSA, Jack, PulseAudio and all the bridges between.

First of all, install Jack2 and the python DBus interface:

sudo pacman -S jack2 python-dbus

Next thing, install a connection manager. I prefer the terminal-based njconnect, which can be installed from the AUR:

yay -S njconnect

I still haven’t solved hotswapping of sound cards, instead I use this script and bind it to a couple of keyboard shortcuts in my sway config:


#!/bin/bash

case "$1" in 
    "rme")
        device=UCX23987081,0
        nperiods=3
        inchannels=18
        outchannels=18
        period=256
        soundcard=0
        rate=48000
        ;;
    "internal")
        case $(hostname) in
            "a15")
                device=Generic_1,0 
                ;;
            "t480s")
                device=PCH,0
                ;;
        esac
        nperiods=2
        inchannels=2
        outchannels=2
        period=512
        soundcard=0
        rate=48000
        ;;
    *)
        notify-send -t 3000 "No soundcard specified"
        soundcard=1
        ;;
esac

if [ $soundcard -eq 0 ]
then
    jack_control stop
    jack_control ds alsa
    jack_control dps device hw:$device
    jack_control dps capture hw:$device
    jack_control dps playback hw:$device
    jack_control dps rate $rate
    jack_control dps nperiods $nperiods
    jack_control dps inchannels $inchannels
    jack_control dps outchannels $outchannels
    jack_control dps period $period
    jack_control dps duplex true
    jack_control dps midi-driver seq
    jack_control start

    wait $!

    jack_control status > /dev/null
    status=$? 
    if [ $status -eq 0 ]
    then
        case $rate in  
            44100) sr="44.1k" ;;
            48000) sr="48k" ;;
            96000) sr="96k" ;;
            *) sr="-" ;;
        esac
        notify-send -t 3000 "$device connected"
        echo $device $period/$sr > $HOME/.local/share/jackinfo
    else
        notify-send -t 3000 "Error: Jack didn't start"
        echo "Jack didn't start" > $HOME/.local/share/jackinfo
    fi
fi

In my sway config I call it like this:

set $mode_audio Audio [a]udacity, [c]adence, [o]live [r]me, [i]nternal soundcard, alsa[m]ixer, [w]ebcam
mode "$mode_audio" {
    bindsym a exec audacity, mode "default"
    bindsym c exec cadence, mode "default"
    bindsym o exec olive-editor, mode "default"
    bindsym r exec select_soundcard.sh rme, mode "default"
    bindsym i exec select_soundcard.sh internal, mode "default"
    bindsym m exec ~/bin/alsamixer.sh, mode "default"
    bindsym w exec guvcview, mode "default"
    bindsym j exec jaaa.sh, mode "default"
    bindsym p exec japa.sh, mode "default"

    bindsym Return mode "default"
    bindsym Escape mode "default"
}

bindsym $mod+p mode "$mode_audio"

This makes it possible for me to hit Alt-p, r or i to get to my soundcards very quickly. It also gives me a little heads up in my notification as well as in my statusline. Notice also that I have bound a bunch of other stuff that I use frequently to other keys in the same modality. This is one of the great selling points for i3-style window managers (and Linux in general. Try doing something like this in MacOS or Windows…).

System Checkup with RealTimeConfigQuickScan

This is an invaluable tool. Install it from AUR:

yay -S realtimeconfigquickscan-git

Run it on your system, and if you manage to turn all the red into green, you should have a fully operational system, fine-tuned for any audio work you want to throw at it.

Limits

Create /etc/security/limits.d/99-audio.conf

@audio - rtprio 90       # maximum realtime priority
@audio - memlock unlimited  # maximum locked-in-memory address space (KB)

CPU Governor

Use tuned-adm to set the cpu governor to performance

tuned-adm profile latency-performance

This is also implemented in the previously mentioned udev rule

Real-time kernel

There is some debate about the need for a real-time kernel. I have generally found it to be necessary for solid performance without xruns, but YMMV… Put this at the bottom of your /etc/pacman.conf:

[dvzrv]
Server = https://pkgbuild.com/~dvzrv/repo/$arch

and run

yay -S linux-rt linux-rt-headers

Put this into your /boot/loader/entries/arch-rt.conf


title Arch Linux
linux /vmlinuz-linux-rt
initrd /amd-ucode.img
initrd /initramfs-linux-rt.img
options cryptdevice=UUID=xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx:cryptroot root=/dev/mapper/cryptroot nvidia-drm.modeset=1 rw

Replace UUID with the correct one from your system. And set your bootloader to boot the rt-kernel by default in /boot/loader/loader.conf

default arch-rt.conf
timeout 3

At some point you will probably want to replace the rt kernel with the rt-lts, its long-term support cousin. Repeat the above steps, replacing rt with rt-lts.

Make PulseAudio play nice with Jack

As mentioned earlier, PipeWire is set to replace PulseAudio and Jack, in order to create a unified interface for sound across both consumer and professional needs. I am not quite ready to make the transition, so in the meantime I run with PulseAudio bridged to Jack.

Install PulseAudio, a mixer, and a couple of necessary bridges and, if needed, enable the user service.

sudo pacman -S pulseaudio pulseaudio-jack pavucontrol cadence
systemctl --user enable --now pulseaudio.socket

This should expose a PulseAudio sink and source to Jack, allowing you to route the audio from your browser to your Jitsi meeting or favorite audio editor. Or any other magic trick supported by the PulseAudio/Jack combo. You might have to open up cadence and manually switch on the PulseAudio bridge. The way I have my system set up I enable the Alsa->PulseAudio->Jack bridge. Additionally I start PulseAudio from cadence as needed.

Useful Tools

These are a bunch of useful tools for fully open-source creativity in no particular order:

Audacity

A surprisingly capable wave editor. There are still some issues with Wayland compatibility that needs to be addressed, which is why I tend to use it in a separate tty running i3.

sudo pacman -S audacity

SuperCollider

The most powerful audio programming language known to humanity. The plugin suite is optional, but recommended.

sudo pacman -S supercollider sc3-plugins

Ardour

Fully-fledged and open-source DAW. What more can you want? Had some stability issues with this one before, but these seemed to be ironed out in recent releases. Add an excellent plugin collection, while you’re at it. The xjadeo and harvid packages are necessary for working with video in Ardour.

sudo pacman -S ardour calf xjadeo harvid

Reaper

Not quite FOSS, but getting close enough to it. Industry-standard and very reasonably priced DAW that you can try out for as long as you want without paying for it. Highly extensible and scriptable. Everything in it can be controlled via OSC and Lua.

yay reaper-bin

ffmpeg

Apparently the program with the world’s longest man pages. If you can’t perform an operation on your video files with ffmpeg you problably can’t do it. Excellent for converting between different formats, compressing, resampling, generating videos from stills and so on.

sudo pacman -S ffmpeg

sox

Does for sound what ffmpeg does for video. The swiss army knife of sound file processing. Transforming 10,000 wave files from stereo to mono? No problem, just run a script like this:


#!/bin/bash
folder=$1
# extension='_mono.wav'

if [ -d $folder ]; then
    for filename in $folder/*; do
        if [ -f $filename ] ; then
            sox $filename "tmp" channels 1
            mv tmp $filename
            echo $filename
        fi
    done
fi

I also needed to install libmad for MP3 conversion to work. Which means the invocation is:

sudo pacman -S sox libmad

jaaa and japa

Excellent spectral visualization. Very useful in conjunction with SuperCollider, which is a bit lacking in that respect.

Lilypond

Music notation software for generating scores.

sudo pacman -S lilypond

Olive Video Editor

The state of Linux video editing was a sad one indeed until olive came along. Even though it is still early (read: buggy) days, the editing experience is far superior to anything else I’ve tried in FOSS-land. Looking very much forward to how this project grows.

yay -S olive

Gimp

Despite its questionable name, a great FOSS alternative to Photoshop.

sudo pacman -S gimp

Darktable

Free and open-source alternative to Lightroom. Great for batch processing of images and ranking.

sudo pacman -S darktable

zathura

Unassuming yet awesome PDF reader with vi-like key bindings. Works even better with a few plugins.

sudo pacman -S zathura zathura-djvu zathura-pdf-poppler

openFrameworks

C++ framework for anything visual. Large user-base, lots of libraries written for or ported to it. Not the fastest Linux bug-fix response time, but once the setup is done this shouldn’t be too much of a problem. Check my earlier guide on how to set it all up.

Krita

Amazing paint program that can also function as a Photoshop replacement. I’ve seen a lot of photographers prefer this over Gimp. You can also do animations with this.

sudo pacman -S krita

Blender

Hollywood level 3D animation program. Immensely powerful stuff.

sudo pacman -S blender