From 36784bfcf10271f6c440ab3bf53eb570955496c3 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 23040a3e..30486f71 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 db17f93b757f0b7c155f1ba7694febc833c797c1 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 a306e4d1..1c7f3859 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 cf252e48fa7981bccc379e94a7ccf2cba9ec9691 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 1c7f3859..0d4d3249 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 f198ee4f6ffaacc34145f021afdc49c208cca4a1 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 0d4d3249..acfc33b8 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 e8829310a2191a4b64a939eaa1a9d195077a9225 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 a4ba5e49..9d3f9292 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 bc66e4c2b5044f9647a72b2aa827efca85e40718 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 f405a139..250d55ea 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 f5b5e6b457047563ceba622d57ad4f67331a5d23 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 250d55ea..b5994609 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 fd47ec3305c6f55f2869499b65ba3983347a421b 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 9d3f9292..dbe98c04 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 bc7e14294c4ef783b9fa870f2cea1a15e1af5f2d 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 b5994609..08b015f5 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 34ab852bc6f71f31f4da40b9070b470666015122 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 37cd61b9..045d3d50 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 ca693dc4509d02a3df864f20de4d9140b30681d6 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 08b015f5..88d3e2eb 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 f38cd624fd62b62714994013508439f8064f5721 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 777d4e63..55e373fd 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 ab2cc51d908cbe513e0fa2a4311a5c7090939020 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 88d3e2eb..8056dbf5 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