From c357c278f9c573ff584016d7c8acfaf8e161f92f Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 05:51:05 +0200 Subject: [PATCH 01/13] Color in logs --- run/power.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/power.sh b/run/power.sh index 23040a3..30486f7 100644 --- a/run/power.sh +++ b/run/power.sh @@ -78,7 +78,7 @@ _graceful_shutdown() { done - echo && info "Quitting..." + echo && echo "❯ Quitting..." echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true return From 95e8b155b82ced94b3ea92b6639d20be48ef0c8d Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 16:23:59 +0200 Subject: [PATCH 02/13] Create vlan if needed --- run/check.sh | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/run/check.sh b/run/check.sh index a306e4d..1c7f385 100644 --- a/run/check.sh +++ b/run/check.sh @@ -7,34 +7,34 @@ set -u RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1) if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then - echo "Failed to connect to guest: $RESPONSE" - exit 1 + echo "Failed to connect to guest: $RESPONSE" && exit 1 fi + # Retrieve the HTTP port number if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then - echo "Failed to parse response from guest: $RESPONSE" - exit 1 + echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi + rest=${RESPONSE#*http_port} rest=${rest#*:} rest=${rest%%,*} PORT=${rest%%\"*} if [ -z "${PORT}" ]; then - echo "Guest has not set a portnumber yet.." - exit 1 + echo "Guest has not set a portnumber yet.." && exit 1 fi + # Retrieve the IP address if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then - echo "Failed to parse response from guest: $RESPONSE" - exit 1 + echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi + rest=${RESPONSE#*eth0} rest=${rest#*ip} rest=${rest#*:} @@ -42,8 +42,28 @@ rest=${rest#*\"} IP=${rest%%\"*} if [ -z "${IP}" ]; then - echo "Guest has not received an IP yet.." - exit 1 + echo "Guest has not received an IP yet.." && exit 1 +fi + + +if [[ "$IP" != "20.20"* ]] && [[ ! -f "/run/vlan.pid" ]] ; then + + echo $$ > "/run/vlan.pid" + + # Create a macvlan network to reach the VM guest + { ip link add link eth0 dsm_vlan type macvlan mode bridge ; rc=$?; } || : + + (( rc != 0 )) && echo "Cannot create macvlan interface." && exit 1 + + HOST_IP=$(ip address show dev eth0 | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) + + #ip address add "${HOST_IP}" dev dsm_vlan + #ip link set dev dsm_vlan up + + #ip route flush dev dsm_vlan + + #ip route add "${IP}"/32 dev dsm_vlan metric 0 + echo "Finished.." fi if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then From d416357a6f53576f77d37490bd0b99e0fac3e031 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 17:17:02 +0200 Subject: [PATCH 03/13] Do not display internal IP --- run/check.sh | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/run/check.sh b/run/check.sh index 1c7f385..0d4d324 100644 --- a/run/check.sh +++ b/run/check.sh @@ -3,30 +3,25 @@ set -u [ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0 -# Retrieve IP from guest for Docker healthcheck +# Retrieve IP from guest VM for Docker healthcheck RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1) if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then echo "Failed to connect to guest: $RESPONSE" && exit 1 fi - # Retrieve the HTTP port number if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi - rest=${RESPONSE#*http_port} rest=${rest#*:} rest=${rest%%,*} PORT=${rest%%\"*} -if [ -z "${PORT}" ]; then - echo "Guest has not set a portnumber yet.." && exit 1 -fi - +[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1 # Retrieve the IP address @@ -34,42 +29,23 @@ if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi - rest=${RESPONSE#*eth0} rest=${rest#*ip} rest=${rest#*:} rest=${rest#*\"} IP=${rest%%\"*} -if [ -z "${IP}" ]; then - echo "Guest has not received an IP yet.." && exit 1 -fi - - -if [[ "$IP" != "20.20"* ]] && [[ ! -f "/run/vlan.pid" ]] ; then - - echo $$ > "/run/vlan.pid" - - # Create a macvlan network to reach the VM guest - { ip link add link eth0 dsm_vlan type macvlan mode bridge ; rc=$?; } || : - - (( rc != 0 )) && echo "Cannot create macvlan interface." && exit 1 - - HOST_IP=$(ip address show dev eth0 | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - - #ip address add "${HOST_IP}" dev dsm_vlan - #ip link set dev dsm_vlan up - - #ip route flush dev dsm_vlan - - #ip route add "${IP}"/32 dev dsm_vlan metric 0 - echo "Finished.." -fi +[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1 if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then echo "Failed to reach ${IP}:${PORT}" exit 1 fi -echo "Healthcheck OK ($IP)" +if [[ "$IP" == "20.20"* ]]; then + echo "Healthcheck OK" +else + echo "Healthcheck OK ( $IP )" +fi + exit 0 From a71ff45bba07c0453a5819c81c3e14f88afd6171 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 17:18:10 +0200 Subject: [PATCH 04/13] Do not display internal IP --- run/check.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/run/check.sh b/run/check.sh index 0d4d324..acfc33b 100644 --- a/run/check.sh +++ b/run/check.sh @@ -11,7 +11,6 @@ if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then fi # Retrieve the HTTP port number - if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi @@ -24,7 +23,6 @@ PORT=${rest%%\"*} [ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1 # Retrieve the IP address - if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi From 4f6ccbd4ff04a823b8122ae3256540ff2242d7dd Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 17:23:40 +0200 Subject: [PATCH 05/13] Error trap --- run/run.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run/run.sh b/run/run.sh index a4ba5e4..9d3f929 100755 --- a/run/run.sh +++ b/run/run.sh @@ -10,11 +10,11 @@ set -Eeuo pipefail : ${DISK_SIZE:='16G'} # Initial data disk size : ${RAM_SIZE:='512M'} # Maximum RAM amount +echo "❯ Starting Virtual DSM for Docker v${VERSION}..." + info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; } error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } - -echo "❯ Starting Virtual DSM for Docker v${VERSION}..." -trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR +trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR [ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11 [ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12 From e2cd4b9c072b1a547472bd722aff03706b204b0b Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 17:37:28 +0200 Subject: [PATCH 06/13] Remove gateway --- run/network.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/run/network.sh b/run/network.sh index f405a13..250d55e 100644 --- a/run/network.sh +++ b/run/network.sh @@ -23,7 +23,6 @@ set -Eeuo pipefail configureDHCP() { VM_NET_VLAN="${VM_NET_TAP}_vlan" - GATEWAY=$(ip r | grep default | awk '{print $3}') NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}') IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) @@ -39,8 +38,8 @@ configureDHCP() { ip address add "${IP}" dev "${VM_NET_VLAN}" ip link set dev "${VM_NET_VLAN}" up - ip route flush dev "${VM_NET_VLAN}" + ip route del "${NETWORK}" dev "${VM_NET_DEV}" ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 From 56ca0068f75aecb9714149e0c323b1fa1e21cf58 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 17:39:34 +0200 Subject: [PATCH 07/13] Comment --- run/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/network.sh b/run/network.sh index 250d55e..b599460 100644 --- a/run/network.sh +++ b/run/network.sh @@ -28,7 +28,7 @@ configureDHCP() { [[ "${DEBUG}" == [Yy1]* ]] && set -x - # Create a macvlan network to allow for communication between the host and the VM guest + # Create a macvlan network to allow for communication from the VM guest to the host { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : if (( rc != 0 )); then From ffe0d6cb0825186bc9e1cf9541821e69795d7f47 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 17:45:20 +0200 Subject: [PATCH 08/13] KVM acceleration --- run/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/run.sh b/run/run.sh index 9d3f929..dbe98c0 100755 --- a/run/run.sh +++ b/run/run.sh @@ -61,7 +61,7 @@ else fi if [ -n "${KVM_ERR}" ]; then - error "KVM acceleration not detected ${KVM_ERR}, please enable it." + error "KVM acceleration not detected ${KVM_ERR}, see the FAQ about this." [[ "${DEBUG}" == [Yy1]* ]] && exit 88 else KVM_OPTS=",accel=kvm -enable-kvm -cpu host" From 6d1f53c077e4d4fb968d0a3f4815527c19b8bf3b Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 19:29:56 +0200 Subject: [PATCH 09/13] Remove vlan code --- run/network.sh | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/run/network.sh b/run/network.sh index b599460..08b015f 100644 --- a/run/network.sh +++ b/run/network.sh @@ -22,48 +22,23 @@ set -Eeuo pipefail configureDHCP() { - VM_NET_VLAN="${VM_NET_TAP}_vlan" - NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}') - IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - - [[ "${DEBUG}" == [Yy1]* ]] && set -x - - # Create a macvlan network to allow for communication from the VM guest to the host - { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : - - if (( rc != 0 )); then - error "Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," - error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 - fi - - ip address add "${IP}" dev "${VM_NET_VLAN}" - ip link set dev "${VM_NET_VLAN}" up - ip route flush dev "${VM_NET_VLAN}" - - ip route del "${NETWORK}" dev "${VM_NET_DEV}" - ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 - # Create a macvtap network for the VM guest - { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : + { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } |: + if (( rc != 0 )); then - error "Capability NET_ADMIN has not been set most likely. Please add the " - error "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 + error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," + error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16 fi ip link set "${VM_NET_TAP}" up - { set +x; } 2>/dev/null - TAP_NR=$(/dev/null + + [[ "${DEBUG}" == [Yy1]* ]] && echo } # ###################################### @@ -235,6 +213,4 @@ fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" -[[ "${DEBUG}" == [Yy1]* ]] && echo && info "Finished network setup.." && echo - return 0 From f576adc75d3c9dded4c67e64aa7427051ad83d8b Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 19:34:48 +0200 Subject: [PATCH 10/13] Space --- run/server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/server.sh b/run/server.sh index 37cd61b..045d3d5 100644 --- a/run/server.sh +++ b/run/server.sh @@ -13,7 +13,7 @@ trap 'stop' EXIT SIGINT SIGTERM SIGHUP html() { - local h="VirtualDSM" + local h="VirtualDSM" h="${h} " h="${h}

$1

" From be2ccee2565e07aaa7cccd801214a391dd9b0a74 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 19:36:02 +0200 Subject: [PATCH 11/13] Spaces --- run/network.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run/network.sh b/run/network.sh index 08b015f..88d3e2e 100644 --- a/run/network.sh +++ b/run/network.sh @@ -25,7 +25,7 @@ configureDHCP() { # Create a macvtap network for the VM guest { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } |: - + if (( rc != 0 )); then error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16 @@ -67,7 +67,7 @@ configureDHCP() { configureNAT () { # Create a bridge with a static IP for the VM guest - + VM_NET_IP='20.20.20.21' [[ "${DEBUG}" == [Yy1]* ]] && set -x @@ -153,7 +153,7 @@ configureNAT () { $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} { set +x; } 2>/dev/null - + [[ "${DEBUG}" == [Yy1]* ]] && echo } From eed7b232b25d9214375ef18ab2819a527859adb7 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 19:37:17 +0200 Subject: [PATCH 12/13] Space --- run/disk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/disk.sh b/run/disk.sh index 777d4e6..55e373f 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -3,7 +3,7 @@ set -Eeuo pipefail # Docker environment variables -: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' +: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' : ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance : ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host. : ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD From a2d12f013129ec3c6cb33118c76faa71d0c271dd Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 19:43:19 +0200 Subject: [PATCH 13/13] Macvtap mode --- run/network.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run/network.sh b/run/network.sh index 88d3e2e..8056dbf 100644 --- a/run/network.sh +++ b/run/network.sh @@ -24,8 +24,8 @@ configureDHCP() { # Create a macvtap network for the VM guest - { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } |: - + { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : + if (( rc != 0 )); then error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16