Compare commits

..

2 Commits

Author SHA1 Message Date
databreach
345fe0c13a Merge 6afb3f1acc into 1b8054e847 2025-05-27 00:51:07 +02:00
databreach
6afb3f1acc Add user scripts folder with LXC scripts from issue #382
Added a user-scripts folder containing the LXC scripts referenced in vdsm/virtual-dsm#382, preserving them before the original repository is deleted.
2025-05-23 20:38:56 +02:00
9 changed files with 247 additions and 37 deletions

View File

@@ -2,6 +2,20 @@ name: Build
on:
workflow_dispatch:
push:
branches:
- master
paths-ignore:
- '**/*.md'
- '**/*.yml'
- '**/*.js'
- '**/*.css'
- '**/*.html'
- 'web/**'
- '.gitignore'
- '.dockerignore'
- '.github/**'
- '.github/workflows/**'
concurrency:
group: build
@@ -22,7 +36,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
with:
fetch-depth: 0
-

View File

@@ -9,7 +9,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
@@ -17,7 +17,7 @@ jobs:
SHELLCHECK_OPTS: -x --source-path=src -e SC2001 -e SC2034 -e SC2064 -e SC2317 -e SC2153 -e SC2028
-
name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.2.0
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
ignore: DL3008,DL3003,DL3006,DL3013

View File

@@ -12,7 +12,7 @@ jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
-
name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4

View File

@@ -1,5 +1,3 @@
# syntax=docker/dockerfile:1
FROM qemux/qemu-host:2.05 AS builder
# FROM golang as builder

View File

@@ -0,0 +1,122 @@
#!/bin/bash
# Constants
CONFIG_DIR="/etc/pve/lxc"
TMP_DIR="/tmp"
# Function to display log messages
log() {
echo -e "$1"
}
# Function to display error and exit
function display_error_and_exit() {
log "Error: $1 Exiting."
exit 1
}
# Function to display information
function display_info {
clear
log "This script is used to configure prerequisites to run Synology Virtual DSM"
log "in a Docker container inside an unprivileged Proxmox LXC container."
log "Please run this script on the Proxmox host, not inside the LXC container.\n"
}
# Check for root privileges
if [ "$EUID" -ne 0 ]; then
display_error_and_exit "Please run this script as root."
fi
display_info
read -p "Do you want to continue? (y/n): " choice
if [[ $choice == "y" || $choice == "Y" ]]; then
read -p "Enter the LXC Container ID (CT ID): " ct_id
read -p "Enter the vGPU card ID (e.g. card1 = 1): " gpu_card
read -p "Enter the vGPU renderD ID (e.g. renderD129 = 129): " gpu_renderd
# Check if ct_id is a non-empty numeric value
if [[ ! $ct_id =~ ^[0-9]+$ ]]; then
display_error_and_exit "Invalid LXC Container ID. Please enter a numeric value."
fi
# Check if gpu_card is a non-empty numeric value
if [[ ! $gpu_card =~ ^[0-9]+$ ]]; then
display_error_and_exit "Invalid vGPU card number. Please enter a numeric value."
fi
# Check if gpu_renderd is a non-empty numeric value
if [[ ! $gpu_renderd =~ ^[0-9]+$ ]]; then
display_error_and_exit "Invalid vGPU renderD number. Please enter a numeric value."
fi
# Check if the configuration file exists
config_file="$CONFIG_DIR/$ct_id.conf"
if [[ ! -f "$config_file" ]]; then
display_error_and_exit "Configuration file $config_file does not exist."
fi
# Check if the LXC container is running
container_status=$(pct status $ct_id 2>&1)
if [[ "$container_status" == *"running"* ]]; then
log "Stopping running LXC container $ct_id..."
pct stop $ct_id || display_error_and_exit "Failed to stop LXC container $ct_id."
fi
# Remove existing dev folder and tun, kvm, and vhost-net devices
if [[ -d "/dev-$ct_id" ]]; then
log "Removing existing /dev-$ct_id folder..."
rm -r "/dev-$ct_id" || display_error_and_exit "Failed to remove existing /dev-$ct_id folder."
fi
# Function to configure devices
function configure_device() {
device=$1
module=$2
major=$3
minor=$4
log "Configuring $device..."
mkdir -p "/dev-$ct_id/net" || display_error_and_exit "Failed to create /dev-$ct_id/net"
mkdir -p "/dev-$ct_id/dri" || display_error_and_exit "Failed to create /dev-$ct_id/dri"
mknod "/dev-$ct_id/$device" c $major $minor || display_error_and_exit "Failed to mknod /dev-$ct_id/$device"
chown 100000:100000 "/dev-$ct_id/$device" || display_error_and_exit "Failed to chown /dev-$ct_id/$device"
#log "Checking if /dev-$ct_id/$device exists..."
if ! [[ -e "/dev-$ct_id/$device" ]]; then
display_error_and_exit "/dev-$ct_id/$device should have been created but does not exist."
fi
}
# Configure devices
configure_device "net/tun" "tun" 10 200
configure_device "kvm" "kvm" 10 232
configure_device "vhost-net" "vhost-net" 10 238
configure_device "dri/card0" "card0" 226 $gpu_card
configure_device "dri/renderD128" "renderD128" 226 $gpu_renderd
# Check and add configuration lines to /et/pve/lxc/<CT ID>.conf
log "Checking and adding configuration to $config_file..."
lines_to_add=(
"lxc.mount.entry: /dev-$ct_id/net/tun dev/net/tun none bind,create=file 0 0"
"lxc.mount.entry: /dev-$ct_id/kvm dev/kvm none bind,create=file 0 0"
"lxc.mount.entry: /dev-$ct_id/vhost-net dev/vhost-net none bind,create=file 0 0"
"lxc.mount.entry: /dev-$ct_id/dri/card0 dev/dri/card0 none bind,create=file 0 0"
"lxc.mount.entry: /dev-$ct_id/dri/renderD128 dev/dri/renderD128 none bind,create=file 0 0"
)
# Error handling for config file changes
for line in "${lines_to_add[@]}"; do
if ! grep -qF "$line" "$config_file"; then
echo "$line" >> "$config_file" || display_error_and_exit "Failed to add line '$line' to $config_file."
fi
done
log "Configuration completed successfully.\n\nStart the docker image (vdsm/virtual-dsm:latest) inside the LXC container."
else
clear
log "\nScript aborted. No changes were made."
fi

105
scripts/virtual-dsm-lxc.sh Normal file
View File

@@ -0,0 +1,105 @@
#!/bin/bash
# Constants
CONFIG_DIR="/etc/pve/lxc"
TMP_DIR="/tmp"
# Function to display log messages
log() {
echo -e "$1"
}
# Function to display error and exit
function display_error_and_exit() {
log "Error: $1 Exiting."
exit 1
}
# Function to display information
function display_info {
clear
log "This script is used to configure prerequisites to run Synology Virtual DSM"
log "in a Docker container inside an unprivileged Proxmox LXC container."
log "Please run this script on the Proxmox host, not inside the LXC container.\n"
}
# Check for root privileges
if [ "$EUID" -ne 0 ]; then
display_error_and_exit "Please run this script as root."
fi
display_info
read -p "Do you want to continue? (y/n): " choice
if [[ $choice == "y" || $choice == "Y" ]]; then
read -p "Enter the LXC Container ID (CT ID): " ct_id
# Check if ct_id is a non-empty numeric value
if [[ ! $ct_id =~ ^[0-9]+$ ]]; then
display_error_and_exit "Invalid LXC Container ID. Please enter a numeric value."
fi
# Check if the configuration file exists
config_file="$CONFIG_DIR/$ct_id.conf"
if [[ ! -f "$config_file" ]]; then
display_error_and_exit "Configuration file $config_file does not exist."
fi
# Check if the LXC container is running
container_status=$(pct status $ct_id 2>&1)
if [[ "$container_status" == *"running"* ]]; then
log "Stopping running LXC container $ct_id..."
pct stop $ct_id || display_error_and_exit "Failed to stop LXC container $ct_id."
fi
# Remove existing dev folder and tun, kvm, and vhost-net devices
if [[ -d "/dev-$ct_id" ]]; then
log "Removing existing /dev-$ct_id folder..."
rm -r "/dev-$ct_id" || display_error_and_exit "Failed to remove existing /dev-$ct_id folder."
fi
# Function to configure devices
function configure_device() {
device=$1
module=$2
major=$3
minor=$4
log "Configuring $device..."
mkdir -p "/dev-$ct_id/net" || display_error_and_exit "Failed to create /dev-$ct_id/net"
mknod "/dev-$ct_id/$device" c $major $minor || display_error_and_exit "Failed to mknod /dev-$ct_id/$device"
chown 100000:100000 "/dev-$ct_id/$device" || display_error_and_exit "Failed to chown /dev-$ct_id/$device"
#log "Checking if /dev-$ct_id/$device exists..."
if ! [[ -e "/dev-$ct_id/$device" ]]; then
display_error_and_exit "/dev-$ct_id/$device should have been created but does not exist."
fi
}
# Configure devices
configure_device "net/tun" "tun" 10 200
configure_device "kvm" "kvm" 10 232
configure_device "vhost-net" "vhost-net" 10 238
# Check and add configuration lines to /et/pve/lxc/<CT ID>.conf
log "Checking and adding configuration to $config_file..."
lines_to_add=(
"lxc.mount.entry: /dev-$ct_id/net/tun dev/net/tun none bind,create=file 0 0"
"lxc.mount.entry: /dev-$ct_id/kvm dev/kvm none bind,create=file 0 0"
"lxc.mount.entry: /dev-$ct_id/vhost-net dev/vhost-net none bind,create=file 0 0"
)
# Error handling for config file changes
for line in "${lines_to_add[@]}"; do
if ! grep -qF "$line" "$config_file"; then
echo "$line" >> "$config_file" || display_error_and_exit "Failed to add line '$line' to $config_file."
fi
done
log "Configuration completed successfully.\n\nStart the docker image (vdsm/virtual-dsm:latest) inside the LXC container."
else
clear
log "\nScript aborted. No changes were made."
fi

View File

@@ -4,12 +4,12 @@ set -Eeuo pipefail
# Configure QEMU for graceful shutdown
API_CMD=6
API_TIMEOUT=50
API_HOST="127.0.0.1:2210"
: "${API_TIMEOUT:="50"}" # API Call timeout
QEMU_TERM=""
QEMU_PORT=7100
: "${QEMU_TIMEOUT:="50"}" # QEMU Termination timeout
QEMU_TIMEOUT=50
QEMU_DIR="/run/shm"
QEMU_PID="$QEMU_DIR/qemu.pid"
QEMU_LOG="$QEMU_DIR/qemu.log"

View File

@@ -128,30 +128,6 @@ else
fi
if [[ "$ARGUMENTS" == *"-cpu host,"* ]]; then
args="${ARGUMENTS} "
prefix="${args/-cpu host,*/}"
suffix="${args/*-cpu host,/}"
param="${suffix%% *}"
suffix="${suffix#* }"
args="${prefix}${suffix}"
ARGUMENTS="${args::-1}"
if [ -z "$CPU_FLAGS" ]; then
CPU_FLAGS="$param"
else
CPU_FLAGS+=",$param"
fi
else
if [[ "$ARGUMENTS" == *"-cpu host"* ]]; then
ARGUMENTS="${ARGUMENTS//-cpu host/}"
fi
fi
if [ -z "$CPU_FLAGS" ]; then
if [ -z "$CPU_FEATURES" ]; then
CPU_FLAGS="$CPU_MODEL"

View File

@@ -69,10 +69,6 @@ if [ ! -d "$STORAGE" ]; then
error "Storage folder ($STORAGE) not found!" && exit 13
fi
if [ ! -w "$STORAGE" ]; then
error "Storage folder ($STORAGE) is not writeable!" && exit 13
fi
# Check filesystem
FS=$(stat -f -c %T "$STORAGE")
@@ -160,7 +156,6 @@ setCountry() {
[ -z "$COUNTRY" ] && getCountry "https://ifconfig.co/json" ".country_iso"
[ -z "$COUNTRY" ] && getCountry "https://api.ip2location.io" ".country_code"
[ -z "$COUNTRY" ] && getCountry "https://ipinfo.io/json" ".country"
[ -z "$COUNTRY" ] && getCountry "https://api.ipquery.io/?format=json" ".location.country_code"
[ -z "$COUNTRY" ] && getCountry "https://api.myip.com" ".cc"
return 0