Plex HW acceleration in LXC container - anyone with success?

server-linux

#7

will do tonight - rather simple approach


#8

Moderator edit: This guide has been formalized thanks to @Johnnyh1975 and is now published permanently here:
https://forums.plex.tv/discussion/301781/pms-installation-guide-when-using-a-proxmox-5-1-lxc-container

Installation guide for Plex Server under Proxmox 5.1 within an LXC Container

1. Create an LXC Container (standard approach, well documented in Proxmox)

Use the standard approach within Proxmox and create a privileged Container (incl. definition of hostname, root password)
Select the your target operating system template, e.g. ubuntu 16.04, ubuntu 17.04 or ubuntu 17.10. (you have to download it from the Proxmox server)
Define the memory and cpu allocation for your Plex container: e.g. 8 cores, 20GB RAM,... as well as network parameters

2. Install on Intel Graphics acceleration drivers on Proxmox Host**

First install on the Proxmox host the intel graphics acceleration drivers. (e.g. via Shell JS in the Proxmox manager)
Proxmox host is running Debian stretch.

apt-get install i965-va-driver

Test if the driver is working. Install vainfo

apt-get install vainfo

Running vainfo should give you an output comparable to

error: can't connect to X server!
libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.3)
vainfo: Driver version: Intel i965 driver for Intel(R) Kabylake - 1.7.3
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Simple : VAEntrypointEncSlice
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointEncSlice
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264MultiviewHigh : VAEntrypointVLD
VAProfileH264MultiviewHigh : VAEntrypointEncSlice
VAProfileH264StereoHigh : VAEntrypointVLD
VAProfileH264StereoHigh : VAEntrypointEncSlice
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileNone : VAEntrypointVideoProc
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileVP8Version0_3 : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointEncSlice
VAProfileVP9Profile2 : VAEntrypointVLD

Well done your host is supporting the appropriate acceleration.

3. GPU passthrough configuration to Plex Container

Find out the right parameter of your graphics card

ls -l /dev/dri

this should give you a comparable output to the following

crw-rw---- 1 root video 226, 0 Dec 29 14:06 card0
crw-rw---- 1 root video 226, 128 Dec 29 14:06 renderD128

Note down the numbers behind video
card0 has the id 226, 0
renderD128 has the id 226,128

Additionally take the fb0 devices as well
ls -l /dev/fb0

This gives the following output

crw-rw---- 1 root video 29, 0 Dec 29 14:06 /dev/fb0
so fb0 has the id 29,0

Next define the gnu passthrough by adding the following lines at the end of your 100.conf file (use the appropriate number 100, 101,... that you assigned before to the Plex container). Please adjust the following lines with the id numbers for your graphics system you have noted down just before. In the last line replace the 100 with the Plex container id of your system.

nano /etc/pve/lxc/100.conf

lxc.cgroup.devices.allow = c 226:0 rvm
lxc.cgroup.devices.allow = c 226:128 rvm
lxc.cgroup.devices.allow = c 29:0 rvm
lxc.autodev: 1
lxc.autodev.hook: /var/lib/lxc/100/mount_hook.sh

The last line calls at boot of the container a shell script that you need to create to mount the devices appropriately..
Let's create it:

nano /var/lib/lxc/100/mount_hook.sh

Add the following lines and adjust the id's to your graphics system:

mkdir -p ${LXC_ROOTFS_MOUNT}/dev/dri
mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/dri/card0 c 226 0
mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/dri/renderD128 c 226 128
mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/fb0 c 29 0

Save the file and make it executable.
chmod 755 /var/lib/lxc/100/mount_hook.sh

Your Plex LXC container is ready to boot up incl. GPU passthrough. Well done!

  1. Boot-up your container and install Plex media server Via Console JS of your container execute the following steps

Login with root and the assigned password in step 1
Make sure your system is up-to-date

apt-get update && sudo apt-get upgrade

Head to the Plex Downloads page. Download the current ubuntu package and make it available inside the container.
Alternatively copy the download link from the web page. Use wget to download the installer via the copied link:

wget https://downloads.plex.tv/...amd64.deb
Make sure to exchange in this command the url by the copied one from the web page.

This example uses the current link for Ubuntu, at the time of writing. Be sure to use the up-to-date version supplied on the Plex website.

Use dpkg to install the Plex server:
dpkg -i plexmediaserver*.deb

Enable Plex Media Server to start on reboot, and then start the server:

systemctl enable plexmediaserver.service
systemctl start plexmediaserver.service

The rest is than standard Plex configuration and media file management which is well documented. So I will not repeat it.

Last step to make sure your Plex server is using hardware acceleration. Within the Plex web interface, go on "settings>server>transcoder". Make sure that advanced options are shown. And checkmark "use hardware acceleration when available"

And now enjoy a fast transcoding experience within an LXC container. On my system the CPU usage was reduced by 50% compared to before :-)


#9

@ChuckPA - Step-by-step Guide is posted


#10

Thank you.

I will transfer to Linux Tips, credit you, direct any errata to you?


#11

@Johnnyh1975

I have a few questions:

  1. PMS download direct link is not advisable. 1.5.5 did not support HW transcode. Will this work with any version supporting HW transcoding?
  2. Do you know the link (or starting point) for Intel drivers (your step #2)

#12

@ChuckPA
yes it will work - exchange it with the newest link and it's fine.
(I was a bit lazy so I copied the link from another guide I used in the past)
the intel drivers are part of the normal Debian repository so apt-get will find it. It's a standard package


#13

Would you mind making those minor updates? I don't want to make any mistakes.


#14

@ChuckPA
updated the download link to the latest public Plex download


#15

Looking good... Except:

You're still using a direct-download link (wget) in the container.

Would you rework that such that:

  1. Download current via the web page
  2. Make the downloaded file available in the container.

If this isn't possible, use the approach of right-click / copy URL for the desired version.


#16

@ChuckPA
your suggestion is incorporated


#17

@Johnnyh1975

Please proof read ?

https://forums.plex.tv/discussion/301781/work-in-progress-do-not-use-pms-installation-guide-when-using-a-proxmox-5-1-lxc-container


#18

@ChuckPA

Found some typos, but can‘t edit the post directly
3rd line in 1st Paragraph: erase ‚the‘
2nd titel: erase first ‚on‘ and erase ‚**‘ at the end
3rd Paragraph, 5th bullet: ‚gnu‘ should be ‚gpu‘

Rest Looks good


#19

There you go. Edits applied.

Barring any last second gaffs on my part which you may find, It's Open for business

Thank you for all your help and patience.

:+1:


#20

Hey,
thank you for the great tutorial.

I have some small corrections:

xc.cgroup.devices.allow = c 226:0 ~~rvm~~ rwm
lxc.cgroup.devices.allow = c 226:128 ~~rvm~~ rwm
lxc.cgroup.devices.allow = c 29:0 ~~rvm~~ rwm
lxc.autodev: 1
~~lxc.autodev.hook:~~ lxc.hook.autodev:/var/lib/lxc/100/mount_hook.sh


#21

@4Me
@ChuckPA

in the Post 12 - the corrections are valid. Sorry for the typos...


#22

I do not see threads and posts as you do.

Please quote the text which is correct?


#23

@ChuckPA

The ohne from 4Me


#24

@4Me
@Johnnyh1975

Edit's applied. Please verify


#25

@ChuckPA
lxc.autodev.hook needs to be changed additionally to lxc.hook.autodev


#26

One last check?