Compare commits

..

2 Commits

Author SHA1 Message Date
databreach
51cedfb50e Merge 6afb3f1acc into 631a558a9f 2025-05-23 20:40:23 +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
17 changed files with 350 additions and 155 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.3.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
@@ -28,7 +26,6 @@ RUN set -eu && \
unzip \
nginx \
procps \
ethtool \
python3 \
python3-pip \
python3-msgpack \
@@ -58,7 +55,7 @@ RUN set -eu && \
COPY --chmod=755 ./src /run/
COPY --chmod=755 ./web /var/www/
COPY --chmod=755 --from=builder /qemu-host.bin /run/host.bin
COPY --chmod=744 ./web/conf/nginx.conf /etc/nginx/default.conf
COPY --chmod=744 ./web/conf/nginx.conf /etc/nginx/sites-enabled/web.conf
ADD --chmod=775 https://raw.githubusercontent.com/sud0woodo/patology/refs/heads/main/patology.py /run/extract.py
VOLUME /storage
@@ -66,7 +63,7 @@ EXPOSE 22 139 445 5000
ENV RAM_SIZE="2G"
ENV CPU_CORES="2"
ENV DISK_SIZE="256G"
ENV DISK_SIZE="16G"
HEALTHCHECK --interval=60s --start-period=45s --retries=2 CMD /run/check.sh

View File

@@ -3,7 +3,7 @@ services:
container_name: dsm
image: vdsm/virtual-dsm
environment:
DISK_SIZE: "256G"
DISK_SIZE: "16G"
devices:
- /dev/kvm
- /dev/net/tun

View File

@@ -8,7 +8,7 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 256Gi
storage: 16Gi
---
apiVersion: apps/v1
kind: Deployment
@@ -31,7 +31,7 @@ spec:
image: vdsm/virtual-dsm
env:
- name: DISK_SIZE
value: "256G"
value: "16G"
ports:
- containerPort: 5000
name: http

View File

@@ -30,7 +30,7 @@ services:
container_name: dsm
image: vdsm/virtual-dsm
environment:
DISK_SIZE: "256G"
DISK_SIZE: "16G"
devices:
- /dev/kvm
- /dev/net/tun
@@ -47,7 +47,7 @@ services:
##### Via Docker CLI:
```bash
docker run -it --rm --name dsm -e "DISK_SIZE=256G" -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v "${PWD:-.}/dsm:/storage" --stop-timeout 120 vdsm/virtual-dsm
docker run -it --rm --name dsm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v "${PWD:-.}/dsm:/storage" --stop-timeout 120 vdsm/virtual-dsm
```
##### Via Kubernetes:
@@ -87,24 +87,35 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
### How do I change the size of the disk?
To expand the default size of 256 GB, locate the `DISK_SIZE` setting in your compose file and modify it to your preferred capacity:
To expand the default size of 16 GB, locate the `DISK_SIZE` setting in your compose file and modify it to your preferred capacity:
```yaml
environment:
DISK_SIZE: "512G"
DISK_SIZE: "128G"
```
> [!TIP]
> This can also be used to resize the existing disk to a larger capacity without any data loss.
### How do I create a growable disk?
By default, the entire capacity of the disk will be reserved in advance.
To create a growable disk that only allocates space that is actually used, add the following environment variable:
```yaml
environment:
DISK_FMT: "qcow2"
```
### How do I add multiple disks?
To create additional disks, modify your compose file like this:
```yaml
environment:
DISK2_SIZE: "500G"
DISK3_SIZE: "750G"
DISK2_SIZE: "32G"
DISK3_SIZE: "64G"
volumes:
- ./example2:/storage2
- ./example3:/storage3
@@ -252,6 +263,14 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
There are only two minor differences: the Virtual Machine Manager package is not available, and Surveillance Station will not include any free licenses.
### How do I run Windows in a container?
You can use [dockur/windows](https://github.com/dockur/windows) for that. It shares many of the same features, and even has completely automatic installation.
### How do I run a Linux desktop in a container?
You can use [qemus/qemu](https://github.com/qemus/qemu) in that case.
### Is this project legal?
Yes, this project contains only open-source code and does not distribute any copyrighted material. Neither does it try to circumvent any copyright protection measures. So under all applicable laws, this project will be considered legal.

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

@@ -82,7 +82,7 @@ isCow() {
supportsDirect() {
local FS=$1
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
if [[ "${FS,,}" == "ecryptfs" ]] || [[ "${FS,,}" == "tmpfs" ]]; then
return 1
fi
@@ -320,7 +320,7 @@ convertDisk() {
msg="Conversion of $DISK_DESC"
html "$msg completed..."
info "$msg to $DST_FMT completed successfully!"
info "$msg to $DST_FMT completed succesfully!"
return 0
}
@@ -507,11 +507,12 @@ addDevice () {
physical="${physical%% *}"
if [ -n "$physical" ]; then
if [[ "$physical" != "512" ]]; then
sectors=",logical_block_size=$logical,physical_block_size=$physical"
if [[ "$physical" != "4096" && "$physical" != "32768" ]]; then
warn "Unknown physical sector size: $physical for $DISK_DEV"
if [[ "$physical" == "512" ]] || [[ "$physical" == "4096" ]]; then
if [[ "$physical" == "4096" ]]; then
sectors=",logical_block_size=$logical,physical_block_size=$physical"
fi
else
warn "Unknown physical sector size: $physical for $DISK_DEV"
fi
else
warn "Failed to determine the sector size for $DISK_DEV"
@@ -534,7 +535,11 @@ case "${DISK_TYPE,,}" in
esac
if [ -z "$ALLOCATE" ]; then
ALLOCATE="N"
if [[ "${DISK_FMT,,}" == "raw" ]]; then
ALLOCATE="Y"
else
ALLOCATE="N"
fi
fi
if [[ "$ALLOCATE" == [Nn]* ]]; then
@@ -549,7 +554,7 @@ DISK_OPTS+=$(createDevice "$BOOT" "$DISK_TYPE" "1" "0xa" "raw" "$DISK_IO" "$DISK
DISK_OPTS+=$(createDevice "$SYSTEM" "$DISK_TYPE" "2" "0xb" "raw" "$DISK_IO" "$DISK_CACHE" "" "")
DISK1_FILE="$STORAGE/${DISK_NAME}"
if [ ! -f "$DISK1_FILE.img" ] && [ -f "$STORAGE/data${DISK_SIZE}.img" ]; then
if [[ ! -f "$DISK1_FILE.img" ]] && [[ -f "$STORAGE/data${DISK_SIZE}.img" ]]; then
# Fallback for legacy installs
mv "$STORAGE/data${DISK_SIZE}.img" "$DISK1_FILE.img"
fi
@@ -558,7 +563,7 @@ DISK2_FILE="/storage2/${DISK_NAME}2"
if [ ! -f "$DISK2_FILE.img" ]; then
# Fallback for legacy installs
FALLBACK="/storage2/data.img"
if [[ -f "$DISK1_FILE.img" && -f "$FALLBACK" ]]; then
if [[ -f "$DISK1_FILE.img" ]] && [[ -f "$FALLBACK" ]]; then
SIZE1=$(stat -c%s "$FALLBACK")
SIZE2=$(stat -c%s "$DISK1_FILE.img")
if [[ SIZE1 -ne SIZE2 ]]; then
@@ -571,7 +576,7 @@ DISK3_FILE="/storage3/${DISK_NAME}3"
if [ ! -f "$DISK3_FILE.img" ]; then
# Fallback for legacy installs
FALLBACK="/storage3/data.img"
if [[ -f "$DISK1_FILE.img" && -f "$FALLBACK" ]]; then
if [[ -f "$DISK1_FILE.img" ]] && [[ -f "$FALLBACK" ]]; then
SIZE1=$(stat -c%s "$FALLBACK")
SIZE2=$(stat -c%s "$DISK1_FILE.img")
if [[ SIZE1 -ne SIZE2 ]]; then

View File

@@ -10,7 +10,7 @@ set -Eeuo pipefail
CPU_VENDOR=$(lscpu | awk '/Vendor ID/{print $3}')
if [[ "$GPU" != [Yy1]* || "$CPU_VENDOR" != "GenuineIntel" || "$ARCH" != "amd64" ]]; then
if [[ "$GPU" != [Yy1]* ]] || [[ "$CPU_VENDOR" != "GenuineIntel" ]] || [[ "$ARCH" != "amd64" ]]; then
[[ "${DISPLAY,,}" == "none" ]] && VGA="none"
DISPLAY_OPTS="-display $DISPLAY -vga $VGA"

View File

@@ -18,7 +18,7 @@ DIR=$(find / -maxdepth 1 -type d -iname "$FN" -print -quit)
if [ -d "$DIR" ]; then
BASE="DSM_VirtualDSM" && URL="file://$DIR"
if [[ ! -s "$STORAGE/$BASE.boot.img" || ! -s "$STORAGE/$BASE.system.img" ]]; then
if [[ ! -s "$STORAGE/$BASE.boot.img" ]] || [[ ! -s "$STORAGE/$BASE.system.img" ]]; then
error "The bind $DIR maps to a file that does not exist!" && exit 65
fi
fi
@@ -34,13 +34,13 @@ if [ -n "$URL" ] && [ ! -s "$FILE" ] && [ ! -d "$DIR" ]; then
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
fi
if [[ "${URL,,}" != "http"* && "${URL,,}" != "file:"* ]] ; then
if [[ "${URL,,}" != "http"* ]] && [[ "${URL,,}" != "file:"* ]] ; then
[ ! -s "$STORAGE/$BASE.pat" ] && error "Invalid URL: $URL" && exit 65
URL="file://$STORAGE/$BASE.pat"
fi
fi
if [[ -s "$STORAGE/$BASE.boot.img" && -s "$STORAGE/$BASE.system.img" ]]; then
if [[ -s "$STORAGE/$BASE.boot.img" ]] && [[ -s "$STORAGE/$BASE.system.img" ]]; then
return 0 # Previous installation found
fi
@@ -88,7 +88,7 @@ if [[ "${FS,,}" == "fuse"* ]]; then
info "Warning: the filesystem of $STORAGE is FUSE, this extra layer will negatively affect performance!"
fi
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
if [[ "${FS,,}" == "ecryptfs" ]] || [[ "${FS,,}" == "tmpfs" ]]; then
info "Warning: the filesystem of $STORAGE is $FS, which does not support O_DIRECT mode, adjusting settings..."
fi

View File

@@ -59,7 +59,7 @@ configureDHCP() {
fi ;;
esac
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
@@ -67,7 +67,6 @@ configureDHCP() {
while ! ip link set "$VM_NET_TAP" up; do
info "Waiting for MAC address $VM_NET_MAC to become available..."
info "If you cloned this machine, please delete the 'dsm.mac' file to generate a different MAC address."
sleep 2
done
@@ -79,7 +78,7 @@ configureDHCP() {
IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"$VM_NET_TAP"/tap*/dev)
(( MAJOR < 1)) && error "Cannot find: sys/devices/virtual/net/$VM_NET_TAP" && return 1
[[ ! -e "$TAP_PATH" && -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "$TAP_PATH"
[[ ! -e "$TAP_PATH" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "$TAP_PATH"
if [[ ! -e "$TAP_PATH" ]]; then
{ mknod "$TAP_PATH" c "$MAJOR" "$MINOR" ; rc=$?; } || :
@@ -153,18 +152,7 @@ getUserPorts() {
list="${list%% }"
for port in $list; do
proto="tcp"
num="$port"
if [[ "$port" == */udp ]]; then
proto="udp"
num="${port%/udp}"
elif [[ "$port" == */tcp ]]; then
proto="tcp"
num="${port%/tcp}"
fi
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
args+="hostfwd=tcp::$port-$VM_NET_IP:$port,"
done
echo "${args%?}"
@@ -173,7 +161,7 @@ getUserPorts() {
getHostPorts() {
local list="$1"
local list=$1
[ -z "$list" ] && echo "" && return 0
@@ -221,9 +209,8 @@ configureNAT() {
# Check port forwarding flag
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
{ sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; rc=$?; } || :
{ sysctl -w net.ipv4.ip_forward=1 > /dev/null; rc=$?; } || :
if (( rc != 0 )) || [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
[[ "$PODMAN" == [Yy1]* ]] && return 1
error "IP forwarding is disabled. $ADD_ERR --sysctl net.ipv4.ip_forward=1"
return 1
fi
@@ -250,7 +237,7 @@ configureNAT() {
error "$tuntap" && return 1
fi
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
@@ -327,7 +314,7 @@ closeBridge() {
closeNetwork() {
if [[ "${WEB:-}" != [Nn]* && "$DHCP" == [Yy1]* ]]; then
if [[ "$DHCP" == [Yy1]* ]]; then
# Shutdown nginx
nginx -s stop 2> /dev/null
@@ -393,13 +380,6 @@ getInfo() {
error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 26
fi
NIC=$(ethtool -i "$VM_NET_DEV" | grep -m 1 -i 'driver:' | awk '{print $(2)}')
if [[ "${NIC,,}" != "veth" && "${NIC,,}" != "macvlan" ]]; then
[[ "$DEBUG" == [Yy1]* ]] && info "Detected NIC: $NIC"
error "This container does not support host mode networking!" && exit 29
fi
BASE_IP="${VM_NET_IP%.*}."
if [ "${VM_NET_IP/$BASE_IP/}" -lt "3" ]; then
@@ -415,7 +395,7 @@ getInfo() {
fi
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
fi
fi
@@ -474,7 +454,7 @@ html "Initializing network..."
if [[ "$DEBUG" == [Yy1]* ]]; then
mtu=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
[[ "$MTU" != "0" && "$MTU" != "$mtu" ]] && line+=" ($MTU)"
[[ "$MTU" != "0" ]] && [[ "$MTU" != "$mtu" ]] && line+=" ($MTU)"
info "$line"
if [ -f /etc/resolv.conf ]; then
nameservers=$(grep '^nameserver*' /etc/resolv.conf | head -c -1 | sed 's/nameserver //g;' | sed -z 's/\n/, /g')
@@ -508,17 +488,13 @@ if [[ "$DHCP" == [Yy1]* ]]; then
else
if [[ "$IP" != "172."* && "$IP" != "10.8"* && "$IP" != "10.9"* ]]; then
if [[ "$IP" != "172."* ]] && [[ "$IP" != "10.8"* ]] && [[ "$IP" != "10.9"* ]]; then
checkOS
fi
if [[ "${WEB:-}" != [Nn]* ]]; then
# Shutdown nginx
nginx -s stop 2> /dev/null
fWait "nginx"
fi
# Shutdown nginx
nginx -s stop 2> /dev/null
fWait "nginx"
if [[ "${NETWORK,,}" != "user"* ]]; then
@@ -534,7 +510,7 @@ else
msg="podman detected, $msg"
fi
warn "$msg"
[ -z "$USER_PORTS" ] && info "Notice: when you want to expose ports in this mode, map them using this variable: \"USER_PORTS=5000,5001\"."
[ -z "$USER_PORTS" ] && info "Notice: port mapping will not work without \"USER_PORTS\" now."
fi
@@ -550,6 +526,6 @@ else
fi
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
[[ "$MTU" != "0" && "$MTU" != "1500" ]] && NET_OPTS+=",host_mtu=$MTU"
[[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]] && NET_OPTS+=",host_mtu=$MTU"
return 0

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

@@ -7,6 +7,7 @@ set -Eeuo pipefail
: "${HOST_CPU:=""}"
: "${CPU_FLAGS:=""}"
: "${CPU_MODEL:=""}"
: "${DEF_MODEL:="qemu64"}"
CLOCKSOURCE="tsc"
[[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter"
@@ -26,13 +27,9 @@ else
esac
fi
if [[ "$KVM" == [Nn]* ]]; then
warn "KVM acceleration is disabled, this will cause the machine to run about 10 times slower!"
else
if [[ "${ARCH,,}" != "amd64" ]]; then
KVM="N"
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, so the machine will run about 10 times slower."
fi
if [[ "${ARCH,,}" != "amd64" ]]; then
KVM="N"
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, this will cause a major loss of performance."
fi
if [[ "$KVM" != [Nn]* ]]; then
@@ -55,8 +52,8 @@ if [[ "$KVM" != [Nn]* ]]; then
if [ -n "$KVM_ERR" ]; then
KVM="N"
if [[ "$OSTYPE" =~ ^darwin ]]; then
warn "you are using macOS which has no KVM support, so the machine will run about 10 times slower."
else
warn "you are using macOS which has no KVM support, this will cause a major loss of performance."
else
kernel=$(uname -a)
case "${kernel,,}" in
*"microsoft"* )
@@ -64,8 +61,8 @@ if [[ "$KVM" != [Nn]* ]]; then
*"synology"* )
error "Please make sure that Synology VMM (Virtual Machine Manager) is installed and that '/dev/kvm' is binded to this container." ;;
*)
error "KVM acceleration is not available $KVM_ERR, this will cause the machine to run about 10 times slower."
error "See the FAQ for possible causes, or disable acceleration by adding the \"KVM=N\" variable (not recommended)." ;;
error "KVM acceleration is not available $KVM_ERR, this will cause a major loss of performance."
error "See the FAQ for possible causes, or continue without it by adding KVM: \"N\" (not recommended)." ;;
esac
[[ "$DEBUG" != [Yy1]* ]] && exit 88
fi
@@ -80,7 +77,7 @@ if [[ "$KVM" != [Nn]* ]]; then
if ! grep -qw "sse4_2" <<< "$flags"; then
info "Your CPU does not have the SSE4 instruction set that Virtual DSM requires, it will be emulated..."
[ -z "$CPU_MODEL" ] && CPU_MODEL="qemu64"
[ -z "$CPU_MODEL" ] && CPU_MODEL="$DEF_MODEL"
CPU_FEATURES+=",+ssse3,+sse4.1,+sse4.2"
fi
@@ -123,7 +120,7 @@ else
CPU_MODEL="max"
CPU_FEATURES+=",migratable=no"
else
CPU_MODEL="qemu64"
CPU_MODEL="$DEF_MODEL"
fi
fi
@@ -131,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

@@ -48,15 +48,8 @@ else
SOCKETS=$(lscpu | grep -m 1 -i 'socket(s)' | awk '{print $(2)}')
fi
CPU_CORES="${CPU_CORES// /}"
[[ "${CPU_CORES,,}" == "max" ]] && CPU_CORES="$CORES"
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
if [ "$CPU_CORES" -gt "$CORES" ]; then
warn "The amount for CPU_CORES (${CPU_CORES}) exceeds the amount of physical cores, so will be limited to ${CORES}."
CPU_CORES="$CORES"
fi
# Check system
if [ ! -d "/dev/shm" ]; then
@@ -76,14 +69,10 @@ 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")
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
if [[ "${FS,,}" == "ecryptfs" ]] || [[ "${FS,,}" == "tmpfs" ]]; then
DISK_IO="threads"
DISK_CACHE="writeback"
fi
@@ -96,12 +85,6 @@ RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
RAM_SIZE="${RAM_SIZE// /}"
[ -z "$RAM_SIZE" ] && error "RAM_SIZE not specified!" && exit 16
if [[ "${RAM_SIZE,,}" == "max" ]]; then
RAM_WANTED=$(( RAM_AVAIL - RAM_SPARE - RAM_SPARE ))
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
RAM_SIZE="${RAM_WANTED}G"
fi
if [ -z "${RAM_SIZE//[0-9. ]}" ]; then
[ "${RAM_SIZE%%.*}" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G" || RAM_SIZE="${RAM_SIZE}M"
fi
@@ -173,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
@@ -202,28 +184,20 @@ addPackage() {
return 0
}
: "${WEB_PORT:="5000"}" # Webserver port
# shellcheck disable=SC2143
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
cp -r /var/www/* /run/shm
html "Starting $APP for Docker..."
sed -i "s/listen 5000 default_server;/listen [::]:5000 default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
if [[ "${WEB:-}" != [Nn]* ]]; then
else
mkdir -p /etc/nginx/sites-enabled
cp /etc/nginx/default.conf /etc/nginx/sites-enabled/web.conf
sed -i "s/listen 5000 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
# shellcheck disable=SC2143
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
fi
# Start webserver
nginx -e stderr
sed -i "s/listen [::]:5000 default_server ipv6only=off;/listen 5000 default_server;/g" /etc/nginx/sites-enabled/web.conf
fi
# Start webserver
cp -r /var/www/* /run/shm
html "Starting $APP for Docker..."
nginx -e stderr
return 0

View File

@@ -123,21 +123,31 @@ cpu() {
fi
cpu="${cpu// CPU/}"
cpu="${cpu// [0-9] Core}"
cpu="${cpu// [0-9][0-9] Core}"
cpu="${cpu// [0-9][0-9][0-9] Core}"
cpu="${cpu// [0-9]th Gen}"
cpu="${cpu// [0-9][0-9]th Gen}"
cpu="${cpu// 4 Core/}"
cpu="${cpu// 6 Core/}"
cpu="${cpu// 8 Core/}"
cpu="${cpu// 10 Core/}"
cpu="${cpu// 12 Core/}"
cpu="${cpu// 16 Core/}"
cpu="${cpu// 32 Core/}"
cpu="${cpu// 64 Core/}"
cpu="${cpu//7th Gen /}"
cpu="${cpu//8th Gen /}"
cpu="${cpu//9th Gen /}"
cpu="${cpu//10th Gen /}"
cpu="${cpu//11th Gen /}"
cpu="${cpu//12th Gen /}"
cpu="${cpu//13th Gen /}"
cpu="${cpu//14th Gen /}"
cpu="${cpu//15th Gen /}"
cpu="${cpu// Processor/}"
cpu="${cpu// Quad core/}"
cpu="${cpu// Dual core/}"
cpu="${cpu// Octa core/}"
cpu="${cpu// Hexa core/}"
cpu="${cpu// Core TM/ Core}"
cpu="${cpu// with Radeon Graphics/}"
cpu="${cpu// with Radeon Vega Graphics/}"
cpu="${cpu// with Radeon Vega Mobile Gfx/}"
cpu="${cpu// w Radeon [0-9][0-9][0-9]M Graphics/}"
[ -z "${cpu// /}" ] && cpu="Unknown"