mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-08-29 12:17:07 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
799649e78c | ||
|
|
12060c72b2 | ||
|
|
6eadd1b953 | ||
|
|
342ca4da03 | ||
|
|
b0b6190560 | ||
|
|
075410e4cf | ||
|
|
2a388b434b | ||
|
|
280c4037f3 | ||
|
|
007bdc735d | ||
|
|
41fc0a6a10 | ||
|
|
7753e4ac74 | ||
|
|
f74bf35202 | ||
|
|
aa472c96c6 | ||
|
|
0dcb880800 | ||
|
|
8daa6973b7 | ||
|
|
3884befa56 | ||
|
|
85b83f8eb1 | ||
|
|
f395dfaa66 | ||
|
|
b3124075ea | ||
|
|
aed909bdee | ||
|
|
d4cf5778e2 | ||
|
|
48de7dd00b | ||
|
|
686e64da3f | ||
|
|
7517dc8b3e | ||
|
|
660fe715e4 | ||
|
|
04ea29ec77 | ||
|
|
02c891cb16 | ||
|
|
0b5d21357e | ||
|
|
e0545b37d7 | ||
|
|
4161c21082 | ||
|
|
48d9a1771d | ||
|
|
471cdbb338 | ||
|
|
e77bca202b | ||
|
|
2e6c01e934 | ||
|
|
302c991c0c | ||
|
|
a89007ee03 | ||
|
|
8a89149d58 | ||
|
|
5e8bbc2868 | ||
|
|
4e48920309 | ||
|
|
8b145924b9 | ||
|
|
a0328e1e9c | ||
|
|
b7f5214a7b | ||
|
|
b0e4c4ac5f | ||
|
|
bbb67aac93 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Virtual DSM",
|
"name": "Virtual DSM",
|
||||||
"service": "vdsm",
|
"service": "dsm",
|
||||||
"forwardPorts": [5000],
|
"forwardPorts": [5000],
|
||||||
"portsAttributes": {
|
"portsAttributes": {
|
||||||
"5000": {
|
"5000": {
|
||||||
@@ -11,7 +11,5 @@
|
|||||||
"otherPortsAttributes": {
|
"otherPortsAttributes": {
|
||||||
"onAutoForward": "ignore"
|
"onAutoForward": "ignore"
|
||||||
},
|
},
|
||||||
"dockerComposeFile": "codespaces.yml",
|
"dockerComposeFile": "codespaces.yml"
|
||||||
"workspaceFolder": "/workspaces/vdsm",
|
|
||||||
"initializeCommand": "docker system prune --all --force"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
-
|
-
|
||||||
name: Docker metadata
|
name: Docker metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v6
|
||||||
with:
|
with:
|
||||||
context: git
|
context: git
|
||||||
images: |
|
images: |
|
||||||
@@ -43,23 +43,23 @@ jobs:
|
|||||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
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@v4
|
||||||
-
|
-
|
||||||
name: Login into Docker Hub
|
name: Login into Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Login to GitHub Container Registry
|
name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v4
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build Docker image
|
name: Build Docker image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Run ShellCheck
|
name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
@@ -24,6 +24,6 @@ jobs:
|
|||||||
failure-threshold: warning
|
failure-threshold: warning
|
||||||
-
|
-
|
||||||
name: Validate JSON and YML files
|
name: Validate JSON and YML files
|
||||||
uses: GrantBirki/json-yaml-validate@v4
|
uses: GrantBirki/json-yaml-validate@v5.0.0
|
||||||
with:
|
with:
|
||||||
yaml_exclude_regex: ".*\\kubernetes\\.yml$"
|
yaml_exclude_regex: ".*\\kubernetes\\.yml$"
|
||||||
|
|||||||
+12
-10
@@ -12,13 +12,15 @@ jobs:
|
|||||||
dockerHubDescription:
|
dockerHubDescription:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
-
|
||||||
-
|
name: Checkout repo
|
||||||
name: Docker Hub Description
|
uses: actions/checkout@v6
|
||||||
uses: peter-evans/dockerhub-description@v5
|
-
|
||||||
with:
|
name: Docker Hub Description
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
uses: peter-evans/dockerhub-description@v5
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
with:
|
||||||
repository: ${{ secrets.DOCKERHUB_REPO }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
short-description: ${{ github.event.repository.description }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
readme-filepath: ./readme.md
|
repository: ${{ secrets.DOCKERHUB_REPO }}
|
||||||
|
short-description: ${{ github.event.repository.description }}
|
||||||
|
readme-filepath: ./readme.md
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
name: "Review"
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
checks: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
review:
|
||||||
|
name: review
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
-
|
||||||
|
name: Spelling
|
||||||
|
uses: reviewdog/action-misspell@v1
|
||||||
|
with:
|
||||||
|
locale: "US"
|
||||||
|
level: warning
|
||||||
|
pattern: |
|
||||||
|
*.md
|
||||||
|
*.sh
|
||||||
|
reporter: github-pr-review
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Hadolint
|
||||||
|
uses: reviewdog/action-hadolint@v1
|
||||||
|
with:
|
||||||
|
level: warning
|
||||||
|
reporter: github-pr-review
|
||||||
|
hadolint_ignore: DL3008 DL3003 DL3006 DL3013
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: YamlLint
|
||||||
|
uses: reviewdog/action-yamllint@v1
|
||||||
|
with:
|
||||||
|
level: warning
|
||||||
|
reporter: github-pr-review
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: ActionLint
|
||||||
|
uses: reviewdog/action-actionlint@v1
|
||||||
|
with:
|
||||||
|
level: warning
|
||||||
|
reporter: github-pr-review
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Shellformat
|
||||||
|
uses: reviewdog/action-shfmt@v1
|
||||||
|
with:
|
||||||
|
level: warning
|
||||||
|
shfmt_flags: "-i 2 -ci -bn"
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Shellcheck
|
||||||
|
uses: reviewdog/action-shellcheck@v1
|
||||||
|
with:
|
||||||
|
level: warning
|
||||||
|
reporter: github-pr-review
|
||||||
|
shellcheck_flags: -x -e SC2001 -e SC2034 -e SC2064 -e SC2317 -e SC2153 -e SC2028
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
+4
-2
@@ -14,6 +14,8 @@ FROM debian:trixie-slim
|
|||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
ARG VERSION_ARG="0.0"
|
ARG VERSION_ARG="0.0"
|
||||||
|
ARG VERSION_PASST="2026_05_07"
|
||||||
|
|
||||||
ARG DEBCONF_NOWARNINGS="yes"
|
ARG DEBCONF_NOWARNINGS="yes"
|
||||||
ARG DEBIAN_FRONTEND="noninteractive"
|
ARG DEBIAN_FRONTEND="noninteractive"
|
||||||
ARG DEBCONF_NONINTERACTIVE_SEEN="true"
|
ARG DEBCONF_NONINTERACTIVE_SEEN="true"
|
||||||
@@ -39,7 +41,7 @@ RUN set -eu && \
|
|||||||
iproute2 \
|
iproute2 \
|
||||||
dnsmasq \
|
dnsmasq \
|
||||||
fakeroot \
|
fakeroot \
|
||||||
apt-utils \
|
apt-utils \
|
||||||
net-tools \
|
net-tools \
|
||||||
e2fsprogs \
|
e2fsprogs \
|
||||||
qemu-utils \
|
qemu-utils \
|
||||||
@@ -49,7 +51,7 @@ RUN set -eu && \
|
|||||||
ca-certificates \
|
ca-certificates \
|
||||||
netcat-openbsd \
|
netcat-openbsd \
|
||||||
qemu-system-x86 && \
|
qemu-system-x86 && \
|
||||||
wget "https://github.com/qemus/passt/releases/download/v2025_09_19/passt_2025_09_19_${TARGETARCH}.deb" -O /tmp/passt.deb -q && \
|
wget "https://github.com/qemus/passt/releases/download/v${VERSION_PASST}/passt_${VERSION_PASST}_${TARGETARCH}.deb" -O /tmp/passt.deb -q --timeout=10 && \
|
||||||
dpkg -i /tmp/passt.deb && \
|
dpkg -i /tmp/passt.deb && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
pip3 install --no-cache-dir --break-system-packages --root-user-action=ignore dissect.cstruct && \
|
pip3 install --no-cache-dir --break-system-packages --root-user-action=ignore dissect.cstruct && \
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ services:
|
|||||||
##### Via Docker CLI:
|
##### Via Docker CLI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -it --rm --name dsm -e "DISK_SIZE=256G" -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v "${PWD:-.}/dsm:/storage" --stop-timeout 120 vdsm/virtual-dsm
|
docker run -it --rm --name dsm -e "DISK_SIZE=256G" -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v "${PWD:-.}/dsm:/storage" --stop-timeout 120 docker.io/vdsm/virtual-dsm
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Via Kubernetes:
|
##### Via Kubernetes:
|
||||||
|
|||||||
+46
-53
@@ -17,6 +17,14 @@ SYSTEM="$STORAGE/$BASE.system.img"
|
|||||||
[ ! -s "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
[ ! -s "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
||||||
[ ! -s "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
[ ! -s "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
||||||
|
|
||||||
|
if ! setOwner "$BOOT"; then
|
||||||
|
error "Failed to set the owner for \"$BOOT\" !"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! setOwner "$SYSTEM"; then
|
||||||
|
error "Failed to set the owner for \"$SYSTEM\" !"
|
||||||
|
fi
|
||||||
|
|
||||||
fmt2ext() {
|
fmt2ext() {
|
||||||
local DISK_FMT="$1"
|
local DISK_FMT="$1"
|
||||||
|
|
||||||
@@ -261,12 +269,14 @@ convertDisk() {
|
|||||||
local TMP_FILE="$DISK_BASE.tmp"
|
local TMP_FILE="$DISK_BASE.tmp"
|
||||||
rm -f "$TMP_FILE"
|
rm -f "$TMP_FILE"
|
||||||
|
|
||||||
|
local DIR
|
||||||
|
DIR=$(dirname "$TMP_FILE")
|
||||||
|
|
||||||
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
||||||
|
|
||||||
local DIR CUR_SIZE SPACE GB
|
local CUR_SIZE SPACE GB
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
DIR=$(dirname "$TMP_FILE")
|
|
||||||
CUR_SIZE=$(getSize "$SOURCE_FILE")
|
CUR_SIZE=$(getSize "$SOURCE_FILE")
|
||||||
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||||
|
|
||||||
@@ -338,23 +348,23 @@ checkFS () {
|
|||||||
DIR=$(dirname "$DISK_FILE")
|
DIR=$(dirname "$DISK_FILE")
|
||||||
[ ! -d "$DIR" ] && return 0
|
[ ! -d "$DIR" ] && return 0
|
||||||
|
|
||||||
if [[ "${FS,,}" == "overlay"* ]]; then
|
if [[ "${FS,,}" == "overlay"* && "${ENGINE,,}" == "docker" ]]; then
|
||||||
info "Warning: the filesystem of $DIR is OverlayFS, this usually means it was binded to an invalid path!"
|
warn "the filesystem of $DIR is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "fuse"* ]]; then
|
if [[ "${FS,,}" == "fuse"* ]]; then
|
||||||
info "Warning: the filesystem of $DIR is FUSE, this extra layer will negatively affect performance!"
|
warn "the filesystem of $DIR is FUSE, this extra layer will negatively affect performance!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! supportsDirect "$FS"; then
|
if ! supportsDirect "$FS"; then
|
||||||
info "Warning: the filesystem of $DIR is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
warn "the filesystem of $DIR is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if isCow "$FS"; then
|
if isCow "$FS"; then
|
||||||
if [ -f "$DISK_FILE" ]; then
|
if [ -f "$DISK_FILE" ]; then
|
||||||
FA=$(lsattr "$DISK_FILE")
|
FA=$(lsattr "$DISK_FILE")
|
||||||
if [[ "$FA" != *"C"* ]]; then
|
if [[ "$FA" != *"C"* ]]; then
|
||||||
info "Warning: COW (copy on write) is not disabled for $DISK_DESC image file $DISK_FILE, this is recommended on ${FS^^} filesystems!"
|
warn "COW (copy on write) is not disabled for $DISK_DESC image file $DISK_FILE, this is recommended on ${FS^^} filesystems!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -437,7 +447,7 @@ addDisk () {
|
|||||||
|
|
||||||
if [[ "${DISK_SPACE,,}" == "max" || "${DISK_SPACE,,}" == "half" ]]; then
|
if [[ "${DISK_SPACE,,}" == "max" || "${DISK_SPACE,,}" == "half" ]]; then
|
||||||
|
|
||||||
local SPARE=2147483648
|
local SPARE=1073741824
|
||||||
FREE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
FREE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||||
|
|
||||||
if [[ "${DISK_SPACE,,}" == "max" ]]; then
|
if [[ "${DISK_SPACE,,}" == "max" ]]; then
|
||||||
@@ -528,21 +538,26 @@ addDisk () {
|
|||||||
GB=$(formatBytes "$FREE")
|
GB=$(formatBytes "$FREE")
|
||||||
LEFT=$(formatBytes "$LEFT")
|
LEFT=$(formatBytes "$LEFT")
|
||||||
CUR_SIZE=$(formatBytes "$CUR_SIZE")
|
CUR_SIZE=$(formatBytes "$CUR_SIZE")
|
||||||
msg="the virtual size of the ${DISK_DESC,,} is $CUR_SIZE"
|
msg="The virtual size of the ${DISK_DESC,,} is $CUR_SIZE"
|
||||||
|
|
||||||
if [[ "$USED" == "0" ]]; then
|
if [ -n "$USED" ] && [[ "$USED" != "0" ]]; then
|
||||||
msg+=","
|
|
||||||
else
|
|
||||||
USED=$(formatBytes "$USED")
|
USED=$(formatBytes "$USED")
|
||||||
msg+=" (of which $USED is used),"
|
msg+=" (of which $USED is used)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
warn "$msg but there is only $GB of free space left in $DIR, make at least $LEFT more room available!"
|
info "$msg, but there is only $GB of free space remaining in $DIR now."
|
||||||
|
info "Please consider making at least $LEFT more space available in $DIR for future expansions."
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f "$DISK_FILE" ]; then
|
||||||
|
if ! setOwner "$DISK_FILE"; then
|
||||||
|
error "Failed to set the owner for \"$DISK_FILE\" !"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
DISK_OPTS+=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE" "" "")
|
DISK_OPTS+=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE" "" "")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -559,18 +574,25 @@ addDevice () {
|
|||||||
[ ! -b "$DISK_DEV" ] && error "Device $DISK_DEV cannot be found! Please add it to the 'devices' section of your compose file." && exit 55
|
[ ! -b "$DISK_DEV" ] && error "Device $DISK_DEV cannot be found! Please add it to the 'devices' section of your compose file." && exit 55
|
||||||
|
|
||||||
local sectors=""
|
local sectors=""
|
||||||
local result logical physical
|
local dev_type=""
|
||||||
result=$(fdisk -l "$DISK_DEV" | grep -m 1 -o "(logical/physical): .*" | cut -c 21-)
|
dev_type=$(lsblk -no TYPE "$DISK_DEV" 2>/dev/null | head -n1)
|
||||||
logical="${result%% *}"
|
|
||||||
physical=$(echo "$result" | grep -m 1 -o "/ .*" | cut -c 3-)
|
|
||||||
physical="${physical%% *}"
|
|
||||||
|
|
||||||
if [ -n "$physical" ]; then
|
# Only detect and apply sector sizes for partitions, not whole disks
|
||||||
if [[ "$physical" != "512" ]]; then
|
# Whole disk passthrough with explicit sector sizes causes DSM not to recognize the disk
|
||||||
sectors=",logical_block_size=$logical,physical_block_size=$physical"
|
if [[ "$dev_type" == "part" ]]; then
|
||||||
|
local result logical physical
|
||||||
|
result=$(fdisk -l "$DISK_DEV" | grep -m 1 -o "(logical/physical): .*" | cut -c 21-)
|
||||||
|
logical="${result%% *}"
|
||||||
|
physical=$(echo "$result" | grep -m 1 -o "/ .*" | cut -c 3-)
|
||||||
|
physical="${physical%% *}"
|
||||||
|
|
||||||
|
if [ -n "$physical" ]; then
|
||||||
|
if [[ "$physical" != "512" ]]; then
|
||||||
|
sectors=",logical_block_size=$logical,physical_block_size=$physical"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Failed to determine the sector size for $DISK_DEV"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
warn "Failed to determine the sector size for $DISK_DEV"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DISK_OPTS+=$(createDevice "$DISK_DEV" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "raw" "$DISK_IO" "$DISK_CACHE" "" "$sectors")
|
DISK_OPTS+=$(createDevice "$DISK_DEV" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "raw" "$DISK_IO" "$DISK_CACHE" "" "$sectors")
|
||||||
@@ -607,37 +629,8 @@ DISK_OPTS+=$(createDevice "$BOOT" "$DISK_TYPE" "1" "0xa" "raw" "$DISK_IO" "$DISK
|
|||||||
DISK_OPTS+=$(createDevice "$SYSTEM" "$DISK_TYPE" "2" "0xb" "raw" "$DISK_IO" "$DISK_CACHE" "" "")
|
DISK_OPTS+=$(createDevice "$SYSTEM" "$DISK_TYPE" "2" "0xb" "raw" "$DISK_IO" "$DISK_CACHE" "" "")
|
||||||
|
|
||||||
DISK1_FILE="$STORAGE/${DISK_NAME}"
|
DISK1_FILE="$STORAGE/${DISK_NAME}"
|
||||||
if [ ! -f "$DISK1_FILE.img" ] && [ -f "$STORAGE/data${DISK_SIZE}.img" ]; then
|
|
||||||
# Fallback for legacy installs
|
|
||||||
mv "$STORAGE/data${DISK_SIZE}.img" "$DISK1_FILE.img"
|
|
||||||
fi
|
|
||||||
|
|
||||||
DISK2_FILE="/storage2/${DISK_NAME}2"
|
DISK2_FILE="/storage2/${DISK_NAME}2"
|
||||||
if [ ! -f "$DISK2_FILE.img" ]; then
|
|
||||||
# Fallback for legacy installs
|
|
||||||
FALLBACK="/storage2/data.img"
|
|
||||||
if [[ -f "$DISK1_FILE.img" && -f "$FALLBACK" ]]; then
|
|
||||||
SIZE1=$(stat -c%s "$FALLBACK")
|
|
||||||
SIZE2=$(stat -c%s "$DISK1_FILE.img")
|
|
||||||
if [[ SIZE1 -ne SIZE2 ]]; then
|
|
||||||
mv "$FALLBACK" "$DISK2_FILE.img"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
DISK3_FILE="/storage3/${DISK_NAME}3"
|
DISK3_FILE="/storage3/${DISK_NAME}3"
|
||||||
if [ ! -f "$DISK3_FILE.img" ]; then
|
|
||||||
# Fallback for legacy installs
|
|
||||||
FALLBACK="/storage3/data.img"
|
|
||||||
if [[ -f "$DISK1_FILE.img" && -f "$FALLBACK" ]]; then
|
|
||||||
SIZE1=$(stat -c%s "$FALLBACK")
|
|
||||||
SIZE2=$(stat -c%s "$DISK1_FILE.img")
|
|
||||||
if [[ SIZE1 -ne SIZE2 ]]; then
|
|
||||||
mv "$FALLBACK" "$DISK3_FILE.img"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
DISK4_FILE="/storage4/${DISK_NAME}4"
|
DISK4_FILE="/storage4/${DISK_NAME}4"
|
||||||
|
|
||||||
: "${DISK2_SIZE:=""}"
|
: "${DISK2_SIZE:=""}"
|
||||||
|
|||||||
+23
-9
@@ -31,7 +31,6 @@ if [ -n "$URL" ] && [ ! -s "$FILE" ] && [ ! -d "$DIR" ]; then
|
|||||||
BASE=$(basename "$URL" .pat)
|
BASE=$(basename "$URL" .pat)
|
||||||
if [ ! -s "$STORAGE/$BASE.system.img" ]; then
|
if [ ! -s "$STORAGE/$BASE.system.img" ]; then
|
||||||
BASE=$(basename "${URL%%\?*}" .pat)
|
BASE=$(basename "${URL%%\?*}" .pat)
|
||||||
BASE="${BASE//+/ }"
|
|
||||||
printf -v BASE '%b' "${BASE//%/\\x}"
|
printf -v BASE '%b' "${BASE//%/\\x}"
|
||||||
BASE="${BASE//[!A-Za-z0-9._-]/_}"
|
BASE="${BASE//[!A-Za-z0-9._-]/_}"
|
||||||
fi
|
fi
|
||||||
@@ -66,7 +65,6 @@ fi
|
|||||||
|
|
||||||
if [ ! -s "$FILE" ]; then
|
if [ ! -s "$FILE" ]; then
|
||||||
BASE=$(basename "${URL%%\?*}" .pat)
|
BASE=$(basename "${URL%%\?*}" .pat)
|
||||||
BASE="${BASE//+/ }"
|
|
||||||
printf -v BASE '%b' "${BASE//%/\\x}"
|
printf -v BASE '%b' "${BASE//%/\\x}"
|
||||||
BASE="${BASE//[!A-Za-z0-9._-]/_}"
|
BASE="${BASE//[!A-Za-z0-9._-]/_}"
|
||||||
fi
|
fi
|
||||||
@@ -82,16 +80,16 @@ rm -f "$STORAGE/$BASE.system.img"
|
|||||||
# Check filesystem
|
# Check filesystem
|
||||||
FS=$(stat -f -c %T "$STORAGE")
|
FS=$(stat -f -c %T "$STORAGE")
|
||||||
|
|
||||||
if [[ "${FS,,}" == "overlay"* ]]; then
|
if [[ "${FS,,}" == "overlay"* && "${ENGINE,,}" == "docker" ]]; then
|
||||||
info "Warning: the filesystem of $STORAGE is OverlayFS, this usually means it was binded to an invalid path!"
|
warn "the filesystem of $STORAGE is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "fuse"* ]]; then
|
if [[ "${FS,,}" == "fuse"* ]]; then
|
||||||
info "Warning: the filesystem of $STORAGE is FUSE, this extra layer will negatively affect performance!"
|
warn "the filesystem of $STORAGE is FUSE, this extra layer will negatively affect performance!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
|
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
|
||||||
info "Warning: the filesystem of $STORAGE is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
warn "the filesystem of $STORAGE is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "fat"* || "${FS,,}" == "vfat"* || "${FS,,}" == "msdos"* ]]; then
|
if [[ "${FS,,}" == "fat"* || "${FS,,}" == "vfat"* || "${FS,,}" == "msdos"* ]]; then
|
||||||
@@ -100,6 +98,10 @@ fi
|
|||||||
|
|
||||||
if [[ "${FS,,}" != "exfat"* && "${FS,,}" != "ntfs"* && "${FS,,}" != "unknown"* ]]; then
|
if [[ "${FS,,}" != "exfat"* && "${FS,,}" != "ntfs"* && "${FS,,}" != "unknown"* ]]; then
|
||||||
TMP="$STORAGE/tmp"
|
TMP="$STORAGE/tmp"
|
||||||
|
rm -rf "$TMP"
|
||||||
|
if ! makeDir "$TMP"; then
|
||||||
|
error "Failed to create directory \"$TMP\" !" && exit 93
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
TMP="/tmp/dsm"
|
TMP="/tmp/dsm"
|
||||||
TMP_SPACE=2147483648
|
TMP_SPACE=2147483648
|
||||||
@@ -108,10 +110,9 @@ else
|
|||||||
if (( TMP_SPACE > SPACE )); then
|
if (( TMP_SPACE > SPACE )); then
|
||||||
error "Not enough free space inside the container, have $SPACE_MB available but need at least 2 GB." && exit 93
|
error "Not enough free space inside the container, have $SPACE_MB available but need at least 2 GB." && exit 93
|
||||||
fi
|
fi
|
||||||
|
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
ROOT_SPACE=536870912
|
ROOT_SPACE=536870912
|
||||||
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
||||||
@@ -224,6 +225,8 @@ if ! touch "$SYSTEM"; then
|
|||||||
error "Could not create file $SYSTEM for the system disk." && exit 98
|
error "Could not create file $SYSTEM for the system disk." && exit 98
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
! setOwner "$SYSTEM" && error "Failed to set the owner for \"$SYSTEM\" !"
|
||||||
|
|
||||||
if [[ "${FS,,}" == "btrfs" ]]; then
|
if [[ "${FS,,}" == "btrfs" ]]; then
|
||||||
{ chattr +C "$SYSTEM"; } || :
|
{ chattr +C "$SYSTEM"; } || :
|
||||||
FA=$(lsattr "$SYSTEM")
|
FA=$(lsattr "$SYSTEM")
|
||||||
@@ -256,7 +259,11 @@ PART="$TMP/partition.fdisk"
|
|||||||
sfdisk -q "$SYSTEM" < "$PART"
|
sfdisk -q "$SYSTEM" < "$PART"
|
||||||
|
|
||||||
MOUNT="$TMP/system"
|
MOUNT="$TMP/system"
|
||||||
rm -rf "$MOUNT" && mkdir -p "$MOUNT"
|
rm -rf "$MOUNT"
|
||||||
|
|
||||||
|
if ! makeDir "$MOUNT"; then
|
||||||
|
error "Failed to create directory \"$MOUNT\" !" && exit 93
|
||||||
|
fi
|
||||||
|
|
||||||
MSG="Extracting system partition..."
|
MSG="Extracting system partition..."
|
||||||
info "Install: $MSG" && html "$MSG"
|
info "Install: $MSG" && html "$MSG"
|
||||||
@@ -291,6 +298,7 @@ fakeroot -- bash -c "set -Eeu;\
|
|||||||
|
|
||||||
rm -rf "$MOUNT"
|
rm -rf "$MOUNT"
|
||||||
echo "$BASE" > "$STORAGE/dsm.ver"
|
echo "$BASE" > "$STORAGE/dsm.ver"
|
||||||
|
! setOwner "$STORAGE/dsm.ver" && error "Failed to set the owner for \"$STORAGE/dsm.ver\" !"
|
||||||
|
|
||||||
if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then
|
if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then
|
||||||
rm -f "$PAT"
|
rm -f "$PAT"
|
||||||
@@ -298,7 +306,13 @@ else
|
|||||||
mv -f "$PAT" "$STORAGE/$BASE.pat"
|
mv -f "$PAT" "$STORAGE/$BASE.pat"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f "$STORAGE/$BASE.pat" ]; then
|
||||||
|
! setOwner "$STORAGE/$BASE.pat" && error "Failed to set the owner for \"$STORAGE/$BASE.pat\" !"
|
||||||
|
fi
|
||||||
|
|
||||||
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
||||||
|
! setOwner "$STORAGE/$BASE.boot.img" && error "Failed to set the owner for \"$STORAGE/$BASE.boot.img\" !"
|
||||||
|
|
||||||
rm -rf "$TMP"
|
rm -rf "$TMP"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
+36
-44
@@ -1,14 +1,18 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
msg="Checking memory..."
|
||||||
|
[[ "$DEBUG" == [Yy1]* ]] && echo "$msg"
|
||||||
|
|
||||||
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
||||||
|
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
||||||
|
|
||||||
if [[ "$RAM_CHECK" != [Nn]* && "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
if [[ "$RAM_CHECK" != [Nn]* && "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
||||||
|
|
||||||
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
wanted=$(numfmt --from=iec "$RAM_SIZE")
|
||||||
|
|
||||||
if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
if (( (wanted + RAM_SPARE) > RAM_AVAIL )); then
|
||||||
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available,"
|
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of free memory available,"
|
||||||
if [[ "${FS,,}" == "zfs" ]]; then
|
if [[ "${FS,,}" == "zfs" ]]; then
|
||||||
info "$msg but since ZFS is active this will be ignored."
|
info "$msg but since ZFS is active this will be ignored."
|
||||||
else
|
else
|
||||||
@@ -16,8 +20,8 @@ if [[ "$RAM_CHECK" != [Nn]* && "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "h
|
|||||||
warn "$msg it will automatically be adjusted to a lower amount."
|
warn "$msg it will automatically be adjusted to a lower amount."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
if (( (wanted + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
||||||
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $AVAIL_MEM of memory available,"
|
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $AVAIL_MEM of free memory available,"
|
||||||
if [[ "${FS,,}" == "zfs" ]]; then
|
if [[ "${FS,,}" == "zfs" ]]; then
|
||||||
info "$msg but since ZFS is active this will be ignored."
|
info "$msg but since ZFS is active this will be ignored."
|
||||||
else
|
else
|
||||||
@@ -30,57 +34,45 @@ fi
|
|||||||
|
|
||||||
if [[ "${RAM_SIZE,,}" == "half" ]]; then
|
if [[ "${RAM_SIZE,,}" == "half" ]]; then
|
||||||
|
|
||||||
RAM_WANTED=$(( RAM_AVAIL / 2 ))
|
if (( (RAM_AVAIL / 2) > RAM_SPARE )); then
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
wanted=$(( (RAM_AVAIL / 2) / 1048577 ))
|
||||||
|
RAM_SIZE="${wanted}M"
|
||||||
if (( "$RAM_WANTED" < 1 )); then
|
info "Allocated $wanted MB of RAM for the virtual machine."
|
||||||
RAM_WANTED=$(( RAM_AVAIL / 2 ))
|
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1048577 ))
|
|
||||||
RAM_SIZE="${RAM_WANTED}M"
|
|
||||||
else
|
else
|
||||||
RAM_SIZE="${RAM_WANTED}G"
|
RAM_SIZE="max"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${RAM_SIZE,,}" == "max" ]]; then
|
if [[ "${RAM_SIZE,,}" == "max" ]]; then
|
||||||
|
|
||||||
RAM_WANTED=$(( RAM_AVAIL - (RAM_SPARE * 3) ))
|
if (( RAM_AVAIL < (RAM_SPARE * 2) )); then
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
|
||||||
|
|
||||||
if (( "$RAM_WANTED" < 1 )); then
|
wanted=$(( RAM_AVAIL / 2 ))
|
||||||
|
|
||||||
RAM_WANTED=$(( RAM_AVAIL - (RAM_SPARE * 2) ))
|
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
|
||||||
|
|
||||||
if (( "$RAM_WANTED" < 1 )); then
|
|
||||||
|
|
||||||
RAM_WANTED=$(( RAM_AVAIL - RAM_SPARE ))
|
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1073741825 ))
|
|
||||||
|
|
||||||
if (( "$RAM_WANTED" < 1 )); then
|
|
||||||
|
|
||||||
RAM_WANTED=$(( RAM_AVAIL - RAM_SPARE ))
|
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1048577 ))
|
|
||||||
|
|
||||||
if (( "$RAM_WANTED" < 1 )); then
|
|
||||||
|
|
||||||
RAM_WANTED=$(( RAM_AVAIL ))
|
|
||||||
RAM_WANTED=$(( RAM_WANTED / 1048577 ))
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
RAM_SIZE="${RAM_WANTED}M"
|
|
||||||
else
|
|
||||||
RAM_SIZE="${RAM_WANTED}G"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
RAM_SIZE="${RAM_WANTED}G"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
RAM_SIZE="${RAM_WANTED}G"
|
|
||||||
|
wanted=$(( RAM_AVAIL - (RAM_SPARE * 3) ))
|
||||||
|
|
||||||
|
if (( wanted < (RAM_SPARE * 6) )); then
|
||||||
|
wanted=$(( RAM_AVAIL - RAM_SPARE ))
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
wanted=$(( wanted / 1048577 ))
|
||||||
|
RAM_SIZE="${wanted}M"
|
||||||
|
|
||||||
|
info "Allocated $wanted MB of RAM for the virtual machine."
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
wanted=$(numfmt --from=iec "$RAM_SIZE")
|
||||||
|
|
||||||
|
if [ "$wanted" -lt "$RAM_MINIMUM" ]; then
|
||||||
|
wanted=$(( wanted / 1048577 ))
|
||||||
|
error "Not enough memory available, there is only $wanted MB left!"
|
||||||
|
exit 16
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
+108
-76
@@ -19,14 +19,16 @@ set -Eeuo pipefail
|
|||||||
: "${VM_NET_HOST:="VirtualDSM"}"
|
: "${VM_NET_HOST:="VirtualDSM"}"
|
||||||
: "${VM_NET_MASK:="255.255.255.0"}"
|
: "${VM_NET_MASK:="255.255.255.0"}"
|
||||||
|
|
||||||
: "${PASST:="passt"}"
|
: "${PASST:="/run/passt"}"
|
||||||
: "${PASST_MTU:=""}"
|
: "${PASST_MTU:=""}"
|
||||||
: "${PASST_OPTS:=""}"
|
: "${PASST_OPTS:=""}"
|
||||||
: "${PASST_DEBUG:=""}"
|
: "${PASST_DEBUG:=""}"
|
||||||
|
: "${PASST_PID:="/var/run/passt.pid"}"
|
||||||
|
|
||||||
: "${DNSMASQ_OPTS:=""}"
|
: "${DNSMASQ_OPTS:=""}"
|
||||||
: "${DNSMASQ_DEBUG:=""}"
|
: "${DNSMASQ_DEBUG:=""}"
|
||||||
: "${DNSMASQ:="/usr/sbin/dnsmasq"}"
|
: "${DNSMASQ:="/usr/sbin/dnsmasq"}"
|
||||||
|
: "${DNSMASQ_PID:="/var/run/dnsmasq.pid"}"
|
||||||
: "${DNSMASQ_CONF_DIR:="/etc/dnsmasq.d"}"
|
: "${DNSMASQ_CONF_DIR:="/etc/dnsmasq.d"}"
|
||||||
|
|
||||||
ADD_ERR="Please add the following setting to your container:"
|
ADD_ERR="Please add the following setting to your container:"
|
||||||
@@ -115,20 +117,21 @@ configureDHCP() {
|
|||||||
|
|
||||||
configureDNS() {
|
configureDNS() {
|
||||||
|
|
||||||
local if="$1"
|
local fa="$1"
|
||||||
local ip="$2"
|
local ip="$2"
|
||||||
local mac="$3"
|
local mac="$3"
|
||||||
local host="$4"
|
local host="$4"
|
||||||
local mask="$5"
|
local mask="$5"
|
||||||
local gateway="$6"
|
local gateway="$6"
|
||||||
|
local arguments="$DNSMASQ_OPTS"
|
||||||
|
|
||||||
echo "$gateway" > /run/shm/qemu.gw
|
echo "$gateway" > /run/shm/qemu.gw
|
||||||
|
|
||||||
[[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0
|
[[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..."
|
||||||
|
|
||||||
local log="/var/log/dnsmasq.log"
|
[ -s "$DNSMASQ_PID" ] && pKill "$(<"$DNSMASQ_PID")"
|
||||||
rm -f "$log"
|
rm -f "$DNSMASQ_PID"
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"tap" | "tun" | "tuntap" | "y" )
|
"tap" | "tun" | "tuntap" | "y" )
|
||||||
@@ -138,40 +141,50 @@ configureDNS() {
|
|||||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||||
|
|
||||||
# dnsmasq configuration:
|
# dnsmasq configuration:
|
||||||
DNSMASQ_OPTS+=" --dhcp-authoritative"
|
arguments+=" --dhcp-authoritative"
|
||||||
|
|
||||||
# Set DHCP range and host
|
# Set DHCP range and host
|
||||||
DNSMASQ_OPTS+=" --dhcp-range=$ip,$ip"
|
arguments+=" --dhcp-range=$ip,$ip"
|
||||||
DNSMASQ_OPTS+=" --dhcp-host=$mac,,$ip,$host,infinite"
|
arguments+=" --dhcp-host=$mac,,$ip,$host,infinite"
|
||||||
|
|
||||||
# Set DNS server and gateway
|
# Set DNS server and gateway
|
||||||
DNSMASQ_OPTS+=" --dhcp-option=option:netmask,$mask"
|
arguments+=" --dhcp-option=option:netmask,$mask"
|
||||||
DNSMASQ_OPTS+=" --dhcp-option=option:router,$gateway"
|
arguments+=" --dhcp-option=option:router,$gateway"
|
||||||
DNSMASQ_OPTS+=" --dhcp-option=option:dns-server,$gateway"
|
arguments+=" --dhcp-option=option:dns-server,$gateway"
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Set interfaces
|
# Set interfaces
|
||||||
DNSMASQ_OPTS+=" --interface=$if"
|
arguments+=" --interface=$fa"
|
||||||
DNSMASQ_OPTS+=" --bind-interfaces"
|
arguments+=" --bind-interfaces"
|
||||||
|
|
||||||
|
# Workaround NET_RAW capability
|
||||||
|
arguments+=" --no-ping"
|
||||||
|
|
||||||
# Add DNS entry for container
|
# Add DNS entry for container
|
||||||
DNSMASQ_OPTS+=" --address=/host.lan/$gateway"
|
arguments+=" --address=/host.lan/$gateway"
|
||||||
|
|
||||||
# Set local dns resolver to dnsmasq when needed
|
# Set local dns resolver to dnsmasq when needed
|
||||||
[ -f /etc/resolv.dnsmasq ] && DNSMASQ_OPTS+=" --resolv-file=/etc/resolv.dnsmasq"
|
[ -f /etc/resolv.dnsmasq ] && arguments+=" --resolv-file=/etc/resolv.dnsmasq"
|
||||||
|
|
||||||
# Enable logging to file
|
# Enable logging to file
|
||||||
DNSMASQ_OPTS+=" --log-facility=$log"
|
local log="/var/log/dnsmasq.log"
|
||||||
|
rm -f "$log"
|
||||||
|
arguments+=" --log-facility=$log"
|
||||||
|
|
||||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
arguments=$(echo "$arguments" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && printf "Dnsmasq arguments:\n\n%s\n\n" "${DNSMASQ_OPTS// -/$'\n-'}"
|
[[ "$DEBUG" == [Yy1]* ]] && printf "Dnsmasq arguments:\n\n%s\n\n" "${arguments// -/$'\n-'}"
|
||||||
|
|
||||||
if ! $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}; then
|
{ $DNSMASQ ${arguments:+ $arguments}; rc=$?; } || :
|
||||||
|
|
||||||
local msg="Failed to start Dnsmasq, reason: $?"
|
if (( rc != 0 )); then
|
||||||
[ -f "$log" ] && cat "$log"
|
|
||||||
error "$msg"
|
local msg="Failed to start Dnsmasq, reason: $rc"
|
||||||
|
|
||||||
|
if [[ "${NETWORK,,}" == "slirp" || "${NETWORK,,}" == "passt" || "$ROOTLESS" != [Yy1]* || "$DEBUG" == [Yy1]* ]]; then
|
||||||
|
[ -f "$log" ] && [ -s "$log" ] && cat "$log"
|
||||||
|
error "$msg"
|
||||||
|
fi
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -218,11 +231,14 @@ getUserPorts() {
|
|||||||
|
|
||||||
for hostport in ${exclude//,/ }; do
|
for hostport in ${exclude//,/ }; do
|
||||||
|
|
||||||
local val="${hostport///tcp}"
|
local port="${hostport///tcp}"
|
||||||
|
port="${port///udp}"
|
||||||
|
|
||||||
if [[ "$num" == "${val///udp}" ]]; then
|
if [[ "$num" == "$port" ]]; then
|
||||||
num=""
|
num=""
|
||||||
warn "Could not assign port ${val///udp} to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
|
if [[ "$port" != "$WEB_PORT" ]]; then
|
||||||
|
warn "Could not assign port $port to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
@@ -232,14 +248,13 @@ getUserPorts() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Remove duplicates
|
# Remove duplicates
|
||||||
ports=$(echo "${ports//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
echo "${ports//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g'
|
||||||
|
|
||||||
echo "$ports"
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getSlirp() {
|
getSlirp() {
|
||||||
|
|
||||||
|
local ip="$1"
|
||||||
local args=""
|
local args=""
|
||||||
local list=""
|
local list=""
|
||||||
|
|
||||||
@@ -255,17 +270,15 @@ getSlirp() {
|
|||||||
proto="udp"
|
proto="udp"
|
||||||
num="${port%/udp}"
|
num="${port%/udp}"
|
||||||
elif [[ "$port" != *"/tcp" ]]; then
|
elif [[ "$port" != *"/tcp" ]]; then
|
||||||
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
args+="hostfwd=$proto::$num-$ip:$num,"
|
||||||
proto="udp"
|
proto="udp"
|
||||||
num="${port%/udp}"
|
num="${port%/udp}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
args+="hostfwd=$proto::$num-$ip:$num,"
|
||||||
done
|
done
|
||||||
|
|
||||||
args=$(echo "$args" | sed 's/,*$//g')
|
echo "$args" | sed 's/,*$//g'
|
||||||
|
|
||||||
echo "${args%?}"
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +299,7 @@ configureSlirp() {
|
|||||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
||||||
|
|
||||||
local forward=""
|
local forward=""
|
||||||
forward=$(getSlirp)
|
forward=$(getSlirp "$ip")
|
||||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
||||||
@@ -306,12 +319,9 @@ configurePasst() {
|
|||||||
NETWORK="passt"
|
NETWORK="passt"
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring user-mode networking..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring user-mode networking..."
|
||||||
|
|
||||||
local log="/var/log/passt.log"
|
local log="/tmp/passt.log"
|
||||||
rm -f "$log"
|
rm -f "$log"
|
||||||
|
|
||||||
local pid="/var/run/dnsmasq.pid"
|
|
||||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
|
||||||
|
|
||||||
local ip="$IP"
|
local ip="$IP"
|
||||||
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
||||||
|
|
||||||
@@ -343,7 +353,7 @@ configurePasst() {
|
|||||||
|
|
||||||
PASST_OPTS+=" -H $VM_NET_HOST"
|
PASST_OPTS+=" -H $VM_NET_HOST"
|
||||||
PASST_OPTS+=" -M $GATEWAY_MAC"
|
PASST_OPTS+=" -M $GATEWAY_MAC"
|
||||||
PASST_OPTS+=" -P /var/run/passt.pid"
|
PASST_OPTS+=" -P $PASST_PID"
|
||||||
PASST_OPTS+=" -l $log"
|
PASST_OPTS+=" -l $log"
|
||||||
PASST_OPTS+=" -q"
|
PASST_OPTS+=" -q"
|
||||||
|
|
||||||
@@ -353,7 +363,12 @@ configurePasst() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
PASST_OPTS=$(echo "$PASST_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
PASST_OPTS=$(echo "$PASST_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
|
||||||
|
if [[ "$DEBUG" == [Yy1]* || "$PASST_DEBUG" == [Yy1]* ]]; then
|
||||||
|
printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ ! -f "$PASST" ] && cp /usr/bin/passt* /run
|
||||||
|
|
||||||
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
||||||
|
|
||||||
@@ -362,7 +377,7 @@ configurePasst() {
|
|||||||
{ $PASST ${PASST_OPTS:+ $PASST_OPTS}; rc=$?; } || :
|
{ $PASST ${PASST_OPTS:+ $PASST_OPTS}; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
[ -f "$log" ] && cat "$log"
|
[ -f "$log" ] && [ -s "$log" ] && cat "$log"
|
||||||
warn "failed to start passt ($rc), falling back to slirp networking!"
|
warn "failed to start passt ($rc), falling back to slirp networking!"
|
||||||
configureSlirp && return 0 || return 1
|
configureSlirp && return 0 || return 1
|
||||||
fi
|
fi
|
||||||
@@ -373,7 +388,7 @@ configurePasst() {
|
|||||||
tail -fn +0 "$log" --pid=$$ &
|
tail -fn +0 "$log" --pid=$$ &
|
||||||
else
|
else
|
||||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||||
[ -f "$log" ] && cat "$log" && echo ""
|
[ -f "$log" ] && [ -s "$log" ] && cat "$log" && echo ""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -394,7 +409,6 @@ configureNAT() {
|
|||||||
|
|
||||||
# Create the necessary file structure for /dev/net/tun
|
# Create the necessary file structure for /dev/net/tun
|
||||||
if [ ! -c /dev/net/tun ]; then
|
if [ ! -c /dev/net/tun ]; then
|
||||||
[[ "$PODMAN" == [Yy1]* ]] && return 1
|
|
||||||
[ ! -d /dev/net ] && mkdir -m 755 /dev/net
|
[ ! -d /dev/net ] && mkdir -m 755 /dev/net
|
||||||
if mknod /dev/net/tun c 10 200; then
|
if mknod /dev/net/tun c 10 200; then
|
||||||
chmod 666 /dev/net/tun
|
chmod 666 /dev/net/tun
|
||||||
@@ -402,6 +416,7 @@ configureNAT() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -c /dev/net/tun ]; then
|
if [ ! -c /dev/net/tun ]; then
|
||||||
|
[[ "$ROOTLESS" == [Yy1]* && "$DEBUG" != [Yy1]* ]] && return 1
|
||||||
warn "$tuntap" && return 1
|
warn "$tuntap" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -409,6 +424,7 @@ configureNAT() {
|
|||||||
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
||||||
{ sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; rc=$?; } || :
|
{ sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; rc=$?; } || :
|
||||||
if (( rc != 0 )) || [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
if (( rc != 0 )) || [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
||||||
|
[[ "$ROOTLESS" == [Yy1]* && "$DEBUG" != [Yy1]* ]] && return 1
|
||||||
warn "IP forwarding is disabled. $ADD_ERR --sysctl net.ipv4.ip_forward=1"
|
warn "IP forwarding is disabled. $ADD_ERR --sysctl net.ipv4.ip_forward=1"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -435,6 +451,7 @@ configureNAT() {
|
|||||||
{ ip link add dev "$VM_NET_BRIDGE" type bridge ; rc=$?; } || :
|
{ ip link add dev "$VM_NET_BRIDGE" type bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
|
[[ "$ROOTLESS" == [Yy1]* && "$DEBUG" != [Yy1]* ]] && return 1
|
||||||
warn "failed to create bridge. $ADD_ERR --cap-add NET_ADMIN" && return 1
|
warn "failed to create bridge. $ADD_ERR --cap-add NET_ADMIN" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -449,6 +466,7 @@ configureNAT() {
|
|||||||
|
|
||||||
# QEMU Works with taps, set tap to the bridge created
|
# QEMU Works with taps, set tap to the bridge created
|
||||||
if ! ip tuntap add dev "$VM_NET_TAP" mode tap; then
|
if ! ip tuntap add dev "$VM_NET_TAP" mode tap; then
|
||||||
|
[[ "$ROOTLESS" == [Yy1]* && "$DEBUG" != [Yy1]* ]] && return 1
|
||||||
warn "$tuntap" && return 1
|
warn "$tuntap" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -471,7 +489,7 @@ configureNAT() {
|
|||||||
warn "failed to set master bridge!" && return 1
|
warn "failed to set master bridge!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if grep -wq "nf_tables" /proc/modules; then
|
if command -v iptables-nft >/dev/null 2>&1 && iptables-nft -V >/dev/null 2>&1; then
|
||||||
update-alternatives --set iptables /usr/sbin/iptables-nft > /dev/null
|
update-alternatives --set iptables /usr/sbin/iptables-nft > /dev/null
|
||||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-nft > /dev/null
|
update-alternatives --set ip6tables /usr/sbin/ip6tables-nft > /dev/null
|
||||||
else
|
else
|
||||||
@@ -489,8 +507,11 @@ configureNAT() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! iptables -t nat -A POSTROUTING -o "$VM_NET_DEV" -j MASQUERADE; then
|
if ! iptables -t nat -A POSTROUTING -o "$VM_NET_DEV" -j MASQUERADE > /dev/null 2>&1; then
|
||||||
warn "$tables" && return 1
|
[[ "$ROOTLESS" == [Yy1]* && "$DEBUG" != [Yy1]* ]] && return 1
|
||||||
|
if ! iptables -t nat -A POSTROUTING -o "$VM_NET_DEV" -j MASQUERADE; then
|
||||||
|
warn "$tables" && return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
@@ -524,23 +545,21 @@ configureNAT() {
|
|||||||
|
|
||||||
closeBridge() {
|
closeBridge() {
|
||||||
|
|
||||||
local pid="/var/run/dnsmasq.pid"
|
[ -s "$PASST_PID" ] && pKill "$(<"$PASST_PID")"
|
||||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
rm -f "$PASST_PID"
|
||||||
rm -f "$pid"
|
|
||||||
|
|
||||||
pid="/var/run/passt.pid"
|
[ -s "$DNSMASQ_PID" ] && pKill "$(<"$DNSMASQ_PID")"
|
||||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
rm -f "$DNSMASQ_PID"
|
||||||
rm -f "$pid"
|
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"user"* | "passt" | "slirp" ) return 0 ;;
|
"user"* | "passt" | "slirp" ) return 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off &> null || true
|
ip link set "$VM_NET_TAP" down promisc off &> /dev/null || true
|
||||||
ip link delete "$VM_NET_TAP" &> null || true
|
ip link delete "$VM_NET_TAP" &> /dev/null || true
|
||||||
|
|
||||||
ip link set "$VM_NET_BRIDGE" down &> null || true
|
ip link set "$VM_NET_BRIDGE" down &> /dev/null || true
|
||||||
ip link delete "$VM_NET_BRIDGE" &> null || true
|
ip link delete "$VM_NET_BRIDGE" &> /dev/null || true
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -586,9 +605,9 @@ closeNetwork() {
|
|||||||
cleanUp() {
|
cleanUp() {
|
||||||
|
|
||||||
# Clean up old files
|
# Clean up old files
|
||||||
|
rm -f "$PASST_PID"
|
||||||
|
rm -f "$DNSMASQ_PID"
|
||||||
rm -f /etc/resolv.dnsmasq
|
rm -f /etc/resolv.dnsmasq
|
||||||
rm -f /var/run/passt.pid
|
|
||||||
rm -f /var/run/dnsmasq.pid
|
|
||||||
|
|
||||||
if [[ -d "/sys/class/net/$VM_NET_TAP" ]]; then
|
if [[ -d "/sys/class/net/$VM_NET_TAP" ]]; then
|
||||||
info "Lingering interface will be removed..."
|
info "Lingering interface will be removed..."
|
||||||
@@ -600,21 +619,22 @@ cleanUp() {
|
|||||||
|
|
||||||
checkOS() {
|
checkOS() {
|
||||||
|
|
||||||
local kernel
|
|
||||||
local os=""
|
local os=""
|
||||||
local if="macvlan"
|
local kernel=""
|
||||||
|
local iface="macvlan"
|
||||||
|
|
||||||
kernel=$(uname -a)
|
kernel=$(uname -a)
|
||||||
|
|
||||||
[[ "${kernel,,}" == *"darwin"* ]] && os="$ENGINE Desktop for macOS"
|
[[ "${kernel,,}" == *"darwin"* ]] && os="$ENGINE Desktop for macOS"
|
||||||
[[ "${kernel,,}" == *"microsoft"* ]] && os="$ENGINE Desktop for Windows"
|
[[ "${kernel,,}" == *"microsoft"* ]] && os="$ENGINE Desktop for Windows"
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
if="macvtap"
|
iface="macvtap"
|
||||||
[[ "${kernel,,}" == *"synology"* ]] && os="Synology Container Manager"
|
[[ "${kernel,,}" == *"synology"* ]] && os="Synology Container Manager"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$os" ]; then
|
if [ -n "$os" ]; then
|
||||||
warn "you are using $os which does not support $if, please revert to bridge networking!"
|
warn "you are using $os which does not support $iface, please revert to bridge networking!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -628,7 +648,7 @@ getInfo() {
|
|||||||
[ -d "/sys/class/net/net1" ] && VM_NET_DEV="net1"
|
[ -d "/sys/class/net/net1" ] && VM_NET_DEV="net1"
|
||||||
[ -d "/sys/class/net/net2" ] && VM_NET_DEV="net2"
|
[ -d "/sys/class/net/net2" ] && VM_NET_DEV="net2"
|
||||||
[ -d "/sys/class/net/net3" ] && VM_NET_DEV="net3"
|
[ -d "/sys/class/net/net3" ] && VM_NET_DEV="net3"
|
||||||
# Automaticly detect the default network interface
|
# Automatically detect the default network interface
|
||||||
[ -z "$VM_NET_DEV" ] && VM_NET_DEV=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
|
[ -z "$VM_NET_DEV" ] && VM_NET_DEV=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
|
||||||
[ -z "$VM_NET_DEV" ] && VM_NET_DEV="eth0"
|
[ -z "$VM_NET_DEV" ] && VM_NET_DEV="eth0"
|
||||||
fi
|
fi
|
||||||
@@ -679,6 +699,20 @@ getInfo() {
|
|||||||
exit 29
|
exit 29
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if uname -a | grep -Eqi 'unraid|truenas'; then
|
||||||
|
|
||||||
|
# Check if host exposes the bridge-nf sysctl
|
||||||
|
# (only visible if br_netfilter is loaded and /proc/sys is accessible)
|
||||||
|
|
||||||
|
BNF="/proc/sys/net/bridge/bridge-nf-call-iptables"
|
||||||
|
|
||||||
|
if [[ -r "$BNF" ]] && [[ "$(cat "$BNF")" != "0" ]]; then
|
||||||
|
warn "external LAN clients may not be able to reach this container, because net.bridge.bridge-nf-call-iptables=1."
|
||||||
|
warn "you can fix this issue by running 'sysctl -w net.bridge.bridge-nf-call-iptables=0' on the host system."
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
if [[ "$IP" != "172."* && "$IP" != "10.8"* && "$IP" != "10.9"* ]]; then
|
if [[ "$IP" != "172."* && "$IP" != "10.8"* && "$IP" != "10.9"* ]]; then
|
||||||
@@ -697,7 +731,7 @@ getInfo() {
|
|||||||
[ -z "$MTU" ] && MTU="0"
|
[ -z "$MTU" ] && MTU="0"
|
||||||
|
|
||||||
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
||||||
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
if [[ "$MTU" != "0" ]] && [ "$MTU" -lt "1500" ]; then
|
||||||
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -710,6 +744,7 @@ getInfo() {
|
|||||||
# Generate MAC address based on Docker container ID in hostname
|
# Generate MAC address based on Docker container ID in hostname
|
||||||
VM_NET_MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/')
|
VM_NET_MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/')
|
||||||
echo "${VM_NET_MAC^^}" > "$file"
|
echo "${VM_NET_MAC^^}" > "$file"
|
||||||
|
! setOwner "$file" && error "Failed to set the owner for \"$file\" !"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -727,13 +762,6 @@ getInfo() {
|
|||||||
|
|
||||||
GATEWAY_MAC=$(echo "$VM_NET_MAC" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
|
GATEWAY_MAC=$(echo "$VM_NET_MAC" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
|
||||||
|
|
||||||
if [[ "$PODMAN" == [Yy1]* && "$DHCP" != [Yy1]* ]]; then
|
|
||||||
if [ -z "$NETWORK" ] || [[ "${NETWORK^^}" == "Y" ]]; then
|
|
||||||
# By default Podman has no permissions for NAT networking
|
|
||||||
NETWORK="user"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||||
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
||||||
[[ "$MTU" != "0" && "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
[[ "$MTU" != "0" && "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
||||||
@@ -788,22 +816,26 @@ else
|
|||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"passt" | "slirp" | "user"* ) ;;
|
"passt" | "slirp" | "user"* ) ;;
|
||||||
"tap" | "tun" | "tuntap" | "y" )
|
"tap" | "tun" | "tuntap" | "y" | "" )
|
||||||
|
|
||||||
# Configure tap interface
|
# Configure tap interface
|
||||||
if ! configureNAT; then
|
if ! configureNAT; then
|
||||||
|
|
||||||
closeBridge
|
closeBridge
|
||||||
NETWORK="user"
|
NETWORK="user"
|
||||||
msg="falling back to user-mode networking!"
|
|
||||||
msg="failed to setup NAT networking, $msg"
|
if [[ "$ROOTLESS" != [Yy1]* || "$DEBUG" == [Yy1]* ]]; then
|
||||||
|
msg="falling back to user-mode networking!"
|
||||||
|
msg="failed to setup NAT networking, $msg"
|
||||||
|
warn "$msg"
|
||||||
|
fi
|
||||||
|
|
||||||
fi ;;
|
fi ;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
"tap" | "tun" | "tuntap" | "y" ) ;;
|
"tap" | "tun" | "tuntap" | "y" | "" ) ;;
|
||||||
"passt" | "user"* )
|
"passt" | "user"* )
|
||||||
|
|
||||||
# Configure for user-mode networking (passt)
|
# Configure for user-mode networking (passt)
|
||||||
@@ -828,7 +860,7 @@ else
|
|||||||
"passt" | "slirp" )
|
"passt" | "slirp" )
|
||||||
|
|
||||||
if [ -z "$USER_PORTS" ]; then
|
if [ -z "$USER_PORTS" ]; then
|
||||||
info "Notice: because user-mode networking is active, if you need to expose ports, add them to the \"USER_PORTS\" variable."
|
info "Notice: because user-mode networking is active, when you need to forward custom ports to DSM, add them to the \"USER_PORTS\" variable."
|
||||||
fi ;;
|
fi ;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|||||||
+1
-3
@@ -10,8 +10,6 @@ API_CMD=6
|
|||||||
API_HOST="127.0.0.1:$COM_PORT"
|
API_HOST="127.0.0.1:$COM_PORT"
|
||||||
|
|
||||||
QEMU_TERM=""
|
QEMU_TERM=""
|
||||||
QEMU_DIR="/run/shm"
|
|
||||||
QEMU_PID="$QEMU_DIR/qemu.pid"
|
|
||||||
QEMU_LOG="$QEMU_DIR/qemu.log"
|
QEMU_LOG="$QEMU_DIR/qemu.log"
|
||||||
QEMU_OUT="$QEMU_DIR/qemu.out"
|
QEMU_OUT="$QEMU_DIR/qemu.out"
|
||||||
QEMU_END="$QEMU_DIR/qemu.end"
|
QEMU_END="$QEMU_DIR/qemu.end"
|
||||||
@@ -52,7 +50,7 @@ finish() {
|
|||||||
# Workaround for zombie pid
|
# Workaround for zombie pid
|
||||||
[ ! -s "$QEMU_PID" ] && break
|
[ ! -s "$QEMU_PID" ] && break
|
||||||
|
|
||||||
if [ "$cnt" == "5" ]; then
|
if [ "$cnt" -eq 5 ]; then
|
||||||
echo && error "QEMU did not terminate itself, forcefully killing process..."
|
echo && error "QEMU did not terminate itself, forcefully killing process..."
|
||||||
{ kill -9 "$pid" || true; } 2>/dev/null
|
{ kill -9 "$pid" || true; } 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|||||||
+3
-4
@@ -12,7 +12,7 @@ CLOCKSOURCE="tsc"
|
|||||||
CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource"
|
CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource"
|
||||||
|
|
||||||
if [ ! -f "$CLOCK" ]; then
|
if [ ! -f "$CLOCK" ]; then
|
||||||
warn "file \"$CLOCK\" cannot not found?"
|
warn "file \"$CLOCK\" cannot be found?"
|
||||||
else
|
else
|
||||||
result=$(<"$CLOCK")
|
result=$(<"$CLOCK")
|
||||||
result="${result//[![:print:]]/}"
|
result="${result//[![:print:]]/}"
|
||||||
@@ -33,9 +33,8 @@ if [[ "$KVM" != [Nn]* ]]; then
|
|||||||
KVM_OPTS=",accel=kvm -enable-kvm -global kvm-pit.lost_tick_policy=discard"
|
KVM_OPTS=",accel=kvm -enable-kvm -global kvm-pit.lost_tick_policy=discard"
|
||||||
|
|
||||||
if ! grep -qw "sse4_2" <<< "$flags"; then
|
if ! grep -qw "sse4_2" <<< "$flags"; then
|
||||||
info "Your CPU does not have the SSE4 instruction set that Virtual DSM requires, it will be emulated..."
|
error "Your CPU does not have the SSE4 instruction set that Virtual DSM requires!"
|
||||||
[ -z "$CPU_MODEL" ] && CPU_MODEL="qemu64"
|
[[ "$DEBUG" != [Yy1]* ]] && exit 88
|
||||||
CPU_FEATURES+=",+ssse3,+sse4.1,+sse4.2"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CPU_MODEL" ]; then
|
if [ -z "$CPU_MODEL" ]; then
|
||||||
|
|||||||
+52
-18
@@ -24,25 +24,47 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
|||||||
|
|
||||||
# Helper variables
|
# Helper variables
|
||||||
|
|
||||||
PODMAN="N"
|
ROOTLESS="N"
|
||||||
|
PRIVILEGED="N"
|
||||||
ENGINE="Docker"
|
ENGINE="Docker"
|
||||||
PROCESS="${APP,,}"
|
PROCESS="${APP,,}"
|
||||||
PROCESS="${PROCESS// /-}"
|
PROCESS="${PROCESS// /-}"
|
||||||
|
|
||||||
if [ -f "/run/.containerenv" ]; then
|
if [ -f "/run/.containerenv" ]; then
|
||||||
PODMAN="Y"
|
ENGINE="${container:-}"
|
||||||
ENGINE="Podman"
|
if [[ "${ENGINE,,}" == *"podman"* ]]; then
|
||||||
|
ROOTLESS="Y"
|
||||||
|
ENGINE="Podman"
|
||||||
|
else
|
||||||
|
[ -z "$ENGINE" ] && ENGINE="Kubernetes"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "❯ Starting $APP for $ENGINE v$(</run/version)..."
|
echo "❯ Starting $APP for $ENGINE v$(</run/version)..."
|
||||||
echo "❯ For support visit $SUPPORT"
|
echo "❯ For support visit $SUPPORT"
|
||||||
|
|
||||||
|
# Get the capability bounding set
|
||||||
|
CAP_BND=$(grep '^CapBnd:' /proc/$$/status | awk '{print $2}')
|
||||||
|
CAP_BND=$(printf "%d" "0x${CAP_BND}")
|
||||||
|
|
||||||
|
# Get the last capability number
|
||||||
|
LAST_CAP=$(cat /proc/sys/kernel/cap_last_cap)
|
||||||
|
|
||||||
|
# Calculate the maximum capability value
|
||||||
|
MAX_CAP=$(((1 << (LAST_CAP + 1)) - 1))
|
||||||
|
|
||||||
|
if [ "${CAP_BND}" -eq "${MAX_CAP}" ]; then
|
||||||
|
ROOTLESS="N"
|
||||||
|
PRIVILEGED="Y"
|
||||||
|
fi
|
||||||
|
|
||||||
INFO="/run/shm/msg.html"
|
INFO="/run/shm/msg.html"
|
||||||
PAGE="/run/shm/index.html"
|
PAGE="/run/shm/index.html"
|
||||||
TEMPLATE="/var/www/index.html"
|
TEMPLATE="/var/www/index.html"
|
||||||
FOOTER1="$APP for $ENGINE v$(</run/version)"
|
FOOTER1="$APP for $ENGINE v$(</run/version)"
|
||||||
FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
||||||
|
|
||||||
|
SOCKETS=1
|
||||||
CPU=$(cpu)
|
CPU=$(cpu)
|
||||||
SYS=$(uname -r)
|
SYS=$(uname -r)
|
||||||
HOST=$(hostname -s)
|
HOST=$(hostname -s)
|
||||||
@@ -51,35 +73,40 @@ MINOR=$(echo "$SYS" | cut -d '.' -f2)
|
|||||||
ARCH=$(dpkg --print-architecture)
|
ARCH=$(dpkg --print-architecture)
|
||||||
CORES=$(grep -c '^processor' /proc/cpuinfo)
|
CORES=$(grep -c '^processor' /proc/cpuinfo)
|
||||||
|
|
||||||
if ! grep -qi "socket(s)" <<< "$(lscpu)"; then
|
if grep -qi "socket(s)" <<< "$(lscpu)"; then
|
||||||
SOCKETS=1
|
SOCKETS=$(lscpu | grep -m 1 -i 'socket(s)' | awk '{print $2}')
|
||||||
else
|
[ -z "${SOCKETS##*[!0-9]*}" ] && SOCKETS=1
|
||||||
SOCKETS=$(lscpu | grep -m 1 -i 'socket(s)' | awk '{print $(2)}')
|
[ "$SOCKETS" -lt "1" ] && SOCKETS=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CPU_CORES="${CPU_CORES// /}"
|
CPU_CORES="${CPU_CORES// /}"
|
||||||
|
[ -z "$CPU_CORES" ] && CPU_CORES=2
|
||||||
[[ "${CPU_CORES,,}" == "max" ]] && CPU_CORES="$CORES"
|
[[ "${CPU_CORES,,}" == "max" ]] && CPU_CORES="$CORES"
|
||||||
[[ "${CPU_CORES,,}" == "half" ]] && CPU_CORES=$(( CORES / 2 ))
|
[[ "${CPU_CORES,,}" == "half" ]] && CPU_CORES=$(( CORES / 2 ))
|
||||||
[[ "${CPU_CORES,,}" == "0" ]] && CPU_CORES="1"
|
[ -z "${CPU_CORES##*[!0-9]*}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
||||||
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
|
||||||
|
|
||||||
|
[ "$CPU_CORES" -lt "1" ] && CPU_CORES=1
|
||||||
if [ "$CPU_CORES" -gt "$CORES" ]; then
|
if [ "$CPU_CORES" -gt "$CORES" ]; then
|
||||||
warn "The amount for CPU_CORES (${CPU_CORES}) exceeds the amount of logical cores available, so will be limited to ${CORES}."
|
warn "The amount for CPU_CORES (${CPU_CORES}) exceeds the amount of logical cores available (${CORES}) and will be limited."
|
||||||
CPU_CORES="$CORES"
|
CPU_CORES="$CORES"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check system
|
# Check system
|
||||||
|
|
||||||
|
QEMU_DIR="/run/shm"
|
||||||
|
|
||||||
if [ ! -d "/dev/shm" ]; then
|
if [ ! -d "/dev/shm" ]; then
|
||||||
error "Directory /dev/shm not found!" && exit 14
|
error "Directory /dev/shm not found!" && exit 14
|
||||||
else
|
else
|
||||||
[ ! -d "/run/shm" ] && ln -s /dev/shm /run/shm
|
[ ! -d "$QEMU_DIR" ] && ln -s /dev/shm "$QEMU_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
QEMU_PID="$QEMU_DIR/qemu.pid"
|
||||||
|
rm -f "$QEMU_PID"
|
||||||
|
|
||||||
# Check folder
|
# Check folder
|
||||||
|
|
||||||
if [[ "${COMMIT:-}" == [Yy1]* ]]; then
|
if [[ "${STORAGE,,}" != "/storage" ]]; then
|
||||||
STORAGE="/local"
|
|
||||||
mkdir -p "$STORAGE"
|
mkdir -p "$STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -88,7 +115,9 @@ if [ ! -d "$STORAGE" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -w "$STORAGE" ]; then
|
if [ ! -w "$STORAGE" ]; then
|
||||||
error "Storage folder ($STORAGE) is not writeable!" && exit 13
|
msg="Storage folder ($STORAGE) is not writeable!"
|
||||||
|
msg+=" If SELinux is active, you need to add the \":Z\" flag to the bind mount."
|
||||||
|
error "$msg" && exit 13
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check filesystem
|
# Check filesystem
|
||||||
@@ -100,12 +129,13 @@ if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Read memory
|
# Read memory
|
||||||
RAM_SPARE=500000000
|
|
||||||
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
||||||
RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
|
RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
|
||||||
|
|
||||||
|
RAM_SPARE=500000000
|
||||||
|
RAM_MINIMUM=136314880
|
||||||
RAM_SIZE="${RAM_SIZE// /}"
|
RAM_SIZE="${RAM_SIZE// /}"
|
||||||
[ -z "$RAM_SIZE" ] && error "RAM_SIZE not specified!" && exit 16
|
[ -z "$RAM_SIZE" ] && RAM_SIZE="2G"
|
||||||
|
|
||||||
if [[ "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
if [[ "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
||||||
|
|
||||||
@@ -115,8 +145,8 @@ if [[ "${RAM_SIZE,,}" != "max" && "${RAM_SIZE,,}" != "half" ]]; then
|
|||||||
|
|
||||||
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
! numfmt --from=iec "$RAM_SIZE" &>/dev/null && error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16
|
! numfmt --from=iec "$RAM_SIZE" &>/dev/null && error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16
|
||||||
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
wanted=$(numfmt --from=iec "$RAM_SIZE")
|
||||||
[ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
[ "$wanted" -lt "$RAM_MINIMUM" ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -165,6 +195,10 @@ if [[ "$KVM" != [Nn]* ]]; then
|
|||||||
if ! grep -qw "vmx\|svm" <<< "$flags"; then
|
if ! grep -qw "vmx\|svm" <<< "$flags"; then
|
||||||
KVM_ERR="(not enabled in BIOS)"
|
KVM_ERR="(not enabled in BIOS)"
|
||||||
fi
|
fi
|
||||||
|
if ! grep -qw "sse4_2" <<< "$flags"; then
|
||||||
|
error "Your CPU does not have the SSE4 instruction set that Virtual DSM requires!"
|
||||||
|
[[ "$DEBUG" != [Yy1]* ]] && exit 88
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
+34
-3
@@ -67,6 +67,37 @@ fKill() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOwner() {
|
||||||
|
local file="$1"
|
||||||
|
local dir uid gid
|
||||||
|
|
||||||
|
[ ! -f "$file" ] && return 1
|
||||||
|
|
||||||
|
dir=$(dirname -- "$file")
|
||||||
|
uid=$(stat -c '%u' "$dir")
|
||||||
|
gid=$(stat -c '%g' "$dir")
|
||||||
|
|
||||||
|
! chown "$uid:$gid" "$file" && return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
makeDir() {
|
||||||
|
local path="$1"
|
||||||
|
local dir uid gid
|
||||||
|
|
||||||
|
[ -d "$path" ] && return 0
|
||||||
|
! mkdir -p "$path" && return 1
|
||||||
|
|
||||||
|
dir=$(dirname -- "$path")
|
||||||
|
uid=$(stat -c '%u' "$dir")
|
||||||
|
gid=$(stat -c '%g' "$dir")
|
||||||
|
|
||||||
|
! chown "$uid:$gid" "$path" && return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
escape () {
|
escape () {
|
||||||
local s
|
local s
|
||||||
s=${1//&/\&}
|
s=${1//&/\&}
|
||||||
@@ -123,11 +154,11 @@ cpu() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cpu="${cpu// CPU/}"
|
cpu="${cpu// CPU/}"
|
||||||
cpu="${cpu// [0-9] Core}"
|
|
||||||
cpu="${cpu// [0-9][0-9] Core}"
|
|
||||||
cpu="${cpu// [0-9][0-9][0-9] Core}"
|
cpu="${cpu// [0-9][0-9][0-9] Core}"
|
||||||
cpu="${cpu//[0-9]th Gen }"
|
cpu="${cpu// [0-9][0-9] Core}"
|
||||||
|
cpu="${cpu// [0-9] Core}"
|
||||||
cpu="${cpu//[0-9][0-9]th Gen }"
|
cpu="${cpu//[0-9][0-9]th Gen }"
|
||||||
|
cpu="${cpu//[0-9]th Gen }"
|
||||||
cpu="${cpu// Processor/}"
|
cpu="${cpu// Processor/}"
|
||||||
cpu="${cpu// Quad core/}"
|
cpu="${cpu// Quad core/}"
|
||||||
cpu="${cpu// Dual core/}"
|
cpu="${cpu// Dual core/}"
|
||||||
|
|||||||
Reference in New Issue
Block a user