mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-06 18:13:43 +08:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e362c9a8a9 | ||
|
|
78817ecfc1 | ||
|
|
8de7f56ff8 | ||
|
|
2e2017470e | ||
|
|
0a0cd98de3 | ||
|
|
17187dd23a | ||
|
|
10237b31cf | ||
|
|
6883efb857 | ||
|
|
1ca55cad8f | ||
|
|
f841eb1ef1 | ||
|
|
1ee49332f3 | ||
|
|
095e618785 | ||
|
|
57a902ad9f |
2
.github/workflows/check.yml
vendored
2
.github/workflows/check.yml
vendored
@@ -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.3.0
|
||||
with:
|
||||
dockerfile: Dockerfile
|
||||
ignore: DL3008,DL3003,DL3006,DL3013
|
||||
|
||||
10
src/disk.sh
10
src/disk.sh
@@ -82,7 +82,7 @@ isCow() {
|
||||
supportsDirect() {
|
||||
local FS=$1
|
||||
|
||||
if [[ "${FS,,}" == "ecryptfs" ]] || [[ "${FS,,}" == "tmpfs" ]]; then
|
||||
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -507,7 +507,7 @@ addDevice () {
|
||||
physical="${physical%% *}"
|
||||
|
||||
if [ -n "$physical" ]; then
|
||||
if [[ "$physical" == "512" ]] || [[ "$physical" == "4096" ]]; then
|
||||
if [[ "$physical" == "512" || "$physical" == "4096" ]]; then
|
||||
if [[ "$physical" == "4096" ]]; then
|
||||
sectors=",logical_block_size=$logical,physical_block_size=$physical"
|
||||
fi
|
||||
@@ -554,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
|
||||
@@ -563,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
|
||||
@@ -576,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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -78,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=$?; } || :
|
||||
@@ -152,7 +152,18 @@ getUserPorts() {
|
||||
list="${list%% }"
|
||||
|
||||
for port in $list; do
|
||||
args+="hostfwd=tcp::$port-$VM_NET_IP:$port,"
|
||||
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,"
|
||||
done
|
||||
|
||||
echo "${args%?}"
|
||||
@@ -238,7 +249,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
|
||||
@@ -315,7 +326,7 @@ closeBridge() {
|
||||
|
||||
closeNetwork() {
|
||||
|
||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||
if [[ "${WEB:-}" != [Nn]* && "$DHCP" == [Yy1]* ]]; then
|
||||
|
||||
# Shutdown nginx
|
||||
nginx -s stop 2> /dev/null
|
||||
@@ -396,7 +407,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
|
||||
@@ -455,7 +466,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')
|
||||
@@ -489,14 +500,18 @@ 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
|
||||
|
||||
if [[ "${NETWORK,,}" != "user"* ]]; then
|
||||
|
||||
# Configure for tap interface
|
||||
@@ -527,6 +542,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
|
||||
|
||||
19
src/proc.sh
19
src/proc.sh
@@ -7,7 +7,6 @@ set -Eeuo pipefail
|
||||
: "${HOST_CPU:=""}"
|
||||
: "${CPU_FLAGS:=""}"
|
||||
: "${CPU_MODEL:=""}"
|
||||
: "${DEF_MODEL:="qemu64"}"
|
||||
|
||||
CLOCKSOURCE="tsc"
|
||||
[[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter"
|
||||
@@ -27,9 +26,13 @@ else
|
||||
esac
|
||||
fi
|
||||
|
||||
if [[ "${ARCH,,}" != "amd64" ]]; then
|
||||
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, this will cause a major loss of performance."
|
||||
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, so the machine will run about 10 times slower."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$KVM" != [Nn]* ]]; then
|
||||
@@ -52,7 +55,7 @@ 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, this will cause a major loss of performance."
|
||||
warn "you are using macOS which has no KVM support, so the machine will run about 10 times slower."
|
||||
else
|
||||
kernel=$(uname -a)
|
||||
case "${kernel,,}" in
|
||||
@@ -61,8 +64,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 a major loss of performance."
|
||||
error "See the FAQ for possible causes, or continue without it by adding KVM: \"N\" (not recommended)." ;;
|
||||
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)." ;;
|
||||
esac
|
||||
[[ "$DEBUG" != [Yy1]* ]] && exit 88
|
||||
fi
|
||||
@@ -77,7 +80,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="$DEF_MODEL"
|
||||
[ -z "$CPU_MODEL" ] && CPU_MODEL="qemu64"
|
||||
CPU_FEATURES+=",+ssse3,+sse4.1,+sse4.2"
|
||||
fi
|
||||
|
||||
@@ -120,7 +123,7 @@ else
|
||||
CPU_MODEL="max"
|
||||
CPU_FEATURES+=",migratable=no"
|
||||
else
|
||||
CPU_MODEL="$DEF_MODEL"
|
||||
CPU_MODEL="qemu64"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
36
src/reset.sh
36
src/reset.sh
@@ -48,8 +48,15 @@ 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,7 +83,7 @@ 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
|
||||
@@ -89,6 +96,12 @@ 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
|
||||
@@ -189,20 +202,25 @@ addPackage() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# 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..."
|
||||
|
||||
if [[ "${WEB:-}" != [Nn]* ]]; then
|
||||
|
||||
# shellcheck disable=SC2143
|
||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||
|
||||
sed -i "s/listen 5000 default_server;/listen [::]:5000 default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
else
|
||||
else
|
||||
|
||||
sed -i "s/listen [::]:5000 default_server ipv6only=off;/listen 5000 default_server;/g" /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
fi
|
||||
|
||||
# Start webserver
|
||||
nginx -e stderr
|
||||
|
||||
fi
|
||||
|
||||
# Start webserver
|
||||
cp -r /var/www/* /run/shm
|
||||
html "Starting $APP for Docker..."
|
||||
nginx -e stderr
|
||||
|
||||
return 0
|
||||
|
||||
27
src/utils.sh
27
src/utils.sh
@@ -123,34 +123,21 @@ cpu() {
|
||||
fi
|
||||
|
||||
cpu="${cpu// CPU/}"
|
||||
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// 48 Core/}"
|
||||
cpu="${cpu// 64 Core/}"
|
||||
cpu="${cpu// 96 Core/}"
|
||||
cpu="${cpu// 128 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// [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// 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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user