From f1fbbb56238c5a66aaa7068d0ef466745cde51e7 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 00:35:08 +0100 Subject: [PATCH 01/20] feat: Configure CPU model --- src/reset.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/reset.sh b/src/reset.sh index d142d30..32b49eb 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -16,10 +16,11 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR : ${COUNTRY:=''} # Country code for mirror : ${CONSOLE:='N'} # Start in console mode : ${ALLOCATE:='Y'} # Preallocate diskspace +: ${RAM_SIZE:='1G'} # Maximum RAM amount +: ${DISK_SIZE:='16G'} # Initial datadisk size : ${ARGUMENTS:=''} # Extra QEMU parameters : ${CPU_CORES:='1'} # Amount of CPU cores -: ${RAM_SIZE:='1G'} # Maximum RAM amount -: ${DISK_SIZE:='16G'} # Initial data disk size +: ${CPU_MODEL:='host'} # CPU model to emulate # Helper variables From c335078aaca5accce3c7502eeeb599ac7a58c931 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 01:00:42 +0100 Subject: [PATCH 02/20] feat: Display emulated CPU --- src/serial.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/serial.sh b/src/serial.sh index 924497c..ea4ec44 100644 --- a/src/serial.sh +++ b/src/serial.sh @@ -10,17 +10,22 @@ set -Eeuo pipefail : ${HOST_MODEL:=''} : ${GUEST_SERIAL:=''} -if [ -z "$HOST_CPU" ]; then +if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host" ]; then HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') fi if [ -n "$HOST_CPU" ]; then - HOST_CPU="$HOST_CPU,," + HOST_CPU="${HOST_CPU%%,*},," else - if [ "$ARCH" == "amd64" ]; then - HOST_CPU="QEMU, Virtual CPU, X86_64" + if [ "$CPU_MODEL" == "host" ]; then + HOST_CPU="QEMU" else - HOST_CPU="QEMU, Virtual CPU, $ARCH" + HOST_CPU="${CPU_MODEL%%,*}" + fi + if [ "$ARCH" == "amd64" ]; then + HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, X86_64" + else + HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, $ARCH" fi fi From 7e125854293c7f6091e0deb83cab3c0145591a5f Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 01:30:34 +0100 Subject: [PATCH 03/20] fix: Error codes --- src/disk.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index e89bcf6..fee7afd 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -34,7 +34,7 @@ fmt2ext() { echo "img" ;; *) - error "Unrecognized disk format: $DISK_FMT" && exit 88 + error "Unrecognized disk format: $DISK_FMT" && exit 78 ;; esac } @@ -50,7 +50,7 @@ ext2fmt() { echo "raw" ;; *) - error "Unrecognized file extension: .$DISK_EXT" && exit 88 + error "Unrecognized file extension: .$DISK_EXT" && exit 78 ;; esac } @@ -70,7 +70,7 @@ getSize() { qemu-img info "$DISK_FILE" -f "$DISK_FMT" | grep '^virtual size: ' | sed 's/.*(\(.*\) bytes)/\1/' ;; *) - error "Unrecognized disk format: $DISK_FMT" && exit 88 + error "Unrecognized disk format: $DISK_FMT" && exit 78 ;; esac } @@ -89,7 +89,7 @@ resizeDisk() { FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .." REQ=$((DATA_SIZE-CUR_SIZE)) - (( REQ < 1 )) && error "Shrinking disks is not supported!" && exit 84 + (( REQ < 1 )) && error "Shrinking disks is not supported!" && exit 71 case "${DISK_FMT,,}" in raw) @@ -97,7 +97,7 @@ resizeDisk() { # Resize file by changing its length if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then - error "$FAIL" && exit 85 + error "$FAIL" && exit 75 fi else @@ -108,13 +108,13 @@ resizeDisk() { if (( REQ > SPACE )); then error "Not enough free space to resize $DISK_DESC to $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.." - error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 84 + error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 74 fi # Resize file by allocating more space if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then - error "$FAIL" && exit 85 + error "$FAIL" && exit 75 fi fi @@ -122,7 +122,7 @@ resizeDisk() { ;; qcow2) if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then - error "$FAIL" && exit 85 + error "$FAIL" && exit 72 fi ;; esac @@ -161,7 +161,7 @@ createDisk() { # Create an empty file if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then rm -f "$DISK_FILE" - error "$FAIL" && exit 87 + error "$FAIL" && exit 77 fi else @@ -172,14 +172,14 @@ createDisk() { if (( DATA_SIZE > SPACE )); then error "Not enough free space to create a $DISK_DESC of $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.." - error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 86 + error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 76 fi # Create an empty file if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then rm -f "$DISK_FILE" - error "$FAIL" && exit 87 + error "$FAIL" && exit 77 fi fi @@ -188,7 +188,7 @@ createDisk() { qcow2) if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then rm -f "$DISK_FILE" - error "$FAIL" && exit 89 + error "$FAIL" && exit 70 fi ;; esac @@ -219,7 +219,7 @@ addDisk () { DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE") if (( DATA_SIZE < 6442450944 )); then - error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 83 + error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73 fi if ! [ -f "$DISK_FILE" ] ; then @@ -243,7 +243,7 @@ addDisk () { if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then rm -f "$TMP_FILE" - error "Failed to convert $DISK_DESC to $DISK_FMT format." && exit 89 + error "Failed to convert $DISK_DESC to $DISK_FMT format." && exit 79 fi mv "$TMP_FILE" "$DISK_FILE" From 95991d8f5d93fc38d07f07c27757fe0b63269dbf Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 01:36:33 +0100 Subject: [PATCH 04/20] fix: Error codes --- src/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/install.sh b/src/install.sh index dfb7420..fc7352f 100644 --- a/src/install.sh +++ b/src/install.sh @@ -242,16 +242,16 @@ SYSTEM_SIZE=4954537983 # Check free diskspace SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) SPACE_GB=$(( (SPACE + 1073741823)/1073741824 )) -(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk, have only $SPACE_GB GB available." && exit 87 +(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk, have only $SPACE_GB GB available." && exit 97 if ! fallocate -l "$SYSTEM_SIZE" "$SYSTEM"; then if ! truncate -s "$SYSTEM_SIZE" "$SYSTEM"; then - rm -f "$SYSTEM" && error "Could not allocate a file for the system disk." && exit 88 + rm -f "$SYSTEM" && error "Could not allocate a file for the system disk." && exit 98 fi fi # Check if file exists -[ ! -f "$SYSTEM" ] && error "System disk does not exist ($SYSTEM)" && exit 89 +[ ! -f "$SYSTEM" ] && error "System disk does not exist ($SYSTEM)" && exit 99 # Check the filesize SIZE=$(stat -c%s "$SYSTEM") From 469ee6794222c7630ee61b172124b24bfd511efc Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 01:42:02 +0100 Subject: [PATCH 05/20] fix: Error codes --- src/network.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network.sh b/src/network.sh index eed1b52..c498549 100644 --- a/src/network.sh +++ b/src/network.sh @@ -187,7 +187,7 @@ if [ ! -c /dev/net/tun ]; then chmod 666 /dev/net/tun fi -[ ! -c /dev/net/tun ] && error "TUN network interface not available..." && exit 85 +[ ! -c /dev/net/tun ] && error "TUN network interface not available..." && exit 25 # Create the necessary file structure for /dev/vhost-net if [ ! -c /dev/vhost-net ]; then @@ -212,7 +212,7 @@ if [[ "$DHCP" == [Yy1]* ]]; then if [[ "$DEBUG" == [Yy1]* ]]; then info "Warning: Are you sure the container is on a macvlan network?" else - error "You can only enable DHCP while the container is on a macvlan network!" && exit 86 + error "You can only enable DHCP while the container is on a macvlan network!" && exit 26 fi fi From fe2d072056269fc30cb228ebb14d982769d89f56 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 02:05:54 +0100 Subject: [PATCH 06/20] fix: Check for SSE4.2 support --- src/config.sh | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/config.sh b/src/config.sh index 60e6c05..9725628 100644 --- a/src/config.sh +++ b/src/config.sh @@ -4,21 +4,29 @@ set -Eeuo pipefail KVM_ERR="" KVM_OPTS="" -if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then - if ! grep -q -e vmx -e svm /proc/cpuinfo; then - KVM_ERR="(vmx/svm disabled)" - fi -else - [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)" -fi +if [ "$ARCH" == "amd64" ]; then -if [ -n "$KVM_ERR" ]; then - if [ "$ARCH" == "amd64" ]; then + if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + if ! grep -q -e vmx -e svm /proc/cpuinfo; then + KVM_ERR="(vmx/svm disabled)" + fi + else + [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)" + fi + + if [ -n "$KVM_ERR" ]; then error "KVM acceleration not detected $KVM_ERR, see the FAQ about this." [[ "$DEBUG" != [Yy1]* ]] && exit 88 + else + if [ "$CPU_MODEL" == "host" ]; then + if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then + error "Your CPU does not have the SSE4.2 instruction set, which is required by DSM." + [[ "$DEBUG" != [Yy1]* ]] && exit 89 + fi + fi + KVM_OPTS=",accel=kvm -enable-kvm -cpu $CPU_MODEL" fi -else - KVM_OPTS=",accel=kvm -enable-kvm -cpu host" + fi DEF_OPTS="-nographic -nodefaults -boot strict=on -display none" From 539f5de6d97c938c9d15830cbdbff5a8d78fbd93 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 02:45:16 +0100 Subject: [PATCH 07/20] fix: Add qemu-user package on arm64 --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 156c4a1..9d37f1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,13 @@ FROM qemux/qemu-host as builder FROM debian:trixie-slim +ARG TARGETPLATFORM ARG DEBCONF_NOWARNINGS="yes" ARG DEBIAN_FRONTEND noninteractive -RUN apt-get update && apt-get -y upgrade && \ - apt-get --no-install-recommends -y install \ +RUN apt-get update && apt-get -y upgrade \ + && if [ "$TARGETPLATFORM" != "linux/amd64" ]; then extra="qemu-user"; fi \ + && apt-get --no-install-recommends -y install \ jq \ tini \ curl \ @@ -32,6 +34,7 @@ RUN apt-get update && apt-get -y upgrade && \ ca-certificates \ netcat-openbsd \ qemu-system-x86 \ + "$extra" \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From 1b3d760f5f0a43cb54616ac49e138751554f277f Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 03:07:08 +0100 Subject: [PATCH 08/20] fix: Set CPU model --- src/serial.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serial.sh b/src/serial.sh index ea4ec44..aaa99b9 100644 --- a/src/serial.sh +++ b/src/serial.sh @@ -17,7 +17,7 @@ fi if [ -n "$HOST_CPU" ]; then HOST_CPU="${HOST_CPU%%,*},," else - if [ "$CPU_MODEL" == "host" ]; then + if [ "$CPU_MODEL" == "host" ] || [ "$CPU_MODEL" == "qemu"* ]; then HOST_CPU="QEMU" else HOST_CPU="${CPU_MODEL%%,*}" From db72acfc4f51a3501e82f19776230064ce3af842 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 03:12:55 +0100 Subject: [PATCH 09/20] feat: Install DSM 7.2 on ARM64 --- src/install.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/install.sh b/src/install.sh index fc7352f..aa106a4 100644 --- a/src/install.sh +++ b/src/install.sh @@ -33,13 +33,7 @@ if [ -z "$DL" ]; then [[ "${COUNTRY^^}" == "CN" ]] && DL="$DL_CHINA" || DL="$DL_GLOBAL" fi -if [ -z "$URL" ]; then - if [ "$ARCH" == "amd64" ]; then - URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat" - else - URL="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat" - fi -fi +[ -z "$URL" ] && URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat" BASE=$(basename "$URL" .pat) @@ -205,8 +199,6 @@ if { tar tf "$PAT"; } >/dev/null 2>&1; then else - [ "$ARCH" != "amd64" ] && addPackage "qemu-user" "QEMU" - info "Install: Extracting downloaded image..." export LD_LIBRARY_PATH="/run/extract" From 38121013663e40a70509468584b9f1e35cfb1ff1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:02:11 +0100 Subject: [PATCH 10/20] feat: Add KVM flag --- src/reset.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/reset.sh b/src/reset.sh index 32b49eb..2b4b035 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -11,13 +11,14 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR # Docker environment variables -: ${GPU:='N'} # Enable GPU passthrough -: ${DEBUG:='N'} # Enable debugging mode +: ${GPU:='N'} # Disable GPU passthrough +: ${KVM:='Y'} # Enable KVM acceleration +: ${DEBUG:='N'} # Disable debugging mode : ${COUNTRY:=''} # Country code for mirror -: ${CONSOLE:='N'} # Start in console mode +: ${CONSOLE:='N'} # Disable console mode : ${ALLOCATE:='Y'} # Preallocate diskspace : ${RAM_SIZE:='1G'} # Maximum RAM amount -: ${DISK_SIZE:='16G'} # Initial datadisk size +: ${DISK_SIZE:='16G'} # Initial data disk size : ${ARGUMENTS:=''} # Extra QEMU parameters : ${CPU_CORES:='1'} # Amount of CPU cores : ${CPU_MODEL:='host'} # CPU model to emulate From 3f2ca67051d4f343da46eb2ed2bc98e12c5d727b Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:22:21 +0100 Subject: [PATCH 11/20] feat: Emulate SSE4.2 on ARM64 --- src/config.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/config.sh b/src/config.sh index 9725628..6a09009 100644 --- a/src/config.sh +++ b/src/config.sh @@ -3,6 +3,7 @@ set -Eeuo pipefail KVM_ERR="" KVM_OPTS="" +QEMU_CPU="qemu64,+ssse3,+sse4,+sse4.1,+sse4.2" if [ "$ARCH" == "amd64" ]; then @@ -15,23 +16,27 @@ if [ "$ARCH" == "amd64" ]; then fi if [ -n "$KVM_ERR" ]; then - error "KVM acceleration not detected $KVM_ERR, see the FAQ about this." - [[ "$DEBUG" != [Yy1]* ]] && exit 88 + error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance." + error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)." + [[ "$KVM" != [Nn]* ]] && [[ "$DEBUG" != [Yy1]* ]] && exit 88 + [ "$CPU_MODEL" == "host" ] && CPU_MODEL="$QEMU_CPU" else - if [ "$CPU_MODEL" == "host" ]; then - if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then - error "Your CPU does not have the SSE4.2 instruction set, which is required by DSM." - [[ "$DEBUG" != [Yy1]* ]] && exit 89 - fi - fi - KVM_OPTS=",accel=kvm -enable-kvm -cpu $CPU_MODEL" + KVM_OPTS=",accel=kvm -enable-kvm" fi + if [ "$CPU_MODEL" == "host" ]; then + if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then + info "Your CPU does not have the SSE4.2 instruction set, it will be emulated.." + CPU_MODEL="host,+ssse3,+sse4,+sse4.1,+sse4.2" + fi + fi +else + [ "$CPU_MODEL" == "host" ] && CPU_MODEL="$QEMU_CPU" fi DEF_OPTS="-nographic -nodefaults -boot strict=on -display none" RAM_OPTS=$(echo "-m $RAM_SIZE" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') -CPU_OPTS="-smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" +CPU_OPTS="-cpu $CPU_MODEL -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}" EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4" EXTRA_OPTS="$EXTRA_OPTS -object rng-random,id=objrng0,filename=/dev/urandom" From d3f77c848cae20adca0610135cc1a5fe53e46290 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:36:00 +0100 Subject: [PATCH 12/20] feat: Emulate SSE4.2 on ARM64 --- src/cpu.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/cpu.sh diff --git a/src/cpu.sh b/src/cpu.sh new file mode 100644 index 0000000..5df8fee --- /dev/null +++ b/src/cpu.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -Eeuo pipefail + +KVM_ERR="" +KVM_OPTS="" +QEMU_CPU="qemu64,+ssse3,+sse4,+sse4.1,+sse4.2" + +if [ "$ARCH" == "amd64" ]; then + + if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + if ! grep -q -e vmx -e svm /proc/cpuinfo; then + KVM_ERR="(vmx/svm disabled)" + fi + else + [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)" + fi + + if [ -n "$KVM_ERR" ]; then + error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance." + error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)." + [[ "$KVM" != [Nn]* ]] && [[ "$DEBUG" != [Yy1]* ]] && exit 88 + [ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" + else + KVM_OPTS=",accel=kvm -enable-kvm" + fi + + if [ "$CPU_MODEL" == "host" ]; then + if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then + info "Your CPU does not have the SSE4.2 instruction set, it will be emulated.." + CPU_MODEL="host,+ssse3,+sse4,+sse4.1,+sse4.2" + fi + fi +else + [ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" +fi + +return 0 From 6670ca4fe1ccf0165e8f7d136bb2e1487260db66 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:36:56 +0100 Subject: [PATCH 13/20] fix: Configuration --- src/config.sh | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/config.sh b/src/config.sh index 6a09009..05fc7a3 100644 --- a/src/config.sh +++ b/src/config.sh @@ -1,39 +1,6 @@ #!/bin/bash set -Eeuo pipefail -KVM_ERR="" -KVM_OPTS="" -QEMU_CPU="qemu64,+ssse3,+sse4,+sse4.1,+sse4.2" - -if [ "$ARCH" == "amd64" ]; then - - if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then - if ! grep -q -e vmx -e svm /proc/cpuinfo; then - KVM_ERR="(vmx/svm disabled)" - fi - else - [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)" - fi - - if [ -n "$KVM_ERR" ]; then - error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance." - error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)." - [[ "$KVM" != [Nn]* ]] && [[ "$DEBUG" != [Yy1]* ]] && exit 88 - [ "$CPU_MODEL" == "host" ] && CPU_MODEL="$QEMU_CPU" - else - KVM_OPTS=",accel=kvm -enable-kvm" - fi - - if [ "$CPU_MODEL" == "host" ]; then - if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then - info "Your CPU does not have the SSE4.2 instruction set, it will be emulated.." - CPU_MODEL="host,+ssse3,+sse4,+sse4.1,+sse4.2" - fi - fi -else - [ "$CPU_MODEL" == "host" ] && CPU_MODEL="$QEMU_CPU" -fi - DEF_OPTS="-nographic -nodefaults -boot strict=on -display none" RAM_OPTS=$(echo "-m $RAM_SIZE" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') CPU_OPTS="-cpu $CPU_MODEL -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" From 2cc1af19b167d2c554291571359311cb7c009f42 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:38:15 +0100 Subject: [PATCH 14/20] fix: Configure CPU --- src/entry.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/entry.sh b/src/entry.sh index c936130..d9ba03f 100755 --- a/src/entry.sh +++ b/src/entry.sh @@ -11,6 +11,7 @@ cd /run . disk.sh # Initialize disks . network.sh # Initialize network . gpu.sh # Initialize graphics +. cpu.sh # Initialize processor . serial.sh # Initialize serialport . power.sh # Configure shutdown . config.sh # Configure arguments From 10915a601ca0316d2834a80f4fe8daf070b17da4 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:44:15 +0100 Subject: [PATCH 15/20] feat: Display emulated CPU --- src/serial.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/serial.sh b/src/serial.sh index aaa99b9..a9e00ba 100644 --- a/src/serial.sh +++ b/src/serial.sh @@ -10,14 +10,14 @@ set -Eeuo pipefail : ${HOST_MODEL:=''} : ${GUEST_SERIAL:=''} -if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host" ]; then +if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host"* ]; then HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') fi if [ -n "$HOST_CPU" ]; then HOST_CPU="${HOST_CPU%%,*},," else - if [ "$CPU_MODEL" == "host" ] || [ "$CPU_MODEL" == "qemu"* ]; then + if [ "$CPU_MODEL" == "host"* ] || [ "$CPU_MODEL" == "qemu"* ]; then HOST_CPU="QEMU" else HOST_CPU="${CPU_MODEL%%,*}" From 8925323a6e914b7567084c0ed81bb23e3a16cbfd Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 04:55:40 +0100 Subject: [PATCH 16/20] feat: KVM flag --- src/cpu.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cpu.sh b/src/cpu.sh index 5df8fee..f87327c 100644 --- a/src/cpu.sh +++ b/src/cpu.sh @@ -5,7 +5,7 @@ KVM_ERR="" KVM_OPTS="" QEMU_CPU="qemu64,+ssse3,+sse4,+sse4.1,+sse4.2" -if [ "$ARCH" == "amd64" ]; then +if [ "$ARCH" == "amd64" ] && [[ "$KVM" != [Nn]* ]]; then if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then if ! grep -q -e vmx -e svm /proc/cpuinfo; then @@ -18,7 +18,7 @@ if [ "$ARCH" == "amd64" ]; then if [ -n "$KVM_ERR" ]; then error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance." error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)." - [[ "$KVM" != [Nn]* ]] && [[ "$DEBUG" != [Yy1]* ]] && exit 88 + [[ "$DEBUG" != [Yy1]* ]] && exit 88 [ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" else KVM_OPTS=",accel=kvm -enable-kvm" @@ -30,8 +30,11 @@ if [ "$ARCH" == "amd64" ]; then CPU_MODEL="host,+ssse3,+sse4,+sse4.1,+sse4.2" fi fi + else + [ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" + fi return 0 From 970a662170c53f719694429b6e86665237539065 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 05:04:17 +0100 Subject: [PATCH 17/20] fix: CPU configuration --- src/serial.sh | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/serial.sh b/src/serial.sh index a9e00ba..db473ef 100644 --- a/src/serial.sh +++ b/src/serial.sh @@ -3,32 +3,12 @@ set -Eeuo pipefail # Docker environment variables -: ${HOST_CPU:=''} : ${HOST_MAC:=''} : ${HOST_DEBUG:=''} : ${HOST_SERIAL:=''} : ${HOST_MODEL:=''} : ${GUEST_SERIAL:=''} -if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host"* ]; then - HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') -fi - -if [ -n "$HOST_CPU" ]; then - HOST_CPU="${HOST_CPU%%,*},," -else - if [ "$CPU_MODEL" == "host"* ] || [ "$CPU_MODEL" == "qemu"* ]; then - HOST_CPU="QEMU" - else - HOST_CPU="${CPU_MODEL%%,*}" - fi - if [ "$ARCH" == "amd64" ]; then - HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, X86_64" - else - HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, $ARCH" - fi -fi - HOST_ARGS=() HOST_ARGS+=("-cpu=$CPU_CORES") HOST_ARGS+=("-cpu_arch=$HOST_CPU") From 32748509ea1c3d0ff2d5c5dc8aed92999d1094b8 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 05:08:34 +0100 Subject: [PATCH 18/20] fix: CPU configuration --- src/cpu.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cpu.sh b/src/cpu.sh index f87327c..c42172d 100644 --- a/src/cpu.sh +++ b/src/cpu.sh @@ -1,9 +1,14 @@ #!/bin/bash set -Eeuo pipefail +# Docker environment variables + +: ${HOST_CPU:=''} +: ${CPU_MODEL:='host'} +: ${QEMU_CPU:='qemu64,+ssse3,+sse4,+sse4.1,+sse4.2'} + KVM_ERR="" KVM_OPTS="" -QEMU_CPU="qemu64,+ssse3,+sse4,+sse4.1,+sse4.2" if [ "$ARCH" == "amd64" ] && [[ "$KVM" != [Nn]* ]]; then @@ -37,4 +42,23 @@ else fi +if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host"* ]; then + HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') +fi + +if [ -n "$HOST_CPU" ]; then + HOST_CPU="${HOST_CPU%%,*},," +else + if [ "$CPU_MODEL" == "host"* ] || [ "$CPU_MODEL" == "qemu"* ]; then + HOST_CPU="QEMU" + else + HOST_CPU="${CPU_MODEL%%,*}" + fi + if [ "$ARCH" == "amd64" ]; then + HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, X86_64" + else + HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, $ARCH" + fi +fi + return 0 From a2e55c5ddae61c18190fe5c42c55022c26228ab1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 05:11:20 +0100 Subject: [PATCH 19/20] fix: Configuration variables --- src/reset.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/reset.sh b/src/reset.sh index 2b4b035..e2ac97a 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -17,11 +17,10 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR : ${COUNTRY:=''} # Country code for mirror : ${CONSOLE:='N'} # Disable console mode : ${ALLOCATE:='Y'} # Preallocate diskspace -: ${RAM_SIZE:='1G'} # Maximum RAM amount -: ${DISK_SIZE:='16G'} # Initial data disk size : ${ARGUMENTS:=''} # Extra QEMU parameters : ${CPU_CORES:='1'} # Amount of CPU cores -: ${CPU_MODEL:='host'} # CPU model to emulate +: ${RAM_SIZE:='1G'} # Maximum RAM amount +: ${DISK_SIZE:='16G'} # Initial data disk size # Helper variables From f93f870626491427125ec282107a7353fdb4aa48 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 06:31:43 +0100 Subject: [PATCH 20/20] feat: CPU features --- src/cpu.sh | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/cpu.sh b/src/cpu.sh index c42172d..edb8800 100644 --- a/src/cpu.sh +++ b/src/cpu.sh @@ -2,15 +2,15 @@ set -Eeuo pipefail # Docker environment variables - + : ${HOST_CPU:=''} : ${CPU_MODEL:='host'} -: ${QEMU_CPU:='qemu64,+ssse3,+sse4,+sse4.1,+sse4.2'} +: ${CPU_FEATURES:='+ssse3,+sse4.1,+sse4.2'} KVM_ERR="" KVM_OPTS="" -if [ "$ARCH" == "amd64" ] && [[ "$KVM" != [Nn]* ]]; then +if [[ "$ARCH" == "amd64" && "$KVM" != [Nn]* ]]; then if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then if ! grep -q -e vmx -e svm /proc/cpuinfo; then @@ -24,40 +24,36 @@ if [ "$ARCH" == "amd64" ] && [[ "$KVM" != [Nn]* ]]; then error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance." error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)." [[ "$DEBUG" != [Yy1]* ]] && exit 88 - [ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" + [[ "$CPU_MODEL" == "host"* ]] && CPU_MODEL="max,$CPU_FEATURES" else KVM_OPTS=",accel=kvm -enable-kvm" fi - if [ "$CPU_MODEL" == "host" ]; then + if [[ "$CPU_MODEL" != *"$CPU_FEATURES"* ]]; then if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then - info "Your CPU does not have the SSE4.2 instruction set, it will be emulated.." - CPU_MODEL="host,+ssse3,+sse4,+sse4.1,+sse4.2" + info "Your CPU does not have the SSE4.2 instruction set that DSM needs, it will be emulated.." + CPU_MODEL="host,$CPU_FEATURES" fi fi else - [ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" + [[ "$CPU_MODEL" == "host"* ]] && CPU_MODEL="max,$CPU_FEATURES" fi -if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host"* ]; then +if [ -z "$HOST_CPU" ]; then HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') fi if [ -n "$HOST_CPU" ]; then HOST_CPU="${HOST_CPU%%,*},," else - if [ "$CPU_MODEL" == "host"* ] || [ "$CPU_MODEL" == "qemu"* ]; then - HOST_CPU="QEMU" - else - HOST_CPU="${CPU_MODEL%%,*}" - fi + HOST_CPU="QEMU, Virtual CPU," if [ "$ARCH" == "amd64" ]; then - HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, X86_64" + HOST_CPU="$HOST_CPU X86_64" else - HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, $ARCH" + HOST_CPU="$HOST_CPU $ARCH" fi fi