2023-04-03 02:43:28 +07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
|
2023-04-14 22:39:21 +07:00
|
|
|
BOOT="$IMG/$BASE.boot.img"
|
|
|
|
[ ! -f "$BOOT" ] && echo "ERROR: Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
2023-04-03 02:43:28 +07:00
|
|
|
|
2023-04-14 22:39:21 +07:00
|
|
|
SYSTEM="$IMG/$BASE.system.img"
|
|
|
|
[ ! -f "$SYSTEM" ] && echo "ERROR: Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
2023-04-03 02:43:28 +07:00
|
|
|
|
2023-04-10 20:27:09 +07: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-14 22:39:21 +07:00
|
|
|
DATA="$IMG/data$DISK_SIZE.img"
|
2023-04-03 02:43:28 +07:00
|
|
|
|
2023-04-14 22:39:21 +07:00
|
|
|
if [ ! -f "$DATA" ]; then
|
2023-04-14 05:01:42 +07:00
|
|
|
# Create an empty file
|
2023-04-15 07:15:18 +07:00
|
|
|
if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then
|
|
|
|
rm -f "${DATA}"
|
|
|
|
echo "ERROR: Not enough free space to create virtual disk." && exit 88
|
|
|
|
fi
|
2023-04-14 05:01:42 +07:00
|
|
|
# Format as BTRFS filesystem
|
2023-04-14 22:39:21 +07:00
|
|
|
mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
|
2023-04-03 02:43:28 +07:00
|
|
|
fi
|
|
|
|
|
2023-04-14 22:39:21 +07:00
|
|
|
[ ! -f "$DATA" ] && echo "ERROR: Virtual DSM data-image does not exist ($DATA)" && exit 83
|
2023-04-03 02:43:28 +07:00
|
|
|
|
2023-04-14 05:01:42 +07:00
|
|
|
# Resizing requires mounting a loop device which in turn requires
|
|
|
|
# the container to be privileged, so we must disable it for now.
|
2023-04-10 20:27:09 +07:00
|
|
|
#
|
2023-04-14 22:39:21 +07:00
|
|
|
# OLD_SIZE=$(stat -c%s "${DATA}")
|
2023-04-10 20:27:09 +07:00
|
|
|
#
|
2023-04-14 05:01:42 +07:00
|
|
|
# if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
|
|
|
|
# echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes"
|
2023-04-10 20:27:09 +07:00
|
|
|
#
|
2023-04-14 05:01:42 +07:00
|
|
|
# if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then
|
2023-04-14 22:39:21 +07:00
|
|
|
# truncate -s "${NEW_SIZE}" "${DATA}"
|
|
|
|
# btrfs filesystem resize "${NEW_SIZE}" "${DATA}"
|
2023-04-14 05:01:42 +07:00
|
|
|
# fi
|
|
|
|
#
|
|
|
|
# if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then
|
2023-04-14 22:39:21 +07:00
|
|
|
# btrfs filesystem resize "${NEW_SIZE}" "${DATA}"
|
|
|
|
# truncate -s "${NEW_SIZE}" "${DATA}"
|
2023-04-14 05:01:42 +07:00
|
|
|
# fi
|
|
|
|
# fi
|
2023-04-10 20:27:09 +07:00
|
|
|
|
2023-04-03 02:43:28 +07:00
|
|
|
KVM_DISK_OPTS="\
|
2023-04-03 18:30:19 +07:00
|
|
|
-device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \
|
2023-04-14 22:39:21 +07:00
|
|
|
-drive file=${BOOT},if=none,id=drive-synoboot,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
|
2023-04-08 05:15:17 +07: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 18:30:19 +07:00
|
|
|
-device virtio-scsi-pci,id=hw-synosys,bus=pcie.0,addr=0xb \
|
2023-04-14 22:39:21 +07:00
|
|
|
-drive file=${SYSTEM},if=none,id=drive-synosys,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
|
2023-04-08 05:15:17 +07: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 18:30:19 +07:00
|
|
|
-device virtio-scsi-pci,id=hw-userdata,bus=pcie.0,addr=0xc \
|
2023-04-14 22:39:21 +07:00
|
|
|
-drive file=${DATA},if=none,id=drive-userdata,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
|
2023-04-08 05:15:17 +07: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"
|