mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-06 18:13:43 +08:00
Compare commits
25 Commits
3db91f077f
...
v7.46
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c44669d91 | ||
|
|
175d90aad7 | ||
|
|
e1e5f8f91d | ||
|
|
dff8abbe1e | ||
|
|
0f97091e61 | ||
|
|
ea0d7ee6cd | ||
|
|
75daa31d36 | ||
|
|
8c44319c45 | ||
|
|
dac574d933 | ||
|
|
fd4c5001e8 | ||
|
|
dfe0b23995 | ||
|
|
6158372eaa | ||
|
|
b1a778d7b2 | ||
|
|
bc0defd813 | ||
|
|
48e7a9fff0 | ||
|
|
c2fa58ef27 | ||
|
|
ea49cb144b | ||
|
|
b8e778a79d | ||
|
|
c70e12f0a2 | ||
|
|
6281205912 | ||
|
|
1ffc5c55b2 | ||
|
|
c3302e1720 | ||
|
|
25227944b5 | ||
|
|
06650e916a | ||
|
|
2e34dffed5 |
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "dsm",
|
|
||||||
"service": "dsm",
|
|
||||||
"forwardPorts": [5000],
|
|
||||||
"dockerComposeFile": "compose.yml"
|
|
||||||
}
|
|
||||||
20
.devcontainer/codespaces.yml
Normal file
20
.devcontainer/codespaces.yml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
services:
|
||||||
|
dsm:
|
||||||
|
container_name: dsm
|
||||||
|
image: vdsm/virtual-dsm
|
||||||
|
environment:
|
||||||
|
ALLOCATE: "Y"
|
||||||
|
RAM_SIZE: "half"
|
||||||
|
DISK_SIZE: "max"
|
||||||
|
CPU_CORES: "max"
|
||||||
|
devices:
|
||||||
|
- /dev/kvm
|
||||||
|
- /dev/net/tun
|
||||||
|
cap_add:
|
||||||
|
- NET_ADMIN
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
|
volumes:
|
||||||
|
- ./dsm:/storage
|
||||||
|
restart: on-failure
|
||||||
|
stop_grace_period: 2m
|
||||||
18
.devcontainer/devcontainer.json
Normal file
18
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "Virtual DSM",
|
||||||
|
"service": "dsm",
|
||||||
|
"containerEnv": {
|
||||||
|
"ALLOCATE": "Y"
|
||||||
|
},
|
||||||
|
"forwardPorts": [5000],
|
||||||
|
"portsAttributes": {
|
||||||
|
"5000": {
|
||||||
|
"label": "Web",
|
||||||
|
"onAutoForward": "openBrowser"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"otherPortsAttributes": {
|
||||||
|
"onAutoForward": "silent"
|
||||||
|
},
|
||||||
|
"dockerComposeFile": "codespaces.yml"
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
.dockerignore
|
.dockerignore
|
||||||
|
.devcontainer
|
||||||
.git
|
.git
|
||||||
.github
|
.github
|
||||||
.gitignore
|
.gitignore
|
||||||
|
|||||||
5
.github/workflows/check.yml
vendored
5
.github/workflows/check.yml
vendored
@@ -22,3 +22,8 @@ jobs:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ignore: DL3008,DL3003,DL3006,DL3013
|
ignore: DL3008,DL3003,DL3006,DL3013
|
||||||
failure-threshold: warning
|
failure-threshold: warning
|
||||||
|
-
|
||||||
|
name: Validate JSON and YML files
|
||||||
|
uses: GrantBirki/json-yaml-validate@v4
|
||||||
|
with:
|
||||||
|
yaml_exclude_regex: ".*\\kubernetes\\.yml$"
|
||||||
|
|||||||
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -1,11 +1,6 @@
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
|
||||||
- '**/*.sh'
|
|
||||||
- 'Dockerfile'
|
|
||||||
- '.github/workflows/test.yml'
|
|
||||||
- '.github/workflows/check.yml'
|
|
||||||
|
|
||||||
name: "Test"
|
name: "Test"
|
||||||
permissions: {}
|
permissions: {}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
### How do I change the amount of CPU or RAM?
|
### How do I change the amount of CPU or RAM?
|
||||||
|
|
||||||
By default, the container will be allowed to use a maximum of 2 CPU cores and 2 GB of RAM.
|
By default, Virtual DSM will be allowed to use 2 CPU cores and 2 GB of RAM.
|
||||||
|
|
||||||
If you want to adjust this, you can specify the desired amount using the following environment variables:
|
If you want to adjust this, you can specify the desired amount using the following environment variables:
|
||||||
|
|
||||||
|
|||||||
@@ -12,32 +12,4 @@ DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
|
|||||||
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS"
|
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS"
|
||||||
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
||||||
|
|
||||||
# Check available memory as the very last step
|
|
||||||
|
|
||||||
if [[ "$RAM_CHECK" != [Nn]* ]]; then
|
|
||||||
|
|
||||||
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
|
||||||
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
|
||||||
|
|
||||||
if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
|
||||||
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available, please set a lower value."
|
|
||||||
[[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17
|
|
||||||
info "$msg"
|
|
||||||
else
|
|
||||||
if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
|
||||||
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $AVAIL_MEM of memory available, please consider a lower value."
|
|
||||||
if [[ "${FS,,}" != "zfs" ]]; then
|
|
||||||
warn "$msg"
|
|
||||||
else
|
|
||||||
info "$msg"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
|
||||||
printf "QEMU arguments:\n\n%s\n\n" "${ARGS// -/$'\n-'}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
23
src/disk.sh
23
src/disk.sh
@@ -98,10 +98,10 @@ createDisk() {
|
|||||||
local FS=$5
|
local FS=$5
|
||||||
local DATA_SIZE DIR SPACE GB FA
|
local DATA_SIZE DIR SPACE GB FA
|
||||||
|
|
||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
|
||||||
|
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
|
|
||||||
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
|
|
||||||
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
@@ -424,7 +424,7 @@ addDisk () {
|
|||||||
local DISK_FMT=$7
|
local DISK_FMT=$7
|
||||||
local DISK_IO=$8
|
local DISK_IO=$8
|
||||||
local DISK_CACHE=$9
|
local DISK_CACHE=$9
|
||||||
local DISK_EXT DIR SPACE DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE
|
local DISK_EXT DIR SPACE GB DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE
|
||||||
|
|
||||||
DISK_EXT=$(fmt2ext "$DISK_FMT")
|
DISK_EXT=$(fmt2ext "$DISK_FMT")
|
||||||
local DISK_FILE="$DISK_BASE.$DISK_EXT"
|
local DISK_FILE="$DISK_BASE.$DISK_EXT"
|
||||||
@@ -432,6 +432,23 @@ addDisk () {
|
|||||||
DIR=$(dirname "$DISK_FILE")
|
DIR=$(dirname "$DISK_FILE")
|
||||||
[ ! -d "$DIR" ] && return 0
|
[ ! -d "$DIR" ] && return 0
|
||||||
|
|
||||||
|
if [[ "${DISK_SPACE,,}" == "max" || "${DISK_SPACE,,}" == "half" ]]; then
|
||||||
|
|
||||||
|
local SPARE=2147483648
|
||||||
|
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||||
|
|
||||||
|
if [[ "${DISK_SPACE,,}" == "max" ]]; then
|
||||||
|
SPACE=$((SPACE-SPARE))
|
||||||
|
else
|
||||||
|
SPACE=$(( SPACE / 2 ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
(( SPACE < SPARE )) && SPACE="$SPARE"
|
||||||
|
GB=$(( SPACE/1073741825 ))
|
||||||
|
DISK_SPACE="${GB}G"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
SPACE="${DISK_SPACE// /}"
|
SPACE="${DISK_SPACE// /}"
|
||||||
[ -z "$SPACE" ] && SPACE="16G"
|
[ -z "$SPACE" ] && SPACE="16G"
|
||||||
[ -z "${SPACE//[0-9. ]}" ] && SPACE="${SPACE}G"
|
[ -z "${SPACE//[0-9. ]}" ] && SPACE="${SPACE}G"
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ cd /run
|
|||||||
. proc.sh # Initialize processor
|
. proc.sh # Initialize processor
|
||||||
. serial.sh # Initialize serialport
|
. serial.sh # Initialize serialport
|
||||||
. power.sh # Configure shutdown
|
. power.sh # Configure shutdown
|
||||||
|
. memory.sh # Check available memory
|
||||||
. config.sh # Configure arguments
|
. config.sh # Configure arguments
|
||||||
|
. finish.sh # Finish initialization
|
||||||
|
|
||||||
trap - ERR
|
trap - ERR
|
||||||
|
|
||||||
|
|||||||
8
src/finish.sh
Normal file
8
src/finish.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||||
|
printf "QEMU arguments:\n\n%s\n\n" "${ARGS// -/$'\n-'}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
86
src/memory.sh
Normal file
86
src/memory.sh
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
||||||
|
|
||||||
|
if [[ "$RAM_CHECK" != [Nn]* && "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
||||||
|
|
||||||
|
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
||||||
|
|
||||||
|
if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
||||||
|
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available,"
|
||||||
|
if [[ "${FS,,}" == "zfs" ]]; then
|
||||||
|
info "$msg but since ZFS is active this will be ignored."
|
||||||
|
else
|
||||||
|
RAM_SIZE="max"
|
||||||
|
warn "$msg it will automatically be adjusted to a lower amount."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
||||||
|
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $AVAIL_MEM of memory available,"
|
||||||
|
if [[ "${FS,,}" == "zfs" ]]; then
|
||||||
|
info "$msg but since ZFS is active this will be ignored."
|
||||||
|
else
|
||||||
|
warn "$msg please consider a lower amount."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${RAM_SIZE,,}" == "half" ]]; then
|
||||||
|
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL / 2 ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
||||||
|
|
||||||
|
if (( "$RAM_WANTED" < 1 )); then
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL / 2 ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1048577 ))
|
||||||
|
RAM_SIZE="${RAM_WANTED}M"
|
||||||
|
else
|
||||||
|
RAM_SIZE="${RAM_WANTED}G"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${RAM_SIZE,,}" == "max" ]]; then
|
||||||
|
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL - (RAM_SPARE * 3) ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
||||||
|
|
||||||
|
if (( "$RAM_WANTED" < 1 )); then
|
||||||
|
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL - (RAM_SPARE * 2) ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
||||||
|
|
||||||
|
if (( "$RAM_WANTED" < 1 )); then
|
||||||
|
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL - RAM_SPARE ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
||||||
|
|
||||||
|
if (( "$RAM_WANTED" < 1 )); then
|
||||||
|
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL - RAM_SPARE ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1048577 ))
|
||||||
|
|
||||||
|
if (( "$RAM_WANTED" < 1 )); then
|
||||||
|
|
||||||
|
RAM_WANTED=$(( RAM_AVAIL ))
|
||||||
|
RAM_WANTED=$(( RAM_WANTED / 1048577 ))
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
RAM_SIZE="${RAM_WANTED}M"
|
||||||
|
else
|
||||||
|
RAM_SIZE="${RAM_WANTED}G"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
RAM_SIZE="${RAM_WANTED}G"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
RAM_SIZE="${RAM_WANTED}G"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
215
src/network.sh
215
src/network.sh
@@ -131,7 +131,7 @@ configureDNS() {
|
|||||||
rm -f "$log"
|
rm -f "$log"
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"nat" | "tap" | "tun" | "tuntap" | "y" )
|
"tap" | "tun" | "tuntap" | "y" )
|
||||||
|
|
||||||
# Create lease file for faster resolve
|
# Create lease file for faster resolve
|
||||||
echo "0 $mac $ip $host 01:$mac" > /var/lib/misc/dnsmasq.leases
|
echo "0 $mac $ip $host 01:$mac" > /var/lib/misc/dnsmasq.leases
|
||||||
@@ -183,65 +183,95 @@ configureDNS() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserPorts() {
|
|
||||||
|
|
||||||
local args=""
|
|
||||||
local list=$1
|
|
||||||
local ssh="22"
|
|
||||||
local dsm="5000"
|
|
||||||
|
|
||||||
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
|
||||||
|
|
||||||
list="${list//,/ }"
|
|
||||||
list="${list## }"
|
|
||||||
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,"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${args%?}"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
getHostPorts() {
|
getHostPorts() {
|
||||||
|
|
||||||
local list="$1"
|
local list=""
|
||||||
list=$(echo "${list// /}" | sed 's/,*$//g')
|
list+="$MON_PORT,"
|
||||||
|
list+="${HOST_PORTS// /},"
|
||||||
|
|
||||||
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
# Remove duplicates
|
||||||
|
list=$(echo "${list//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
||||||
if [[ "${NETWORK,,}" == "passt" ]]; then
|
|
||||||
|
|
||||||
local DNS_PORT="53"
|
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
|
||||||
[ -z "$list" ] && list="$DNS_PORT" || list+=",$DNS_PORT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -z "$list" ] && list="$COM_PORT" || list+=",$COM_PORT"
|
|
||||||
[ -z "$list" ] && list="$CHR_PORT" || list+=",$CHR_PORT"
|
|
||||||
[ -z "$list" ] && list="$WSD_PORT" || list+=",$WSD_PORT"
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$list"
|
echo "$list"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUserPorts() {
|
||||||
|
|
||||||
|
local ssh="22"
|
||||||
|
local dsm="5000,5001"
|
||||||
|
|
||||||
|
local list="$ssh,$dsm,"
|
||||||
|
list+="${USER_PORTS// /},"
|
||||||
|
|
||||||
|
local exclude
|
||||||
|
exclude=$(getHostPorts)
|
||||||
|
|
||||||
|
local ports=""
|
||||||
|
local userport=""
|
||||||
|
local hostport=""
|
||||||
|
|
||||||
|
for userport in ${list//,/ }; do
|
||||||
|
|
||||||
|
local num="${userport///tcp}"
|
||||||
|
num="${num///udp}"
|
||||||
|
|
||||||
|
for hostport in ${exclude//,/ }; do
|
||||||
|
|
||||||
|
local val="${hostport///tcp}"
|
||||||
|
|
||||||
|
if [[ "$num" == "${val///udp}" ]]; then
|
||||||
|
num=""
|
||||||
|
warn "Could not assign port ${val///udp} to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -n "$num" ] && ports+="$userport,"
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove duplicates
|
||||||
|
ports=$(echo "${ports//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
||||||
|
|
||||||
|
echo "$ports"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
getSlirp() {
|
||||||
|
|
||||||
|
local args=""
|
||||||
|
local list=""
|
||||||
|
|
||||||
|
list=$(getUserPorts)
|
||||||
|
|
||||||
|
for port in ${list//,/ }; do
|
||||||
|
|
||||||
|
local proto="tcp"
|
||||||
|
local num="${port%/tcp}"
|
||||||
|
[ -z "$num" ] && continue
|
||||||
|
|
||||||
|
if [[ "$port" == *"/udp" ]]; then
|
||||||
|
proto="udp"
|
||||||
|
num="${port%/udp}"
|
||||||
|
elif [[ "$port" != *"/tcp" ]]; then
|
||||||
|
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||||
|
proto="udp"
|
||||||
|
num="${port%/udp}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||||
|
done
|
||||||
|
|
||||||
|
args=$(echo "$args" | sed 's/,*$//g')
|
||||||
|
|
||||||
|
echo "${args%?}"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
configureSlirp() {
|
configureSlirp() {
|
||||||
|
|
||||||
|
NETWORK="slirp"
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
||||||
|
|
||||||
local ip="$IP"
|
local ip="$IP"
|
||||||
@@ -255,23 +285,25 @@ configureSlirp() {
|
|||||||
|
|
||||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
||||||
|
|
||||||
local forward
|
local forward=""
|
||||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
forward=$(getSlirp)
|
||||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
||||||
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
echo "$gateway" > /run/shm/qemu.gw
|
||||||
|
else
|
||||||
|
[ ! -f /etc/resolv.dnsmasq ] && cp /etc/resolv.conf /etc/resolv.dnsmasq
|
||||||
|
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
||||||
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
|
||||||
|
|
||||||
VM_NET_IP="$ip"
|
VM_NET_IP="$ip"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
configurePasst() {
|
configurePasst() {
|
||||||
|
|
||||||
|
NETWORK="passt"
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring user-mode networking..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring user-mode networking..."
|
||||||
|
|
||||||
local log="/var/log/passt.log"
|
local log="/var/log/passt.log"
|
||||||
@@ -298,16 +330,17 @@ configurePasst() {
|
|||||||
PASST_OPTS+=" -n $VM_NET_MASK"
|
PASST_OPTS+=" -n $VM_NET_MASK"
|
||||||
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
||||||
|
|
||||||
exclude=$(getHostPorts "$HOST_PORTS")
|
local forward=""
|
||||||
|
forward=$(getUserPorts)
|
||||||
|
forward="${forward///tcp}"
|
||||||
|
forward="${forward///udp}"
|
||||||
|
|
||||||
if [ -z "$exclude" ]; then
|
if [ -n "$forward" ]; then
|
||||||
exclude="%${VM_NET_DEV}/all"
|
forward="%${VM_NET_DEV}/$forward"
|
||||||
else
|
PASST_OPTS+=" -t $forward"
|
||||||
exclude="%${VM_NET_DEV}/~${exclude//,/,~}"
|
PASST_OPTS+=" -u $forward"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PASST_OPTS+=" -t $exclude"
|
|
||||||
PASST_OPTS+=" -u $exclude"
|
|
||||||
PASST_OPTS+=" -H $VM_NET_HOST"
|
PASST_OPTS+=" -H $VM_NET_HOST"
|
||||||
PASST_OPTS+=" -M $GATEWAY_MAC"
|
PASST_OPTS+=" -M $GATEWAY_MAC"
|
||||||
PASST_OPTS+=" -P /var/run/passt.pid"
|
PASST_OPTS+=" -P /var/run/passt.pid"
|
||||||
@@ -315,7 +348,7 @@ configurePasst() {
|
|||||||
PASST_OPTS+=" -q"
|
PASST_OPTS+=" -q"
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
||||||
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
[ ! -f /etc/resolv.dnsmasq ] && cp /etc/resolv.conf /etc/resolv.dnsmasq
|
||||||
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -323,10 +356,17 @@ configurePasst() {
|
|||||||
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
||||||
|
|
||||||
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
||||||
local msg="Failed to start passt, reason: $?"
|
|
||||||
|
rm -f "$log"
|
||||||
|
PASST_OPTS="${PASST_OPTS/ -q/}"
|
||||||
|
{ $PASST ${PASST_OPTS:+ $PASST_OPTS}; rc=$?; } || :
|
||||||
|
|
||||||
|
if (( rc != 0 )); then
|
||||||
[ -f "$log" ] && cat "$log"
|
[ -f "$log" ] && cat "$log"
|
||||||
error "$msg"
|
warn "failed to start passt ($rc), falling back to slirp networking!"
|
||||||
return 1
|
configureSlirp && return 0 || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
||||||
@@ -439,7 +479,7 @@ configureNAT() {
|
|||||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exclude=$(getHostPorts "$HOST_PORTS")
|
exclude=$(getHostPorts)
|
||||||
|
|
||||||
if [ -n "$exclude" ]; then
|
if [ -n "$exclude" ]; then
|
||||||
if [[ "$exclude" != *","* ]]; then
|
if [[ "$exclude" != *","* ]]; then
|
||||||
@@ -599,12 +639,17 @@ getInfo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
||||||
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1)
|
{ IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1); rc=$?; } 2>/dev/null || :
|
||||||
IP6=""
|
|
||||||
|
|
||||||
|
if (( rc != 0 )); then
|
||||||
|
error "Could not determine container IP address!" && exit 26
|
||||||
|
fi
|
||||||
|
|
||||||
|
IP6=""
|
||||||
# shellcheck disable=SC2143
|
# shellcheck disable=SC2143
|
||||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||||
IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up)
|
{ IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up); rc=$?; } 2>/dev/null || :
|
||||||
|
(( rc != 0 )) && IP6=""
|
||||||
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -651,11 +696,6 @@ getInfo() {
|
|||||||
[ -z "$MTU" ] && MTU="$mtu"
|
[ -z "$MTU" ] && MTU="$mtu"
|
||||||
[ -z "$MTU" ] && MTU="0"
|
[ -z "$MTU" ] && MTU="0"
|
||||||
|
|
||||||
if [ "$MTU" -gt "1500" ]; then
|
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "MTU size is too large: $MTU, ignoring..."
|
|
||||||
MTU="0"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
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"
|
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
||||||
@@ -747,8 +787,8 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"user"* | "passt" | "slirp" ) ;;
|
"passt" | "slirp" | "user"* ) ;;
|
||||||
"nat" | "tap" | "tun" | "tuntap" | "y" )
|
"tap" | "tun" | "tuntap" | "y" )
|
||||||
|
|
||||||
# Configure tap interface
|
# Configure tap interface
|
||||||
if ! configureNAT; then
|
if ! configureNAT; then
|
||||||
@@ -762,11 +802,9 @@ else
|
|||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ "${NETWORK,,}" == "user"* ]] && NETWORK="passt"
|
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"nat" | "tap" | "tun" | "tuntap" | "y" ) ;;
|
"tap" | "tun" | "tuntap" | "y" ) ;;
|
||||||
"passt" )
|
"passt" | "user"* )
|
||||||
|
|
||||||
# Configure for user-mode networking (passt)
|
# Configure for user-mode networking (passt)
|
||||||
if ! configurePasst; then
|
if ! configurePasst; then
|
||||||
@@ -780,16 +818,21 @@ else
|
|||||||
if ! configureSlirp; then
|
if ! configureSlirp; then
|
||||||
error "Failed to configure user-mode networking!"
|
error "Failed to configure user-mode networking!"
|
||||||
exit 24
|
exit 24
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$USER_PORTS" ]; then
|
|
||||||
info "Notice: slirp networking is active, so when you want to expose ports, you will need to map them using this variable: \"USER_PORTS=5000,5001\"."
|
|
||||||
fi ;;
|
fi ;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case "${NETWORK,,}" in
|
||||||
|
"passt" | "slirp" )
|
||||||
|
|
||||||
|
if [ -z "$USER_PORTS" ]; then
|
||||||
|
info "Notice: because user-mode networking is active, if you need to expose ports, add them to the \"USER_PORTS\" variable."
|
||||||
|
fi ;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
||||||
|
|||||||
33
src/reset.sh
33
src/reset.sh
@@ -59,10 +59,12 @@ fi
|
|||||||
|
|
||||||
CPU_CORES="${CPU_CORES// /}"
|
CPU_CORES="${CPU_CORES// /}"
|
||||||
[[ "${CPU_CORES,,}" == "max" ]] && CPU_CORES="$CORES"
|
[[ "${CPU_CORES,,}" == "max" ]] && CPU_CORES="$CORES"
|
||||||
|
[[ "${CPU_CORES,,}" == "half" ]] && CPU_CORES=$(( CORES / 2 ))
|
||||||
|
[[ "${CPU_CORES,,}" == "0" ]] && CPU_CORES="1"
|
||||||
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
||||||
|
|
||||||
if [ "$CPU_CORES" -gt "$CORES" ]; then
|
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}."
|
warn "The amount for CPU_CORES (${CPU_CORES}) exceeds the amount of logical cores available, so will be limited to ${CORES}."
|
||||||
CPU_CORES="$CORES"
|
CPU_CORES="$CORES"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -105,20 +107,18 @@ RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
|
|||||||
RAM_SIZE="${RAM_SIZE// /}"
|
RAM_SIZE="${RAM_SIZE// /}"
|
||||||
[ -z "$RAM_SIZE" ] && error "RAM_SIZE not specified!" && exit 16
|
[ -z "$RAM_SIZE" ] && error "RAM_SIZE not specified!" && exit 16
|
||||||
|
|
||||||
if [[ "${RAM_SIZE,,}" == "max" ]]; then
|
if [[ "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; 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
|
if [ -z "${RAM_SIZE//[0-9. ]}" ]; then
|
||||||
[ "${RAM_SIZE%%.*}" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G" || RAM_SIZE="${RAM_SIZE}M"
|
[ "${RAM_SIZE%%.*}" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G" || RAM_SIZE="${RAM_SIZE}M"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
! numfmt --from=iec "$RAM_SIZE" &>/dev/null && error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16
|
! numfmt --from=iec "$RAM_SIZE" &>/dev/null && error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16
|
||||||
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
||||||
[ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
[ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Print system info
|
# Print system info
|
||||||
SYS="${SYS/-generic/}"
|
SYS="${SYS/-generic/}"
|
||||||
@@ -133,15 +133,6 @@ TOTAL_MEM=$(formatBytes "$RAM_TOTAL" "up")
|
|||||||
echo "❯ CPU: ${CPU} | RAM: ${AVAIL_MEM/ GB/}/$TOTAL_MEM | DISK: $SPACE_GB (${FS}) | KERNEL: ${SYS}..."
|
echo "❯ CPU: ${CPU} | RAM: ${AVAIL_MEM/ GB/}/$TOTAL_MEM | DISK: $SPACE_GB (${FS}) | KERNEL: ${SYS}..."
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Check available memory
|
|
||||||
|
|
||||||
if [[ "$RAM_CHECK" != [Nn]* ]] && (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
|
||||||
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
|
||||||
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available, please set a lower value."
|
|
||||||
[[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17
|
|
||||||
info "$msg"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check KVM support
|
# Check KVM support
|
||||||
|
|
||||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||||
|
|||||||
@@ -1,16 +1,31 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
lastmsg=""
|
||||||
path="/run/shm/msg.html"
|
path="/run/shm/msg.html"
|
||||||
|
|
||||||
if [ -f "$path" ] && [ -s "$path" ]; then
|
refresh() {
|
||||||
echo -n "s: " && cat "$path"
|
|
||||||
fi
|
[ ! -f "$path" ] && return 0
|
||||||
|
[ ! -s "$path" ] && return 0
|
||||||
|
|
||||||
|
msg=$(< "$path")
|
||||||
|
msg="${msg%$'\n'}"
|
||||||
|
|
||||||
|
[ -z "$msg" ] && return 0
|
||||||
|
[[ "$msg" == "$lastmsg" ]] && return 0
|
||||||
|
|
||||||
|
lastmsg="$msg"
|
||||||
|
echo "s: $msg"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh
|
||||||
|
|
||||||
inotifywait -m "$path" |
|
inotifywait -m "$path" |
|
||||||
while read -r fp event fn; do
|
while read -r fp event fn; do
|
||||||
case "${event,,}" in
|
case "${event,,}" in
|
||||||
"modify"* ) echo -n "s: " && cat "$path" ;;
|
"modify"* ) refresh ;;
|
||||||
"delete_self" ) echo "c: vnc" ;;
|
"delete_self" ) echo "c: vnc" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -93,6 +93,12 @@ function processInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractContent(s) {
|
||||||
|
var span = document.createElement('span');
|
||||||
|
span.innerHTML = s;
|
||||||
|
return span.textContent || span.innerText;
|
||||||
|
};
|
||||||
|
|
||||||
function setInfo(msg, loading, error) {
|
function setInfo(msg, loading, error) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -119,9 +125,17 @@ function setInfo(msg, loading, error) {
|
|||||||
spin.style.visibility = 'hidden';
|
spin.style.visibility = 'hidden';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var p = "<p class=\"loading\">";
|
||||||
loading = !!loading;
|
loading = !!loading;
|
||||||
if (loading) {
|
if (loading) {
|
||||||
msg = "<p class=\"loading\">" + msg + "</p>";
|
msg = p + msg + "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.includes(p)) {
|
||||||
|
if (el.innerHTML.includes(p)) {
|
||||||
|
el.getElementsByClassName('loading')[0].textContent = extractContent(msg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
el.innerHTML = msg;
|
el.innerHTML = msg;
|
||||||
|
|||||||
Reference in New Issue
Block a user