Skip to main content

Add an Automatic DRI Device Update Script to Proxmox

Create a new file called /usr/local/bin/update-lxc-dri-devices.sh with this content:

#!/bin/bash

echo "Updating LXC container DRI device paths..."

# find first card that matches
pattern="/dev/dri/card*"
cards=( $pattern )
firstCard="${cards[0]}"
#firstCard="/dev/dri/card0" # for testing
echo "Found $firstCard..."

# find .conf files that contain /dev/dri/card#
confs=("$(grep -rlP '\/dev\/dri\/card\d' --include '*.conf' -- /etc/pve/lxc)")

# loop over them, updating them if they don't already contain the correct device
for f in $confs;
do
echo -n "* Checking LXC config $f..."
if (grep "$firstCard" "$f" >/dev/null)
then
echo "no update needed."
else
oldMatch=("$(grep -P "\/dev\/dri\/card\d" "$f")")
sed -i.bak "s,/dev/dri/card[0-9],$firstCard,g" "$f"
echo "update needed:"
echo "- old: $oldMatch"
newMatch=("$(grep -P '\/dev\/dri\/card\d' "$f")")
echo "- new: $newMatch"
fi
done

echo "Done."

Allow execute on this new file:

chmod +x /usr/local/bin/update-lxc-dri-devices.sh

Create a new file called /etc/systemd/system/update-lxc-dri-devices.service:

[Unit]
Description=Update LXC DRI device mappings
After=pve-cluster.service
Wants=pve-cluster.service
Before=pve-manager.service

[Service]
ExecStart=/usr/local/bin/update-lxc-dri-devices.sh

[Install]
WantedBy=pve-manager.service

Enable it by running:

systemctl enable update-lxc-dri-devices.service

Test it by running:

systemctl start update-lxc-dri-devices.service

Check the status with:

journalctl -b | grep update-lxc-dri-devices