Update hw-acceleration.sh

This commit is contained in:
CanbiZ 2025-03-27 14:30:33 +01:00
parent e5c251f21c
commit 1be9bd2bd4

View File

@ -66,12 +66,10 @@ function detect_features() {
} }
function select_hw_features() { function select_hw_features() {
local opts SELECTED_FEATURES=$(whiptail --title "Hardware Options" --checklist \
opts=$(whiptail --title "Hardware Options" --checklist \
"Select hardware features to passthrough:" 20 60 10 \ "Select hardware features to passthrough:" 20 60 10 \
"${AVAILABLE_FEATURES[@]}" 3>&1 1>&2 2>&3) || exit 1 "${AVAILABLE_FEATURES[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit 1
SELECTED_FEATURES=$(echo "$opts" | tr -d '"')
[[ -z "$SELECTED_FEATURES" ]] && { [[ -z "$SELECTED_FEATURES" ]] && {
msg warn "No passthrough options selected." msg warn "No passthrough options selected."
exit 1 exit 1
@ -79,17 +77,19 @@ function select_hw_features() {
} }
function select_lxc_targets() { function select_lxc_targets() {
local list
local opts=() local opts=()
list=$(pct list | awk 'NR>1 {print $1 "|" $2}') || return 1 while IFS= read -r line; do
while IFS="|" read -r id name; do local id name conf
[[ -f "/etc/pve/lxc/${id}.conf" ]] && opts+=("$id" "$name (CTID: $id)" OFF) id=$(awk '{print $1}' <<<"$line")
done <<<"$list" name=$(awk '{print $2}' <<<"$line")
conf="/etc/pve/lxc/${id}.conf"
[[ -f "$conf" ]] && opts+=("$id" "$name (CTID: $id)" OFF)
done < <(pct list | tail -n +2)
[[ ${#opts[@]} -eq 0 ]] && { if [[ ${#opts[@]} -eq 0 ]]; then
msg warn "No LXC containers found." msg warn "No containers found. Make sure you have running LXCs."
exit 1 exit 1
} fi
SELECTED_CTIDS=$(whiptail --title "Select LXC Containers" --checklist \ SELECTED_CTIDS=$(whiptail --title "Select LXC Containers" --checklist \
"Choose container(s) to apply passthrough:" 20 60 10 \ "Choose container(s) to apply passthrough:" 20 60 10 \
@ -165,16 +165,31 @@ function install_drivers() {
for opt in $SELECTED_FEATURES; do for opt in $SELECTED_FEATURES; do
case "$opt" in case "$opt" in
intel) intel)
msg info "Installing Intel drivers in CT $ctid..." msg info "Installing Intel drivers/tools in CT $ctid..."
pct exec "$ctid" -- bash -c "apt-get update && apt-get install -y va-driver-all vainfo intel-gpu-tools ocl-icd-libopencl1 intel-opencl-icd && adduser \$(id -un 0) video && adduser \$(id -un 0) render" >/dev/null 2>&1 pct exec "$ctid" -- bash -c "
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y \
va-driver-all vainfo intel-gpu-tools \
ocl-icd-libopencl1 intel-opencl-icd >/dev/null
adduser root video >/dev/null 2>&1 || true
adduser root render >/dev/null 2>&1 || true
"
;; ;;
nvidia) nvidia)
msg info "Installing NVIDIA drivers/tools in CT $ctid..." msg info "Installing NVIDIA container tools in CT $ctid..."
pct exec "$ctid" -- bash -c "apt-get update && apt-get install -y nvidia-container-runtime nvidia-utils-525" >/dev/null 2>&1 || true pct exec "$ctid" -- bash -c "
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y \
nvidia-container-runtime nvidia-utils-525 >/dev/null 2>&1 || true
"
;; ;;
amd) amd)
msg info "Installing AMD ROCm tools in CT $ctid..." msg info "Installing AMD ROCm tools in CT $ctid..."
pct exec "$ctid" -- bash -c "apt-get update && apt-get install -y rocm-smi rocm-utils" >/dev/null 2>&1 || true pct exec "$ctid" -- bash -c "
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y \
rocm-smi rocm-utils >/dev/null 2>&1 || true
"
;; ;;
esac esac
done done
@ -198,21 +213,19 @@ function main() {
amd) apply_amd "$conf" && updated=1 ;; amd) apply_amd "$conf" && updated=1 ;;
esac esac
done done
if [[ "$updated" -eq 1 ]]; then [[ "$updated" -eq 1 ]] && updated_cts+=("$ctid")
updated_cts+=("$ctid") install_drivers "$ctid"
install_drivers "$ctid"
fi
done done
if [[ ${#updated_cts[@]} -gt 0 ]]; then if [[ ${#updated_cts[@]} -gt 0 ]]; then
msg ok "Updated passthrough in container(s): ${updated_cts[*]}" msg ok "Hardware passthrough updated in: ${updated_cts[*]}"
if whiptail --title "Restart Containers" --yesno "Restart now?\n${updated_cts[*]}" 10 60; then if whiptail --yesno "Restart updated container(s)?\n${updated_cts[*]}" 10 60; then
for ctid in "${updated_cts[@]}"; do for ctid in "${updated_cts[@]}"; do
pct restart "$ctid" pct restart "$ctid"
done done
msg ok "Containers restarted: ${updated_cts[*]}" msg ok "Containers restarted: ${updated_cts[*]}"
else else
msg info "Reboot manually to apply changes." msg info "Please restart the container(s) manually."
fi fi
else else
msg warn "No passthrough or driver changes were applied." msg warn "No passthrough or driver changes were applied."