# Hetzner - Using iGPU for Hardware Acceleration

## Preface

A basic guide for enabling the internal GPU (iGPU) on Intel CPUs for Hetzner servers. Only tested on the machines with i7 CPUs.

This is loosely based off a [reddit comment](https://www.reddit.com/r/seedboxes/comments/57uq5e/hardware_video_encoding_on_hetzner_server_with/d8yfg8t/), with some changes to work with Ubuntu 18.04.

EDIT - December 21st, 2021: I've also followed my own guide for Debian 11, with an i7-8700k (on Hetzner). So it should work for Ubuntu 20.04 and Debian 10 as well. You might need to install some Intel drivers from `apt` (e.g. `intel-media-va-driver`), but I'm not entirely sure.

## Grub

> Remove hetzner's default grub config "nomodeset" which blocks loading of video card drivers. Open /etc/default/grub.d/hetzner.cfg, and comment out #GRUB_CMDLINE_LINUX_DEFAULT="nomodeset"

This file doesn't exist on Hetzner's Ubuntu 18.04 minimal image, so here are the correct steps.

1. `sudo nano /etc/default/grub`
2. Remove `nomodeset` from `GRUB_CMDLINE_LINUX_DEFAULT`
	- I don't recommend commenting the whole line out, since there might be other options supplied there. If there aren't, it should be safe to comment I guess.
3. `sudo update-grub` to update the bootloader.
	- Don't reboot yet.
    
## Enabling drivers

Pretty much follow this as written:

> Comment all line referencing i915 in this file.  
> `sudo nano /etc/modprobe.d/blacklist-hetzner.conf`

1. Open `sudo nano /etc/modprobe.d/blacklist-hetzner.conf`
2. Comment `blacklist i915` and `blacklist i915_bdw` by adding a `#` in front:
	- `#blacklist i915`
	- `#blacklist i915_bdw`
3. Here's how my file looks like:
```
### Hetzner Online GmbH - installimage
### silence any onboard speaker
blacklist pcspkr
blacklist snd_pcsp
### i915 driver blacklisted due to various bugs
### especially in combination with nomodeset
#blacklist i915
#blacklist i915_bdw
### mei driver blacklisted due to serious bugs
blacklist mei
blacklist mei-me
blacklist sm750fb
```

## Allowing Plex to use iGPU (non-Docker)

> Add user emby (or plex) to the video group:  
> `sudo usermod -a -G video emby`

Doing it for Plex is practically the same.

1. `sudo adduser plex video` **or** `sudo usermod -aG video plex`
	- You only need to use one of them.
    
## Allowing Plex to use iGPU (Docker)

I recommend using [LinuxServer's Docker image](https://github.com/linuxserver/docker-plex). Though with that said, I don't have any experience with it lol.

### Docker Compose

With a `docker-compose.yml` file, add a `devices:` to your container config:

```yml
devices:
	- "/dev/dri:/dev/dri"
```

Here's an example config file with `devices` specified:

```yml
---
version: "2"
services:
  plex:
    image: linuxserver/plex
    container_name: plex
    network_mode: host
    devices:
      - "/dev/dri:/dev/dri"
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
    volumes:
      - ./config:/config
      - /data/PlexMedia:/data/PlexMedia
    restart: unless-stopped
```

### `docker run` (not recommended)

If you're running your Docker image manually (why?) then add `--device=/dev/dri:/dev/dri` as [documented on LinuxServer's GitHub](https://github.com/linuxserver/docker-plex#hardware-acceleration)