From 150c450bf6b7e20980a7e8441301e457dbf7837d Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 09:37:36 +0100 Subject: [PATCH 01/10] docs: Default folder --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 03ec6b3..aac409c 100644 --- a/readme.md +++ b/readme.md @@ -39,7 +39,7 @@ services: ports: - 5000:5000 volumes: - - /opt/dsm:/storage + - /var/dsm:/storage restart: on-failure stop_grace_period: 2m ``` @@ -65,14 +65,14 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti * ### How do I change the location of the virtual disk? - To change the virtual disk's location from the default Docker volume, include the following bind mount in your compose file: + To change the location of the virtual disk, include the following bind mount in your compose file: ```yaml volumes: - - /home/user/data:/storage + - /var/dsm:/storage ``` - Replace the example path `/home/user/data` with the desired storage folder. + Replace the example path `/var/dsm` with the desired storage folder. * ### How do I add multiple disks? From 95c3b2caad748c084ee5134894eb0f512a6448c9 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 09:39:19 +0100 Subject: [PATCH 02/10] fix: Default folder --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8aef6bc..cbbc42d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,6 @@ services: ports: - 5000:5000 volumes: - - /opt/dsm:/storage + - /var/dsm:/storage restart: on-failure stop_grace_period: 2m From 7f77bb88ab1b9be1a12d5c97af01637c3a563ec5 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 09:50:07 +0100 Subject: [PATCH 03/10] fix: Grammar --- src/cpu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpu.sh b/src/cpu.sh index 1cad10a..0070fdc 100644 --- a/src/cpu.sh +++ b/src/cpu.sh @@ -31,7 +31,7 @@ if [[ "$ARCH" == "amd64" && "$KVM" != [Nn]* ]]; then if [ -n "$KVM_OPTS" ]; then if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then - error "Your host CPU does not has the SSE4.2 instruction set that Virtual DSM requires to boot." + error "Your host CPU does not have the SSE4.2 instruction set that Virtual DSM requires to boot." error "Disable KVM by setting KVM=N to emulate a compatible CPU, at the cost of performance." [[ "$DEBUG" != [Yy1]* ]] && exit 89 fi From aaded40a4ff5e144afe724012357e8aff61b6fd6 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 09:54:07 +0100 Subject: [PATCH 04/10] fix: Cleanup server files --- src/reset.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reset.sh b/src/reset.sh index e2ac97a..e6e8acf 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -43,6 +43,7 @@ rm -f /run/qemu.count # Cleanup dirs rm -rf /tmp/dsm +rm -f /tmp/server.* rm -rf "$STORAGE/tmp" # Helper functions From 8b0ec3bef7a9039905bfd0f5ed080ffa8290c08e Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 09:57:50 +0100 Subject: [PATCH 05/10] fix: Remove healthcheck exception --- src/print.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/print.sh b/src/print.sh index 929e2c6..71be97c 100644 --- a/src/print.sh +++ b/src/print.sh @@ -7,6 +7,7 @@ error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; } file="/run/dsm.url" shutdown="/run/qemu.count" url="http://127.0.0.1:2210/read?command=10" + resp_err="Guest returned an invalid response:" jq_err="Failed to parse response from guest: jq error" @@ -19,8 +20,6 @@ do sleep 3 [ -f "$shutdown" ] && exit 1 - - # Healthcheck may have intervened [ -f "$file" ] && break # Retrieve IP from guest VM From 107a4b87d51777d1c57db890bf173bc9db097be0 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 10:04:00 +0100 Subject: [PATCH 06/10] fix: Quotes --- src/power.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/power.sh b/src/power.sh index 6fd105b..18f87c1 100644 --- a/src/power.sh +++ b/src/power.sh @@ -5,8 +5,8 @@ set -Eeuo pipefail QEMU_PORT=7100 QEMU_TIMEOUT=50 -QEMU_PID=/run/qemu.pid -QEMU_COUNT=/run/qemu.count +QEMU_PID="/run/qemu.pid" +QEMU_COUNT="/run/qemu.count" rm -f "$QEMU_PID" rm -f "$QEMU_COUNT" From 7a592e0cea1862049cf735bfed361529848316f1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 10:08:55 +0100 Subject: [PATCH 07/10] docs: DHCP mode --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index aac409c..1bf9d6f 100644 --- a/readme.md +++ b/readme.md @@ -170,7 +170,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti - 'c *:* rwm' ``` - Please note that even if you don't need DHCP, it's still recommended to enable this feature as it prevents NAT issues and increases performance by using a `macvtap` interface. + Please note that even if you don't want DHCP, it's still recommended to enable this feature as it prevents NAT issues and increases performance by using a `macvtap` interface. In that case just set a static IP from the DSM control panel after you enabled this mode. * ### How do I passthrough the GPU? From e7cdbb1db5370141adb2f4df77340eb844c8c875 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 10:51:30 +0100 Subject: [PATCH 08/10] feat: Optimize qcow2 flags --- src/disk.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index fee7afd..fae10fb 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -23,6 +23,8 @@ DISK_OPTS="\ -drive file=$SYSTEM,if=none,id=drive-synosys,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on \ -device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,rotation_rate=$DISK_ROTATION,bootindex=2" +: ${QCOW_FLAGS:='nocow=on,preallocation=metadata,lazy_refcounts=on'} + fmt2ext() { local DISK_FMT=$1 @@ -137,7 +139,7 @@ convertDisk() { case "$DST_FMT" in qcow2) - CONV_FLAGS="$CONV_FLAGS -c" + CONV_FLAGS="$CONV_FLAGS -c -o $QCOW_FLAGS" ;; esac @@ -186,7 +188,7 @@ createDisk() { fi ;; qcow2) - if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then + if ! qemu-img create -f "$DISK_FMT" -o "$QCOW_FLAGS" -- "$DISK_FILE" "$DISK_SPACE" ; then rm -f "$DISK_FILE" error "$FAIL" && exit 70 fi From 72085d37118cf2045e8be6303e67fa0315505e9a Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 11:17:26 +0100 Subject: [PATCH 09/10] fix: Set qcow2 flags --- src/disk.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index fae10fb..549e7d9 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -8,6 +8,7 @@ set -Eeuo pipefail : ${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 +: ${DISK_FLAGS:='nocow=on'} # Specify the options for use with the qcow2 format BOOT="$STORAGE/$BASE.boot.img" SYSTEM="$STORAGE/$BASE.system.img" @@ -23,8 +24,6 @@ DISK_OPTS="\ -drive file=$SYSTEM,if=none,id=drive-synosys,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on \ -device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,rotation_rate=$DISK_ROTATION,bootindex=2" -: ${QCOW_FLAGS:='nocow=on,preallocation=metadata,lazy_refcounts=on'} - fmt2ext() { local DISK_FMT=$1 @@ -123,7 +122,7 @@ resizeDisk() { fi ;; qcow2) - if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then + if ! qemu-img resize -f "$DISK_FMT" -o "$DISK_FLAGS" "$DISK_FILE" "$DISK_SPACE" ; then error "$FAIL" && exit 72 fi ;; @@ -139,12 +138,12 @@ convertDisk() { case "$DST_FMT" in qcow2) - CONV_FLAGS="$CONV_FLAGS -c -o $QCOW_FLAGS" + CONV_FLAGS="$CONV_FLAGS -c -o $DISK_FLAGS" ;; esac # shellcheck disable=SC2086 - qemu-img convert $CONV_FLAGS -f "$SOURCE_FMT" -O "$DST_FMT" -- "$SOURCE_FILE" "$DST_FILE" + qemu-img convert -f "$SOURCE_FMT" $CONV_FLAGS -O "$DST_FMT" -- "$SOURCE_FILE" "$DST_FILE" } createDisk() { @@ -188,7 +187,7 @@ createDisk() { fi ;; qcow2) - if ! qemu-img create -f "$DISK_FMT" -o "$QCOW_FLAGS" -- "$DISK_FILE" "$DISK_SPACE" ; then + if ! qemu-img create -f "$DISK_FMT" -o "$DISK_FLAGS" -- "$DISK_FILE" "$DISK_SPACE" ; then rm -f "$DISK_FILE" error "$FAIL" && exit 70 fi From d66be1a22837ccd458a1cf266bcdc203683dca09 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 17 Dec 2023 11:25:42 +0100 Subject: [PATCH 10/10] fix: Do not set flags on resize --- src/disk.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 549e7d9..b04c2c2 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -3,12 +3,12 @@ set -Eeuo pipefail # Docker environment variables -: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' -: ${DISK_FMT:='raw'} # Disk file format, 'raw' by default for best performance -: ${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 -: ${DISK_FLAGS:='nocow=on'} # Specify the options for use with the qcow2 format +: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' +: ${DISK_FMT:='raw'} # Disk file format, 'raw' by default for best performance +: ${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 +: ${DISK_FLAGS:='nocow=on'} # Specify the options for use with the qcow2 format BOOT="$STORAGE/$BASE.boot.img" SYSTEM="$STORAGE/$BASE.system.img" @@ -122,7 +122,7 @@ resizeDisk() { fi ;; qcow2) - if ! qemu-img resize -f "$DISK_FMT" -o "$DISK_FLAGS" "$DISK_FILE" "$DISK_SPACE" ; then + if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then error "$FAIL" && exit 72 fi ;;