mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-06 18:13:43 +08:00
Compare commits
9 Commits
v7.45
...
0f97091e61
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f97091e61 | ||
|
|
ea0d7ee6cd | ||
|
|
75daa31d36 | ||
|
|
8c44319c45 | ||
|
|
dac574d933 | ||
|
|
fd4c5001e8 | ||
|
|
dfe0b23995 | ||
|
|
6158372eaa | ||
|
|
b1a778d7b2 |
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "dsm",
|
||||
"service": "dsm",
|
||||
"forwardPorts": [5000],
|
||||
"dockerComposeFile": ".github/codespaces.yml"
|
||||
}
|
||||
20
.devcontainer/devcontainer.json
Normal file
20
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Virtual DSM",
|
||||
"service": "dsm",
|
||||
"containerEnv": {
|
||||
"RAM_SIZE": "max",
|
||||
"DISK_SIZE": "max",
|
||||
"CPU_CORES": "max"
|
||||
},
|
||||
"forwardPorts": [5000],
|
||||
"portsAttributes": {
|
||||
"5000": {
|
||||
"label": "Web",
|
||||
"onAutoForward": "openBrowser"
|
||||
}
|
||||
},
|
||||
"otherPortsAttributes": {
|
||||
"onAutoForward": "silent"
|
||||
},
|
||||
"dockerComposeFile": "codespaces.yml"
|
||||
}
|
||||
@@ -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?
|
||||
|
||||
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:
|
||||
|
||||
|
||||
@@ -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=$(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
|
||||
|
||||
13
src/disk.sh
13
src/disk.sh
@@ -432,11 +432,18 @@ addDisk () {
|
||||
DIR=$(dirname "$DISK_FILE")
|
||||
[ ! -d "$DIR" ] && return 0
|
||||
|
||||
if [[ "${DISK_SPACE,,}" == "max" ]]; then
|
||||
if [[ "${DISK_SPACE,,}" == "max" || "${DISK_SPACE,,}" == "half" ]]; then
|
||||
|
||||
local SPARE=536870912
|
||||
local SPARE=2147483648
|
||||
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||
(( SPACE < SPARE )) && SPACE="$SPARE" || SPACE=$((SPACE-SPARE))
|
||||
|
||||
if [[ "${DISK_SPACE,,}" == "max" ]]; then
|
||||
SPACE=$((SPACE-SPARE))
|
||||
else
|
||||
SPACE=$(( SPACE / 2 ))
|
||||
fi
|
||||
|
||||
(( SPACE < SPARE )) && SPACE="$SPARE"
|
||||
GB=$(( SPACE/1073741825 ))
|
||||
DISK_SPACE="${GB}G"
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ cd /run
|
||||
. serial.sh # Initialize serialport
|
||||
. power.sh # Configure shutdown
|
||||
. config.sh # Configure arguments
|
||||
. memory.sh # Check available memory
|
||||
. finish.sh # Finish initialization
|
||||
|
||||
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
|
||||
@@ -131,7 +131,7 @@ configureDNS() {
|
||||
rm -f "$log"
|
||||
|
||||
case "${NETWORK,,}" in
|
||||
"nat" | "tap" | "tun" | "tuntap" | "y" )
|
||||
"tap" | "tun" | "tuntap" | "y" )
|
||||
|
||||
# Create lease file for faster resolve
|
||||
echo "0 $mac $ip $host 01:$mac" > /var/lib/misc/dnsmasq.leases
|
||||
@@ -271,6 +271,7 @@ getSlirp() {
|
||||
|
||||
configureSlirp() {
|
||||
|
||||
NETWORK="slirp"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
||||
|
||||
local ip="$IP"
|
||||
@@ -302,6 +303,7 @@ configureSlirp() {
|
||||
|
||||
configurePasst() {
|
||||
|
||||
NETWORK="passt"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring user-mode networking..."
|
||||
|
||||
local log="/var/log/passt.log"
|
||||
@@ -785,8 +787,8 @@ else
|
||||
fi
|
||||
|
||||
case "${NETWORK,,}" in
|
||||
"user"* | "passt" | "slirp" ) ;;
|
||||
"nat" | "tap" | "tun" | "tuntap" | "y" )
|
||||
"passt" | "slirp" | "user"* ) ;;
|
||||
"tap" | "tun" | "tuntap" | "y" )
|
||||
|
||||
# Configure tap interface
|
||||
if ! configureNAT; then
|
||||
@@ -800,11 +802,9 @@ else
|
||||
|
||||
esac
|
||||
|
||||
[[ "${NETWORK,,}" == "user"* ]] && NETWORK="passt"
|
||||
|
||||
case "${NETWORK,,}" in
|
||||
"nat" | "tap" | "tun" | "tuntap" | "y" ) ;;
|
||||
"passt" )
|
||||
"tap" | "tun" | "tuntap" | "y" ) ;;
|
||||
"passt" | "user"* )
|
||||
|
||||
# Configure for user-mode networking (passt)
|
||||
if ! configurePasst; then
|
||||
|
||||
33
src/reset.sh
33
src/reset.sh
@@ -59,6 +59,8 @@ fi
|
||||
|
||||
CPU_CORES="${CPU_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
|
||||
|
||||
if [ "$CPU_CORES" -gt "$CORES" ]; then
|
||||
@@ -105,20 +107,18 @@ 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 [[ "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
||||
|
||||
if [ -z "${RAM_SIZE//[0-9. ]}" ]; then
|
||||
[ "${RAM_SIZE%%.*}" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G" || RAM_SIZE="${RAM_SIZE}M"
|
||||
fi
|
||||
if [ -z "${RAM_SIZE//[0-9. ]}" ]; then
|
||||
[ "${RAM_SIZE%%.*}" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G" || RAM_SIZE="${RAM_SIZE}M"
|
||||
fi
|
||||
|
||||
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
|
||||
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
||||
[ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
||||
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
|
||||
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
||||
[ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
||||
|
||||
fi
|
||||
|
||||
# Print system info
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user