mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-06 18:13:43 +08:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
354bd2429b | ||
|
|
c1d3d15d4e | ||
|
|
95b2b83ac6 | ||
|
|
c3c4d966b4 | ||
|
|
a768fecfde | ||
|
|
01e41a4014 | ||
|
|
eb4852683b | ||
|
|
6218333fec | ||
|
|
f32d8cbefc | ||
|
|
3e985502c2 | ||
|
|
ad3132e8c2 | ||
|
|
830ace0e47 | ||
|
|
1c36893729 | ||
|
|
a87aaab6f7 | ||
|
|
21699b8960 | ||
|
|
87ee25d404 | ||
|
|
c1714f9e6b | ||
|
|
754765b766 | ||
|
|
419f0cf571 | ||
|
|
55d9ac521f | ||
|
|
3406b3b471 | ||
|
|
f067ad2458 | ||
|
|
7eafd0a969 | ||
|
|
116f30bc0a | ||
|
|
04aa20e836 | ||
|
|
3bf4cc861b | ||
|
|
3c6620a3f9 | ||
|
|
ab0ea5a1d8 | ||
|
|
f894ad2686 | ||
|
|
570340d4e5 | ||
|
|
7dbe706282 | ||
|
|
0c9559f695 | ||
|
|
3113e2b64e | ||
|
|
f0ce992a27 | ||
|
|
6334cfc8bc | ||
|
|
451a569617 | ||
|
|
44d82d6544 | ||
|
|
618ec66401 | ||
|
|
d24ae86c12 | ||
|
|
32db74e50d | ||
|
|
503c89f08c | ||
|
|
c9e6e65991 |
85
.github/workflows/build.yml
vendored
85
.github/workflows/build.yml
vendored
@@ -7,12 +7,16 @@ on:
|
||||
- master
|
||||
paths-ignore:
|
||||
- '**/*.md'
|
||||
- '**/*.yml'
|
||||
- '**/*.yml'
|
||||
- '.gitignore'
|
||||
- '.dockerignore'
|
||||
- '.github/**'
|
||||
- '.github/workflows/**'
|
||||
|
||||
concurrency:
|
||||
group: build
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
name: Check
|
||||
@@ -22,37 +26,34 @@ jobs:
|
||||
needs: shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: write
|
||||
packages: write
|
||||
contents: read
|
||||
steps:
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Prepare Docker build
|
||||
id: prepare
|
||||
run: |
|
||||
|
||||
PLATFORMS="linux/amd64,linux/arm64"
|
||||
VERSION="${{ vars.MAJOR }}.${{ vars.MINOR }}"
|
||||
|
||||
TAGS=()
|
||||
TAGS=("${{ github.repository }}:latest")
|
||||
TAGS+=("${{ github.repository }}:${VERSION}")
|
||||
#TAGS+=("${{ secrets.DOCKERHUB_MIRROR }}:latest")
|
||||
#TAGS+=("${{ secrets.DOCKERHUB_MIRROR }}:${VERSION}")
|
||||
TAGS+=("ghcr.io/${{ github.repository }}:latest")
|
||||
TAGS+=("ghcr.io/${{ github.repository }}:${VERSION}")
|
||||
|
||||
echo "tags=${TAGS[@]}" >> $GITHUB_OUTPUT
|
||||
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||
echo "docker_platforms=${PLATFORMS}" >> $GITHUB_OUTPUT
|
||||
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
||||
name: Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
context: git
|
||||
images: |
|
||||
${{ secrets.DOCKERHUB_REPO }}
|
||||
ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=raw,value=latest,priority=100
|
||||
type=raw,value=${{ vars.MAJOR }}.${{ vars.MINOR }}
|
||||
labels: |
|
||||
org.opencontainers.image.title=${{ vars.NAME }}
|
||||
env:
|
||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
-
|
||||
name: Login into Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
@@ -66,36 +67,28 @@ jobs:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: Build Docker image
|
||||
run: |
|
||||
|
||||
TAGS=(${{ steps.prepare.outputs.tags }})
|
||||
|
||||
echo "Build date: ${{ steps.prepare.outputs.build_date }}"
|
||||
echo "Docker platform: ${{ steps.prepare.outputs.docker_platforms }}"
|
||||
echo "Tags: ${{ steps.prepare.outputs.tags }}"
|
||||
|
||||
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
|
||||
--output "type=image,push=true" \
|
||||
--progress=plain \
|
||||
--build-arg "BUILD_ARG=${GITHUB_RUN_ID}" \
|
||||
--build-arg "VERSION_ARG=${{ steps.prepare.outputs.version }}" \
|
||||
--build-arg "DATE_ARG=${{ steps.prepare.outputs.build_date }}" \
|
||||
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
|
||||
$(printf "%s" "${TAGS[@]/#/ --tag }" ) .
|
||||
-
|
||||
name: Clear Docker credentials
|
||||
run: |
|
||||
rm -f ${HOME}/.docker/config.json
|
||||
name: Build Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
provenance: false
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
annotations: ${{ steps.meta.outputs.annotations }}
|
||||
build-args: |
|
||||
VCS_REF=${GITHUB_SHA::8}
|
||||
VERSION_ARG=${{ steps.meta.outputs.version }}
|
||||
-
|
||||
name: Create a release
|
||||
uses: action-pack/github-release@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
with:
|
||||
tag: "v${{ steps.prepare.outputs.version }}"
|
||||
title: "v${{ steps.prepare.outputs.version }}"
|
||||
tag: "v${{ steps.meta.outputs.version }}"
|
||||
title: "v${{ steps.meta.outputs.version }}"
|
||||
-
|
||||
name: Increment version variable
|
||||
uses: action-pack/bump@v2
|
||||
|
||||
24
Dockerfile
24
Dockerfile
@@ -14,7 +14,8 @@ ARG DEBIAN_FRONTEND noninteractive
|
||||
|
||||
RUN apt-get update && apt-get -y upgrade && \
|
||||
apt-get --no-install-recommends -y install \
|
||||
tini \
|
||||
jq \
|
||||
tini \
|
||||
curl \
|
||||
cpio \
|
||||
wget \
|
||||
@@ -33,7 +34,7 @@ RUN apt-get update && apt-get -y upgrade && \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
COPY src/*.sh /run/
|
||||
COPY ./src /run/
|
||||
COPY --from=builder /qemu-host.bin /run/host.bin
|
||||
RUN chmod +x /run/*.sh && chmod +x /run/*.bin
|
||||
|
||||
@@ -45,24 +46,13 @@ EXPOSE 139
|
||||
EXPOSE 445
|
||||
EXPOSE 5000
|
||||
|
||||
ENV CPU_CORES "1"
|
||||
ENV RAM_SIZE "1G"
|
||||
ENV DISK_SIZE "16G"
|
||||
ENV RAM_SIZE "512M"
|
||||
ENV CPU_CORES "1"
|
||||
|
||||
ARG DATE_ARG=""
|
||||
ARG BUILD_ARG=0
|
||||
ARG VERSION_ARG="0.0"
|
||||
ENV VERSION=$VERSION_ARG
|
||||
RUN echo "$VERSION_ARG" > /run/version
|
||||
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.title="Virtual DSM"
|
||||
LABEL org.opencontainers.image.created=${DATE_ARG}
|
||||
LABEL org.opencontainers.image.revision=${BUILD_ARG}
|
||||
LABEL org.opencontainers.image.version=${VERSION_ARG}
|
||||
LABEL org.opencontainers.image.source="https://github.com/vdsm/virtual-dsm/"
|
||||
LABEL org.opencontainers.image.url="https://hub.docker.com/r/vdsm/virtual-dsm/"
|
||||
LABEL org.opencontainers.image.description="Virtual DSM in a docker container"
|
||||
|
||||
HEALTHCHECK --interval=60s --retries=2 CMD /run/check.sh
|
||||
HEALTHCHECK --interval=60s --start-period=45s --retries=2 CMD /run/check.sh
|
||||
|
||||
ENTRYPOINT ["/usr/bin/tini", "-s", "/run/entry.sh"]
|
||||
|
||||
@@ -4,11 +4,12 @@ services:
|
||||
container_name: dsm
|
||||
image: vdsm/virtual-dsm:latest
|
||||
environment:
|
||||
CPU_CORES: "1"
|
||||
DISK_SIZE: "16G"
|
||||
RAM_SIZE: "512M"
|
||||
RAM_SIZE: "1G"
|
||||
CPU_CORES: "1"
|
||||
devices:
|
||||
- /dev/kvm
|
||||
- /dev/net/tun
|
||||
- /dev/vhost-net
|
||||
device_cgroup_rules:
|
||||
- 'c *:* rwm'
|
||||
|
||||
75
readme.md
75
readme.md
@@ -10,11 +10,12 @@
|
||||
[![Pulls]][hub_url]
|
||||
|
||||
</div></h1>
|
||||
|
||||
Virtual DSM in a docker container.
|
||||
|
||||
## Features
|
||||
|
||||
- Multi-platform
|
||||
- Multiple disks
|
||||
- KVM acceleration
|
||||
- GPU passthrough
|
||||
- Upgrades supported
|
||||
@@ -33,7 +34,6 @@ services:
|
||||
DISK_SIZE: "16G"
|
||||
devices:
|
||||
- /dev/kvm
|
||||
- /dev/vhost-net
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
ports:
|
||||
@@ -58,7 +58,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
||||
|
||||
```yaml
|
||||
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.
|
||||
@@ -74,6 +74,19 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
||||
|
||||
Replace the example path `/home/user/data` with the desired storage folder.
|
||||
|
||||
* ### How do I add multiple disks?
|
||||
|
||||
To create additional disks, modify your compose file like this:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
DISK2_SIZE: "32G"
|
||||
DISK3_SIZE: "64G"
|
||||
volumes:
|
||||
- /home/example:/storage2
|
||||
- /mnt/data/example:/storage3
|
||||
```
|
||||
|
||||
* ### How do I change the space reserved by the virtual disk?
|
||||
|
||||
By default, the entire disk space is reserved in advance. To create a growable disk that only reserves the space that is actually used, add the following environment variable:
|
||||
@@ -84,41 +97,15 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
||||
```
|
||||
|
||||
Keep in mind that this will not affect any of your existing disks, it only applies to newly created disks.
|
||||
|
||||
* ### How do I add multiple disks?
|
||||
|
||||
To mount extra volumes, modify your compose file like this:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
DISK2_SIZE: "32G"
|
||||
DISK3_SIZE: "64G"
|
||||
volumes:
|
||||
- /home/example2:/storage2
|
||||
- /home/example3:/storage3
|
||||
```
|
||||
|
||||
Additionally, it's also possible to passthrough raw disk devices like this:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
DEVICE2: "/dev/vdc1"
|
||||
DEVICE3: "/dev/vdc2"
|
||||
devices:
|
||||
- /dev/vdc1
|
||||
- /dev/vdc2
|
||||
```
|
||||
|
||||
Please beware that any pre-existing partitions and data on those devices will be wiped.
|
||||
|
||||
* ### 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
|
||||
environment:
|
||||
RAM_SIZE: "4G"
|
||||
CPU_CORES: "4"
|
||||
RAM_SIZE: "2048M"
|
||||
```
|
||||
|
||||
* ### How do I verify if my system supports KVM?
|
||||
@@ -185,18 +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.
|
||||
|
||||
* ### How do I install a specific version of vDSM?
|
||||
|
||||
By default, version 7.2.1 will be installed, but if you prefer an older version, you can add its download URL to your compose file as follows:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
URL: "https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||
```
|
||||
|
||||
With this method, it is even possible to switch between different versions while keeping all your file data intact.
|
||||
|
||||
* ### 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:
|
||||
|
||||
@@ -208,7 +184,18 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
|
||||
```
|
||||
|
||||
This can be used to enable the facial recognition function in Synology Photos for example.
|
||||
|
||||
|
||||
* ### How do I install a specific version of vDSM?
|
||||
|
||||
By default, version 7.2.1 will be installed, but if you prefer an older version, you can add its download URL to your compose file as follows:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
URL: "https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||
```
|
||||
|
||||
With this method, it is even possible to switch between different versions while keeping all your file data intact.
|
||||
|
||||
* ### What are the differences compared to the standard DSM?
|
||||
|
||||
There are only two minor differences: the Virtual Machine Manager package is not available, and Surveillance Station will not include any free licenses.
|
||||
|
||||
387
src/disk.sh
387
src/disk.sh
@@ -14,228 +14,209 @@ SYSTEM="$STORAGE/$BASE.system.img"
|
||||
[ ! -f "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
||||
[ ! -f "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
||||
|
||||
DATA="${STORAGE}/data.img"
|
||||
|
||||
if [[ ! -f "${DATA}" ]] && [[ -f "$STORAGE/data$DISK_SIZE.img" ]]; then
|
||||
# Fallback for legacy installs
|
||||
DATA="$STORAGE/data$DISK_SIZE.img"
|
||||
fi
|
||||
|
||||
MIN_SIZE=6442450944
|
||||
DISK_SIZE=$(echo "${DISK_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
|
||||
|
||||
if (( DATA_SIZE < MIN_SIZE )); then
|
||||
error "Please increase DISK_SIZE to at least 6 GB." && exit 83
|
||||
fi
|
||||
|
||||
if [ -f "${DATA}" ]; then
|
||||
|
||||
OLD_SIZE=$(stat -c%s "${DATA}")
|
||||
|
||||
if [ "$DATA_SIZE" -gt "$OLD_SIZE" ]; then
|
||||
|
||||
info "Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.."
|
||||
|
||||
if [[ "${ALLOCATE}" == [Nn]* ]]; then
|
||||
|
||||
# Resize file by changing its length
|
||||
if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
|
||||
error "Could not resize the file for the virtual disk." && exit 85
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
REQ=$((DATA_SIZE-OLD_SIZE))
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1)
|
||||
|
||||
if (( REQ > SPACE )); then
|
||||
error "Not enough free space to resize virtual disk to ${DISK_SIZE}."
|
||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 84
|
||||
fi
|
||||
|
||||
# Resize file by allocating more space
|
||||
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
|
||||
if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
|
||||
error "Could not resize the file for the virtual disk." && exit 85
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${ALLOCATE}" == [Zz]* ]]; then
|
||||
|
||||
GB=$(( (REQ + 1073741823)/1073741824 ))
|
||||
|
||||
info "Preallocating ${GB} GB of diskspace, please wait..."
|
||||
dd if=/dev/urandom of="${DATA}" seek="${OLD_SIZE}" count="${REQ}" bs=1M iflag=count_bytes oflag=seek_bytes status=none
|
||||
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then
|
||||
|
||||
info "Shrinking existing disks is not supported yet!"
|
||||
info "Creating backup of old drive in storage folder..."
|
||||
|
||||
mv -f "${DATA}" "${DATA}.bak"
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${DATA}" ]; then
|
||||
|
||||
if [[ "${ALLOCATE}" == [Nn]* ]]; then
|
||||
|
||||
# Create an empty file
|
||||
if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
|
||||
rm -f "${DATA}"
|
||||
error "Could not create a file for the virtual disk." && exit 87
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1)
|
||||
|
||||
if (( DATA_SIZE > SPACE )); then
|
||||
error "Not enough free space to create a virtual disk of ${DISK_SIZE}."
|
||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 86
|
||||
fi
|
||||
|
||||
# Create an empty file
|
||||
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
|
||||
if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
|
||||
rm -f "${DATA}"
|
||||
error "Could not create a file for the virtual disk." && exit 87
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${ALLOCATE}" == [Zz]* ]]; then
|
||||
|
||||
info "Preallocating ${DISK_SIZE} of diskspace, please wait..."
|
||||
dd if=/dev/urandom of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes status=none
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if file exists
|
||||
if [ ! -f "${DATA}" ]; then
|
||||
error "Virtual disk does not exist ($DATA)" && exit 88
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Check the filesize
|
||||
SIZE=$(stat -c%s "${DATA}")
|
||||
|
||||
if [[ SIZE -ne DATA_SIZE ]]; then
|
||||
error "Virtual disk has the wrong size: ${SIZE}" && exit 89
|
||||
fi
|
||||
|
||||
DISK_OPTS="\
|
||||
-device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \
|
||||
-drive file=${BOOT},if=none,id=drive-synoboot,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-synoboot.0,channel=0,scsi-id=0,lun=0,drive=drive-synoboot,id=synoboot0,rotation_rate=${DISK_ROTATION},bootindex=1 \
|
||||
-device virtio-scsi-pci,id=hw-synosys,bus=pcie.0,addr=0xb \
|
||||
-drive file=${SYSTEM},if=none,id=drive-synosys,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,rotation_rate=${DISK_ROTATION},bootindex=2 \
|
||||
-device virtio-scsi-pci,id=hw-userdata,bus=pcie.0,addr=0xc \
|
||||
-drive file=${DATA},if=none,id=drive-userdata,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-userdata.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata,id=userdata0,rotation_rate=${DISK_ROTATION},bootindex=3"
|
||||
-device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,rotation_rate=${DISK_ROTATION},bootindex=2"
|
||||
|
||||
addDisk () {
|
||||
|
||||
local FS
|
||||
local GB
|
||||
local DIR
|
||||
local REQ
|
||||
local SPACE
|
||||
local CUR_SIZE
|
||||
local DATA_SIZE
|
||||
local DISK_ID=$1
|
||||
local DISK_FILE=$2
|
||||
local DISK_DESC=$3
|
||||
local DISK_SPACE=$4
|
||||
local DISK_INDEX=$5
|
||||
local DISK_ADDRESS=$6
|
||||
|
||||
DIR=$(dirname "${DISK_FILE}")
|
||||
[ ! -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"
|
||||
DISK_SPACE=$(echo "${DISK_SPACE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
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
|
||||
fi
|
||||
|
||||
if [ -f "${DISK_FILE}" ]; then
|
||||
|
||||
CUR_SIZE=$(stat -c%s "${DISK_FILE}")
|
||||
|
||||
if [ "$DATA_SIZE" -gt "$CUR_SIZE" ]; then
|
||||
|
||||
GB=$(( (CUR_SIZE + 1073741823)/1073741824 ))
|
||||
info "Resizing ${DISK_DESC} from ${GB}G to ${DISK_SPACE} .."
|
||||
|
||||
if [[ "${ALLOCATE}" == [Nn]* ]]; then
|
||||
|
||||
# Resize file by changing its length
|
||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
error "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE} .." && exit 85
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
REQ=$((DATA_SIZE-CUR_SIZE))
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
|
||||
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 "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 84
|
||||
fi
|
||||
|
||||
# Resize file by allocating more space
|
||||
if ! fallocate -l "${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
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${DISK_FILE}" ]; then
|
||||
|
||||
if [[ "${ALLOCATE}" == [Nn]* ]]; then
|
||||
|
||||
# Create an empty file
|
||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
rm -f "${DISK_FILE}"
|
||||
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
|
||||
if (( DATA_SIZE > SPACE )); then
|
||||
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 ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 86
|
||||
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 "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
DISK_OPTS="${DISK_OPTS} \
|
||||
-device virtio-scsi-pci,id=hw-${DISK_ID},bus=pcie.0,addr=${DISK_ADDRESS} \
|
||||
-drive file=${DISK_FILE},if=none,id=drive-${DISK_ID},format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-${DISK_ID}.0,channel=0,scsi-id=0,lun=0,drive=drive-${DISK_ID},id=${DISK_ID},rotation_rate=${DISK_ROTATION},bootindex=${DISK_INDEX}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
DISK1_FILE="${STORAGE}/data.img"
|
||||
|
||||
if [[ ! -f "${DISK1_FILE}" ]] && [[ -f "${STORAGE}/data${DISK_SIZE}.img" ]]; then
|
||||
# Fallback for legacy installs
|
||||
mv "${STORAGE}/data${DISK_SIZE}.img" "${DISK1_FILE}"
|
||||
fi
|
||||
|
||||
DISK2_FILE="/storage2/data2.img"
|
||||
|
||||
if [ ! -f "${DISK2_FILE}" ]; then
|
||||
# Fallback for legacy installs
|
||||
FALLBACK="/storage2/data.img"
|
||||
if [[ -f "${DISK1_FILE}" ]] && [[ -f "${FALLBACK}" ]]; then
|
||||
SIZE1=$(stat -c%s "${FALLBACK}")
|
||||
SIZE2=$(stat -c%s "${DISK1_FILE}")
|
||||
if [[ SIZE1 -ne SIZE2 ]]; then
|
||||
mv "${FALLBACK}" "${DISK2_FILE}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
DISK3_FILE="/storage3/data3.img"
|
||||
|
||||
if [ ! -f "${DISK3_FILE}" ]; then
|
||||
# Fallback for legacy installs
|
||||
FALLBACK="/storage3/data.img"
|
||||
if [[ -f "${DISK1_FILE}" ]] && [[ -f "${FALLBACK}" ]]; then
|
||||
SIZE1=$(stat -c%s "${FALLBACK}")
|
||||
SIZE2=$(stat -c%s "${DISK1_FILE}")
|
||||
if [[ SIZE1 -ne SIZE2 ]]; then
|
||||
mv "${FALLBACK}" "${DISK3_FILE}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
DISK4_FILE="/storage4/data4.img"
|
||||
DISK5_FILE="/storage5/data5.img"
|
||||
DISK6_FILE="/storage6/data6.img"
|
||||
|
||||
: ${DISK2_SIZE:=''}
|
||||
EXTRA_SIZE=DISK2_SIZE
|
||||
EXTRA_DISK="/storage2/data.img"
|
||||
|
||||
if [ -d "$(dirname "${EXTRA_DISK}")" ]; then
|
||||
|
||||
if [ ! -f "${EXTRA_DISK}" ]; then
|
||||
[ -z "$EXTRA_SIZE" ] && EXTRA_SIZE="16G"
|
||||
if ! truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}"; then
|
||||
error "Could not create the file for the second disk." && exit 53
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$EXTRA_SIZE" ]; then
|
||||
CUR_SIZE=$(stat -c%s "${EXTRA_DISK}")
|
||||
DATA_SIZE=$(numfmt --from=iec "${EXTRA_SIZE}")
|
||||
if [ "$DATA_SIZE" -gt "$CUR_SIZE" ]; then
|
||||
truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}"
|
||||
fi
|
||||
fi
|
||||
|
||||
DISK_OPTS="${DISK_OPTS} \
|
||||
-device virtio-scsi-pci,id=hw-userdata2,bus=pcie.0,addr=0xd \
|
||||
-drive file=${EXTRA_DISK},if=none,id=drive-userdata2,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-userdata2.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata2,id=userdata2,rotation_rate=${DISK_ROTATION},bootindex=4"
|
||||
|
||||
fi
|
||||
|
||||
: ${DISK3_SIZE:=''}
|
||||
EXTRA_SIZE=DISK3_SIZE
|
||||
EXTRA_DISK="/storage3/data.img"
|
||||
: ${DISK4_SIZE:=''}
|
||||
: ${DISK5_SIZE:=''}
|
||||
: ${DISK6_SIZE:=''}
|
||||
|
||||
if [ -d "$(dirname "${EXTRA_DISK}")" ]; then
|
||||
addDisk "userdata" "${DISK1_FILE}" "disk" "${DISK_SIZE}" "3" "0xc"
|
||||
addDisk "userdata2" "${DISK2_FILE}" "disk2" "${DISK2_SIZE}" "4" "0xd"
|
||||
addDisk "userdata3" "${DISK3_FILE}" "disk3" "${DISK3_SIZE}" "5" "0xe"
|
||||
addDisk "userdata4" "${DISK4_FILE}" "disk4" "${DISK4_SIZE}" "9" "0x7"
|
||||
addDisk "userdata5" "${DISK5_FILE}" "disk5" "${DISK5_SIZE}" "10" "0x8"
|
||||
addDisk "userdata6" "${DISK6_FILE}" "disk6" "${DISK6_SIZE}" "11" "0x9"
|
||||
|
||||
if [ ! -f "${EXTRA_DISK}" ]; then
|
||||
[ -z "$EXTRA_SIZE" ] && EXTRA_SIZE="16G"
|
||||
if ! truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}"; then
|
||||
error "Could not create the file for the third disk." && exit 54
|
||||
fi
|
||||
fi
|
||||
addDevice () {
|
||||
|
||||
if [ -n "$EXTRA_SIZE" ]; then
|
||||
CUR_SIZE=$(stat -c%s "${EXTRA_DISK}")
|
||||
DATA_SIZE=$(numfmt --from=iec "${EXTRA_SIZE}")
|
||||
if [ "$DATA_SIZE" -gt "$CUR_SIZE" ]; then
|
||||
truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}"
|
||||
fi
|
||||
fi
|
||||
local DISK_ID=$1
|
||||
local DISK_DEV=$2
|
||||
local DISK_INDEX=$3
|
||||
local DISK_ADDRESS=$4
|
||||
|
||||
[ -z "${DISK_DEV}" ] && return 0
|
||||
[ ! -b "${DISK_DEV}" ] && error "Device ${DISK_DEV} cannot be found! Please add it to the 'devices' section of your compose file." && exit 55
|
||||
|
||||
DISK_OPTS="${DISK_OPTS} \
|
||||
-device virtio-scsi-pci,id=hw-userdata3,bus=pcie.0,addr=0xe \
|
||||
-drive file=${EXTRA_DISK},if=none,id=drive-userdata3,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-userdata3.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata3,id=userdata3,rotation_rate=${DISK_ROTATION},bootindex=5"
|
||||
-device virtio-scsi-pci,id=hw-${DISK_ID},bus=pcie.0,addr=${DISK_ADDRESS} \
|
||||
-drive file=${DISK_DEV},if=none,id=drive-${DISK_ID},format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-${DISK_ID}.0,channel=0,scsi-id=0,lun=0,drive=drive-${DISK_ID},id=${DISK_ID},rotation_rate=${DISK_ROTATION},bootindex=${DISK_INDEX}"
|
||||
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
: ${DEVICE:=''} # Docker variable to passthrough a block device, like /dev/vdc1.
|
||||
: ${DEVICE2:=''}
|
||||
: ${DEVICE3:=''}
|
||||
: ${DEVICE4:=''}
|
||||
: ${DEVICE5:=''}
|
||||
: ${DEVICE6:=''}
|
||||
|
||||
if [ -n "${DEVICE}" ]; then
|
||||
|
||||
[ ! -b "${DEVICE}" ] && error "Device ${DEVICE} cannot be found! Please add it to the 'devices' section of your compose file." && exit 55
|
||||
|
||||
DISK_OPTS="${DISK_OPTS} \
|
||||
-device virtio-scsi-pci,id=hw-userdata4,bus=pcie.0,addr=0xf \
|
||||
-drive file=${DEVICE},if=none,id=drive-userdata4,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-userdata4.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata4,id=userdata4,rotation_rate=${DISK_ROTATION},bootindex=6"
|
||||
|
||||
fi
|
||||
|
||||
if [ -n "${DEVICE2}" ]; then
|
||||
|
||||
[ ! -b "${DEVICE2}" ] && error "Device ${DEVICE2} cannot be found! Please add it to the 'devices' section of your compose file." && exit 56
|
||||
|
||||
DISK_OPTS="${DISK_OPTS} \
|
||||
-device virtio-scsi-pci,id=hw-userdata5,bus=pcie.0,addr=0x5 \
|
||||
-drive file=${DEVICE2},if=none,id=drive-userdata5,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-userdata5.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata5,id=userdata5,rotation_rate=${DISK_ROTATION},bootindex=7"
|
||||
|
||||
fi
|
||||
|
||||
if [ -n "${DEVICE3}" ]; then
|
||||
|
||||
[ ! -b "${DEVICE3}" ] && error "Device ${DEVICE3} cannot be found! Please add it to the 'devices' section of your compose file." && exit 57
|
||||
|
||||
DISK_OPTS="${DISK_OPTS} \
|
||||
-device virtio-scsi-pci,id=hw-userdata6,bus=pcie.0,addr=0x6 \
|
||||
-drive file=${DEVICE3},if=none,id=drive-userdata6,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \
|
||||
-device scsi-hd,bus=hw-userdata6.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata6,id=userdata6,rotation_rate=${DISK_ROTATION},bootindex=8"
|
||||
|
||||
fi
|
||||
addDevice "userdata7" "${DEVICE}" "6" "0xf"
|
||||
addDevice "userdata8" "${DEVICE2}" "7" "0x5"
|
||||
addDevice "userdata9" "${DEVICE3}" "8" "0x6"
|
||||
addDevice "userdata4" "${DEVICE4}" "9" "0x7"
|
||||
addDevice "userdata5" "${DEVICE5}" "10" "0x8"
|
||||
addDevice "userdata6" "${DEVICE6}" "11" "0x9"
|
||||
|
||||
return 0
|
||||
|
||||
23
src/entry.sh
23
src/entry.sh
@@ -1,22 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
echo "❯ Starting Virtual DSM for Docker v${VERSION}..."
|
||||
echo "❯ Starting Virtual DSM for Docker v$(</run/version)..."
|
||||
echo "❯ For support visit https://github.com/vdsm/virtual-dsm/"
|
||||
|
||||
cd /run
|
||||
|
||||
. reset.sh # Initialize system
|
||||
. install.sh # Run installation
|
||||
. disk.sh # Initialize disks
|
||||
. network.sh # Initialize network
|
||||
. gpu.sh # Initialize graphics
|
||||
. serial.sh # Initialize serialport
|
||||
. power.sh # Configure shutdown
|
||||
. config.sh # Configure arguments
|
||||
. reset.sh # Initialize system
|
||||
. install.sh # Run installation
|
||||
. disk.sh # Initialize disks
|
||||
. network.sh # Initialize network
|
||||
. gpu.sh # Initialize graphics
|
||||
. serial.sh # Initialize serialport
|
||||
. power.sh # Configure shutdown
|
||||
. config.sh # Configure arguments
|
||||
|
||||
trap - ERR
|
||||
|
||||
if [[ "${CONSOLE}" == [Yy]* ]]; then
|
||||
exec qemu-system-x86_64 -pidfile "${QEMU_PID}" ${ARGS:+ $ARGS}
|
||||
exit $?
|
||||
fi
|
||||
|
||||
set -m
|
||||
(
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && info "$VERS" && set -x
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
STORAGE="/storage"
|
||||
[ ! -d "$STORAGE" ] && error "Storage folder (${STORAGE}) not found!" && exit 13
|
||||
: ${URL:=''} # URL of the PAT file to be downloaded.
|
||||
: ${DEV:='Y'} # Controls whether device nodes are created.
|
||||
|
||||
if [ -f "$STORAGE"/dsm.ver ]; then
|
||||
BASE=$(cat "${STORAGE}/dsm.ver")
|
||||
@@ -21,17 +21,37 @@ fi
|
||||
# Display wait message
|
||||
/run/server.sh 5000 install &
|
||||
|
||||
# Download the required files from the Synology website
|
||||
DL="https://global.synologydownload.com/download/DSM"
|
||||
# Detect country
|
||||
COUNTRY=""
|
||||
{ JSON=$(curl -sfk https://ipinfo.io); rc=$?; } || :
|
||||
|
||||
if (( rc == 0 )); then
|
||||
{ COUNTRY=$(echo "$JSON" | jq -r '.country' 2> /dev/null); rc=$?; } || :
|
||||
(( rc != 0 )) || [[ "$COUNTRY" == "null" ]] && COUNTRY=""
|
||||
fi
|
||||
|
||||
if [[ -z "$COUNTRY" ]]; then
|
||||
{ JSON=$(curl -sfk https://api.ipapi.is); rc=$?; } || :
|
||||
if (( rc == 0 )); then
|
||||
{ COUNTRY=$(echo "$JSON" | jq -r '.location.country_code' 2> /dev/null); rc=$?; } || :
|
||||
(( rc != 0 )) || [[ "$COUNTRY" == "null" ]] && COUNTRY=""
|
||||
fi
|
||||
fi
|
||||
|
||||
# Select download mirror based on country
|
||||
if [ "$COUNTRY" == "CN" ]; then
|
||||
DL="https://cndl.synology.cn/download/DSM"
|
||||
else
|
||||
DL="https://global.synologydownload.com/download/DSM"
|
||||
fi
|
||||
|
||||
# Select default version based on architecture
|
||||
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
|
||||
|
||||
# Check if output is to interactive TTY
|
||||
@@ -48,27 +68,42 @@ rm -f "$STORAGE"/"$BASE".agent
|
||||
rm -f "$STORAGE"/"$BASE".boot.img
|
||||
rm -f "$STORAGE"/"$BASE".system.img
|
||||
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
|
||||
# Check filesystem
|
||||
MIN_SPACE=6442450944
|
||||
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"* && \
|
||||
"$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then
|
||||
TMP="$STORAGE/tmp"
|
||||
else
|
||||
TMP="/tmp/dsm"
|
||||
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
|
||||
|
||||
rm -rf /tmp/dsm
|
||||
rm -rf "$STORAGE/tmp"
|
||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation, need at least 6 GB." && exit 95
|
||||
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
|
||||
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
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"
|
||||
|
||||
@@ -109,8 +144,14 @@ if [ -f "${RDC}" ]; then
|
||||
{ xz -dc <"$RDC" >"$TMP/rd" 2>/dev/null; rc=$?; } || :
|
||||
(( rc != 1 )) && error "Failed to unxz $RDC, reason $rc" && exit 91
|
||||
|
||||
{ (cd "$TMP" && cpio -idm <"$TMP/rd" 2>/dev/null); rc=$?; } || :
|
||||
(( rc != 0 )) && error "Failed to cpio $RDC, reason $rc" && exit 92
|
||||
if [[ "${DEV}" == [Nn]* ]]; then
|
||||
# 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=$?; } || :
|
||||
else
|
||||
{ (cd "$TMP" && cpio -idm <"$TMP/rd" 2>/dev/null); rc=$?; } || :
|
||||
fi
|
||||
|
||||
(( rc != 0 )) && error "Failed to extract $RDC, reason $rc" && exit 92
|
||||
|
||||
mkdir -p /run/extract
|
||||
for file in $TMP/usr/lib/libcurl.so.4 \
|
||||
@@ -202,14 +243,13 @@ BOOT=$(find "$TMP" -name "*.bin.zip")
|
||||
BOOT=$(echo "$BOOT" | head -c -5)
|
||||
unzip -q -o "$BOOT".zip -d "$TMP"
|
||||
|
||||
[[ "${ALLOCATE}" == [Zz]* ]] && info "Install: Allocating diskspace..."
|
||||
|
||||
SYSTEM="$TMP/sys.img"
|
||||
SYSTEM_SIZE=4954537983
|
||||
|
||||
# Check free diskspace
|
||||
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 ! truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||
@@ -217,11 +257,6 @@ if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${ALLOCATE}" == [Zz]* ]]; then
|
||||
info "Install: Preallocating 4 GB of diskspace..."
|
||||
dd if=/dev/urandom of="${SYSTEM}" count="${SYSTEM_SIZE}" bs=1M iflag=count_bytes status=none
|
||||
fi
|
||||
|
||||
# Check if file exists
|
||||
[ ! -f "${SYSTEM}" ] && error "System disk does not exist ($SYSTEM)" && exit 89
|
||||
|
||||
@@ -249,7 +284,13 @@ MOUNT="$TMP/system"
|
||||
rm -rf "$MOUNT" && mkdir -p "$MOUNT"
|
||||
|
||||
mv "$HDA.tgz" "$HDA.txz"
|
||||
tar xpfJ "$HDA.txz" --absolute-names -C "$MOUNT/"
|
||||
|
||||
if [[ "${DEV}" == [Nn]* ]]; then
|
||||
# Exclude dev/ from tar extract
|
||||
tar xpfJ "$HDA.txz" --absolute-names --exclude="dev" -C "$MOUNT/"
|
||||
else
|
||||
tar xpfJ "$HDA.txz" --absolute-names -C "$MOUNT/"
|
||||
fi
|
||||
|
||||
[ -d "$PKG" ] && mv "$PKG/" "$MOUNT/.SynoUpgradePackages/"
|
||||
rm -f "$MOUNT/.SynoUpgradePackages/ActiveInsight-"*
|
||||
@@ -269,12 +310,6 @@ rm -rf "$MOUNT"
|
||||
|
||||
echo "$BASE" > "$STORAGE"/dsm.ver
|
||||
|
||||
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space in storage folder, need at least 6 GB." && exit 94
|
||||
fi
|
||||
|
||||
mv -f "$PAT" "$STORAGE"/"$BASE".pat
|
||||
mv -f "$BOOT" "$STORAGE"/"$BASE".boot.img
|
||||
mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
||||
|
||||
@@ -11,7 +11,6 @@ set -Eeuo pipefail
|
||||
: ${VM_NET_MAC:="$MAC"}
|
||||
: ${VM_NET_HOST:='VirtualDSM'}
|
||||
|
||||
: ${DNS_SERVERS:=''}
|
||||
: ${DNSMASQ_OPTS:=''}
|
||||
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
|
||||
: ${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
|
||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||
|
||||
# Build DNS options from container /etc/resolv.conf
|
||||
|
||||
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
|
||||
|
||||
# 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"
|
||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
@@ -147,8 +121,6 @@ configureNAT () {
|
||||
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
||||
|
||||
# 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 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
|
||||
@@ -223,12 +195,10 @@ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
|
||||
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
fi
|
||||
|
||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||
|
||||
14
src/reset.sh
14
src/reset.sh
@@ -10,14 +10,14 @@ trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
||||
|
||||
# Docker environment variables
|
||||
|
||||
: ${URL:=''} # URL of the PAT file
|
||||
: ${GPU:='N'} # Enable GPU passthrough
|
||||
: ${DEBUG:='N'} # Enable debugging mode
|
||||
: ${CONSOLE:='N'} # Start in console mode
|
||||
: ${ALLOCATE:='Y'} # Preallocate diskspace
|
||||
: ${ARGUMENTS:=''} # Extra QEMU parameters
|
||||
: ${CPU_CORES:='1'} # Amount of CPU cores
|
||||
: ${RAM_SIZE:='1G'} # Maximum RAM amount
|
||||
: ${DISK_SIZE:='16G'} # Initial data disk size
|
||||
: ${RAM_SIZE:='512M'} # Maximum RAM amount
|
||||
|
||||
# Helper variables
|
||||
|
||||
@@ -26,10 +26,20 @@ MINOR=$(uname -r | cut -d '.' -f2)
|
||||
ARCH=$(dpkg --print-architecture)
|
||||
VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1)
|
||||
|
||||
# Check folder
|
||||
|
||||
STORAGE="/storage"
|
||||
[ ! -d "$STORAGE" ] && error "Storage folder (${STORAGE}) not found!" && exit 13
|
||||
|
||||
# Cleanup files
|
||||
|
||||
rm -f /run/dsm.url
|
||||
rm -f /run/qemu.pid
|
||||
rm -f /run/qemu.count
|
||||
|
||||
# Cleanup dirs
|
||||
|
||||
rm -rf /tmp/dsm
|
||||
rm -rf "$STORAGE/tmp"
|
||||
|
||||
return 0
|
||||
|
||||
@@ -48,7 +48,7 @@ sleep 0.2
|
||||
while ! nc -z -w1 127.0.0.1 2210 > /dev/null 2>&1; do
|
||||
sleep 0.1
|
||||
cnt=$((cnt + 1))
|
||||
(( cnt > 20 )) && error "Failed to connect to qemu-host.." && exit 58
|
||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 58
|
||||
done
|
||||
|
||||
cnt=0
|
||||
@@ -56,7 +56,7 @@ cnt=0
|
||||
while ! nc -z -w1 127.0.0.1 12345 > /dev/null 2>&1; do
|
||||
sleep 0.1
|
||||
cnt=$((cnt + 1))
|
||||
(( cnt > 20 )) && error "Failed to connect to qemu-host.." && exit 59
|
||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 59
|
||||
done
|
||||
|
||||
# Configure serial ports
|
||||
|
||||
Reference in New Issue
Block a user