Skip to content

Instantly share code, notes, and snippets.

@kralicky
Created November 12, 2021 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kralicky/43bd9ab885da03545134a1cdf484b1ad to your computer and use it in GitHub Desktop.
Save kralicky/43bd9ab885da03545134a1cdf484b1ad to your computer and use it in GitHub Desktop.
VGPU mediated device persistence
[Unit]
Description=Start defined mediated devices
Requires=nvidia-vgpu-mgr.service
Requires=nvidia-vgpud.service
After=nvidia-vgpu-mgr.service
After=nvidia-vgpud.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/start-defined-vgpus.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
while true; do
devices=$(/usr/local/bin/mdevctl list -d | grep -v '\(active\)' | awk '{ printf "%s ",$1 }')
if [ -z "$devices" ]; then
echo "No unstarted mediated devices found."
exit 0
fi
num=$(echo "$devices" | wc -w)
echo "Attempting to start $num mediated devices"
for device in $devices; do
/usr/local/bin/mdevctl start --uuid $device
if [ $? -ne 0 ]; then
echo "Failed to start device $device, will retry in 10 seconds."
sleep 10
continue 2
else
echo "Successfully started device $device"
fi
done
echo "Successfully started $num devices."
exit 0
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment