From 3b364a546c105abbe5e2b32dafa9c0fffeca9cfd Mon Sep 17 00:00:00 2001 From: MacRimi <123239993+MacRimi@users.noreply.github.com> Date: Sat, 1 Feb 2025 09:13:31 +0100 Subject: [PATCH] Update configure_igpu_lxc.sh --- scripts/configure_igpu_lxc.sh | 168 +++++++++++++++++++++++----------- 1 file changed, 114 insertions(+), 54 deletions(-) diff --git a/scripts/configure_igpu_lxc.sh b/scripts/configure_igpu_lxc.sh index f099664..d56ea7a 100644 --- a/scripts/configure_igpu_lxc.sh +++ b/scripts/configure_igpu_lxc.sh @@ -10,22 +10,21 @@ # Last Updated: 28/01/2025 # ========================================================== # Description: -# This script automates the process of enabling and configuring -# Intel integrated GPU (iGPU) support in Proxmox VE LXC containers. -# It performs the following main tasks: -# - Selects a target LXC container -# - Ensures the container is set to privileged mode -# - Configures the LXC container for iGPU passthrough -# - Installs necessary iGPU drivers and tools inside the container -# - Manages container restarts as needed +# This script automates the configuration and installation of +# Coral TPU and iGPU support in Proxmox VE containers. It: +# - Configures a selected LXC container for hardware acceleration +# - Installs and sets up Coral TPU drivers on the Proxmox host +# - Installs necessary drivers inside the container +# - Manages required system and container restarts # -# The script aims to simplify the setup of hardware-accelerated -# graphics capabilities in LXC containers, enabling efficient -# use of Intel iGPUs for tasks such as transcoding, rendering, -# and accelerating graphics-intensive applications. +# The script aims to simplify the process of enabling +# AI-powered video analysis capabilities in containers +# LXC, leveraging hardware acceleration for +# improved performance. # ========================================================== # Configuration ============================================ +REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main" BASE_DIR="/usr/local/share/proxmenux" UTILS_FILE="$BASE_DIR/utils.sh" VENV_PATH="/opt/googletrans-env" @@ -33,32 +32,16 @@ VENV_PATH="/opt/googletrans-env" if [[ -f "$UTILS_FILE" ]]; then source "$UTILS_FILE" 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_container() { - clear CONTAINERS=$(pct list | awk 'NR>1 {print $1, $3}' | xargs -n2) if [ -z "$CONTAINERS" ]; then msg_error "$(translate 'No containers available in Proxmox.')" @@ -81,8 +64,29 @@ select_container() { 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 CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf" if [ ! -f "$CONFIG_FILE" ]; then @@ -99,14 +103,11 @@ ensure_privileged_container() { chown -R root:root "$STORAGE_PATH" fi msg_ok "$(translate 'Container changed to privileged.')" + else + msg_ok "$(translate 'The container is already privileged.')" 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 echo "features: nesting=1" >> "$CONFIG_FILE" fi @@ -126,24 +127,83 @@ configure_lxc_for_igpu() { echo "lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file" >> "$CONFIG_FILE" 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 exec "$CONTAINER_ID" -- bash -c " - apt-get update && \ - 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 - " - msg_ok "$(translate 'iGPU drivers installed inside the container.')" + + CORAL_M2=$(lspci | grep -i "Global Unichip") + if [[ -n "$CORAL_M2" ]]; then + DRIVER_OPTION=$(whiptail --title "$(translate 'Select driver version')" \ + --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'))" \ + 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 <