mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-06 18:13:43 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c70fa3d00a | ||
|
|
fea0ba09f6 | ||
|
|
7d2af63eac | ||
|
|
2e73bf560e | ||
|
|
bfc8d7a9c6 | ||
|
|
a1e9936572 |
31
compose.yml
31
compose.yml
@@ -1,16 +1,17 @@
|
|||||||
services:
|
services:
|
||||||
dsm:
|
dsm:
|
||||||
container_name: dsm
|
container_name: dsm
|
||||||
image: vdsm/virtual-dsm:latest
|
image: vdsm/virtual-dsm
|
||||||
environment:
|
environment:
|
||||||
DISK_SIZE: "16G"
|
DISK_SIZE: "16G"
|
||||||
devices:
|
devices:
|
||||||
- /dev/kvm
|
- /dev/kvm
|
||||||
- /dev/net/tun
|
- /dev/net/tun
|
||||||
cap_add:
|
cap_add:
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
ports:
|
ports:
|
||||||
- 5000:5000
|
- 5000:5000
|
||||||
volumes:
|
volumes:
|
||||||
- /var/dsm:/storage
|
- ./dsm:/storage
|
||||||
stop_grace_period: 2m
|
restart: always
|
||||||
|
stop_grace_period: 2m
|
||||||
|
|||||||
@@ -10,58 +10,68 @@ spec:
|
|||||||
requests:
|
requests:
|
||||||
storage: 16Gi
|
storage: 16Gi
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: apps/v1
|
||||||
kind: Pod
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: dsm
|
name: dsm
|
||||||
labels:
|
labels:
|
||||||
name: dsm
|
name: dsm
|
||||||
spec:
|
spec:
|
||||||
containers:
|
replicas: 1
|
||||||
- name: dsm
|
selector:
|
||||||
image: vdsm/virtual-dsm
|
matchLabels:
|
||||||
env:
|
app: dsm
|
||||||
- name: RAM_SIZE
|
template:
|
||||||
value: "1G"
|
metadata:
|
||||||
- name: CPU_CORES
|
labels:
|
||||||
value: "1"
|
app: dsm
|
||||||
- name: DISK_SIZE
|
spec:
|
||||||
value: "16G"
|
containers:
|
||||||
ports:
|
- name: dsm
|
||||||
- containerPort: 5000
|
image: vdsm/virtual-dsm
|
||||||
securityContext:
|
env:
|
||||||
capabilities:
|
- name: DISK_SIZE
|
||||||
add:
|
value: "16G"
|
||||||
- NET_ADMIN
|
ports:
|
||||||
privileged: true
|
- containerPort: 5000
|
||||||
volumeMounts:
|
name: http
|
||||||
- mountPath: /storage
|
protocol: TCP
|
||||||
name: storage
|
securityContext:
|
||||||
- mountPath: /dev/kvm
|
capabilities:
|
||||||
name: dev-kvm
|
add:
|
||||||
- mountPath: /dev/net/tun
|
- NET_ADMIN
|
||||||
name: dev-tun
|
privileged: true
|
||||||
terminationGracePeriodSeconds: 120
|
volumeMounts:
|
||||||
volumes:
|
- mountPath: /storage
|
||||||
- name: storage
|
name: storage
|
||||||
persistentVolumeClaim:
|
- mountPath: /dev/kvm
|
||||||
claimName: dsm-pvc
|
name: dev-kvm
|
||||||
- hostPath:
|
- mountPath: /dev/net/tun
|
||||||
path: /dev/kvm
|
name: dev-tun
|
||||||
name: dev-kvm
|
terminationGracePeriodSeconds: 120
|
||||||
- hostPath:
|
volumes:
|
||||||
path: /dev/net/tun
|
- name: storage
|
||||||
type: CharDevice
|
persistentVolumeClaim:
|
||||||
name: dev-tun
|
claimName: dsm-pvc
|
||||||
|
- hostPath:
|
||||||
|
path: /dev/kvm
|
||||||
|
name: dev-kvm
|
||||||
|
- hostPath:
|
||||||
|
path: /dev/net/tun
|
||||||
|
type: CharDevice
|
||||||
|
name: dev-tun
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: dsm
|
name: dsm
|
||||||
spec:
|
spec:
|
||||||
|
internalTrafficPolicy: Cluster
|
||||||
ports:
|
ports:
|
||||||
- name: tcp-5000
|
- name: http
|
||||||
port: 5000
|
port: 5000
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 5000
|
||||||
selector:
|
selector:
|
||||||
name: dsm
|
app: dsm
|
||||||
type: NodePort
|
type: ClusterIP
|
||||||
|
|||||||
25
readme.md
25
readme.md
@@ -39,7 +39,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 5000:5000
|
- 5000:5000
|
||||||
volumes:
|
volumes:
|
||||||
- /var/dsm:/storage
|
- ./dsm:/storage
|
||||||
restart: always
|
restart: always
|
||||||
stop_grace_period: 2m
|
stop_grace_period: 2m
|
||||||
```
|
```
|
||||||
@@ -47,7 +47,7 @@ services:
|
|||||||
Via Docker CLI:
|
Via Docker CLI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -it --rm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN --stop-timeout 120 vdsm/virtual-dsm
|
docker run -it --rm --name dsm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v ${PWD:-.}/dsm:/storage --stop-timeout 120 vdsm/virtual-dsm
|
||||||
```
|
```
|
||||||
|
|
||||||
Via Kubernetes:
|
Via Kubernetes:
|
||||||
@@ -84,10 +84,10 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
volumes:
|
volumes:
|
||||||
- /var/dsm:/storage
|
- ./dsm:/storage
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace the example path `/var/dsm` with the desired storage folder.
|
Replace the example path `./dsm` with the desired storage folder or named volume.
|
||||||
|
|
||||||
### How do I change the size of the disk?
|
### How do I change the size of the disk?
|
||||||
|
|
||||||
@@ -112,9 +112,6 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
DISK_FMT: "qcow2"
|
DISK_FMT: "qcow2"
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
> This may reduce the write performance of the disk.
|
|
||||||
|
|
||||||
### How do I add multiple disks?
|
### How do I add multiple disks?
|
||||||
|
|
||||||
To create additional disks, modify your compose file like this:
|
To create additional disks, modify your compose file like this:
|
||||||
@@ -124,8 +121,8 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
DISK2_SIZE: "32G"
|
DISK2_SIZE: "32G"
|
||||||
DISK3_SIZE: "64G"
|
DISK3_SIZE: "64G"
|
||||||
volumes:
|
volumes:
|
||||||
- /home/example:/storage2
|
- ./example2:/storage2
|
||||||
- /mnt/data/example:/storage3
|
- ./example3:/storage3
|
||||||
```
|
```
|
||||||
|
|
||||||
### How do I pass-through a disk?
|
### How do I pass-through a disk?
|
||||||
@@ -245,19 +242,19 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
- /dev/dri
|
- /dev/dri
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!TIP]
|
> [!NOTE]
|
||||||
> This can be used to enable the facial recognition function in Synology Photos for example.
|
> This can be used to enable the facial recognition function in Synology Photos, but does not provide hardware transcoding for video.
|
||||||
|
|
||||||
### How do I install a specific version of vDSM?
|
### How do I install a specific version of vDSM?
|
||||||
|
|
||||||
By default, version 7.2 will be installed, but if you prefer an older version, you can add its download URL to your compose file as follows:
|
By default, version 7.2 will be installed, but if you prefer an older version, you can add the download URL of the `.pat` file to your compose file as follows:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
URL: "https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
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.
|
With this method, it is even possible to switch back and forth between versions while keeping your file data intact.
|
||||||
|
|
||||||
If you don't have internet access, it's also possible to skip the download by setting URL to:
|
If you don't have internet access, it's also possible to skip the download by setting URL to:
|
||||||
|
|
||||||
@@ -266,7 +263,7 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
URL: "DSM_VirtualDSM_42218.pat"
|
URL: "DSM_VirtualDSM_42218.pat"
|
||||||
```
|
```
|
||||||
|
|
||||||
after placing a file called `DSM_VirtualDSM_42218.pat` in your `/storage` folder.
|
after placing a copy of [DSM_VirtualDSM_42218.pat](https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat) in the root of your `/storage` folder.
|
||||||
|
|
||||||
### What are the differences compared to the standard DSM?
|
### What are the differences compared to the standard DSM?
|
||||||
|
|
||||||
|
|||||||
@@ -427,12 +427,13 @@ addDisk () {
|
|||||||
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
||||||
DISK_SPACE=$(echo "${DISK_SPACE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
DISK_SPACE=$(echo "${DISK_SPACE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
[[ -z "${DISK_SPACE//[0-9]}" ]] && DISK_SPACE="${DISK_SPACE}G"
|
[[ -z "${DISK_SPACE//[0-9]}" ]] && DISK_SPACE="${DISK_SPACE}G"
|
||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
|
||||||
|
|
||||||
if (( DATA_SIZE < 1 )); then
|
if ! numfmt --from=iec "$DISK_SPACE" &>/dev/null; then
|
||||||
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
|
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
|
|
||||||
if (( DATA_SIZE < 6442450944 )); then
|
if (( DATA_SIZE < 6442450944 )); then
|
||||||
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
|
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -59,8 +59,10 @@ configureDHCP() {
|
|||||||
fi ;;
|
fi ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
|
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
|
||||||
warn "Failed to set MTU size.."
|
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
|
||||||
|
warn "Failed to set MTU size.."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while ! ip link set "$VM_NET_TAP" up; do
|
while ! ip link set "$VM_NET_TAP" up; do
|
||||||
@@ -197,7 +199,6 @@ configureNAT() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a bridge with a static IP for the VM guest
|
# Create a bridge with a static IP for the VM guest
|
||||||
|
|
||||||
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
@@ -218,8 +219,10 @@ configureNAT() {
|
|||||||
error "$tuntap" && return 1
|
error "$tuntap" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
|
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
|
||||||
warn "Failed to set MTU size.."
|
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
|
||||||
|
warn "Failed to set MTU size.."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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/')
|
||||||
@@ -275,6 +278,22 @@ configureNAT() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeBridge() {
|
||||||
|
|
||||||
|
local pid="/var/run/dnsmasq.pid"
|
||||||
|
[ -s "$pid" ] && pKill "$(<"$pid")"
|
||||||
|
|
||||||
|
[[ "${NETWORK,,}" == "user"* ]] && return 0
|
||||||
|
|
||||||
|
ip link set "$VM_NET_TAP" down promisc off &> null || true
|
||||||
|
ip link delete "$VM_NET_TAP" &> null || true
|
||||||
|
|
||||||
|
ip link set dockerbridge down &> null || true
|
||||||
|
ip link delete dockerbridge &> null || true
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
closeNetwork() {
|
closeNetwork() {
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
@@ -290,26 +309,16 @@ closeNetwork() {
|
|||||||
exec 30<&- || true
|
exec 30<&- || true
|
||||||
exec 40<&- || true
|
exec 40<&- || true
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" != [Yy1]* ]]; then
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down || true
|
closeBridge
|
||||||
ip link delete "$VM_NET_TAP" || true
|
return 0
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
local pid="/var/run/dnsmasq.pid"
|
|
||||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
|
||||||
|
|
||||||
[[ "${NETWORK,,}" == "user"* ]] && return 0
|
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off || true
|
|
||||||
ip link delete "$VM_NET_TAP" || true
|
|
||||||
|
|
||||||
ip link set dockerbridge down || true
|
|
||||||
ip link delete dockerbridge || true
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ip link set "$VM_NET_TAP" down || true
|
||||||
|
ip link delete "$VM_NET_TAP" || true
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,6 +366,16 @@ getInfo() {
|
|||||||
MTU=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
|
MTU=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$MTU" -gt "1500" ]; then
|
||||||
|
info "MTU size is too large: $MTU, ignoring..." && MTU="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
||||||
|
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
|
||||||
|
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$VM_NET_MAC" ]; then
|
if [ -z "$VM_NET_MAC" ]; then
|
||||||
local file="$STORAGE/dsm.mac"
|
local file="$STORAGE/dsm.mac"
|
||||||
[ -s "$file" ] && VM_NET_MAC=$(<"$file")
|
[ -s "$file" ] && VM_NET_MAC=$(<"$file")
|
||||||
@@ -399,7 +418,10 @@ getInfo
|
|||||||
html "Initializing network..."
|
html "Initializing network..."
|
||||||
|
|
||||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||||
info "Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $MTU"
|
mtu=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
|
||||||
|
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
||||||
|
[[ "$MTU" != "0" ]] && [[ "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
||||||
|
info "$line"
|
||||||
[ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf
|
[ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
@@ -442,15 +464,10 @@ else
|
|||||||
# Configure for tap interface
|
# Configure for tap interface
|
||||||
if ! configureNAT; then
|
if ! configureNAT; then
|
||||||
|
|
||||||
|
closeBridge
|
||||||
NETWORK="user"
|
NETWORK="user"
|
||||||
warn "falling back to usermode networking! Performance will be bad and port mapping will not work."
|
warn "falling back to usermode networking! Performance will be bad and port mapping will not work."
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off &> null || true
|
|
||||||
ip link delete "$VM_NET_TAP" &> null || true
|
|
||||||
|
|
||||||
ip link set dockerbridge down &> null || true
|
|
||||||
ip link delete dockerbridge &> null || true
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
@@ -464,6 +481,7 @@ else
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NET_OPTS+=" -device $ADAPTER,romfile=,netdev=hostnet0,mac=$VM_NET_MAC,host_mtu=$MTU,id=net0"
|
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
||||||
|
[[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]] && NET_OPTS+=",host_mtu=$MTU"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ 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_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')
|
||||||
|
[[ -z ${RAM_SIZE//[0-9]} ]] && [ "$RAM_SIZE" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G"
|
||||||
|
! numfmt --from=iec "$RAM_SIZE" &>/dev/null && error "Invalid RAM size: $RAM_SIZE" && exit 15
|
||||||
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
||||||
|
[ "$RAM_WANTED" -lt "136314880 " ] && error "Invalid RAM size: $RAM_SIZE" && exit 16
|
||||||
|
|
||||||
AVAIL_GB=$(( RAM_AVAIL/1073741824 ))
|
AVAIL_GB=$(( RAM_AVAIL/1073741824 ))
|
||||||
TOTAL_GB=$(( (RAM_TOTAL + 1073741823)/1073741824 ))
|
TOTAL_GB=$(( (RAM_TOTAL + 1073741823)/1073741824 ))
|
||||||
WANTED_GB=$(( (RAM_WANTED + 1073741823)/1073741824 ))
|
WANTED_GB=$(( (RAM_WANTED + 1073741823)/1073741824 ))
|
||||||
|
|||||||
Reference in New Issue
Block a user