fix: Device support (#552)

This commit is contained in:
Kroese 2024-01-12 18:01:20 +01:00 committed by GitHub
parent a407d2d94d
commit 6a0c708224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 38 deletions

View File

@ -188,6 +188,23 @@ 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. This can be used to enable the facial recognition function in Synology Photos for example.
* ### How do I passthrough a disk?
When running the container inside a virtualized environment, it is recommended to passthrough disk devices directly instead of binding folders containing images, as these devices are already based on an image.
This allows for easier management and higher performance. To do so, you can add those devices to your compose file:
```yaml
environment:
DEVICE: "/dev/sda"
DEVICE2: "/dev/sdb"
devices:
- /dev/sda
- /dev/sdb
```
Please beware that any existing data on the device will be wiped, as DSM will format its partition table during first use. Do NOT passthrough devices containing valueable data.
* ### How do I install a specific version of vDSM? * ### 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: 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:

View File

@ -401,6 +401,25 @@ addDisk () {
return 0 return 0
} }
addDevice () {
local DISK_ID=$1
local DISK_DEV=$2
local DISK_DESC=$3
local DISK_INDEX=$4
local DISK_ADDRESS=$5
[ -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-$DISK_ID,iothread=io2,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"
return 0
}
DISK_EXT="$(fmt2ext "$DISK_FMT")" || exit $? DISK_EXT="$(fmt2ext "$DISK_FMT")" || exit $?
if [[ "$ALLOCATE" == [Nn]* ]]; then if [[ "$ALLOCATE" == [Nn]* ]]; then
@ -444,52 +463,38 @@ if [ ! -f "$DISK3_FILE.img" ]; then
fi fi
DISK4_FILE="/storage4/data4" DISK4_FILE="/storage4/data4"
DISK5_FILE="/storage5/data5"
DISK6_FILE="/storage6/data6"
: ${DISK2_SIZE:=''} : ${DISK2_SIZE:=''}
: ${DISK3_SIZE:=''} : ${DISK3_SIZE:=''}
: ${DISK4_SIZE:=''} : ${DISK4_SIZE:=''}
: ${DISK5_SIZE:=''}
: ${DISK6_SIZE:=''}
addDisk "userdata" "$DISK1_FILE" "$DISK_EXT" "disk" "$DISK_SIZE" "3" "0xc" "$DISK_FMT" || exit $? : ${DEVICE:=''} # Docker variables to passthrough a block device, like /dev/vdc1.
addDisk "userdata2" "$DISK2_FILE" "$DISK_EXT" "disk2" "$DISK2_SIZE" "4" "0xd" "$DISK_FMT" || exit $?
addDisk "userdata3" "$DISK3_FILE" "$DISK_EXT" "disk3" "$DISK3_SIZE" "5" "0xe" "$DISK_FMT" || exit $?
addDisk "userdata4" "$DISK4_FILE" "$DISK_EXT" "disk4" "$DISK4_SIZE" "9" "0x7" "$DISK_FMT" || exit $?
addDisk "userdata5" "$DISK5_FILE" "$DISK_EXT" "disk5" "$DISK5_SIZE" "10" "0x8" "$DISK_FMT" || exit $?
addDisk "userdata6" "$DISK6_FILE" "$DISK_EXT" "disk6" "$DISK6_SIZE" "11" "0x9" "$DISK_FMT" || exit $?
addDevice () {
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-$DISK_ID,iothread=io2,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"
return 0
}
: ${DEVICE:=''} # Docker variable to passthrough a block device, like /dev/vdc1.
: ${DEVICE2:=''} : ${DEVICE2:=''}
: ${DEVICE3:=''} : ${DEVICE3:=''}
: ${DEVICE4:=''} : ${DEVICE4:=''}
: ${DEVICE5:=''}
: ${DEVICE6:=''}
addDevice "userdata7" "$DEVICE" "6" "0xf" || exit $? if [ -n "$DEVICE" ]; then
addDevice "userdata8" "$DEVICE2" "7" "0x5" || exit $? addDevice "userdata" "$DEVICE" "device" "3" "0xc" || exit $?
addDevice "userdata9" "$DEVICE3" "8" "0x6" || exit $? else
addDevice "userdata4" "$DEVICE4" "9" "0x7" || exit $? addDisk "userdata" "$DISK1_FILE" "$DISK_EXT" "disk" "$DISK_SIZE" "3" "0xc" "$DISK_FMT" || exit $?
addDevice "userdata5" "$DEVICE5" "10" "0x8" || exit $? fi
addDevice "userdata6" "$DEVICE6" "11" "0x9" || exit $?
if [ -n "$DEVICE2" ]; then
addDevice "userdata2" "$DEVICE2" "device2" "4" "0xd" || exit $?
else
addDisk "userdata2" "$DISK2_FILE" "$DISK_EXT" "disk2" "$DISK2_SIZE" "4" "0xd" "$DISK_FMT" || exit $?
fi
if [ -n "$DEVICE3" ]; then
addDevice "userdata3" "$DEVICE3" "device3" "5" "0xe" || exit $?
else
addDisk "userdata3" "$DISK3_FILE" "$DISK_EXT" "disk3" "$DISK3_SIZE" "5" "0xe" "$DISK_FMT" || exit $?
fi
if [ -n "$DEVICE4" ]; then
addDevice "userdata4" "$DEVICE4" "device4" "6" "0xf" || exit $?
else
addDisk "userdata4" "$DISK4_FILE" "$DISK_EXT" "disk4" "$DISK4_SIZE" "6" "0xf" "$DISK_FMT" || exit $?
fi
return 0 return 0