Skip to content

Instantly share code, notes, and snippets.

@mitchmikusek
Last active July 23, 2022 05:31
Show Gist options
  • Save mitchmikusek/34e408a7aa44bf339ffad55b1d86c616 to your computer and use it in GitHub Desktop.
Save mitchmikusek/34e408a7aa44bf339ffad55b1d86c616 to your computer and use it in GitHub Desktop.
Personal Arch Setup Guide

Arch Setup

TODOs

  • add mirror ranking (Pac-Man-contribute)
  • add lightdm config for monitors

Install Core Packages

sudo pacman -S --needed --noconfirm \
    base-devel git cmake \
    man-pages man-db \
    pass xclip tldr tree \
    rofi \
    unrar unzip p7zip \
    pavucontrol \
    noto-fonts noto-fonts-cjk noto-fonts-emoji noto-fonts-extra

#Flatpaks
sudo pacman -S --needed --noconfirm flatpak
flatpak install --noninteractive flathub \
    org.libreoffice.LibreOffice \
    com.obsproject.Studio \
    com.google.Chrome \
    com.discordapp.Discord \
    com.valvesoftware.Steam \
    org.videolan.VLC \
    org.gimp.GIMP \
    com.github.tchx84.Flatseal \
    org.qbittorent.qBittorent \
    org.kde.kdenlive \
    org.inkscape.Inkscape \
    org.audacityteam.Audacity

Setup Fish Shell

Install

sudo pacman -S fish
chsh -s /usr/bin/fish
#logout to take effect

Output Config

mkdir -p $HOME/.config/fish
echo '
set PATH $HOME/.emacs.d/bin $PATH

alias emacs "emacsclient -c -a emacs"

if status is-interactive
   # Commands to run in interactive sessions can go here
end   
' | tee ~/.config/fish/config.fish

Setup I3 Config

# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!

#Variables
set $terminal   alacritty
set $browser    firefox

# Set Mod Key
set $mod Mod4

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
font pango:monospace 10

# Start XDG autostart .desktop files using dex. See also
# https://wiki.archlinux.org/index.php/XDG_Autostart
exec --no-startup-id dex --autostart --environment i3

# xss-lock grabs a logind suspend inhibit lock and will use i3lock to lock the
# screen before suspend. Use loginctl lock-session to lock your screen.
exec --no-startup-id xss-lock --transfer-sleep-lock -- i3lock --nofork

# NetworkManager is the most popular way to manage wireless networks on Linux,
# and nm-applet is a desktop environment-independent system tray GUI for it.
exec --no-startup-id nm-applet

# udiskie for usb auto-mount
exec --no-startup-id udiskie --no-notify --tray

# emac's daemon
exec --no-startup-id /usr/bin/emacs --daemon

# adjust screen resolutions
exec_always --no-startup-id xrandr --output DisplayPort-0 --mode 2560x1440 --refresh 144.0 --primary --output DisplayPort-1 --mode 2560x1440 --refresh 60 --rotate right --right-of DisplayPort-0

# Use pactl to adjust volume in PulseAudio.
set $refresh_i3status killall -SIGUSR1 i3status
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -10% && $refresh_i3status
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle && $refresh_i3status
bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $refresh_i3status

# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# start a terminal
bindsym $mod+Return exec $terminal

# start a web browser
bindsym $mod+b exec $browser

# kill focused window
bindsym $mod+Shift+q kill

# Pass access
bindsym $mod+Shift+p exec --no-startup-id passmenu
        
# start dmenu (a program launcher)
#bindsym $mod+d exec --no-startup-id dmenu_run
bindsym $mod+d exec --no-startup-id rofi -show combi -combi-modi run#window#drun#ssh -theme DarkBlue
bindsym $mod+Shift+d exec --no-startup-id i3-dmenu-desktop

# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+semicolon focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+semicolon move right

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

# focus the parent container
bindsym $mod+a focus parent

# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
set $ws1 "1"
set $ws2 "2"
set $ws3 "3"
set $ws4 "4"
set $ws5 "5"
set $ws6 "6"
set $ws7 "7"
set $ws8 "8"
set $ws9 "9"
set $ws10 "10"

# Assign Workspaces to Monitors
workspace $ws1 output DisplayPort-0
workspace $ws2 output DisplayPort-0
workspace $ws3 output DisplayPort-0
workspace $ws4 output DisplayPort-0
workspace $ws5 output DisplayPort-0
workspace $ws6 output DisplayPort-1
workspace $ws7 output DisplayPort-1
workspace $ws8 output DisplayPort-1
workspace $ws9 output DisplayPort-1
workspace $ws10 output DisplayPort-1

exec --no-startup-id i3-msg workspace 1
exec --no-startup-id i3-msg workspace 10

# switch to workspace
bindsym $mod+1 workspace number $ws1
bindsym $mod+2 workspace number $ws2
bindsym $mod+3 workspace number $ws3
bindsym $mod+4 workspace number $ws4
bindsym $mod+5 workspace number $ws5
bindsym $mod+6 workspace number $ws6
bindsym $mod+7 workspace number $ws7
bindsym $mod+8 workspace number $ws8
bindsym $mod+9 workspace number $ws9
bindsym $mod+0 workspace number $ws10

# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number $ws1
bindsym $mod+Shift+2 move container to workspace number $ws2
bindsym $mod+Shift+3 move container to workspace number $ws3
bindsym $mod+Shift+4 move container to workspace number $ws4
bindsym $mod+Shift+5 move container to workspace number $ws5
bindsym $mod+Shift+6 move container to workspace number $ws6
bindsym $mod+Shift+7 move container to workspace number $ws7
bindsym $mod+Shift+8 move container to workspace number $ws8
bindsym $mod+Shift+9 move container to workspace number $ws9
bindsym $mod+Shift+0 move container to workspace number $ws10

# reload the configuration file
bindsym $mod+Shift+c reload

# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart

# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode

        # Pressing left will shrink the window’s width.
        # Pressing right will grow the window’s width.
        # Pressing up will shrink the window’s height.
        # Pressing down will grow the window’s height.
        bindsym j resize shrink width 10 px or 10 ppt
        bindsym k resize grow height 10 px or 10 ppt
        bindsym l resize shrink height 10 px or 10 ppt
        bindsym semicolon resize grow width 10 px or 10 ppt

        # same bindings, but for the arrow keys
        bindsym Left resize shrink width 10 px or 10 ppt
        bindsym Down resize grow height 10 px or 10 ppt
        bindsym Up resize shrink height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

        # back to normal: Enter or Escape or $mod+r
        bindsym Return mode "default"
        bindsym Escape mode "default"
        bindsym $mod+r mode "default"
}

bindsym $mod+r mode "resize"

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
        status_command i3status
}

Setup AUR Helper

pushd /opt
sudo git clone https://aur.archlinux.org/paru.git
sudo chown -R mitch /opt/paru
cd paru
makepkg -si --noconfirm
popd

Setup USB Auto-Mounting

sudo pacman -S --needed udiskie
# Launch with - udiskie --no-notify --tray &

Setup DOOM Emacs

sudo pacman -S --needed emacs ripgrep cmake

git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.emacs.d
doom sync
doom install

# Set daemon to autolaunch and alias emac to connect using the client
#/usr/bin/emacs --daemon &
#emacsclient -c -a 'emacs'

Graphics Packages

AMD

Packages

sudo pacman -S --needed mesa xf86-video-amdgpu vulkan-radeon libva-mesa-driver mesa-vdpau

Monitor Setup

xrandr --output DisplayPort-0 --mode 2560x1440 --refresh 144.0 --primary --output DisplayPort-1 --mode 2560x1440 --refresh 60 --rotate right --right-of DisplayPort-0

NVIDIA

sudo pacman -S --needed nvidia nvidia-settings

KVM + Dual-Card GPU Passthrough

Set Primary GPU

echo -e "Section \"Device\"\n	Identifier \"AMD\"\n	Driver \"amdgpu\"\nEndSection" | sudo tee /etc/X11/xorg.conf.d/20-amdgpu.conf

cat /etc/X11/xorg.conf.d/20-amdgpu.conf

Get IOMMU Groups

These will be useful to have handy

#!/bin/bash
for g in `find /sys/kernel/iommu_groups/* -maxdepth 0 -type d | sort -V`; do
    echo "IOMMU Group ${g##*/}:"
    for d in $g/devices/*; do
        echo -e "\t$(lspci -nns ${d##*/})"
    done;
done;

Enable IOMMU & Isolate Devices

via systemd

In file `/boot/loader/entries/linux.conf`, append the following flags to options:

amd_iommu=on iommu=pt vfio-pci.ids=10de:2208,10de:1aef

via Grub

#check current value
grep --context=3 "GRUB_CMDLINE_LINUX=" /etc/default/grub

#update line (IDs needed?, in default?)
sudo sed -i 's/GRUB_CMDLINE_LINUX=\".*\"/GRUB_CMDLINE_LINUX=\"amd_iommu=on iommu=pt vfio-pci.ids=10de:2208,10de:1aef\"/g' /etc/default/grub

# verify change
grep --context=3 "GRUB_CMDLINE_LINUX=" /etc/default/grub

# Reconfigure Grub
sudo grub-mkconfig -o /boot/grub/grub.cfg

# Restart to take effect
sudo reboot now

via mkinitcpio

Alternatively to Grub, the IDs may be added to a modprobe conf file. Since these conf files are embedded in the initramfs image, any changes require regenerating a new image each time:

# Add vfio-pci targets
sudo touch /etc/modprobe.d/vfio.conf
echo 'options vfio-pci ids=10de:2208,10de:1aef' | sudo tee -a /etc/modprobe.d/vfio.conf
echo 'softdep nvidia pre: vfio-pci' | sudo tee -a /etc/modprobe.d/vfio.conf

# Verify
cat /etc/modprobe.d/vfio.conf

# https://wiki.archlinux.org/title/Mkinitcpio#Image_creation_and_activation
#rebuild initramfs
sudo mkinitcpio -p linux

Load vfio-pci early

Load drivers in order

# Load vfio before other drivers
# in /etc/mkinitcpio.conf
# Add the following to MODULES vfio_pci vfio vfio_iommu_type1 vfio_virqfd amdgpu

# Add modconf to Hooks line

# Verify
cat /etc/mkinitcpio.conf

# https://wiki.archlinux.org/title/Mkinitcpio#Image_creation_and_activation
#rebuild initramfs
sudo mkinitcpio -p linux

# Restart to take effect
sudo reboot now

# Verify that the configuration worked
sudo dmesg | grep -i vfio
lspci -nnk

Setting up OVMF-based guest virtual machine

sudo pacman -S --needed qemu-desktop libvirt edk2-ovmf virt-manager iptables-nft dnsmasq virt-viewer swtpm libguestfs

You can now start the virtualization service.

# Autostart in the future and start right now
systemctl enable --now libvirtd

# You can verify loaded and active by running
systemctl status libvirtd

To avoid needing a password to use virt manager, lets add our user to the group

sudo usermod -aG libvirt mitch

We’ll want to start the default network and have it auto start. To do so run the following commands

sudo virsh net-start default
sudo virsh net-autostart default

If the commands fail, do the following to manually enable. Launch virt manager, highlight `QEMU/KVM` by clicking it, and then click `Edit` -> `Connection Details`. In the new window, click `Virtual Networks`, highlight `default` and press the `Start Network` button near the bottom. Additionally, check the box that says `Autostart On Boot`

We’ll also want to setup XML Editing & Guest Inspection. Click `Edit` -> `Preferences`. In the Preferences window, check `Enable XML Editing` and `Enable libguestfs VM introspection`. As it says, you’ll need to restart the app for it to take effect

Monitoring

radeontop radeon-profile
lw_sensor psensor

Backup & Restore VMs

Backup

#!/usr/bin/env bash

# Setup Main Output Directory
output_dir=$1
if [ "$output_dir" == "" ]; then
    $output_dir=./
fi

# Gather VMs
vm_names=$(sudo virsh list --all | tail -n +3 | head -n -1 | awk '{ print $2 }')
for vm in $vm_names
do
    # Create VM output Directory
    vm_output_dir=$output_dir/$vm
    mkdir -p $vm_output_dir

    # Copy each hdd to the vm output directory
    vm_hdds=$(sudo virsh domblklist $vm | tail -n +3 | head -n -1 | awk '( $2 != "-" )' | awk '{ print $2 }')
    for hdd in $vm_hdds
    do
        sudo rsync --info=progress $hdd $vm_output_dir
    done

    # Copy vm xml config to output directory
    sudo virsh dumpxml $vm | tee $vm_output_dir/$vm.xml
done

Restore

#!/usr/bin/env bash

# Setup input directory
input_dir=$1

if [ "$input_dir" == "" ]; then
    $input_dir=./
fi

# Gather VMs to Restore
vm_paths=$(ls -d $input_dir/*)
for vm_path in $vm_paths
do
    # Get VM Name
    vm=$(basename $vm_path)

    # Copy HDD
    sudo rsync --info=progress --exclude '*.xml' $vm_path/* /var/lib/libvirt/images/

    # Import Config
    sudo virsh define --file $vm_path/$vm.xml
done

Setup Windows VM

  1. Create new VM 1.1) Choose Local install Media 1.2) Select ISO or CDROM install Media 1.2.1) Click Browse 1.2.2) Click Browse Local 1.2.3) Navigate to and select install media 1.2.4) If prompted to correct read permissions, choose yes 1.3) Choose Memory and CPU 1.3.1) Memory 16GB - 16384 1.3.2) CPUs - 16 1.4) Choose HDD Size 1.4.1) 250GB 1.5) Ready to begin install 1.5.1) Rename if desired (win11) 1.5.2) Check customize configuration before install 1.5.3) Choose Finish
  2. Configure the VM 2.1) Overview 2.1.1) Ensure Chipset is Q35 2.1.2) Select UEFI x64 Secure Boot Firmware 2.2) SATA Disk 1 2.2.1) Change Disk Bus to VirtIO 2.3) Add Hardware 2.3.1) Add VirtiO Driver Disc 2.3.1.1) Select Storage, Device Type CDROM Device and the disk image 2.3.2) Add Passthrough GPU 2.3.2.1) Select PCI Host Device and Select GPU Elements to pass through 2.3.3) Add TPM 2.3.3.1) Select TPM, Advance Options Model CRB and Version 2.0 2.4) Manual Config Click Overview and select the xml tab Replace <vcpu>16</vcpu> with the CPU Pinning Contents
<vcpu placement="static">16</vcpu>
  <iothreads>2</iothreads>
  <cputune>
    <vcpupin vcpu="0" cpuset="8"/>
    <vcpupin vcpu="1" cpuset="24"/>
    <vcpupin vcpu="2" cpuset="9"/>
    <vcpupin vcpu="3" cpuset="25"/>
    <vcpupin vcpu="4" cpuset="10"/>
    <vcpupin vcpu="5" cpuset="26"/>
    <vcpupin vcpu="6" cpuset="11"/>
    <vcpupin vcpu="7" cpuset="27"/>
    <vcpupin vcpu="8" cpuset="12"/>
    <vcpupin vcpu="9" cpuset="28"/>
    <vcpupin vcpu="10" cpuset="13"/>
    <vcpupin vcpu="11" cpuset="29"/>
    <vcpupin vcpu="12" cpuset="14"/>
    <vcpupin vcpu="13" cpuset="30"/>
    <vcpupin vcpu="14" cpuset="15"/>
    <vcpupin vcpu="15" cpuset="31"/>
    <emulatorpin cpuset="0-1"/>
    <iothreadpin iothread="1" cpuset="0-1"/>
    <iothreadpin iothread="2" cpuset="2-3"/>
  </cputune>

Replace <features> with the following

<features>
  <acpi/>
  <apic/>
  <hyperv mode="custom">
    <relaxed state="on"/>
    <vapic state="on"/>
    <spinlocks state="on" retries="8191"/>
    <vpindex state="on"/>
    <synic state="on"/>
    <stimer state="on"/>
    <reset state="on"/>
    <vendor_id state="on" value="NZXT"/>
    <frequencies state="on"/>
  </hyperv>
  <kvm>
    <hidden state="on"/>
  </kvm>
  <vmport state="off"/>
  <smm state="on"/>
  <ioapic driver="kvm"/>
</features>

Replace <cpu mode=”host-passthrough” /> with the following

<cpu mode="host-passthrough" check="none" migratable="on">
  <topology sockets="1" dies="1" cores="8" threads="2"/>
  <cache mode="passthrough"/>
  <feature policy="require" name="topoext"/>
  <feature policy="disable" name="hypervisor"/>
</cpu>

then choose begin installiation, clicking a key in the VM when prompted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment