virtual-dsm/disk.sh

52 lines
2.2 KiB
Bash
Raw Normal View History

2023-04-02 21:43:28 +02:00
#!/usr/bin/env bash
set -eu
IMG="/storage"
BASE=$(basename "$URL" .pat)
FILE="$IMG/$BASE.boot.img"
[ ! -f "$FILE" ] && echo "ERROR: Virtual DSM boot-image does not exist ($FILE)" && exit 81
FILE="$IMG/$BASE.system.img"
[ ! -f "$FILE" ] && echo "ERROR: Virtual DSM system-image does not exist ($FILE)" && exit 82
2023-04-10 15:27:09 +02:00
DISK_SIZE=$(echo "${DISK_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
NEW_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
2023-04-02 21:43:28 +02:00
FILE="$IMG/data$DISK_SIZE.img"
if [ ! -f "$FILE" ]; then
2023-04-10 15:27:09 +02:00
truncate -s "${NEW_SIZE}" "${FILE}"
2023-04-13 20:46:49 +02:00
mkfs.btrfs -q -L data -d single -m dup "${FILE}" > /dev/null
2023-04-02 21:43:28 +02:00
#qemu-img convert -f raw -O qcow2 -o extended_l2=on,cluster_size=128k,compression_type=zstd,preallocation=metadata "$TMP" "$FILE"
fi
[ ! -f "$FILE" ] && echo "ERROR: Virtual DSM data-image does not exist ($FILE)" && exit 83
2023-04-10 15:27:09 +02:00
#OLD_SIZE=$(stat -c%s "${FILE}")
#
#if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
# echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes"
#
# if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then
# truncate -s "${NEW_SIZE}" "${FILE}"
# btrfs filesystem resize "${NEW_SIZE}" "${FILE}"
# fi
#
# if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then
# btrfs filesystem resize "${NEW_SIZE}" "${FILE}"
# truncate -s "${NEW_SIZE}" "${FILE}"
# fi
#fi
2023-04-02 21:43:28 +02:00
KVM_DISK_OPTS="\
2023-04-03 13:30:19 +02:00
-device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \
2023-04-08 03:56:48 +02:00
-drive file=${IMG}/${BASE}.boot.img,if=none,id=drive-synoboot,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
2023-04-08 00:15:17 +02:00
-device scsi-hd,bus=hw-synoboot.0,channel=0,scsi-id=0,lun=0,drive=drive-synoboot,id=synoboot0,rotation_rate=1,bootindex=1 \
2023-04-03 13:30:19 +02:00
-device virtio-scsi-pci,id=hw-synosys,bus=pcie.0,addr=0xb \
2023-04-08 03:56:48 +02:00
-drive file=${IMG}/${BASE}.system.img,if=none,id=drive-synosys,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
2023-04-08 00:15:17 +02:00
-device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,rotation_rate=1,bootindex=2 \
2023-04-03 13:30:19 +02:00
-device virtio-scsi-pci,id=hw-userdata,bus=pcie.0,addr=0xc \
2023-04-08 03:56:48 +02:00
-drive file=${IMG}/data${DISK_SIZE}.img,if=none,id=drive-userdata,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
2023-04-08 00:15:17 +02:00
-device scsi-hd,bus=hw-userdata.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata,id=userdata0,rotation_rate=1,bootindex=3"