mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff9fd9b377 | ||
|
|
9e61be15e6 | ||
|
|
b1d53b42ca | ||
|
|
143a2151fb | ||
|
|
7fd29e30b3 | ||
|
|
efe46e1fdc | ||
|
|
2cf4ca07f4 | ||
|
|
b88207f0dd | ||
|
|
70e10b1d56 | ||
|
|
ced994d94a | ||
|
|
354bd2429b | ||
|
|
c1d3d15d4e | ||
|
|
95b2b83ac6 | ||
|
|
c3c4d966b4 | ||
|
|
a768fecfde | ||
|
|
01e41a4014 | ||
|
|
eb4852683b |
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -49,6 +49,8 @@ jobs:
|
|||||||
type=raw,value=${{ vars.MAJOR }}.${{ vars.MINOR }}
|
type=raw,value=${{ vars.MAJOR }}.${{ vars.MINOR }}
|
||||||
labels: |
|
labels: |
|
||||||
org.opencontainers.image.title=${{ vars.NAME }}
|
org.opencontainers.image.title=${{ vars.NAME }}
|
||||||
|
env:
|
||||||
|
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -72,10 +74,10 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
provenance: false
|
provenance: false
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64,linux/arm
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
annotations: ${{ steps.meta.outputs.labels }}
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
build-args: |
|
build-args: |
|
||||||
VCS_REF=${GITHUB_SHA::8}
|
VCS_REF=${GITHUB_SHA::8}
|
||||||
VERSION_ARG=${{ steps.meta.outputs.version }}
|
VERSION_ARG=${{ steps.meta.outputs.version }}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ 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 \
|
apt-get --no-install-recommends -y install \
|
||||||
tini \
|
jq \
|
||||||
|
tini \
|
||||||
curl \
|
curl \
|
||||||
cpio \
|
cpio \
|
||||||
wget \
|
wget \
|
||||||
@@ -45,9 +46,9 @@ EXPOSE 139
|
|||||||
EXPOSE 445
|
EXPOSE 445
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
ENV CPU_CORES "1"
|
ENV RAM_SIZE "1G"
|
||||||
ENV DISK_SIZE "16G"
|
ENV DISK_SIZE "16G"
|
||||||
ENV RAM_SIZE "512M"
|
ENV CPU_CORES "1"
|
||||||
|
|
||||||
ARG VERSION_ARG="0.0"
|
ARG VERSION_ARG="0.0"
|
||||||
RUN echo "$VERSION_ARG" > /run/version
|
RUN echo "$VERSION_ARG" > /run/version
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ services:
|
|||||||
container_name: dsm
|
container_name: dsm
|
||||||
image: vdsm/virtual-dsm:latest
|
image: vdsm/virtual-dsm:latest
|
||||||
environment:
|
environment:
|
||||||
CPU_CORES: "1"
|
|
||||||
DISK_SIZE: "16G"
|
DISK_SIZE: "16G"
|
||||||
RAM_SIZE: "512M"
|
RAM_SIZE: "1G"
|
||||||
|
CPU_CORES: "1"
|
||||||
devices:
|
devices:
|
||||||
- /dev/kvm
|
- /dev/kvm
|
||||||
- /dev/net/tun
|
- /dev/net/tun
|
||||||
|
|||||||
10
readme.md
10
readme.md
@@ -15,7 +15,7 @@ Virtual DSM in a docker container.
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Multi-platform
|
- Multiple disks
|
||||||
- KVM acceleration
|
- KVM acceleration
|
||||||
- GPU passthrough
|
- GPU passthrough
|
||||||
- Upgrades supported
|
- Upgrades supported
|
||||||
@@ -58,7 +58,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
DISK_SIZE: "256G"
|
DISK_SIZE: "128G"
|
||||||
```
|
```
|
||||||
|
|
||||||
This can also be used to resize the existing disk to a larger capacity without any data loss.
|
This can also be used to resize the existing disk to a larger capacity without any data loss.
|
||||||
@@ -100,12 +100,12 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
|||||||
|
|
||||||
* ### How do I increase the amount of CPU or RAM?
|
* ### How do I increase the amount of CPU or RAM?
|
||||||
|
|
||||||
By default, a single core and 512 MB of RAM are allocated to the container. To increase this, add the following environment variables:
|
By default, a single core and 1 GB of RAM are allocated to the container. To increase this, add the following environment variables:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
|
RAM_SIZE: "4G"
|
||||||
CPU_CORES: "4"
|
CPU_CORES: "4"
|
||||||
RAM_SIZE: "2048M"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
* ### How do I verify if my system supports KVM?
|
* ### How do I verify if my system supports KVM?
|
||||||
@@ -172,7 +172,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
|||||||
|
|
||||||
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 need DHCP, it's still recommended to enable this feature as it prevents NAT issues and increases performance by using a `macvtap` interface.
|
||||||
|
|
||||||
* ### How do I passthrough my GPU?
|
* ### How do I passthrough the GPU?
|
||||||
|
|
||||||
To passthrough your Intel GPU, add the following lines to your compose file:
|
To passthrough your Intel GPU, add the following lines to your compose file:
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ file="/run/dsm.url"
|
|||||||
if [ ! -f "$file" ]; then
|
if [ ! -f "$file" ]; then
|
||||||
|
|
||||||
# Retrieve IP from guest VM for Docker healthcheck
|
# Retrieve IP from guest VM for Docker healthcheck
|
||||||
RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
RESPONSE=$(curl -s -m 30 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
||||||
echo "Failed to connect to guest: $RESPONSE" && exit 1
|
echo "Failed to connect to guest: $RESPONSE" && exit 1
|
||||||
|
|||||||
23
src/disk.sh
23
src/disk.sh
@@ -24,6 +24,7 @@ DISK_OPTS="\
|
|||||||
|
|
||||||
addDisk () {
|
addDisk () {
|
||||||
|
|
||||||
|
local FS
|
||||||
local GB
|
local GB
|
||||||
local DIR
|
local DIR
|
||||||
local REQ
|
local REQ
|
||||||
@@ -39,6 +40,12 @@ addDisk () {
|
|||||||
|
|
||||||
DIR=$(dirname "${DISK_FILE}")
|
DIR=$(dirname "${DISK_FILE}")
|
||||||
[ ! -d "${DIR}" ] && return 0
|
[ ! -d "${DIR}" ] && return 0
|
||||||
|
|
||||||
|
FS=$(stat -f -c %T "$DIR")
|
||||||
|
|
||||||
|
if [[ "$FS" == "overlay"* ]]; then
|
||||||
|
info "Warning: the filesystem of ${DIR} is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
|
fi
|
||||||
|
|
||||||
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
||||||
DISK_SPACE=$(echo "${DISK_SPACE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
DISK_SPACE=$(echo "${DISK_SPACE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
@@ -70,16 +77,17 @@ addDisk () {
|
|||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
if (( REQ > SPACE )); then
|
if (( REQ > SPACE )); then
|
||||||
error "Not enough free space to resize ${DISK_DESC} to ${DISK_SPACE} .."
|
error "Not enough free space to resize ${DISK_DESC} to ${DISK_SPACE} in ${DIR}, it has only ${SPACE_GB} GB available.."
|
||||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 84
|
error "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 84
|
||||||
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 "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE} .." && exit 85
|
error "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE}" && exit 85
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -94,24 +102,25 @@ addDisk () {
|
|||||||
# 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 "Could not create a file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
if (( DATA_SIZE > SPACE )); then
|
if (( DATA_SIZE > SPACE )); then
|
||||||
error "Not enough free space to create ${DISK_DESC} of ${DISK_SPACE} .."
|
error "Not enough free space to create ${DISK_DESC} of ${DISK_SPACE} in ${DIR}, it has only ${SPACE_GB} GB available.."
|
||||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 86
|
error "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 86
|
||||||
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 "Could not create a file for ${DISK_DESC} (${DISK_FILE}) of ${DISK_SPACE} .." && exit 87
|
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
25
src/gpu.sh
25
src/gpu.sh
@@ -18,28 +18,7 @@ fi
|
|||||||
chmod 666 /dev/dri/card0
|
chmod 666 /dev/dri/card0
|
||||||
chmod 666 /dev/dri/renderD128
|
chmod 666 /dev/dri/renderD128
|
||||||
|
|
||||||
if ! apt-mark showinstall | grep -q "xserver-xorg-video-intel"; then
|
addPackage "xserver-xorg-video-intel" "Intel GPU drivers"
|
||||||
|
addPackage "qemu-system-modules-opengl" "OpenGL module"
|
||||||
info "Installing Intel GPU drivers..."
|
|
||||||
|
|
||||||
export DEBCONF_NOWARNINGS="yes"
|
|
||||||
export DEBIAN_FRONTEND="noninteractive"
|
|
||||||
|
|
||||||
apt-get -qq update
|
|
||||||
apt-get -qq --no-install-recommends -y install xserver-xorg-video-intel > /dev/null
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! apt-mark showinstall | grep -q "qemu-system-modules-opengl"; then
|
|
||||||
|
|
||||||
info "Installing OpenGL module..."
|
|
||||||
|
|
||||||
export DEBCONF_NOWARNINGS="yes"
|
|
||||||
export DEBIAN_FRONTEND="noninteractive"
|
|
||||||
|
|
||||||
apt-get -qq update
|
|
||||||
apt-get -qq --no-install-recommends -y install qemu-system-modules-opengl > /dev/null
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -14,24 +14,30 @@ fi
|
|||||||
[ -n "$URL" ] && BASE=$(basename "$URL" .pat)
|
[ -n "$URL" ] && BASE=$(basename "$URL" .pat)
|
||||||
|
|
||||||
if [[ -f "$STORAGE/$BASE.boot.img" ]] && [[ -f "$STORAGE/$BASE.system.img" ]]; then
|
if [[ -f "$STORAGE/$BASE.boot.img" ]] && [[ -f "$STORAGE/$BASE.system.img" ]]; then
|
||||||
# Previous installation found
|
return 0 # Previous installation found
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Display wait message
|
# Display wait message
|
||||||
/run/server.sh 5000 install &
|
/run/server.sh 5000 install &
|
||||||
|
|
||||||
# Download the required files from the Synology website
|
DL=""
|
||||||
DL="https://global.synologydownload.com/download/DSM"
|
DL_CHINA="https://cndl.synology.cn/download/DSM"
|
||||||
|
DL_GLOBAL="https://global.synologydownload.com/download/DSM"
|
||||||
|
|
||||||
|
[[ "${URL,,}" == *"cndl.synology"* ]] && DL="$DL_CHINA"
|
||||||
|
[[ "${URL,,}" == *"global.synology"* ]] && DL="$DL_GLOBAL"
|
||||||
|
|
||||||
|
if [ -z "$DL" ]; then
|
||||||
|
[ -z "$COUNTRY" ] && setCountry
|
||||||
|
[[ "${COUNTRY^^}" == "CN" ]] && DL="$DL_CHINA" || DL="$DL_GLOBAL"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$URL" ]; then
|
if [ -z "$URL" ]; then
|
||||||
|
|
||||||
if [ "$ARCH" == "amd64" ]; then
|
if [ "$ARCH" == "amd64" ]; then
|
||||||
URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
|
URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
|
||||||
else
|
else
|
||||||
URL="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
URL="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if output is to interactive TTY
|
# Check if output is to interactive TTY
|
||||||
@@ -43,32 +49,54 @@ fi
|
|||||||
|
|
||||||
BASE=$(basename "$URL" .pat)
|
BASE=$(basename "$URL" .pat)
|
||||||
|
|
||||||
rm -f "$STORAGE"/"$BASE".pat
|
if [[ "$URL" != "file://${STORAGE}/${BASE}.pat" ]]; then
|
||||||
|
rm -f "$STORAGE"/"$BASE".pat
|
||||||
|
fi
|
||||||
|
|
||||||
rm -f "$STORAGE"/"$BASE".agent
|
rm -f "$STORAGE"/"$BASE".agent
|
||||||
rm -f "$STORAGE"/"$BASE".boot.img
|
rm -f "$STORAGE"/"$BASE".boot.img
|
||||||
rm -f "$STORAGE"/"$BASE".system.img
|
rm -f "$STORAGE"/"$BASE".system.img
|
||||||
|
|
||||||
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
|
|
||||||
|
# Check filesystem
|
||||||
|
MIN_ROOT=471859200
|
||||||
MIN_SPACE=6442450944
|
MIN_SPACE=6442450944
|
||||||
FS=$(stat -f -c %T "$STORAGE")
|
FS=$(stat -f -c %T "$STORAGE")
|
||||||
|
|
||||||
|
if [[ "$FS" == "overlay"* ]]; then
|
||||||
|
info "Warning: the filesystem of ${STORAGE} is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$FS" != "fat"* && "$FS" != "vfat"* && "$FS" != "exfat"* && \
|
if [[ "$FS" != "fat"* && "$FS" != "vfat"* && "$FS" != "exfat"* && \
|
||||||
"$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then
|
"$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then
|
||||||
TMP="$STORAGE/tmp"
|
TMP="$STORAGE/tmp"
|
||||||
else
|
else
|
||||||
TMP="/tmp/dsm"
|
TMP="/tmp/dsm"
|
||||||
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
||||||
(( MIN_SPACE > SPACE )) && TMP="$STORAGE/tmp"
|
if (( MIN_SPACE > SPACE )); then
|
||||||
|
TMP="$STORAGE/tmp"
|
||||||
|
info "Warning: the ${FS} filesystem of ${STORAGE} does not support UNIX permissions.."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf /tmp/dsm
|
|
||||||
rm -rf "$STORAGE/tmp"
|
|
||||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
||||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation, need at least 6 GB." && exit 95
|
(( MIN_ROOT > SPACE )) && error "Not enough free space in container root, need at least 450 MB available." && exit 96
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 95
|
||||||
|
|
||||||
|
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
||||||
|
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 94
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Download the required files from the Synology website
|
||||||
|
|
||||||
RDC="$STORAGE/dsm.rd"
|
RDC="$STORAGE/dsm.rd"
|
||||||
|
|
||||||
@@ -149,9 +177,17 @@ info "Install: Downloading $(basename "$URL")..."
|
|||||||
PAT="/$BASE.pat"
|
PAT="/$BASE.pat"
|
||||||
rm -f "$PAT"
|
rm -f "$PAT"
|
||||||
|
|
||||||
{ wget "$URL" -O "$PAT" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
|
if [[ "$URL" == "file://"* ]]; then
|
||||||
|
|
||||||
|
cp "${URL:7}" "$PAT"
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
{ wget "$URL" -O "$PAT" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
|
||||||
|
(( rc != 0 )) && error "Failed to download $URL, reason: $rc" && exit 69
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
(( rc != 0 )) && error "Failed to download $URL, reason: $rc" && exit 69
|
|
||||||
[ ! -f "$PAT" ] && error "Failed to download $URL" && exit 69
|
[ ! -f "$PAT" ] && error "Failed to download $URL" && exit 69
|
||||||
|
|
||||||
SIZE=$(stat -c%s "$PAT")
|
SIZE=$(stat -c%s "$PAT")
|
||||||
@@ -167,17 +203,7 @@ if { tar tf "$PAT"; } >/dev/null 2>&1; then
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
if [ "$ARCH" != "amd64" ]; then
|
[ "$ARCH" != "amd64" ] && addPackage "qemu-user" "QEMU"
|
||||||
|
|
||||||
info "Install: Installing QEMU..."
|
|
||||||
|
|
||||||
export DEBCONF_NOWARNINGS="yes"
|
|
||||||
export DEBIAN_FRONTEND="noninteractive"
|
|
||||||
|
|
||||||
apt-get -qq update
|
|
||||||
apt-get -qq --no-install-recommends -y install qemu-user > /dev/null
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
info "Install: Extracting downloaded image..."
|
info "Install: Extracting downloaded image..."
|
||||||
|
|
||||||
@@ -213,7 +239,8 @@ 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)
|
||||||
(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk." && exit 87
|
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
|
||||||
|
|
||||||
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
|
||||||
@@ -274,13 +301,12 @@ rm -rf "$MOUNT"
|
|||||||
|
|
||||||
echo "$BASE" > "$STORAGE"/dsm.ver
|
echo "$BASE" > "$STORAGE"/dsm.ver
|
||||||
|
|
||||||
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
if [[ "$URL" == "file://${STORAGE}/${BASE}.pat" ]]; then
|
||||||
# Check free diskspace
|
rm -f "$PAT"
|
||||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
else
|
||||||
(( MIN_SPACE > SPACE )) && error "Not enough free space in storage folder, need at least 6 GB." && exit 94
|
mv -f "$PAT" "$STORAGE"/"$BASE".pat
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv -f "$PAT" "$STORAGE"/"$BASE".pat
|
|
||||||
mv -f "$BOOT" "$STORAGE"/"$BASE".boot.img
|
mv -f "$BOOT" "$STORAGE"/"$BASE".boot.img
|
||||||
mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ set -Eeuo pipefail
|
|||||||
: ${VM_NET_MAC:="$MAC"}
|
: ${VM_NET_MAC:="$MAC"}
|
||||||
: ${VM_NET_HOST:='VirtualDSM'}
|
: ${VM_NET_HOST:='VirtualDSM'}
|
||||||
|
|
||||||
: ${DNS_SERVERS:=''}
|
|
||||||
: ${DNSMASQ_OPTS:=''}
|
: ${DNSMASQ_OPTS:=''}
|
||||||
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
|
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
|
||||||
: ${DNSMASQ_CONF_DIR:='/etc/dnsmasq.d'}
|
: ${DNSMASQ_CONF_DIR:='/etc/dnsmasq.d'}
|
||||||
@@ -78,33 +77,8 @@ configureDNS () {
|
|||||||
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
||||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||||
|
|
||||||
# Build DNS options from container /etc/resolv.conf
|
# Set DNS server and gateway
|
||||||
|
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,${VM_NET_IP%.*}.1 --dhcp-option=option:router,${VM_NET_IP%.*}.1"
|
||||||
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
|
||||||
echo "/etc/resolv.conf:" && echo && cat /etc/resolv.conf && echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
mapfile -t nameservers < <( { grep '^nameserver' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/nameserver //' | sed 's/ //g')
|
|
||||||
searchdomains=$( { grep '^search' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/search //' | sed 's/#.*//' | sed 's/\s*$//g' | sed 's/ /,/g')
|
|
||||||
domainname=$(echo "$searchdomains" | awk -F"," '{print $1}')
|
|
||||||
|
|
||||||
for nameserver in "${nameservers[@]}"; do
|
|
||||||
nameserver=$(echo "$nameserver" | sed 's/#.*//' )
|
|
||||||
if ! [[ "$nameserver" =~ .*:.* ]]; then
|
|
||||||
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="1.1.1.1"
|
|
||||||
|
|
||||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,$DNS_SERVERS --dhcp-option=option:router,${VM_NET_IP%.*}.1"
|
|
||||||
|
|
||||||
if [ -n "$searchdomains" ] && [ "$searchdomains" != "." ]; then
|
|
||||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains --dhcp-option=option:domain-name,$domainname"
|
|
||||||
else
|
|
||||||
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
@@ -147,8 +121,6 @@ configureNAT () {
|
|||||||
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
||||||
|
|
||||||
# Add internet connection to the VM
|
# Add internet connection to the VM
|
||||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
|
||||||
|
|
||||||
iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
|
iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
|
||||||
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p tcp -j DNAT --to $VM_NET_IP
|
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p tcp -j DNAT --to $VM_NET_IP
|
||||||
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p udp -j DNAT --to $VM_NET_IP
|
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p udp -j DNAT --to $VM_NET_IP
|
||||||
@@ -223,12 +195,10 @@ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
|||||||
|
|
||||||
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
||||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
||||||
|
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||||
|
|
||||||
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
||||||
|
|
||||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
|
||||||
info "Container IP is ${IP} with gateway ${GATEWAY}" && echo
|
info "Container IP is ${IP} with gateway ${GATEWAY}" && echo
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
QEMU_PORT=7100
|
QEMU_PORT=7100
|
||||||
QEMU_TIMEOUT=50
|
QEMU_TIMEOUT=50
|
||||||
|
|
||||||
QEMU_PID=/run/qemu.pid
|
QEMU_PID=/run/qemu.pid
|
||||||
QEMU_COUNT=/run/qemu.count
|
QEMU_COUNT=/run/qemu.count
|
||||||
|
|
||||||
@@ -26,18 +25,18 @@ _graceful_shutdown() {
|
|||||||
[ ! -f "${QEMU_PID}" ] && exit 130
|
[ ! -f "${QEMU_PID}" ] && exit 130
|
||||||
[ -f "${QEMU_COUNT}" ] && return
|
[ -f "${QEMU_COUNT}" ] && return
|
||||||
|
|
||||||
echo && info "Received $1 signal, shutting down..."
|
|
||||||
echo 0 > "${QEMU_COUNT}"
|
echo 0 > "${QEMU_COUNT}"
|
||||||
|
echo && info "Received $1 signal, shutting down..."
|
||||||
|
|
||||||
# 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 -s -m 5 -S http://127.0.0.1:2210/read?command=6 2>&1)
|
RESPONSE=$(curl -s -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
if [[ ! "${RESPONSE}" =~ "\"success\"" ]]; then
|
||||||
|
|
||||||
echo && error "Could not send shutdown command to the guest ($RESPONSE)"
|
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
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ do
|
|||||||
# Retrieve IP from guest VM
|
# Retrieve IP from guest VM
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
RESPONSE=$(curl -s -m 30 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
||||||
|
|||||||
63
src/reset.sh
63
src/reset.sh
@@ -12,12 +12,13 @@ trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
|||||||
|
|
||||||
: ${GPU:='N'} # Enable GPU passthrough
|
: ${GPU:='N'} # Enable GPU passthrough
|
||||||
: ${DEBUG:='N'} # Enable debugging mode
|
: ${DEBUG:='N'} # Enable debugging mode
|
||||||
|
: ${COUNTRY:=''} # Country code for mirror
|
||||||
: ${CONSOLE:='N'} # Start in console mode
|
: ${CONSOLE:='N'} # Start in 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
|
||||||
|
: ${RAM_SIZE:='1G'} # Maximum RAM amount
|
||||||
: ${DISK_SIZE:='16G'} # Initial data disk size
|
: ${DISK_SIZE:='16G'} # Initial data disk size
|
||||||
: ${RAM_SIZE:='512M'} # Maximum RAM amount
|
|
||||||
|
|
||||||
# Helper variables
|
# Helper variables
|
||||||
|
|
||||||
@@ -42,4 +43,64 @@ rm -f /run/qemu.count
|
|||||||
rm -rf /tmp/dsm
|
rm -rf /tmp/dsm
|
||||||
rm -rf "$STORAGE/tmp"
|
rm -rf "$STORAGE/tmp"
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
|
||||||
|
getCountry () {
|
||||||
|
|
||||||
|
local rc
|
||||||
|
local json
|
||||||
|
local result
|
||||||
|
local url=$1
|
||||||
|
local query=$2
|
||||||
|
|
||||||
|
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && return 0
|
||||||
|
|
||||||
|
{ result=$(echo "$json" | jq -r "$query" 2> /dev/null); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && return 0
|
||||||
|
|
||||||
|
[[ ${#result} -ne 2 ]] && return 0
|
||||||
|
[[ "${result^^}" == "XX" ]] && return 0
|
||||||
|
|
||||||
|
COUNTRY="${result^^}"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setCountry () {
|
||||||
|
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://api.ipapi.is" ".location.country_code"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://ifconfig.co/json" ".country_iso"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://ipinfo.io/json" ".country"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://api.myip.com" ".cc"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
addPackage () {
|
||||||
|
|
||||||
|
local pkg=$1
|
||||||
|
local desc=$2
|
||||||
|
|
||||||
|
if apt-mark showinstall | grep -qx "$pkg"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Installing $desc..."
|
||||||
|
|
||||||
|
export DEBCONF_NOWARNINGS="yes"
|
||||||
|
export DEBIAN_FRONTEND="noninteractive"
|
||||||
|
|
||||||
|
[ -z "$COUNTRY" ] && setCountry
|
||||||
|
|
||||||
|
if [[ "${COUNTRY^^}" == "CN" ]]; then
|
||||||
|
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
|
||||||
|
fi
|
||||||
|
|
||||||
|
apt-get -qq update
|
||||||
|
apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ fi
|
|||||||
cnt=0
|
cnt=0
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
|
|
||||||
while ! nc -z -w1 127.0.0.1 2210 > /dev/null 2>&1; do
|
while ! nc -z -w2 127.0.0.1 2210 > /dev/null 2>&1; do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
cnt=$((cnt + 1))
|
cnt=$((cnt + 1))
|
||||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 58
|
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 58
|
||||||
@@ -53,7 +53,7 @@ done
|
|||||||
|
|
||||||
cnt=0
|
cnt=0
|
||||||
|
|
||||||
while ! nc -z -w1 127.0.0.1 12345 > /dev/null 2>&1; do
|
while ! nc -z -w2 127.0.0.1 12345 > /dev/null 2>&1; do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
cnt=$((cnt + 1))
|
cnt=$((cnt + 1))
|
||||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 59
|
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 59
|
||||||
|
|||||||
Reference in New Issue
Block a user