hw-acceleration.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. set -eEuo pipefail
  7. function header_info {
  8. clear
  9. cat <<"EOF"
  10. __ ___ __ ___ __ __ _
  11. / // / | /| / / / _ |___________ / /__ _______ _/ /_(_)__ ___
  12. / _ /| |/ |/ / / __ / __/ __/ -_) / -_) __/ _ `/ __/ / _ \/ _ \
  13. /_//_/ |__/|__/ /_/ |_\__/\__/\__/_/\__/_/ \_,_/\__/_/\___/_//_/
  14. EOF
  15. }
  16. header_info
  17. echo "Loading..."
  18. whiptail --backtitle "Proxmox VE Helper Scripts" --title "Add HW Acceleration" --yesno "This Will Add HW Acceleration to an exixting LXC Container. Proceed?" 10 68 || exit
  19. NODE=$(hostname)
  20. PREV_MENU=()
  21. MSG_MAX_LENGTH=0
  22. privileged_containers=$(pct list | awk 'NR>1 && system("grep -q \047unprivileged: 1\047 /etc/pve/lxc/" $1 ".conf")')
  23. if [ -z "$privileged_containers" ]; then
  24. whiptail --msgbox "No Privileged Containers Found." 10 58
  25. exit
  26. fi
  27. while read -r TAG ITEM; do
  28. OFFSET=2
  29. ((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
  30. PREV_MENU+=("$TAG" "$ITEM " "OFF")
  31. done < <(echo "$privileged_containers")
  32. privileged_container=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Privileged Containers on $NODE" --checklist "\nSelect a Container To Add HW Acceleration:\n" 16 $((MSG_MAX_LENGTH + 23)) 6 "${PREV_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
  33. header_info
  34. cat <<EOF >>/etc/pve/lxc/${privileged_container}.conf
  35. lxc.cgroup2.devices.allow: c 226:0 rwm
  36. lxc.cgroup2.devices.allow: c 226:128 rwm
  37. lxc.cgroup2.devices.allow: c 29:0 rwm
  38. lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file
  39. lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir
  40. lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
  41. EOF
  42. pct exec $privileged_container -- bash -c "apt-get -y install va-driver-all && apt-get -y install ocl-icd-libopencl1 && apt-get install -y intel-opencl-icd && chgrp video /dev/dri && chmod 755 /dev/dri && chmod 660 /dev/dri/*"
  43. header_info
  44. echo -e "Completed Successfully!\n"
  45. echo -e "Reboot container $privileged_container to apply the new settings\n"