mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d22a3a4c7d | ||
|
|
f93f870626 | ||
|
|
a2e55c5dda | ||
|
|
32748509ea | ||
|
|
970a662170 | ||
|
|
8925323a6e | ||
|
|
10915a601c | ||
|
|
2cc1af19b1 | ||
|
|
6670ca4fe1 | ||
|
|
d3f77c848c | ||
|
|
3f2ca67051 | ||
|
|
3812101366 | ||
|
|
db72acfc4f | ||
|
|
1b3d760f5f | ||
|
|
539f5de6d9 | ||
|
|
fe2d072056 | ||
|
|
469ee67942 | ||
|
|
95991d8f5d | ||
|
|
7e12585429 | ||
|
|
c335078aac | ||
|
|
f1fbbb5623 | ||
|
|
b6502e0a38 | ||
|
|
2fab3e5897 | ||
|
|
a4ea89d6e7 | ||
|
|
c451f253fa | ||
|
|
03121b6c6d | ||
|
|
007d20c315 | ||
|
|
26d6fa9fcc | ||
|
|
b9f3e52ba4 |
6
.github/renovate.json
vendored
6
.github/renovate.json
vendored
@@ -1,6 +1,4 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"config:base",
|
"extends": ["config:recommended", ":disableDependencyDashboard"]
|
||||||
":disableDependencyDashboard"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -79,16 +79,14 @@ jobs:
|
|||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
build-args: |
|
build-args: |
|
||||||
VCS_REF=${GITHUB_SHA::8}
|
|
||||||
VERSION_ARG=${{ steps.meta.outputs.version }}
|
VERSION_ARG=${{ steps.meta.outputs.version }}
|
||||||
-
|
-
|
||||||
name: Create a release
|
name: Create a release
|
||||||
uses: action-pack/github-release@v2
|
uses: action-pack/github-release@v2
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
|
||||||
with:
|
with:
|
||||||
tag: "v${{ steps.meta.outputs.version }}"
|
tag: "v${{ steps.meta.outputs.version }}"
|
||||||
title: "v${{ steps.meta.outputs.version }}"
|
title: "v${{ steps.meta.outputs.version }}"
|
||||||
|
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Increment version variable
|
name: Increment version variable
|
||||||
uses: action-pack/bump@v2
|
uses: action-pack/bump@v2
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ FROM qemux/qemu-host as builder
|
|||||||
|
|
||||||
FROM debian:trixie-slim
|
FROM debian:trixie-slim
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
ARG DEBCONF_NOWARNINGS="yes"
|
ARG DEBCONF_NOWARNINGS="yes"
|
||||||
ARG DEBIAN_FRONTEND noninteractive
|
ARG DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && \
|
RUN apt-get update && apt-get -y upgrade \
|
||||||
apt-get --no-install-recommends -y install \
|
&& if [ "$TARGETPLATFORM" != "linux/amd64" ]; then extra="qemu-user"; fi \
|
||||||
|
&& apt-get --no-install-recommends -y install \
|
||||||
jq \
|
jq \
|
||||||
tini \
|
tini \
|
||||||
curl \
|
curl \
|
||||||
@@ -32,6 +34,7 @@ RUN apt-get update && apt-get -y upgrade && \
|
|||||||
ca-certificates \
|
ca-certificates \
|
||||||
netcat-openbsd \
|
netcat-openbsd \
|
||||||
qemu-system-x86 \
|
qemu-system-x86 \
|
||||||
|
"$extra" \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /opt/dsm:/storage
|
- /opt/dsm:/storage
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
stop_grace_period: 1m
|
stop_grace_period: 2m
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /opt/dsm:/storage
|
- /opt/dsm:/storage
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
stop_grace_period: 1m
|
stop_grace_period: 2m
|
||||||
```
|
```
|
||||||
|
|
||||||
Via `docker run`
|
Via `docker run`
|
||||||
|
|||||||
34
src/check.sh
34
src/check.sh
@@ -5,42 +5,12 @@ set -Eeuo pipefail
|
|||||||
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
|
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
|
||||||
|
|
||||||
file="/run/dsm.url"
|
file="/run/dsm.url"
|
||||||
|
[ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
|
||||||
if [ ! -f "$file" ]; then
|
|
||||||
|
|
||||||
# Retrieve IP from guest VM for Docker healthcheck
|
|
||||||
|
|
||||||
{ json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || :
|
|
||||||
(( rc != 0 )) && echo "Failed to connect to guest: curl error $rc" && exit 1
|
|
||||||
|
|
||||||
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
|
||||||
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
|
||||||
[[ "$result" == "null" ]] && echo "Guest returned invalid response: $json" && exit 1
|
|
||||||
|
|
||||||
if [[ "$result" != "success" ]] ; then
|
|
||||||
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
|
||||||
echo "Guest replied $result: $msg" && exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
|
||||||
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
|
||||||
[[ "$port" == "null" ]] && echo "Guest has not set a portnumber yet.." && exit 1
|
|
||||||
[ -z "$port" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
|
||||||
|
|
||||||
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
|
||||||
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
|
||||||
[[ "$ip" == "null" ]] && echo "Guest returned invalid response: $json" && exit 1
|
|
||||||
[ -z "$ip" ] && echo "Guest has not received an IP yet.." && exit 1
|
|
||||||
|
|
||||||
echo "$ip:$port" > $file
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
location=$(cat "$file")
|
location=$(cat "$file")
|
||||||
|
|
||||||
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
||||||
echo "Failed to reach http://$location"
|
echo "Failed to reach page at http://$location" && exit 1
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Healthcheck OK"
|
echo "Healthcheck OK"
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -Eeuo pipefail
|
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"
|
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')
|
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}"
|
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="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
|
||||||
EXTRA_OPTS="$EXTRA_OPTS -object rng-random,id=objrng0,filename=/dev/urandom"
|
EXTRA_OPTS="$EXTRA_OPTS -object rng-random,id=objrng0,filename=/dev/urandom"
|
||||||
|
|||||||
60
src/cpu.sh
Normal file
60
src/cpu.sh
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#!/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
|
||||||
28
src/disk.sh
28
src/disk.sh
@@ -34,7 +34,7 @@ fmt2ext() {
|
|||||||
echo "img"
|
echo "img"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unrecognized disk format: $DISK_FMT" && exit 88
|
error "Unrecognized disk format: $DISK_FMT" && exit 78
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ ext2fmt() {
|
|||||||
echo "raw"
|
echo "raw"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unrecognized file extension: .$DISK_EXT" && exit 88
|
error "Unrecognized file extension: .$DISK_EXT" && exit 78
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ getSize() {
|
|||||||
qemu-img info "$DISK_FILE" -f "$DISK_FMT" | grep '^virtual size: ' | sed 's/.*(\(.*\) bytes)/\1/'
|
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
|
esac
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ resizeDisk() {
|
|||||||
FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .."
|
FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .."
|
||||||
|
|
||||||
REQ=$((DATA_SIZE-CUR_SIZE))
|
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
|
case "${DISK_FMT,,}" in
|
||||||
raw)
|
raw)
|
||||||
@@ -97,7 +97,7 @@ resizeDisk() {
|
|||||||
|
|
||||||
# Resize file by changing its length
|
# Resize file by changing its length
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
error "$FAIL" && exit 85
|
error "$FAIL" && exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -108,13 +108,13 @@ resizeDisk() {
|
|||||||
|
|
||||||
if (( REQ > SPACE )); then
|
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 "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
|
fi
|
||||||
|
|
||||||
# Resize file by allocating more space
|
# Resize file by allocating more space
|
||||||
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
error "$FAIL" && exit 85
|
error "$FAIL" && exit 75
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ resizeDisk() {
|
|||||||
;;
|
;;
|
||||||
qcow2)
|
qcow2)
|
||||||
if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then
|
if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then
|
||||||
error "$FAIL" && exit 85
|
error "$FAIL" && exit 72
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -161,7 +161,7 @@ createDisk() {
|
|||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 87
|
error "$FAIL" && exit 77
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -172,14 +172,14 @@ createDisk() {
|
|||||||
|
|
||||||
if (( DATA_SIZE > SPACE )); then
|
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 "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
|
fi
|
||||||
|
|
||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 87
|
error "$FAIL" && exit 77
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ createDisk() {
|
|||||||
qcow2)
|
qcow2)
|
||||||
if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then
|
if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 89
|
error "$FAIL" && exit 70
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -219,7 +219,7 @@ addDisk () {
|
|||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
|
|
||||||
if (( DATA_SIZE < 6442450944 )); then
|
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
|
fi
|
||||||
|
|
||||||
if ! [ -f "$DISK_FILE" ] ; then
|
if ! [ -f "$DISK_FILE" ] ; then
|
||||||
@@ -243,7 +243,7 @@ addDisk () {
|
|||||||
|
|
||||||
if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then
|
if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then
|
||||||
rm -f "$TMP_FILE"
|
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
|
fi
|
||||||
|
|
||||||
mv "$TMP_FILE" "$DISK_FILE"
|
mv "$TMP_FILE" "$DISK_FILE"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ cd /run
|
|||||||
. disk.sh # Initialize disks
|
. disk.sh # Initialize disks
|
||||||
. network.sh # Initialize network
|
. network.sh # Initialize network
|
||||||
. gpu.sh # Initialize graphics
|
. gpu.sh # Initialize graphics
|
||||||
|
. cpu.sh # Initialize processor
|
||||||
. serial.sh # Initialize serialport
|
. serial.sh # Initialize serialport
|
||||||
. power.sh # Configure shutdown
|
. power.sh # Configure shutdown
|
||||||
. config.sh # Configure arguments
|
. config.sh # Configure arguments
|
||||||
|
|||||||
@@ -29,16 +29,11 @@ DL_GLOBAL="https://global.synologydownload.com/download/DSM"
|
|||||||
|
|
||||||
if [ -z "$DL" ]; then
|
if [ -z "$DL" ]; then
|
||||||
[ -z "$COUNTRY" ] && setCountry
|
[ -z "$COUNTRY" ] && setCountry
|
||||||
|
[ -z "$COUNTRY" ] && info "Warning: could not detect country to select mirror!"
|
||||||
[[ "${COUNTRY^^}" == "CN" ]] && DL="$DL_CHINA" || DL="$DL_GLOBAL"
|
[[ "${COUNTRY^^}" == "CN" ]] && DL="$DL_CHINA" || DL="$DL_GLOBAL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$URL" ]; then
|
[ -z "$URL" ] && URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
|
||||||
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
|
|
||||||
|
|
||||||
BASE=$(basename "$URL" .pat)
|
BASE=$(basename "$URL" .pat)
|
||||||
|
|
||||||
@@ -140,12 +135,13 @@ if [ -f "$RDC" ]; then
|
|||||||
if [[ "$DEV" == [Nn]* ]]; then
|
if [[ "$DEV" == [Nn]* ]]; then
|
||||||
# Exclude dev/ from cpio extract
|
# Exclude dev/ from cpio extract
|
||||||
{ (cd "$TMP" && cpio -it < "$TMP/rd" | grep -Ev 'dev/' | while read -r entry; do cpio -idm "$entry" < "$TMP/rd" 2>/dev/null; done); rc=$?; } || :
|
{ (cd "$TMP" && cpio -it < "$TMP/rd" | grep -Ev 'dev/' | while read -r entry; do cpio -idm "$entry" < "$TMP/rd" 2>/dev/null; done); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && error "Failed to extract $RDC, reason $rc" && exit 92
|
||||||
else
|
else
|
||||||
{ (cd "$TMP" && cpio -idm <"$TMP/rd" 2>/dev/null); rc=$?; } || :
|
{ (cd "$TMP" && cpio -idm <"$TMP/rd" 2>/dev/null); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && error "Failed to extract $RDC, reason $rc"
|
||||||
|
(( rc != 0 )) && error "If the container runs unprivileged, please set DEV=N to exclude device nodes." && exit 92
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(( rc != 0 )) && error "Failed to extract $RDC, reason $rc" && exit 92
|
|
||||||
|
|
||||||
mkdir -p /run/extract
|
mkdir -p /run/extract
|
||||||
for file in $TMP/usr/lib/libcurl.so.4 \
|
for file in $TMP/usr/lib/libcurl.so.4 \
|
||||||
$TMP/usr/lib/libmbedcrypto.so.5 \
|
$TMP/usr/lib/libmbedcrypto.so.5 \
|
||||||
@@ -203,8 +199,6 @@ if { tar tf "$PAT"; } >/dev/null 2>&1; then
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
[ "$ARCH" != "amd64" ] && addPackage "qemu-user" "QEMU"
|
|
||||||
|
|
||||||
info "Install: Extracting downloaded image..."
|
info "Install: Extracting downloaded image..."
|
||||||
|
|
||||||
export LD_LIBRARY_PATH="/run/extract"
|
export LD_LIBRARY_PATH="/run/extract"
|
||||||
@@ -240,16 +234,16 @@ SYSTEM_SIZE=4954537983
|
|||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
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 ! fallocate -l "$SYSTEM_SIZE" "$SYSTEM"; then
|
||||||
if ! truncate -s "$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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if file exists
|
# 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
|
# Check the filesize
|
||||||
SIZE=$(stat -c%s "$SYSTEM")
|
SIZE=$(stat -c%s "$SYSTEM")
|
||||||
|
|||||||
@@ -156,11 +156,15 @@ closeNetwork () {
|
|||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
|
|
||||||
|
{ pkill -f server.sh || true; } 2>/dev/null
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down || true
|
ip link set "$VM_NET_TAP" down || true
|
||||||
ip link delete "$VM_NET_TAP" || true
|
ip link delete "$VM_NET_TAP" || true
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
{ pkill -f dnsmasq || true; } 2>/dev/null
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off || true
|
ip link set "$VM_NET_TAP" down promisc off || true
|
||||||
ip link delete "$VM_NET_TAP" || true
|
ip link delete "$VM_NET_TAP" || true
|
||||||
|
|
||||||
@@ -183,7 +187,7 @@ if [ ! -c /dev/net/tun ]; then
|
|||||||
chmod 666 /dev/net/tun
|
chmod 666 /dev/net/tun
|
||||||
fi
|
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
|
# Create the necessary file structure for /dev/vhost-net
|
||||||
if [ ! -c /dev/vhost-net ]; then
|
if [ ! -c /dev/vhost-net ]; then
|
||||||
@@ -208,7 +212,7 @@ if [[ "$DHCP" == [Yy1]* ]]; then
|
|||||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||||
info "Warning: Are you sure the container is on a macvlan network?"
|
info "Warning: Are you sure the container is on a macvlan network?"
|
||||||
else
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
18
src/power.sh
18
src/power.sh
@@ -27,17 +27,23 @@ _graceful_shutdown() {
|
|||||||
[ -f "$QEMU_COUNT" ] && return
|
[ -f "$QEMU_COUNT" ] && return
|
||||||
|
|
||||||
echo 0 > "$QEMU_COUNT"
|
echo 0 > "$QEMU_COUNT"
|
||||||
echo && info "Received $1 signal, shutting down..."
|
echo && info "Received $1 signal, sending shutdown command..."
|
||||||
|
|
||||||
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
||||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
||||||
|
|
||||||
# Send shutdown command to guest agent via serial port
|
# Send shutdown command to guest agent via serial port
|
||||||
response=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)
|
url="http://127.0.0.1:2210/read?command=6&timeout=50"
|
||||||
|
response=$(curl -sk -m 52 -S "$url" 2>&1)
|
||||||
|
|
||||||
if [[ ! "$response" =~ "\"success\"" ]]; then
|
if [[ "$response" =~ "\"success\"" ]]; then
|
||||||
|
|
||||||
echo && error "Failed to send shutdown command ( $response )."
|
echo && info "Virtual DSM is now ready to shutdown..."
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
response="${response#*message\"\: \"}"
|
||||||
|
echo && error "Failed to send shutdown command: ${response%%\"*}"
|
||||||
|
|
||||||
kill -15 "$(cat "$QEMU_PID")"
|
kill -15 "$(cat "$QEMU_PID")"
|
||||||
pkill -f qemu-system-x86_64 || true
|
pkill -f qemu-system-x86_64 || true
|
||||||
@@ -64,7 +70,11 @@ _graceful_shutdown() {
|
|||||||
echo && echo "❯ Quitting..."
|
echo && echo "❯ Quitting..."
|
||||||
echo 'quit' | nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 || true
|
echo 'quit' | nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
{ pkill -f print.sh || true; } 2>/dev/null
|
||||||
|
{ pkill -f host.bin || true; } 2>/dev/null
|
||||||
|
|
||||||
closeNetwork
|
closeNetwork
|
||||||
|
sleep 1
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/print.sh
30
src/print.sh
@@ -5,21 +5,33 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; }
|
|||||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||||
|
|
||||||
file="/run/dsm.url"
|
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"
|
||||||
|
|
||||||
while [ ! -f "$file" ]
|
while [ ! -f "$file" ]
|
||||||
do
|
do
|
||||||
|
|
||||||
|
# Check if not shutting down
|
||||||
|
[ -f "$shutdown" ] && exit 1
|
||||||
|
|
||||||
sleep 3
|
sleep 3
|
||||||
[ -f "$file" ] && continue
|
|
||||||
|
[ -f "$shutdown" ] && exit 1
|
||||||
|
|
||||||
|
# Healthcheck may have intervened
|
||||||
|
[ -f "$file" ] && break
|
||||||
|
|
||||||
# Retrieve IP from guest VM
|
# Retrieve IP from guest VM
|
||||||
|
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
|
||||||
|
|
||||||
{ json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || :
|
[ -f "$shutdown" ] && exit 1
|
||||||
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
|
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
|
||||||
|
|
||||||
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$result" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
[[ "$result" == "null" ]] && error "$resp_err $json" && continue
|
||||||
|
|
||||||
if [[ "$result" != "success" ]] ; then
|
if [[ "$result" != "success" ]] ; then
|
||||||
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
||||||
@@ -27,19 +39,21 @@ do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$port" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
[[ "$port" == "null" ]] && error "$resp_err $json" && continue
|
||||||
[ -z "$port" ] && continue
|
[ -z "$port" ] && continue
|
||||||
|
|
||||||
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$ip" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
[[ "$ip" == "null" ]] && error "$resp_err $json" && continue
|
||||||
[ -z "$ip" ] && continue
|
[ -z "$ip" ] && continue
|
||||||
|
|
||||||
echo "$ip:$port" > $file
|
echo "$ip:$port" > $file
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ -f "$shutdown" ] && exit 1
|
||||||
|
|
||||||
location=$(cat "$file")
|
location=$(cat "$file")
|
||||||
|
|
||||||
if [[ "$location" != "20.20"* ]]; then
|
if [[ "$location" != "20.20"* ]]; then
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
|||||||
|
|
||||||
# Docker environment variables
|
# Docker environment variables
|
||||||
|
|
||||||
: ${GPU:='N'} # Enable GPU passthrough
|
: ${GPU:='N'} # Disable GPU passthrough
|
||||||
: ${DEBUG:='N'} # Enable debugging mode
|
: ${KVM:='Y'} # Enable KVM acceleration
|
||||||
|
: ${DEBUG:='N'} # Disable debugging mode
|
||||||
: ${COUNTRY:=''} # Country code for mirror
|
: ${COUNTRY:=''} # Country code for mirror
|
||||||
: ${CONSOLE:='N'} # Start in console mode
|
: ${CONSOLE:='N'} # Disable console mode
|
||||||
: ${ALLOCATE:='Y'} # Preallocate diskspace
|
: ${ALLOCATE:='Y'} # Preallocate diskspace
|
||||||
: ${ARGUMENTS:=''} # Extra QEMU parameters
|
: ${ARGUMENTS:=''} # Extra QEMU parameters
|
||||||
: ${CPU_CORES:='1'} # Amount of CPU cores
|
: ${CPU_CORES:='1'} # Amount of CPU cores
|
||||||
|
|||||||
@@ -3,27 +3,12 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
# Docker environment variables
|
# Docker environment variables
|
||||||
|
|
||||||
: ${HOST_CPU:=''}
|
|
||||||
: ${HOST_MAC:=''}
|
: ${HOST_MAC:=''}
|
||||||
: ${HOST_DEBUG:=''}
|
: ${HOST_DEBUG:=''}
|
||||||
: ${HOST_SERIAL:=''}
|
: ${HOST_SERIAL:=''}
|
||||||
: ${HOST_MODEL:=''}
|
: ${HOST_MODEL:=''}
|
||||||
: ${GUEST_SERIAL:=''}
|
: ${GUEST_SERIAL:=''}
|
||||||
|
|
||||||
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 [ "$ARCH" == "amd64" ]; then
|
|
||||||
HOST_CPU="QEMU, Virtual CPU, X86_64"
|
|
||||||
else
|
|
||||||
HOST_CPU="QEMU, Virtual CPU, $ARCH"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
HOST_ARGS=()
|
HOST_ARGS=()
|
||||||
HOST_ARGS+=("-cpu=$CPU_CORES")
|
HOST_ARGS+=("-cpu=$CPU_CORES")
|
||||||
HOST_ARGS+=("-cpu_arch=$HOST_CPU")
|
HOST_ARGS+=("-cpu_arch=$HOST_CPU")
|
||||||
|
|||||||
Reference in New Issue
Block a user