# Installation

***

A lot of the information for the installation below were obtained from,

{% embed url="<https://wiki.archlinux.org/title/Installation_guide>" %}
Arch Linux wiki for most of the information
{% endembed %}

{% embed url="<https://nerdstuff.org/posts/2020/05/31/installing-arch-btrfs-luks/>" %}
This guide showed the correct way to mount btrfs and generate fstab for it
{% endembed %}

{% embed url="<https://walian.co.uk/arch-install-with-secure-boot-btrfs-tpm2-luks-encryption-unified-kernel-images.html>" %}
Contains some good information that I could not figure out easily from wiki
{% endembed %}

***

## To-Do

* Use [Discoverable Partitions](https://uapi-group.org/specifications/specs/discoverable_partitions_specification/) to remove the need for UUID. Ensure it is supported for btrfs.
* btrfs based swap support might be nice to add just to safeguard against applications that might need it.

## Useful Resources

* [Zapping](https://www.rodsbooks.com/gdisk/wipegpt.html) MBR and/or GPT on the disk.

***

## ArchISO Commands

{% code overflow="wrap" %}

```bash
# check if internet connection is available
ping archlinux.org

# Wi-Fi
iwctl --passphrase <passphrase> station <name> connect <SSID>

# Activate SSH for ArchISO
passwd
ip add

localectl list-keymaps
loadkeys ie

# 64 for UEFI
cat /sys/firmware/efi/fw_platform_size

# check if time is right
timedatectl

# check which drive to use, nvme0nX or sdaX
lsblk
# gdisk /dev/sda, expert mode to zap it if needed.
cfdisk /dev/sda
# EFI 1GB, rest linux filesystem

# format the partitions
mkfs.fat -F 32 /dev/sda1
mkfs.btrfs /dev/sda2

# mount, create subvolumes, unmount
mount /dev/sda2 /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
umount -R /mnt

# mount the subvolumes and efi
mount -o defaults,compress=zstd,subvol=@ /dev/sda2 /mnt
mount --mkdir -o defaults,compress=zstd,subvol=@home /dev/sda2 /mnt/home
mount --mkdir /dev/sda1 /mnt/efi

# check mirrors, set parallel downloads on
cat /etc/pacman.d/mirrorlist
vim /etc/pacman.conf

# pacstrap stuff
# install either amd-ucode or intel-ucode
pacstrap -K /mnt base base-devel linux linux-firmware bash-completion btrfs-progs timeshift sbctl zram-generator nano neovim networkmanager iwd openssh git wget reflector zsh man-db man-pages texinfo tldr amd-ucode
# Add grub and efibootmgr if installing GRUB

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

# CHROOT INTO SYSTEM
arch-chroot /mnt

ln -sf /usr/share/zoneinfo/Europe/Dublin /etc/localtime
hwclock --systohc

nvim /etc/locale.gen
# uncomment locale
locale-gen

echo "LANG=en_IE.UTF-8" > /etc/locale.conf
echo "KEYMAP=ie" > /etc/vconsole.conf
echo "arch" > /etc/hostname

# users n stuff
passwd
useradd -m -G wheel -s /bin/zsh spec
passwd spec
EDITOR=nvim visudo
# uncomment wheel

# parallel downloads
nvim /etc/pacman.conf
# 32 bit support
# !!! enable multilib here too !!!
pacman -Syy

# zsh init
su spec
# 1 10 21 31e0 0
exit

# systemd-boot install
ls /sys/firmware/efi/efivars
# if files are available, UEFI boot is on
# check wiki otherwise
bootctl install

# Kernel parameters
echo "root=UUID=$(blkid -s UUID -o value /dev/sda2) rootflags=subvol=@ rw quiet splash" > /etc/kernel/cmdline

# UKI (i couldnt get the normal systemd-boot to work with btrfs lole)
# this is better anyway we ball
sbctl create-keys
sbctl enroll-keys -m
# verify won't work within chroot, it is to check which files to sign
sbctl verify
sbctl sign -s /boot/vmlinuz-linux
sbctl sign -s /boot/EFI/BOOT/BOOTX64.EFI
sbctl bundle --amducode /boot/amd-ucode.img --save /efi/EFI/Linux/arch-linux.efi
sbctl generate-bundles --sign

# set iwd as wifi backend for networkmanager
nvim /etc/NetworkManager/conf.d/wifi_backend.conf
[device]
wifi.backend=iwd

# install zram
nvim /etc/systemd/zram-generator.conf
[zram0]
zram-size = min(ram / 2, 4096)
compression-algorithm = zstd
swap-priority = 100
fs-type = swap

nvim /etc/sysctl.d/99-vm-zram-parameters.conf
vm.swappiness = 180
vm.watermark_boost_factor = 0
vm.watermark_scale_factor = 125
vm.page-cluster = 0

# if zram schtuff was done outside of chroot
systemctl daemon-reload
systemctl enable /dev/zram0
systemctl start /dev/zram0
systemctl status systemd-zram-setup@zram0.service

# systemd stuff
systemctl enable NetworkManager.service
systemctl enable systemd-timesyncd.service
systemctl enable sshd.service

# exit chroot
exit # or C-d
umount -R /mnt
reboot
```

{% endcode %}

***

## NVIDIA (Sadge)

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash"><strong># Nvidia schtuff
</strong># Did this on a Turing card, 3090 Ti and a Pascal card, 1060 Max-Q

# check gpu
lspci -k | grep -A 2 -E "(VGA|3D)"
pacman -S nvidia nvidia-settings lib32-nvidia-utils
# nvidia-settings is X11 only :(

# disable nouveau
# !!! Remove kms from the HOOKS array in /etc/mkinitcpio.conf
# early load nvidia
MODULES=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
mkinitcpio -P

# pacman hook to auto regenerate initramfs on nvidia update
nvim /etc/pacman.d/hooks/nvidia.hook
[Trigger]
Operation=Install
Operation=Upgrade
Operation=Remove
Type=Package
# Uncomment the installed NVIDIA package
Target=nvidia
#Target=nvidia-open
#Target=nvidia-lts
Target=linux
# Change the linux part above if a different kernel is used

[Action]
Description=Update NVIDIA module in initcpio
Depends=mkinitcpio
When=PostTransaction
NeedsTargets
Exec=/bin/sh -c 'while read -r trg; do case $trg in linux*) exit 0; esac; done; /usr/bin/mkinitcpio -P'

# add nvidia to kernel parameters
nvim /etc/kernel/cmdline
# append the following
# use fbdev if driver version >550
nvidia_drm.modeset=1 nvidia_drm.fbdev=1

# regenerate UKI with the new kernel parameters
sbctl generate-bundles --sign
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.specarino.com/specs-corner/arch/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
