Unverified Commit d22a3a4c authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Support more CPU models

feat: Support more CPU models
parents b6502e0a f93f8706
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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/*

+1 −21
Original line number Diff line number Diff line
#!/bin/bash
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 [ -n "$KVM_ERR" ]; then
  if [ "$ARCH" == "amd64" ]; then
    error "KVM acceleration not detected $KVM_ERR, see the FAQ about this."
    [[ "$DEBUG" != [Yy1]* ]] && exit 88
  fi
else
  KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
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"

src/cpu.sh

0 → 100644
+60 −0
Original line number Diff line number Diff line
#!/bin/bash
set -Eeuo pipefail

# Docker environment variables

: ${HOST_CPU:=''}
: ${CPU_MODEL:='host'}
: ${CPU_FEATURES:='+ssse3,+sse4.1,+sse4.2'}

KVM_ERR=""
KVM_OPTS=""

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
      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)."
    [[ "$DEBUG" != [Yy1]* ]] && exit 88
    [[ "$CPU_MODEL" == "host"* ]] && CPU_MODEL="max,$CPU_FEATURES"
  else
    KVM_OPTS=",accel=kvm -enable-kvm"
  fi

  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 that DSM needs, it will be emulated.."
      CPU_MODEL="host,$CPU_FEATURES"
    fi
  fi

else

  [[ "$CPU_MODEL" == "host"* ]] && CPU_MODEL="max,$CPU_FEATURES"

fi

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
  HOST_CPU="QEMU, Virtual CPU,"
  if [ "$ARCH" == "amd64" ]; then
    HOST_CPU="$HOST_CPU X86_64"
  else
    HOST_CPU="$HOST_CPU $ARCH"
  fi
fi

return 0
+14 −14
Original line number Diff line number Diff line
@@ -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"
+1 −0
Original line number Diff line number Diff line
@@ -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
Loading