mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-28 12:16:53 +00:00
Update configure_igpu_lxc.sh
This commit is contained in:
parent
0763e41602
commit
3b364a546c
@ -10,22 +10,21 @@
|
|||||||
# Last Updated: 28/01/2025
|
# Last Updated: 28/01/2025
|
||||||
# ==========================================================
|
# ==========================================================
|
||||||
# Description:
|
# Description:
|
||||||
# This script automates the process of enabling and configuring
|
# This script automates the configuration and installation of
|
||||||
# Intel integrated GPU (iGPU) support in Proxmox VE LXC containers.
|
# Coral TPU and iGPU support in Proxmox VE containers. It:
|
||||||
# It performs the following main tasks:
|
# - Configures a selected LXC container for hardware acceleration
|
||||||
# - Selects a target LXC container
|
# - Installs and sets up Coral TPU drivers on the Proxmox host
|
||||||
# - Ensures the container is set to privileged mode
|
# - Installs necessary drivers inside the container
|
||||||
# - Configures the LXC container for iGPU passthrough
|
# - Manages required system and container restarts
|
||||||
# - Installs necessary iGPU drivers and tools inside the container
|
|
||||||
# - Manages container restarts as needed
|
|
||||||
#
|
#
|
||||||
# The script aims to simplify the setup of hardware-accelerated
|
# The script aims to simplify the process of enabling
|
||||||
# graphics capabilities in LXC containers, enabling efficient
|
# AI-powered video analysis capabilities in containers
|
||||||
# use of Intel iGPUs for tasks such as transcoding, rendering,
|
# LXC, leveraging hardware acceleration for
|
||||||
# and accelerating graphics-intensive applications.
|
# improved performance.
|
||||||
# ==========================================================
|
# ==========================================================
|
||||||
|
|
||||||
# Configuration ============================================
|
# Configuration ============================================
|
||||||
|
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
|
||||||
BASE_DIR="/usr/local/share/proxmenux"
|
BASE_DIR="/usr/local/share/proxmenux"
|
||||||
UTILS_FILE="$BASE_DIR/utils.sh"
|
UTILS_FILE="$BASE_DIR/utils.sh"
|
||||||
VENV_PATH="/opt/googletrans-env"
|
VENV_PATH="/opt/googletrans-env"
|
||||||
@ -33,32 +32,16 @@ VENV_PATH="/opt/googletrans-env"
|
|||||||
if [[ -f "$UTILS_FILE" ]]; then
|
if [[ -f "$UTILS_FILE" ]]; then
|
||||||
source "$UTILS_FILE"
|
source "$UTILS_FILE"
|
||||||
fi
|
fi
|
||||||
initialize_cache
|
|
||||||
load_language
|
|
||||||
|
|
||||||
|
load_language
|
||||||
|
initialize_cache
|
||||||
# ==========================================================
|
# ==========================================================
|
||||||
|
|
||||||
|
|
||||||
# Validate that the selected container is valid
|
|
||||||
validate_container_id() {
|
|
||||||
if [ -z "$CONTAINER_ID" ]; then
|
|
||||||
msg_error "$(translate 'Container ID not defined. Make sure to select a container first.')"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the container is running and stop it before configuration
|
|
||||||
if pct status "$CONTAINER_ID" | grep -q "running"; then
|
|
||||||
msg_info "$(translate 'Stopping the container before applying configuration...')"
|
|
||||||
pct stop "$CONTAINER_ID"
|
|
||||||
msg_ok "$(translate 'Container stopped.')"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Select LXC container
|
# Select LXC container
|
||||||
select_container() {
|
select_container() {
|
||||||
clear
|
|
||||||
CONTAINERS=$(pct list | awk 'NR>1 {print $1, $3}' | xargs -n2)
|
CONTAINERS=$(pct list | awk 'NR>1 {print $1, $3}' | xargs -n2)
|
||||||
if [ -z "$CONTAINERS" ]; then
|
if [ -z "$CONTAINERS" ]; then
|
||||||
msg_error "$(translate 'No containers available in Proxmox.')"
|
msg_error "$(translate 'No containers available in Proxmox.')"
|
||||||
@ -81,8 +64,29 @@ select_container() {
|
|||||||
msg_ok "$(translate 'Container selected:') $CONTAINER_ID"
|
msg_ok "$(translate 'Container selected:') $CONTAINER_ID"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate and change to privileged if necessary
|
|
||||||
ensure_privileged_container() {
|
|
||||||
|
|
||||||
|
# Validate that the selected container is valid
|
||||||
|
validate_container_id() {
|
||||||
|
if [ -z "$CONTAINER_ID" ]; then
|
||||||
|
msg_error "$(translate 'Container ID not defined. Make sure to select a container first.')"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the container is running and stop it before configuration
|
||||||
|
if pct status "$CONTAINER_ID" | grep -q "running"; then
|
||||||
|
msg_info "$(translate 'Stopping the container before applying configuration...')"
|
||||||
|
pct stop "$CONTAINER_ID"
|
||||||
|
msg_ok "$(translate 'Container stopped.')"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Configure LXC for Coral TPU and iGPU
|
||||||
|
configure_lxc_hardware() {
|
||||||
validate_container_id
|
validate_container_id
|
||||||
CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf"
|
CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf"
|
||||||
if [ ! -f "$CONFIG_FILE" ]; then
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
@ -99,14 +103,11 @@ ensure_privileged_container() {
|
|||||||
chown -R root:root "$STORAGE_PATH"
|
chown -R root:root "$STORAGE_PATH"
|
||||||
fi
|
fi
|
||||||
msg_ok "$(translate 'Container changed to privileged.')"
|
msg_ok "$(translate 'Container changed to privileged.')"
|
||||||
|
else
|
||||||
|
msg_ok "$(translate 'The container is already privileged.')"
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
# Configure iGPU in the container
|
|
||||||
configure_lxc_for_igpu() {
|
|
||||||
ensure_privileged_container
|
|
||||||
CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf"
|
|
||||||
|
|
||||||
|
# Configure iGPU
|
||||||
if ! grep -q "features: nesting=1" "$CONFIG_FILE"; then
|
if ! grep -q "features: nesting=1" "$CONFIG_FILE"; then
|
||||||
echo "features: nesting=1" >> "$CONFIG_FILE"
|
echo "features: nesting=1" >> "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
@ -126,24 +127,83 @@ configure_lxc_for_igpu() {
|
|||||||
echo "lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file" >> "$CONFIG_FILE"
|
echo "lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file" >> "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg_ok "$(translate 'iGPU configuration added to container') $CONTAINER_ID."
|
# Configure Coral TPU (USB and M.2)
|
||||||
|
if ! grep -Pq "^lxc.cgroup2.devices.allow: c 189:\* rwm # Coral USB$" "$CONFIG_FILE"; then
|
||||||
|
echo "lxc.cgroup2.devices.allow: c 189:* rwm # Coral USB" >> "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -Pq "^lxc.mount.entry: /dev/bus/usb dev/bus/usb none bind,optional,create=dir$" "$CONFIG_FILE"; then
|
||||||
|
echo "lxc.mount.entry: /dev/bus/usb dev/bus/usb none bind,optional,create=dir" >> "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -Pq "^lxc.mount.entry: /dev/apex_0 dev/apex_0 none bind,optional,create=file$" "$CONFIG_FILE"; then
|
||||||
|
echo "lxc.mount.entry: /dev/apex_0 dev/apex_0 none bind,optional,create=file" >> "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg_ok "$(translate 'Coral TPU and iGPU configuration added to container') $CONTAINER_ID."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install iGPU drivers in the container
|
|
||||||
install_igpu_in_container() {
|
|
||||||
echo -ne "\r${TAB}${YW}-$(translate 'Installing iGPU drivers inside the container...') ${CL}"
|
|
||||||
|
|
||||||
|
# Install Coral TPU drivers in the container
|
||||||
|
install_coral_in_container() {
|
||||||
|
echo -ne "\r${TAB}${YW}- $(translate 'Installing iGPU and Coral TPU drivers inside the container...') ${CL}"
|
||||||
|
|
||||||
pct start "$CONTAINER_ID"
|
pct start "$CONTAINER_ID"
|
||||||
pct exec "$CONTAINER_ID" -- bash -c "
|
|
||||||
apt-get update && \
|
CORAL_M2=$(lspci | grep -i "Global Unichip")
|
||||||
apt-get install -y va-driver-all ocl-icd-libopencl1 intel-opencl-icd vainfo intel-gpu-tools && \
|
if [[ -n "$CORAL_M2" ]]; then
|
||||||
chgrp video /dev/dri && chmod 755 /dev/dri && \
|
DRIVER_OPTION=$(whiptail --title "$(translate 'Select driver version')" \
|
||||||
adduser root video && adduser root render
|
--menu "$(translate 'Choose the driver version for Coral M.2:\n\nCaution: Maximum mode generates more heat.')" 15 60 2 \
|
||||||
"
|
1 "libedgetpu1-std ($(translate 'standard performance'))" \
|
||||||
msg_ok "$(translate 'iGPU drivers installed inside the container.')"
|
2 "libedgetpu1-max ($(translate 'maximum performance'))" 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
|
case "$DRIVER_OPTION" in
|
||||||
|
1) DRIVER_PACKAGE="libedgetpu1-std" ;;
|
||||||
|
2) DRIVER_PACKAGE="libedgetpu1-max" ;;
|
||||||
|
*) DRIVER_PACKAGE="libedgetpu1-std" ;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
DRIVER_PACKAGE="libedgetpu1-std"
|
||||||
|
fi
|
||||||
|
|
||||||
|
pct exec "$CONTAINER_ID" -- bash <<EOF
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "- Updating package lists..."
|
||||||
|
apt-get update
|
||||||
|
|
||||||
|
echo "- Installing iGPU drivers..."
|
||||||
|
apt-get install -y va-driver-all ocl-icd-libopencl1 intel-opencl-icd vainfo intel-gpu-tools
|
||||||
|
chgrp video /dev/dri && chmod 755 /dev/dri
|
||||||
|
adduser root video && adduser root render
|
||||||
|
|
||||||
|
echo "- Installing Coral TPU dependencies..."
|
||||||
|
apt-get install -y gnupg python3 python3-pip python3-venv
|
||||||
|
|
||||||
|
echo "- Adding Coral TPU repository..."
|
||||||
|
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/coral-edgetpu.gpg
|
||||||
|
echo 'deb [signed-by=/usr/share/keyrings/coral-edgetpu.gpg] https://packages.cloud.google.com/apt coral-edgetpu-stable main' | tee /etc/apt/sources.list.d/coral-edgetpu.list
|
||||||
|
|
||||||
|
echo "- Updating package lists again..."
|
||||||
|
apt-get update
|
||||||
|
|
||||||
|
echo "- Installing Coral TPU driver (\$DRIVER_PACKAGE)..."
|
||||||
|
apt-get install -y \$DRIVER_PACKAGE
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
msg_ok "$(translate 'iGPU and Coral TPU drivers installed inside the container.')"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execution
|
|
||||||
|
|
||||||
select_container
|
select_container
|
||||||
configure_lxc_for_igpu
|
configure_lxc_hardware
|
||||||
install_igpu_in_container
|
install_coral_in_container
|
||||||
msg_ok "$(translate 'iGPU configuration completed in container') $CONTAINER_ID."
|
|
||||||
|
|
||||||
|
|
||||||
|
msg_ok "$(translate 'Configuration completed.')"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user