# Fedora Gaming PC

## Drive Setup

This assumes 2x 1TB drives and 1x 500GB drive. Note that I'm not encrypting the steam drive.
This is because you can get *slightly* better performance out of an unencrypted drive. Plus,
realistically, nothing but steam common stuff will be stored there so there's nothing to
protect.

1. Erase the drives completely. Don't format. Make sure each only has free space.
2. Launch the installer
3. Select all 3 drives and select "Advanced Custom (Blivet-GUI)"
4. Click Done
5. On the 500GB drive create a 1024MB ext4 partition, label it boot, and mount it at "/boot"
6. On the 500GB drive create a 600MB efi partition, label it efi, and mount it at "/boot/efi"
7. On the 500GB drive create an encrypted btrfs partition with the rest of the space and mount it at "/"
8. On the slower 1TB drive create an encrypted btrfs partition and mount it at "/home"
9. On the faster 1TB drive create an unencrypted btrfs partition and mount it at "/steam"
10. Click "Done" and begin installation

## btrbk

```bash
sudo dnf install btrbk
```

As usual, you'll need a snapshot service and backup service. These get more complicated
with multi-drive mounts (but actually easier at the same time since each volume is self-
contained).

/etc/btrbk/btrbk_snapshots.conf

```conf
snapshot_preserve_min   24h
snapshot_preserve       24h 14d

volume /mnt/btr_pools
    subvolume           root
    snapshot_dir        root/.snapshots

volume /mnt/btr_pools
    subvolume           home
    snapshot_dir        home/.snapshots

volume /mnt/btr_pools
    subvolume           steam
    snapshot_dir        steam/.snapshots
```

/etc/btrbk/btrbk_backup.conf

```conf
snapshot_preserve_min   all
snapshot_create         no
target_preserve_min     no
target_preserve         24h 7d 4w *m

volume /mnt/btr_pools
    subvolume           root
    snapshot_dir        root/.snapshots
    target              /mnt/backup/root

volume /mnt/btr_pools
    subvolume           home
    snapshot_dir        home/.snapshots
    target              /mnt/backup/home

volume /mnt/btr_pools
    subvolume           steam
    snapshot_dir        steam/.snapshots
    target              /mnt/backup/steam
```

Then you'll need a service to run btrbk_snapshots and btrbk_backup.

/etc/systemd/system/btrbk_snapshots.service

```conf
[Unit]
Description=Runs btrbk with config file at /etc/btrbk/btrbk_snapshots.conf

[Service]
ExecStart=/usr/bin/btrbk -c /etc/btrbk/btrbk_snapshots.conf -v run
```

/etc/systemd/system/btrbk_backup.service

```conf
[Unit]
Description=Runs btrbk with config file at /etc/btrbk/btrbk_backup.conf

[Service]
ExecStart=/usr/bin/btrbk -c /etc/btrbk/btrbk_backup.conf -v run
```

And timers to run the btrbk services on a regular schedule.

/etc/systemd/system/btrbk_snapshots.timer

```conf
[Unit]
Description=Run btrbk_snapshots every hour

[Timer]
OnCalendar=hourly

AccuracySec=10min
Persistent=true
Unit=btrbk_snapshots.service

[Install]
WantedBy=timers.target
```

/etc/systemd/system/btrbk_backup.timer

```conf
[Unit]
Description=Run btrbk_backup every hour

[Timer]
OnCalendar=hourly
AccuracySec=10min
Persistent=true
Unit=btrbk_backup.service

[Install]
WantedBy=timers.target
```

## RDP with autologin

https://askubuntu.com/questions/1396745/21-10-make-screen-share-password-permanent

### Autologin

1. Enable autologin from the gnome user settings

### Create an RDP keychain

1. Open "Passwords and Keys" app on the desktop. Password and Keys App
2. Create a new "Password Keyring" using the "+" icon. Create a new Password Keyring
3. Name the new keyring "Zero Security Keyring" or something that reminds you it will be un-encrypted. Leave the password blank so that the keychain is unencrypted. You will be warned that you are creating an unencrypted keychain.
4. Right-click on the new keyring and choose "set as default" Set the new keyring as the default
5. Click on the old "Default" keyring and delete "GNOME Remote Desktop RDP Credentials" Delete the old RDP password from the "Default keyring"
6. Open settings and set a new RDP password set a new RDP password
7. Check that the password was stored under the "Zero Security Keyring" Check that the RDP password was stored in the new keychain
9. Right click on "Default" keyring and choose "set as default" Remember to set "Default keyring" as the default

## Set Hostname

```bash
hostnamectl set-hostname gamebox
```

## Fira Code

Copy all ttf files into /usr/share/fonts/FiraCode

`sudo fc-cache -v`

## Terminal

1. Rename default profile to "Fira Code"
2. Set the terminal size to 160x60
3. Set the default font to Fira Code
4. Relaunch the terminal

## Disable Gnome Software Updates (packagekitd and software)

To prevent Gnome Shell from starting Software open Settings->Search and disable Software from there.

Run the following to disable auto updating:

```bash
sudo systemctl disable packagekit
sudo systemctl stop packagekit
sudo systemctl mask packagekit

dconf write /org/gnome/software/allow-updates false
dconf write /org/gnome/software/download-updates false
```

Update the system:

`sudo dnf update --refresh`

Reboot.

## Gnome Tweaks

`sudo dnf install gnome-tweaks`

1. Fonts -> Monospace Text -> Fira Code Regular
2. Keyboard & Mouse -> Acceleration Profile -> Flat
5. Top Bar -> Clock -> Weekday -> On
6. Top Bar -> Clock -> Seconds -> On

## Disable Hot Corner

```bash
dconf write /org/gnome/desktop/interface/enable-hot-corners false
```

## Extensions

`sudo dnf install gnome-extensions-app`

Restore to ~/.local/share/gnome-shell/extensions

Vitals:

1. CPU GHz, CPU %, CPU Temp
2. RAM Free
3. Disk Free
4. Network down, Network up

## Automatic Disk Decryption with TPM2

`sudo dnf install vim`

It's a friendlier experience to just encrypt your root partition with tpm
and unlock your remaining drives with key files stored at /etc/lukskeys. This
way you only need to reregister one key with your tpm and the remaining drives
will be unlocked automatically.

https://gist.github.com/jdoss/777e8b52c8d88eb87467935769c98a95

Create a function in ~./bashrc.d/cryptenroll.sh:

```bash
function tpm-luks-enroll {
    read -s -p "Password: " PASSWORD
    export PASSWORD=$PASSWORD
    sudo -E systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+2+4+7 /dev/nvme1n1p3
    unset password
}
function tpm-luks-reenroll {
    read -s -p "Password: " PASSWORD
    export PASSWORD=$PASSWORD
    sudo -E systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+2+4+7 --wipe-slot=tpm2 /dev/nvme1n1p3
    unset password
}
```

Add your luks keys to the tpm module and set up boot parameters:

```bash
# Enroll for the first time
tpm-luks-enroll

# Add tpm2 configuration option to /etc/crypttab FOR EVERY DISK
luks-$UUID UUID=disk-$UUID none tpm2-device=auto,discard

# Add rd.luks.options=tpm2-device=auto to grub
sudo grubby --args="rd.luks.options=tpm2-device=auto" --update-kernel=ALL

sudo dracut -f
```

When you update the kernel:

```bash
tpm-luks-reenroll
```

Reboot.

Or you can create a systemd service which does the reenroll automatically:

```conf
[Unit]
Description=Automatically runs systemd-cryptenroll on login

[Service]
Type=oneshot
ExecStart=/usr/bin/systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+2+4+7 --wipe-slot=tpm2 /dev/nvme0n1p3
Environment=PASSWORD=<password>

[Install]
WantedBy=multi-user.target
```

## RDP with autologin

https://askubuntu.com/questions/1396745/21-10-make-screen-share-password-permanent

### Autologin

1. Enable autologin from the gnome user settings
2. Create a systemd user service to lock the screen after autologin

```bash
mkdir -p ~/.local/share/systemd/user/autolock.service
vim ~/.local/share/systemd/user/autolock.service
```

**~/.local/share/systemd/user/autolock.service**

```service
[Unit]
Description=Auto lock after auto login

[Service]
Type=oneshot
ExecStart=/bin/bash -c "sleep 5 && loginctl lock-session"

[Install]
WantedBy=default.target
```

systemctl --user enable autolock.service

### Create an RDP keychain

`sudo dnf install seahorse`

1. Open "Passwords and Keys" app on the desktop. Password and Keys App
2. Create a new "Password Keyring" using the "+" icon. Create a new Password Keyring
3. Name the new keyring "Zero Security Keyring" or something that reminds you it will be un-encrypted. Leave the password blank so that the keychain is unencrypted. You will be warned that you are creating an unencrypted keychain.
4. Right-click on the new keyring and choose "set as default" Set the new keyring as the default
5. Click on the old "Default" keyring and delete "GNOME Remote Desktop RDP Credentials" Delete the old RDP password from the "Default keyring"
6. Open settings and set a new RDP password set a new RDP password
7. Check that the password was stored under the "Zero Security Keyring" Check that the RDP password was stored in the new keychain
9. Right click on "Default" keyring and choose "set as default" Remember to set "Default keyring" as the default

Reboot.

## Flatpack

```bash
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak update
```

## Steam

### Install ProtonUp-Qt

```bash
flatpak install flathub net.davidotek.pupgui2
```

### Install Steam

```bash
sudo dnf install https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install steam
sudo chown ducoterra:ducoterra /steam

# If libbz2 is missing (or some other error)
cd ~/.local/share/Steam/
./steam.sh --reset
```

Flatpak

```bash
sudo flatpak install com.valvesoftware.Steam
sudo flatpak install com.valvesoftware.Steam.CompatibilityTool.Proton-GE
flatpak override --user --filesystem=/home/ducoterra/Steam com.valvesoftware.Steam
```

### Enable OBS Game Capture

<https://github.com/nowrep/obs-vkcapture>

```bash
sudo dnf install cmake gcc gcc-c++ obs-studio-devel mesa-libGL-devel vulkan-loader-devel

git clone ssh://git@gitea.reeseapps.com:2222/mirrors/obs-vkcapture.git
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make && make install
```

Add `env OBS_VKCAPTURE=1 %command%` to your launch options for the game you want to capture.

## OBS

<https://www.reddit.com/r/linux_gaming/comments/w4i3qf/easy_way_to_get_good_4k_60fps_obs_encoding>

```bash
sudo flatpak install \
    com.obsproject.Studio \
    com.obsproject.Studio.Plugin.Gstreamer \
    org.freedesktop.Platform.GStreamer.gstreamer-vaapi \
    com.obsproject.Studio.Plugin.OBSVkCapture
```

Create a new scene and add "Game Capture" to it. When you start a game with the above
launch option (`env OBS_VKCAPTURE=1 %command%`) OBS will automatically pick it up.

Use advanced settings to select the GStreamer encoder and the VA-API encoder type.

![obs_hardware_encoding_settings](obs_hardware_encoding.png)

## FFMPEG with hardware encoding/decoding

First you'll need mesa-va-drivers-freeworld which provides x264 and hevc support for
vaapi decoding. First you'll need to install [https://rpmfusion.org/Configuration](rpm fusion).
Then the freeworld drivers need to be swapped with mesa-va-drivers:

```bash
sudo dnf swap mesa-va-drivers mesa-va-drivers-freeworld
```

To check what hardware decoding is supported by your system you'll need vainfo:

```bash
sudo dnf install libva-utils
```

Running `vainfo` will show all available profiles. You should see H264, HEVC, AV1, and VP9.

Then with ffmpeg you can run

```bash
ffmpeg \
-hwaccel vaapi \
-vaapi_device /dev/dri/renderD128 \
-hwaccel_output_format vaapi \
-i input.mkv \
-c:v hevc_vaapi \
-b:v 0 \
test.mp4
```

## Power Button Behavior

The power button is controlled from 2 locations:

1. DCONF (or gnoem settings) at `gnome.settings-daemon.plugins.power`
2. ACPI at /etc/acpi/events/powerconf

The powerconf acpi configuration will execute at the same time the gnome settings do.
This can lead to situations where the gnome settings say "suspend" but the acpi settings
say "shutdown". On waking up your laptop it will immediately shutdown.

The solution is to comment out everything in /etc/acpi/events/powerconf and rely on the
gnome settings **OR** set the gnome settings to "nothing" and edit
`/etc/acpi/actions/power.sh` with the behavior you expect. Either way you should pick
one to control power button behavior.

## Discord

vim ~/.local/share/applications/Discord.desktop

```conf
[Desktop Entry]
Encoding=UTF-8
Name=Discord
Exec=/home/ducoterra/Applications/Discord/Discord
Icon=/home/ducoterra/Applications/Discord/discord.png
Type=Application
Categories=Communication;
```

## AppImage Launcher

Download RPM from https://github.com/TheAssassin/AppImageLauncher/releases/tag/v2.2.0

## Snap

```bash
sudo dnf install -y snapd
sudo ln -s /var/lib/snapd/snap /snap # for classic snap support
ln -s /var/lib/snapd/desktop/applications ~/.local/share/applications/snap # make apps show up in gnome
sudo reboot now
```

### Minecraft

1. You can find extra java versions at /etc/alternatives
2. You need to `dnf install xrandr` to launch any modpacks
3. You can create a desktop icon by putting this at ~/.local/share/applications/*.desktop:

```
[Desktop Entry]
Encoding=UTF-8
Name=Minecraft
Exec=/home/ducoterra/Applications/minecraft-launcher
Icon=/home/ducoterra/.icons/minecraft-launcher.png
Type=Application
Categories=Games;
```

### Sound

If you want to disable a specific device or tell Fedora not to use a specific device
as output or input (looking at you yeti microphone, you're not a speaker), you can
install pulse audio control for much more fine-tuned... control.

Setting your speakers to analog output seems to work best for a USB dac if it has
a separate volume knob since this ties the volume knob on the dac to the internal
volume of your computer.

Setting your mic to analog input works just fine on a yeti usb mic.

```bash
sudo dnf install pavucontrol
```

### Disable Wayland (Don't do this)

Edit /etc/gdm/custom.conf

```conf
[daemon]
WaylandEnable=false
DefaultSession=gnome-xorg.desktop
```

### Discord sharing not working

THIS IS PROBABLY A PER-APP THING

Likely the thing you're trying to share doesn't work, it's not wayland's fault.

If you're trying to share firefox - download the firefox binary and dnf
uninstall the other one. For whatever reason the preinstalled binary doesn't
like screen share. You can use the following:

~/.local/share/applications/firefox.desktop

```conf
[Desktop Entry]
Encoding=UTF-8
Name=Firefox
Exec=/home/ducoterra/Applications/firefox/firefox-bin
Icon=/home/ducoterra/.icons/firefox.svg
Type=Application
Categories=Browser;
```

## Install ffmpegthumbnailer, remove totem

totem-thumbnailer crashes all the time and isn't as good as ffmpeg's thumbnailer.
What's more, totem video player ("Videos" by default on gnome) is not as good as vlc
and doesn't work very well for anything more than basic video playback.

```bash
sudo dnf remove totem
sudo dnf install ffmpegthumbnailer
```

## Login script from SSH

Useful for when you can't log in yourself but you need to launch steam.

```bash
loginctl unlock-sessions
read -s pass && echo -n $pass | gnome-keyring-daemon --unlock --replace
```
