Skip to content

Commit

Permalink
feat: Add automatic device type (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese committed May 27, 2024
1 parent fb1751f commit c135c4c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
9 changes: 4 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ kubectl apply -f kubernetes.yml

* ### How do I pass-through a disk?

It is possible to pass-through disk devices directly by adding them to your compose file in this way:
It is possible to pass-through a disk device directly, by adding it to your compose file in this way:

```yaml
devices:
- /dev/disk/by-uuid/12345-12345-12345-12345-12345:/disk2
- /dev/disk/by-uuid/45678-45678-45678-45678-45678:/disk3
```

Make sure to bind the disk via its UUID (obtainable via `lsblk -o name,uuid`) instead of its name (`/dev/sdc`), to prevent ever binding the wrong disk when the drive letters happen to change.
Expand All @@ -129,11 +128,11 @@ kubectl apply -f kubernetes.yml

Do NOT use this feature with the goal of sharing files from the host, they will all be lost without warning when DSM creates the volume.

* ### How do I increase the amount of CPU or RAM?
* ### How do I change the amount of CPU or RAM?

By default, a single CPU core and 1 GB of RAM are allocated to the container.
By default, the container will be allowed to use a maximum of 1 CPU core and 1 GB of RAM.

If there arises a need to increase this, add the following environment variables:
If you want to adjust this, you can specify the desired amount using the following environment variables:

```yaml
environment:
Expand Down
2 changes: 1 addition & 1 deletion src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -Eeuo pipefail
DEF_OPTS="-nodefaults -boot strict=on"
RAM_OPTS=$(echo "-m ${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
CPU_OPTS="-cpu $CPU_FLAGS -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1"
MAC_OPTS="-machine type=q35,usb=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
MAC_OPTS="-machine type=q35,smm=off,usb=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
DEV_OPTS="$DEV_OPTS -object rng-random,id=objrng0,filename=/dev/urandom"
DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
Expand Down
15 changes: 9 additions & 6 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,29 @@ createDevice () {

local index=""
[ -n "$DISK_INDEX" ] && index=",bootindex=$DISK_INDEX"
local result="-drive file=$DISK_FILE,id=$DISK_ID,if=none,format=$DISK_FMT,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on"
local result="-drive file=$DISK_FILE,id=$DISK_ID,format=$DISK_FMT,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on"

case "${DISK_TYPE,,}" in
"auto" )
echo "$result"
;;
"usb" )
result="$result \
result="$result,if=none \
-device usb-storage,drive=${DISK_ID}${index}"
echo "$result"
;;
"ide" )
result="$result \
result="$result,if=none \
-device ide-hd,drive=${DISK_ID},bus=ide.$DISK_INDEX,rotation_rate=$DISK_ROTATION${index}"
echo "$result"
;;
"blk" | "virtio-blk" )
result="$result \
result="$result,if=none \
-device virtio-blk-pci,drive=${DISK_ID},scsi=off,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2${index}"
echo "$result"
;;
"scsi" | "virtio-scsi" )
result="$result \
result="$result,if=none \
-device virtio-scsi-pci,id=${DISK_ID}b,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2 \
-device scsi-hd,drive=${DISK_ID},bus=${DISK_ID}b.0,channel=0,scsi-id=0,lun=0,rotation_rate=$DISK_ROTATION${index}"
echo "$result"
Expand Down Expand Up @@ -480,7 +483,7 @@ html "Initializing disks..."

case "${DISK_TYPE,,}" in
"" ) DISK_TYPE="scsi" ;;
"ide" | "usb" | "blk" | "scsi" ) ;;
"auto" | "ide" | "usb" | "blk" | "scsi" ) ;;
* ) error "Invalid DISK_TYPE, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
esac

Expand Down
2 changes: 1 addition & 1 deletion src/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ tail -fn +0 "$QEMU_LOG" 2>/dev/null &
cat "$QEMU_TERM" 2>/dev/null & wait $! || :

sleep 1 & wait $!
finish 0
[ ! -f "$QEMU_END" ] && finish 0
6 changes: 3 additions & 3 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ if [[ "$DHCP" == [Yy1]* ]]; then

! checkOS && [[ "$DEBUG" != [Yy1]* ]] && exit 19

if [[ "$GATEWAY" == "172."* ]]; then
warn "your gateway IP starts with 172.* which is often a sign that you are not on a macvlan network (required for DHCP)!"
if [[ "$IP" == "172."* ]]; then
warn "container IP starts with 172.* which is often a sign that you are not on a macvlan network (required for DHCP)!"
fi

# Configuration for DHCP IP
Expand All @@ -341,7 +341,7 @@ if [[ "$DHCP" == [Yy1]* ]]; then

else

if [[ "$GATEWAY" != "172."* ]] && [[ "$GATEWAY" != "10.8"* ]] && [[ "$GATEWAY" != "10.9"* ]]; then
if [[ "$IP" != "172."* ]] && [[ "$IP" != "10.8"* ]] && [[ "$IP" != "10.9"* ]]; then
! checkOS && [[ "$DEBUG" != [Yy1]* ]] && exit 19
fi

Expand Down
3 changes: 2 additions & 1 deletion src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ HOST=$(hostname -s)
KERNEL=$(echo "$SYS" | cut -b 1)
MINOR=$(echo "$SYS" | cut -d '.' -f2)
ARCH=$(dpkg --print-architecture)
CPU=$(lscpu | grep -m 1 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
SOCKETS=$(lscpu | grep -m 1 -i 'socket(s)' | awk '{print $(2)}')
CPU=$(lscpu | grep -m 1 -i 'model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')

# Check system

Expand Down

0 comments on commit c135c4c

Please sign in to comment.