This commit is contained in:
CanbiZ
2025-04-09 14:23:35 +02:00
parent 2671c388d0
commit b67b565d23
17 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
clear
if command -v pveversion >/dev/null 2>&1; then echo -e "⚠️ Can't Run from the Proxmox Shell"; exit; fi
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
BGN=$(echo "\033[4;92m")
GN=$(echo "\033[1;92m")
DGN=$(echo "\033[32m")
CL=$(echo "\033[m")
BFR="\\r\\033[K"
HOLD="-"
CM="${GN}${CL}"
CROSS="${RD}${CL}"
APP="Home Assistant Container"
while true; do
read -p "This will restore ${APP} from a backup. Proceed(y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
clear
function header_info {
cat <<"EOF"
__ __ ___ _ __ __
/ / / /___ ____ ___ ___ / | __________(_)____/ /_____ _____ / /_
/ /_/ / __ \/ __ `__ \/ _ \ / /| | / ___/ ___/ / ___/ __/ __ `/ __ \/ __/
/ __ / /_/ / / / / / / __/ / ___ |(__ |__ ) (__ ) /_/ /_/ / / / / /_
/_/ /_/\____/_/ /_/ /_/\___/ /_/ |_/____/____/_/____/\__/\__,_/_/ /_/\__/
RESTORE FROM BACKUP
EOF
}
header_info
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
if [ -z "$(ls -A /var/lib/docker/volumes/hass_config/_data/backups/)" ]; then
msg_error "No backups found! \n"
exit 1
fi
DIR=/var/lib/docker/volumes/hass_config/_data/restore
if [ -d "$DIR" ]; then
msg_ok "Restore Directory Exists."
else
mkdir -p /var/lib/docker/volumes/hass_config/_data/restore
msg_ok "Created Restore Directory."
fi
cd /var/lib/docker/volumes/hass_config/_data/backups/
PS3="Please enter your choice: "
files="$(ls -A .)"
select filename in ${files}; do
msg_ok "You selected ${BL}${filename}${CL}"
break
done
msg_info "Stopping Home Assistant"
docker stop homeassistant &>/dev/null
msg_ok "Stopped Home Assistant"
msg_info "Restoring Home Assistant using ${filename}"
tar xvf ${filename} -C /var/lib/docker/volumes/hass_config/_data/restore &>/dev/null
cd /var/lib/docker/volumes/hass_config/_data/restore
tar -xvf homeassistant.tar.gz &>/dev/null
if ! command -v rsync >/dev/null 2>&1; then apt-get install -y rsync &>/dev/null; fi
rsync -a /var/lib/docker/volumes/hass_config/_data/restore/data/ /var/lib/docker/volumes/hass_config/_data
rm -rf /var/lib/docker/volumes/hass_config/_data/restore/*
msg_ok "Restore Complete"
msg_ok "Starting Home Assistant \n"
docker start homeassistant

View File

@@ -0,0 +1,86 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
clear
if command -v pveversion >/dev/null 2>&1; then echo -e "⚠️ Can't Run from the Proxmox Shell"; exit; fi
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
BGN=$(echo "\033[4;92m")
GN=$(echo "\033[1;92m")
DGN=$(echo "\033[32m")
CL=$(echo "\033[m")
BFR="\\r\\033[K"
HOLD="-"
CM="${GN}${CL}"
CROSS="${RD}${CL}"
APP="Home Assistant Core"
while true; do
read -p "This will restore ${APP} from a backup. Proceed(y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
clear
function header_info {
cat <<"EOF"
__ __ ___ _ __ __ ______
/ / / /___ ____ ___ ___ / | __________(_)____/ /_____ _____ / /_ / ____/___ ________
/ /_/ / __ \/ __ `__ \/ _ \ / /| | / ___/ ___/ / ___/ __/ __ `/ __ \/ __/ / / / __ \/ ___/ _ \
/ __ / /_/ / / / / / / __/ / ___ |(__ |__ ) (__ ) /_/ /_/ / / / / /_ / /___/ /_/ / / / __/
/_/ /_/\____/_/ /_/ /_/\___/ /_/ |_/____/____/_/____/\__/\__,_/_/ /_/\__/ \____/\____/_/ \___/
RESTORE FROM BACKUP
EOF
}
header_info
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
if [ -z "$(ls -A /root/.homeassistant/backups/)" ]; then
msg_error "No backups found! \n"
exit 1
fi
DIR=/root/.homeassistant/restore
if [ -d "$DIR" ]; then
msg_ok "Restore Directory Exists."
else
mkdir -p /root/.homeassistant/restore
msg_ok "Created Restore Directory."
fi
cd /root/.homeassistant/backups/
PS3="Please enter your choice: "
files="$(ls -A .)"
select filename in ${files}; do
msg_ok "You selected ${BL}${filename}${CL}"
break
done
msg_info "Stopping Home Assistant"
sudo service homeassistant stop
msg_ok "Stopped Home Assistant"
msg_info "Restoring Home Assistant using ${filename}"
tar xvf ${filename} -C /root/.homeassistant/restore &>/dev/null
cd /root/.homeassistant/restore
tar -xvf homeassistant.tar.gz &>/dev/null
if ! command -v rsync >/dev/null 2>&1; then apt-get install -y rsync &>/dev/null; fi
rsync -a /root/.homeassistant/restore/data/ /root/.homeassistant
rm -rf /root/.homeassistant/restore/*
msg_ok "Restore Complete"
msg_ok "Starting Home Assistant \n"
sudo service homeassistant start

View File

@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
function header_info {
clear
cat <<"EOF"
____ _ __ ____ __
/ __/___(_)__ ____ _/ /____ / __/_ _____ ___ ___ ____/ /_
/ _// __/ / _ `/ _ `/ __/ -_) _\ \/ // / _ \/ _ \/ _ \/ __/ __/
/_/ /_/ /_/\_, /\_,_/\__/\__/ /___/\_,_/ .__/ .__/\___/_/ \__/
/___/ /_/ /_/
EOF
}
header_info
while true; do
read -p "This will Prepare a LXC Container for Frigate. Proceed (y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
header_info
# The array of device types
# CHAR_DEVS+=(major:minor)
CHAR_DEVS+=("1:1") # mem
CHAR_DEVS+=("29:0") # fb0
CHAR_DEVS+=("188:.*") # ttyUSB*
CHAR_DEVS+=("189:.*") # bus/usb/*
CHAR_DEVS+=("226:0") # card0
CHAR_DEVS+=("226:128") # renderD128
# Proccess char device string
for char_dev in ${CHAR_DEVS[@]}; do
[ ! -z "${CHAR_DEV_STRING-}" ] && CHAR_DEV_STRING+=" -o"
CHAR_DEV_STRING+=" -regex \".*/${char_dev}\""
done
# Store autodev hook script in a variable
read -r -d '' HOOK_SCRIPT <<-EOF || true
for char_dev in \$(find /sys/dev/char -regextype sed $CHAR_DEV_STRING); do
dev="/dev/\$(sed -n "/DEVNAME/ s/^.*=\(.*\)$/\1/p" \${char_dev}/uevent)";
mkdir -p \$(dirname \${LXC_ROOTFS_MOUNT}\${dev});
for link in \$(udevadm info --query=property \$dev | sed -n "s/DEVLINKS=//p"); do
mkdir -p \${LXC_ROOTFS_MOUNT}\$(dirname \$link);
cp -dpR \$link \${LXC_ROOTFS_MOUNT}\${link};
done;
cp -dpR \$dev \${LXC_ROOTFS_MOUNT}\${dev};
done;
EOF
# Remove newline char from the variable
HOOK_SCRIPT=${HOOK_SCRIPT//$'\n'/}
# Generate menu of LXC containers in current node
NODE=$(hostname)
while read -r line; do
TAG=$(echo "$line" | awk '{print $1}')
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
fi
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(pct list | awk 'NR>1')
# Selection menu for LXC containers
while [ -z "${CTID:+x}" ]; do
CTID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --radiolist \
"\nSelect a container to add support:\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit
done
# Add autodev settings
CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf
sed '/autodev/d' $CTID_CONFIG_PATH >CTID.conf
cat CTID.conf >$CTID_CONFIG_PATH
cat <<EOF >>$CTID_CONFIG_PATH
lxc.autodev: 1
lxc.hook.autodev: bash -c '$HOOK_SCRIPT'
EOF
echo -e "\e[1;33m \nFinished....Reboot ${CTID} LXC to apply the changes.\n \e[0m"
# In the Proxmox web shell run
# bash -c "$(curl -fsSL https://github.com/community-scripts/ProxmoxVED/raw/main/misc/frigate-support.sh)"
# Reboot the LXC to apply the changes

68
tools/pve/gpu-amd.func Normal file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# AMD GPU Helper Functions for Proxmox LXC / ROCm passthrough
# Author: CanbiZ
# License: MIT
set -euo pipefail
function exit_script() {
printf "⚠️ User exited script\n"
exit 0
}
function msg() {
local type="$1"
shift
case "$type" in
info) printf " \033[36m➤\033[0m %s\n" "$@" ;;
ok) printf " \033[32m✔\033[0m %s\n" "$@" ;;
warn) printf " \033[33m⚠\033[0m %s\n" "$@" >&2 ;;
err) printf " \033[31m✘\033[0m %s\n" "$@" >&2 ;;
esac
}
function amd_gpu_available() {
lspci | grep -qi 'VGA.*AMD' && [[ -e /dev/kfd ]]
}
function passthrough_amd_to_lxc() {
local ctid="$1"
local conf="/etc/pve/lxc/${ctid}.conf"
if ! amd_gpu_available; then
msg warn "No AMD GPU with ROCm support detected"
return 1
fi
grep -q "/dev/kfd" "$conf" 2>/dev/null && return 0
{
echo "# AMD ROCm GPU"
echo "lxc.cgroup2.devices.allow: c 226:* rwm"
echo "lxc.cgroup2.devices.allow: c 238:* rwm"
echo "lxc.mount.entry: /dev/kfd dev/kfd none bind,optional,create=file"
echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir"
} >>"$conf"
msg ok "AMD ROCm passthrough applied to CT $ctid"
return 0
}
function install_amd_tools_in_ct() {
local ctid="$1"
if pct exec "$ctid" -- grep -qi alpine /etc/os-release; then
msg warn "Skipping tool installation: Alpine container detected"
return 0
fi
msg info "Installing AMD GPU tools in CT $ctid..."
pct exec "$ctid" -- bash -c "
apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y rocm-smi rocm-utils &&
adduser \$(id -un 0) video &&
adduser \$(id -un 0) render" >/dev/null 2>&1 || true
msg ok "Installed ROCm tools inside CT $ctid"
}

90
tools/pve/gpu-intel.func Normal file
View File

@@ -0,0 +1,90 @@
#!/usr/bin/env bash
# Intel GPU Helper Functions for Proxmox LXC / VAAPI passthrough
# Author: CanbiZ
# License: MIT
set -euo pipefail
function exit_script() {
printf "⚠️ User exited script\n"
exit 0
}
function msg() {
local type="$1"
shift
case "$type" in
info) printf " \033[36m➤\033[0m %s\n" "$@" ;;
ok) printf " \033[32m✔\033[0m %s\n" "$@" ;;
warn) printf " \033[33m⚠\033[0m %s\n" "$@" >&2 ;;
err) printf " \033[31m✘\033[0m %s\n" "$@" >&2 ;;
esac
}
function intel_gpu_available() {
[[ -e /dev/dri/renderD128 ]] && lspci | grep -qi 'VGA.*Intel'
}
function is_alpine_ct() {
local ctid="$1"
pct exec "$ctid" -- sh -c 'grep -qi alpine /etc/os-release' >/dev/null 2>&1
}
function passthrough_intel_to_lxc() {
local ctid="$1"
local conf="/etc/pve/lxc/${ctid}.conf"
if ! intel_gpu_available; then
msg warn "No Intel iGPU detected on host"
return 1
fi
{
echo "# Intel iGPU (VAAPI)"
echo "lxc.cgroup2.devices.allow: c 226:* rwm"
echo "lxc.cgroup2.devices.allow: c 29:0 rwm"
echo "lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file"
echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir"
echo "lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file"
} >>"$conf"
msg ok "Intel VAAPI passthrough applied to CT $ctid"
return 0
}
function install_intel_tools_in_ct() {
local ctid="$1"
local install_nonfree="yes"
if is_alpine_ct "$ctid"; then
msg warn "Skipping Intel tool install for Alpine CT $ctid"
return 0
fi
if [[ "$install_nonfree" == "yes" ]]; then
msg info "Enabling non-free sources in $ctid..."
pct exec "$ctid" -- bash -c '
grep -q "non-free" /etc/apt/sources.list && exit 0
cat <<EOF > /etc/apt/sources.list.d/non-free.list
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
EOF
'
fi
msg info "Installing Intel tools in CT $ctid..."
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 intel-media-va-driver-non-free >/dev/null 2>&1
adduser root video >/dev/null 2>&1 || true
adduser root render >/dev/null 2>&1 || true
"
msg ok "Installed Intel VAAPI tools in $ctid"
}

128
tools/pve/gpu-nvidia.func Normal file
View File

@@ -0,0 +1,128 @@
#!/usr/bin/env bash
# NVIDIA GPU Integration for Proxmox LXC
# Author: CanbiZ
# License: MIT
set -euo pipefail
function nvidia_exit() {
printf "⚠️ User exited script\n"
exit 0
}
function msg() {
local type="$1"
shift
case "$type" in
info) printf " \033[36m➤\033[0m %s\n" "$@" ;;
ok) printf " \033[32m✔\033[0m %s\n" "$@" ;;
warn) printf " \033[33m⚠\033[0m %s\n" "$@" >&2 ;;
err) printf " \033[31m✘\033[0m %s\n" "$@" >&2 ;;
esac
}
function nvidia_check_driver_installed() {
command -v nvidia-smi &>/dev/null
}
function nvidia_get_driver_version() {
nvidia-smi --query-gpu=driver_version --format=csv,noheader,nounits 2>/dev/null | head -n1
}
function nvidia_get_cuda_version() {
nvidia-smi --query-gpu=cuda_version --format=csv,noheader,nounits 2>/dev/null | head -n1
}
function nvidia_validate_driver_version() {
if ! nvidia_check_driver_installed; then
msg err "NVIDIA drivers not found"
nvidia_exit
fi
local ver major
ver=$(nvidia_get_driver_version)
major=${ver%%.*}
if ((major < 500)); then
msg warn "Detected old NVIDIA driver version: $ver"
read -rp "Continue anyway? [y/N]: " confirm
[[ "${confirm,,}" =~ ^(y|yes)$ ]] || nvidia_exit
fi
}
function nvidia_validate_cuda_version() {
if ! nvidia_check_driver_installed; then
msg err "NVIDIA drivers not found"
nvidia_exit
fi
local ver major
ver=$(nvidia_get_cuda_version)
major=${ver%%.*}
if ((major < 11)); then
msg warn "Detected old CUDA version: $ver"
read -rp "Continue anyway? [y/N]: " confirm
[[ "${confirm,,}" =~ ^(y|yes)$ ]] || nvidia_exit
fi
}
function nvidia_setup_kernel_modules() {
local modfile="/etc/modules-load.d/nvidia.conf"
local udevfile="/etc/udev/rules.d/70-nvidia.rules"
printf "nvidia\nnvidia_uvm\nnvidia_drm\n" >"$modfile"
cat <<EOF >"$udevfile"
KERNEL=="nvidia", RUN+="/bin/bash -c '/usr/bin/nvidia-smi -L && chmod 666 /dev/nvidia*'"
KERNEL=="nvidia_uvm", RUN+="/bin/bash -c '/usr/bin/nvidia-modprobe -c0 -u && chmod 0666 /dev/nvidia-uvm*'"
EOF
msg ok "NVIDIA modules configured"
msg warn "Reboot the host to apply kernel changes"
}
function nvidia_select_gpu_minor() {
local menu=() max=0
while IFS= read -r path; do
local dev="${path##*/}"
local info="/proc/driver/nvidia/gpus/${dev}/information"
[[ -f "$info" ]] || continue
local model minor
model=$(awk -F': ' '/Model:/ {print $2}' "$info")
minor=$(awk '/Device Minor/ {print $NF}' "$info")
menu+=("$minor" "$model" "OFF")
((${#model} > max)) && max=${#model}
done < <(find /proc/driver/nvidia/gpus -mindepth 1 -type d)
[[ ${#menu[@]} -eq 0 ]] && msg err "No NVIDIA GPU found" && return 1
[[ ${#menu[@]} -eq 3 ]] && printf "%s" "${menu[0]}" && return
whiptail --title "NVIDIA GPU Selection" --radiolist \
"Select GPU for passthrough:" 15 $((max + 40)) 6 \
"${menu[@]}" 3>&1 1>&2 2>&3
}
function nvidia_lxc_passthrough() {
local ctid="$1" minor="$2"
local conf="/etc/pve/lxc/${ctid}.conf"
local devices=(
"/dev/nvidia${minor}"
"/dev/nvidiactl"
"/dev/nvidia-uvm"
"/dev/nvidia-uvm-tools"
)
local devnums=()
for dev in "${devices[@]}"; do
[[ -e "$dev" ]] || continue
local major_hex
major_hex=$(stat -c '%t' "$dev")
devnums+=($((16#$major_hex)))
echo "lxc.mount.entry: $dev ${dev##*/} none bind,optional,create=file" >>"$conf"
done
echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir" >>"$conf"
for n in "${devnums[@]}"; do
echo "lxc.cgroup2.devices.allow: c ${n}:* rwm" >>"$conf"
done
msg ok "Installed NVIDIA GPU tools in $ctid"
}

79
tools/pve/host-backup.sh Normal file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
function header_info {
clear
cat <<"EOF"
__ __ __ ___ __
/ // /__ ___ / /_ / _ )___ _____/ /____ _____
/ _ / _ \(_-</ __/ / _ / _ `/ __/ '_/ // / _ \
/_//_/\___/___/\__/ /____/\_,_/\__/_/\_\\_,_/ .__/
/_/
EOF
}
# Function to perform backup
function perform_backup {
local BACKUP_PATH
local DIR
local DIR_DASH
local BACKUP_FILE
local selected_directories=()
# Get backup path from user
BACKUP_PATH=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "\nDefaults to /root/\ne.g. /mnt/backups/" 11 68 --title "Directory to backup to:" 3>&1 1>&2 2>&3) || return
# Default to /root/ if no input
BACKUP_PATH="${BACKUP_PATH:-/root/}"
# Get directory to work in from user
DIR=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "\nDefaults to /etc/\ne.g. /root/, /var/lib/pve-cluster/ etc." 11 68 --title "Directory to work in:" 3>&1 1>&2 2>&3) || return
# Default to /etc/ if no input
DIR="${DIR:-/etc/}"
DIR_DASH=$(echo "$DIR" | tr '/' '-')
BACKUP_FILE="$(hostname)${DIR_DASH}backup"
# Build a list of directories for backup
local CTID_MENU=()
while read -r dir; do
CTID_MENU+=("$(basename "$dir")" "$dir " "OFF")
done < <(ls -d "${DIR}"*)
# Allow the user to select directories
local HOST_BACKUP
while [ -z "${HOST_BACKUP:+x}" ]; do
HOST_BACKUP=$(whiptail --backtitle "Proxmox VE Host Backup" --title "Working in the ${DIR} directory " --checklist \
"\nSelect what files/directories to backup:\n" 16 $(((${#DIRNAME} + 2) + 88)) 6 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || return
for selected_dir in ${HOST_BACKUP//\"/}; do
selected_directories+=("${DIR}$selected_dir")
done
done
# Perform the backup
header_info
echo -e "This will create a backup in\e[1;33m $BACKUP_PATH \e[0mfor these files and directories\e[1;33m ${selected_directories[*]} \e[0m"
read -p "Press ENTER to continue..."
header_info
echo "Working..."
tar -czf "$BACKUP_PATH$BACKUP_FILE-$(date +%Y_%m_%d).tar.gz" --absolute-names "${selected_directories[@]}"
header_info
echo -e "\nFinished"
echo -e "\e[1;33m \nA backup is rendered ineffective when it remains stored on the host.\n \e[0m"
sleep 2
}
# Main script execution loop
while true; do
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE Host Backup" --yesno "This will create backups for particular files and directories located within a designated directory. Proceed?" 10 88); then
perform_backup
else
break
fi
done

View File

@@ -0,0 +1,202 @@
#!/usr/bin/env bash
#
# Title: Proxmox LXC Hardware Passthrough & GPU Acceleration Setup
# Description: Enables hardware passthrough for USB, Intel, NVIDIA, AMD GPUs inside privileged LXC containers.
# Installs optional drivers/tools inside the container (vainfo, intel-gpu-tools, OpenCL, etc.)
# Only supports PRIVILEGED containers for GPU passthrough.
# License: MIT
# Author: MickLesk (CanbiZ)
# Repo: https://github.com/community-scripts/ProxmoxVED
#
# Usage: bash -c "$(wget -qLO - https://github.com/community-scripts/ProxmoxVED/raw/main/misc/hw-acceleration.sh)"
#
# Requires:
# - Proxmox VE 8.1+
# - Privileged LXC Containers
# - GPU device available on host
#
# Features:
# - USB Serial Passthrough
# - Intel VAAPI passthrough + (optional) non-free drivers
# - NVIDIA GPU passthrough for LXC (binds /dev/nvidia*)
# - AMD GPU passthrough (experimental)
# - Container driver installation via APT
# - User group assignments (video/render)
# - Interactive menu system via whiptail
#
# Proxmox LXC Hardware Passthrough & GPU Acceleration Setup
# https://github.com/community-scripts/ProxmoxVED
set -euo pipefail
TEMP_DIR=$(mktemp -d)
trap 'rm -rf $TEMP_DIR' EXIT
source <(wget -qO- https://github.com/community-scripts/ProxmoxVED/raw/main/scripts/tools/gpu-nvidia.func)
source <(wget -qO- https://github.com/community-scripts/ProxmoxVED/raw/main/scripts/tools/gpu-intel.func)
source <(wget -qO- https://github.com/community-scripts/ProxmoxVED/raw/main/scripts/tools/gpu-amd.func)
function header_info() {
clear
cat <<"EOF"
__ ___ __ ___ __ __ _
/ // / | /| / / / _ |___________ / /__ _______ _/ /_(_)__ ___
/ _ /| |/ |/ / / __ / __/ __/ -_) / -_) __/ _ `/ __/ / _ \/ _ \
/_//_/ |__/|__/ /_/ |_\__/\__/\__/_/\__/_/ \_,_/\__/_/\___/_//_/
LXC Hardware Integration Tool for Proxmox VE
EOF
}
function msg() {
local type="$1"
shift
case "$type" in
info) printf " \033[36m➤\033[0m %s\n" "$@" ;;
ok) printf " \033[32m✔\033[0m %s\n" "$@" ;;
warn) printf " \033[33m⚠\033[0m %s\n" "$@" >&2 ;;
err) printf " \033[31m✘\033[0m %s\n" "$@" >&2 ;;
esac
}
function prompt_features() {
local features=()
printf "\nAvailable features:\n"
if [[ -e /dev/ttyUSB0 || -e /dev/ttyACM0 ]]; then
echo " [1] USB Passthrough"
features+=("usb")
fi
if [[ -e /dev/dri/renderD128 ]]; then
echo " [2] Intel iGPU (VAAPI)"
features+=("intel")
fi
if [[ -e /dev/nvidia0 ]]; then
echo " [3] NVIDIA GPU"
features+=("nvidia")
fi
if [[ -e /dev/kfd ]]; then
echo " [4] AMD GPU (ROCm)"
features+=("amd")
fi
if [[ ${#features[@]} -eq 0 ]]; then
msg err "No supported hardware found on host."
exit 1
fi
echo
read -rp "Enter number(s) separated by space (e.g. 1 3): " choices
SELECTED_FEATURES=()
for i in $choices; do
case "$i" in
1) SELECTED_FEATURES+=("usb") ;;
2) SELECTED_FEATURES+=("intel") ;;
3) SELECTED_FEATURES+=("nvidia") ;;
4) SELECTED_FEATURES+=("amd") ;;
esac
done
if [[ ${#SELECTED_FEATURES[@]} -eq 0 ]]; then
msg warn "No valid feature selected."
exit 1
fi
}
function select_lxc_cts() {
mapfile -t containers < <(pct list | awk 'NR>1 {print $1 "|" $2}')
if [[ ${#containers[@]} -eq 0 ]]; then
msg warn "No LXC containers found."
exit 1
fi
echo
echo "Available Containers:"
for entry in "${containers[@]}"; do
ctid="${entry%%|*}"
name="${entry##*|}"
echo " [$ctid] $name"
done
echo
read -rp "Enter container ID(s) separated by space: " SELECTED_CTIDS
if [[ -z "$SELECTED_CTIDS" ]]; then
msg warn "No containers selected."
exit 1
fi
}
function apply_usb_passthrough() {
local conf="$1"
grep -q "ttyUSB" "$conf" 2>/dev/null && return
cat <<EOF >>"$conf"
# USB Passthrough
lxc.cgroup2.devices.allow: a
lxc.cap.drop:
lxc.cgroup2.devices.allow: c 188:* rwm
lxc.cgroup2.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir
lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file
lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file
lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file
lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file
EOF
}
function main() {
header_info
prompt_features
select_lxc_cts
local updated_cts=()
for ctid in $SELECTED_CTIDS; do
local conf="/etc/pve/lxc/${ctid}.conf"
local updated=0
for feature in "${SELECTED_FEATURES[@]}"; do
case "$feature" in
usb)
msg info "Applying USB passthrough to CT $ctid..."
apply_usb_passthrough "$conf" && updated=1
;;
intel)
msg info "Applying Intel VAAPI passthrough to CT $ctid..."
passthrough_intel_to_lxc "$ctid" && install_intel_tools_in_ct "$ctid" && updated=1
;;
amd)
msg info "Applying AMD GPU passthrough to CT $ctid..."
passthrough_amd_to_lxc "$ctid" && install_amd_tools_in_ct "$ctid" && updated=1
;;
nvidia)
msg info "Checking NVIDIA GPU on host..."
check_nvidia_driver_status && check_cuda_version
gpu_minor=$(select_nvidia_gpu) || continue
passthrough_nvidia_to_lxc "$ctid" "$gpu_minor" && updated=1
;;
esac
done
if [[ "$updated" -eq 1 ]]; then
updated_cts+=("$ctid")
fi
done
echo
if [[ ${#updated_cts[@]} -gt 0 ]]; then
msg ok "Updated: ${updated_cts[*]}"
read -rp "Restart updated container(s)? [y/N]: " restart
if [[ "${restart,,}" == "y" ]]; then
for ctid in "${updated_cts[@]}"; do
pct reboot "$ctid"
msg ok "Restarted container $ctid"
done
else
msg info "Manual restart required for: ${updated_cts[*]}"
fi
else
msg warn "No passthrough applied."
fi
}
main

100
tools/pve/kernel-clean.sh Normal file
View File

@@ -0,0 +1,100 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG
# Author: MickLesk
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
function header_info {
clear
cat <<"EOF"
__ __ __ ________
/ //_/__ _________ ___ / / / ____/ /__ ____ _____
/ ,< / _ \/ ___/ __ \/ _ \/ / / / / / _ \/ __ `/ __ \
/ /| / __/ / / / / / __/ / / /___/ / __/ /_/ / / / /
/_/ |_\___/_/ /_/ /_/\___/_/ \____/_/\___/\__,_/_/ /_/
EOF
}
# Color variables
YW="\033[33m"
GN="\033[1;92m"
RD="\033[01;31m"
CL="\033[m"
header_info
# Check /boot/efi disk space
boot_efi_usage=$(df -h /boot/efi | awk 'NR==2 {print $5}' | sed 's/%//')
threshold=90 # Set threshold for disk usage percentage
if [ "$boot_efi_usage" -ge "$threshold" ]; then
echo -e "${RD}/boot/efi is ${boot_efi_usage}% full. Kernel cleanup may be required.${CL}"
echo -e "${YW}Available kernels in /boot/efi:${CL}"
ls -lh /boot/efi | awk '{print $9}'
echo -e "\n${YW}Would you like to clean up old kernels? (y/n):${CL}"
read -r clean_up
if [[ "$clean_up" == "y" ]]; then
echo -e "${YW}Running cleanup...${CL}"
apt-get autoremove -y >/dev/null 2>&1 && update-grub >/dev/null 2>&1
echo -e "${GN}Cleanup completed.${CL}"
else
echo -e "${RD}Cleanup skipped.${CL}"
fi
else
echo -e "${GN}/boot/efi has sufficient space (${boot_efi_usage}%). No cleanup needed.${CL}"
fi
# Detect current kernel
current_kernel=$(uname -r)
available_kernels=$(dpkg --list | grep 'kernel-.*-pve' | awk '{print $2}' | grep -v "$current_kernel" | sort -V)
if [ -z "$available_kernels" ]; then
echo -e "${GN}No old kernels detected. Current kernel: ${current_kernel}${CL}"
exit 0
fi
echo -e "${YW}Available kernels for removal:${CL}"
echo "$available_kernels" | nl -w 2 -s '. '
echo -e "\n${YW}Select kernels to remove (comma-separated, e.g., 1,2):${CL}"
read -r selected
# Parse selection
IFS=',' read -r -a selected_indices <<<"$selected"
kernels_to_remove=()
for index in "${selected_indices[@]}"; do
kernel=$(echo "$available_kernels" | sed -n "${index}p")
if [ -n "$kernel" ]; then
kernels_to_remove+=("$kernel")
fi
done
if [ ${#kernels_to_remove[@]} -eq 0 ]; then
echo -e "${RD}No valid selection made. Exiting.${CL}"
exit 1
fi
# Confirm removal
echo -e "${YW}Kernels to be removed:${CL}"
printf "%s\n" "${kernels_to_remove[@]}"
read -rp "Proceed with removal? (y/n): " confirm
if [[ "$confirm" != "y" ]]; then
echo -e "${RD}Aborted.${CL}"
exit 1
fi
# Remove kernels
for kernel in "${kernels_to_remove[@]}"; do
echo -e "${YW}Removing $kernel...${CL}"
if apt-get purge -y "$kernel" >/dev/null 2>&1; then
echo -e "${GN}Successfully removed: $kernel${CL}"
else
echo -e "${RD}Failed to remove: $kernel. Check dependencies.${CL}"
fi
done
# Clean up and update GRUB
echo -e "${YW}Cleaning up...${CL}"
apt-get autoremove -y >/dev/null 2>&1 && update-grub >/dev/null 2>&1
echo -e "${GN}Cleanup and GRUB update complete.${CL}"

159
tools/pve/pyenv.sh Normal file
View File

@@ -0,0 +1,159 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
set -e
YW=$(echo "\033[33m")
RD=$(echo "\033[01;31m")
BL=$(echo "\033[36m")
GN=$(echo "\033[1;92m")
CL=$(echo "\033[m")
CM="${GN}${CL}"
CROSS="${RD}${CL}"
BFR="\\r\\033[K"
HOLD="-"
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
if command -v pveversion >/dev/null 2>&1; then msg_error "Can't Install on Proxmox "; exit; fi
msg_info "Installing pyenv"
apt-get install -y \
make \
build-essential \
libjpeg-dev \
libpcap-dev \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
autoconf \
git \
curl \
sudo \
llvm \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
libopenjp2-7 \
libtiff5 \
libturbojpeg0-dev \
liblzma-dev &>/dev/null
git clone https://github.com/pyenv/pyenv.git ~/.pyenv &>/dev/null
set +e
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.bashrc
msg_ok "Installed pyenv"
. ~/.bashrc
set -e
msg_info "Installing Python 3.11.1"
pyenv install 3.11.1 &>/dev/null
pyenv global 3.11.1
msg_ok "Installed Python 3.11.1"
read -r -p "Would you like to install Home Assistant Beta? <y/N> " prompt
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
msg_info "Installing Home Assistant Beta"
cat <<EOF >/etc/systemd/system/homeassistant.service
[Unit]
Description=Home Assistant
After=network-online.target
[Service]
Type=simple
WorkingDirectory=/root/.homeassistant
ExecStart=/srv/homeassistant/bin/hass -c "/root/.homeassistant"
RestartForceExitStatus=100
[Install]
WantedBy=multi-user.target
EOF
mkdir /srv/homeassistant
cd /srv/homeassistant
python3 -m venv .
source bin/activate
python3 -m pip install wheel &>/dev/null
pip3 install --upgrade pip &>/dev/null
pip3 install psycopg2-binary &>/dev/null
pip3 install --pre homeassistant &>/dev/null
systemctl enable homeassistant &>/dev/null
msg_ok "Installed Home Assistant Beta"
echo -e " Go to $(hostname -I | awk '{print $1}'):8123"
hass
fi
read -r -p "Would you like to install ESPHome Beta? <y/N> " prompt
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
msg_info "Installing ESPHome Beta"
mkdir /srv/esphome
cd /srv/esphome
python3 -m venv .
source bin/activate
python3 -m pip install wheel &>/dev/null
pip3 install --upgrade pip &>/dev/null
pip3 install --pre esphome &>/dev/null
cat <<EOF >/srv/esphome/start.sh
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
source /srv/esphome/bin/activate
esphome dashboard /srv/esphome/
EOF
chmod +x start.sh
cat <<EOF >/etc/systemd/system/esphomedashboard.service
[Unit]
Description=ESPHome Dashboard Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/srv/esphome
ExecStart=/srv/esphome/start.sh
RestartSec=30
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now esphomedashboard &>/dev/null
msg_ok "Installed ESPHome Beta"
echo -e " Go to $(hostname -I | awk '{print $1}'):6052"
exec $SHELL
fi
read -r -p "Would you like to install Matter-Server (Beta)? <y/N> " prompt
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
msg_info "Installing Matter Server"
apt-get install -y \
libcairo2-dev \
libjpeg62-turbo-dev \
libgirepository1.0-dev \
libpango1.0-dev \
libgif-dev \
g++ &>/dev/null
python3 -m pip install wheel
pip3 install --upgrade pip
pip install python-matter-server[server]
msg_ok "Installed Matter Server"
echo -e "Start server > python -m matter_server.server"
fi
msg_ok "\nFinished\n"
exec $SHELL

View File

@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
set -eEuo pipefail
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
GN=$(echo "\033[1;92m")
CL=$(echo "\033[m")
function header_info {
clear
cat <<"EOF"
____ _ ____________ __ ____ _ ________
/ __ \_________ _ ______ ___ ____ _ _| | / / ____/ __ \ / /_____ / __ \_________ _ ______ ___ ____ _ _| | / / ____/
/ /_/ / ___/ __ \| |/_/ __ `__ \/ __ \| |/_/ | / / __/ / / / / / __/ __ \ / /_/ / ___/ __ \| |/_/ __ `__ \/ __ \| |/_/ | / / __/
/ ____/ / / /_/ /> </ / / / / / /_/ /> < | |/ / /___/ /_/ / / /_/ /_/ / / ____/ / / /_/ /> </ / / / / / /_/ /> < | |/ / /___
/_/ /_/ \____/_/|_/_/ /_/ /_/\____/_/|_| |___/_____/_____/ \__/\____/ /_/ /_/ \____/_/|_/_/ /_/ /_/\____/_/|_| |___/_____/
EOF
}
function update_container() {
container=$1
os=$(pct config "$container" | awk '/^ostype/ {print $2}')
if [[ "$os" == "ubuntu" || "$os" == "debian" ]]; then
echo -e "${BL}[Info]${GN} Checking /usr/bin/update in ${BL}$container${CL} (OS: ${GN}$os${CL})"
if pct exec "$container" -- [ -e /usr/bin/update ]; then
pct exec "$container" -- bash -c "sed -i 's/ProxmoxVED/ProxmoxVE/g' /usr/bin/update"
if pct exec "$container" -- grep -q "ProxmoxVE" /usr/bin/update; then
echo -e "${GN}[Success]${CL} /usr/bin/update updated in ${BL}$container${CL}.\n"
else
echo -e "${RD}[Error]${CL} /usr/bin/update in ${BL}$container${CL} could not be updated properly.\n"
fi
else
echo -e "${RD}[Error]${CL} /usr/bin/update not found in container ${BL}$container${CL}.\n"
fi
fi
}
function update_motd() {
container=$1
os=$(pct config "$container" | awk '/^ostype/ {print $2}')
motd_file="/etc/profile.d/00_lxc-details.sh"
echo -e "${BL}[Info]${GN} Updating MOTD in ${BL}$container${CL} (OS: ${GN}$os${CL})"
if [ "$os" = "alpine" ]; then
shell="ash"
else
shell="bash"
fi
pct exec "$container" -- $shell -c "
if [ \"$os\" = \"alpine\" ]; then
IP=\$(ip -4 addr show eth0 | awk '/inet / {print \$2}' | cut -d/ -f1 | head -n 1)
else
IP=\$(hostname -I | awk '{print \$1}')
fi
cat << EOF > $motd_file
#!/bin/sh
echo \"\"
echo \"🌐 Provided by: community-scripts ORG | GitHub: https://github.com/community-scripts/ProxmoxVE\"
echo \"🖥️ OS: \$(grep ^NAME /etc/os-release | cut -d= -f2 | tr -d '\"') - Version: \$(grep ^VERSION_ID /etc/os-release | cut -d= -f2 | tr -d '\"')\"
echo \"🏠 Hostname: \$(hostname)\"
echo \"💡 IP Address: \$IP\"
EOF
chmod +x $motd_file
"
echo -e "${GN}[Success]${CL} MOTD updated for ${BL}$container${CL}.\n"
}
function remove_dev_tag() {
container=$1
current_tags=$(pct config "$container" | awk '/^tags/ {print $2}')
if [[ "$current_tags" == *"community-script-dev"* ]]; then
new_tags=$(echo "$current_tags" | sed 's/,*community-script-dev,*//g' | sed 's/^,//' | sed 's/,$//')
if [[ -z "$new_tags" ]]; then
pct set "$container" -tags "community-script"
else
pct set "$container" -tags "$new_tags,community-script"
fi
echo -e "${GN}[Success]${CL} 'community-script-dev' tag removed and 'community-script' added for ${BL}$container${CL}.\n"
fi
}
header_info
echo "Searching for containers with 'community-script-dev' tag..."
found=0
for container in $(pct list | awk '{if(NR>1) print $1}'); do
tags=$(pct config "$container" | awk '/^tags/ {print $2}')
if [[ "$tags" == *"community-script-dev"* ]]; then
found=1
update_container "$container"
update_motd "$container"
remove_dev_tag "$container"
fi
done
if [[ $found -eq 0 ]]; then
echo -e "${RD}[Error]${CL} No containers found with the tag 'community-script-dev'. Exiting script."
exit 1
fi
header_info
echo -e "${GN}The process is complete.${CL}\n"

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
echo -e "\e[1;33m This script will allow USB passthrough to a PRIVILEGED LXC Container ONLY\e[0m"
while true; do
read -p "Did you replace 106 with your LXC ID? Proceed(y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR >/dev/null
CHAR_DEVS+=("166:.*")
CHAR_DEVS+=("188:.*")
CHAR_DEVS+=("189:.*")
for char_dev in ${CHAR_DEVS[@]}; do
[ ! -z "${CHAR_DEV_STRING-}" ] && CHAR_DEV_STRING+=" -o"
CHAR_DEV_STRING+=" -regex \".*/${char_dev}\""
done
read -r -d '' HOOK_SCRIPT <<-EOF || true
for char_dev in \$(find /sys/dev/char -regextype sed $CHAR_DEV_STRING); do
dev="/dev/\$(sed -n "/DEVNAME/ s/^.*=\(.*\)$/\1/p" \${char_dev}/uevent)";
mkdir -p \$(dirname \${LXC_ROOTFS_MOUNT}\${dev});
for link in \$(udevadm info --query=property \$dev | sed -n "s/DEVLINKS=//p"); do
mkdir -p \${LXC_ROOTFS_MOUNT}\$(dirname \$link);
cp -dpR \$link \${LXC_ROOTFS_MOUNT}\${link};
done;
cp -dpR \$dev \${LXC_ROOTFS_MOUNT}\${dev};
done;
EOF
HOOK_SCRIPT=${HOOK_SCRIPT//$'\n'/}
CTID=$1
CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf
sed '/autodev/d' $CTID_CONFIG_PATH >CTID.conf
cat CTID.conf >$CTID_CONFIG_PATH
cat <<EOF >>$CTID_CONFIG_PATH
lxc.autodev: 1
lxc.hook.autodev: bash -c '$HOOK_SCRIPT'
EOF
echo -e "\e[1;33m Finished....Reboot ${CTID} LXC to apply the changes \e[0m"