This commit is contained in:
Kroese 2023-04-14 17:42:44 +02:00 committed by GitHub
parent 83cea7b77f
commit 76be4f69de

17
disk.sh
View file

@ -1,22 +1,21 @@
#!/usr/bin/env bash
set -eu
IMG="/storage"
FILE="$IMG/boot.img"
[ ! -f "$FILE" ] && echo "ERROR: Boot image does not exist ($FILE)" && exit 81
BOOT="$IMG/boot.img"
[ ! -f "$BOOT" ] && echo "ERROR: Boot image does not exist ($BOOT)" && exit 81
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}")
DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
FILE="$IMG/data${DISK_SIZE}.img"
[ ! -f "$FILE" ] && truncate -s "${NEW_SIZE}" "${FILE}"
[ ! -f "$FILE" ] && echo "ERROR: Data image does not exist ($FILE)" && exit 83
DATA="$IMG/data${DISK_SIZE}.img"
[ ! -f "$DATA" ] && truncate -s "${DATA_SIZE}" "${DATA}"
[ ! -f "$DATA" ] && echo "ERROR: Data image does not exist ($DATA)" && exit 83
KVM_DISK_OPTS="\
-drive id=cdrom0,if=none,format=raw,readonly=on,file=${IMG}/boot.img \
-drive id=cdrom0,if=none,format=raw,readonly=on,file=${BOOT} \
-device virtio-scsi-pci,id=scsi0 \
-device scsi-cd,bus=scsi0.0,drive=cdrom0 \
-device virtio-scsi-pci,id=hw-userdata,bus=pcie.0,addr=0xa \
-drive file=${IMG}/data${DISK_SIZE}.img,if=none,id=drive-userdata,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
-drive file=${DATA},if=none,id=drive-userdata,format=raw,cache=none,aio=native,discard=on,detect-zeroes=on \
-device scsi-hd,bus=hw-userdata.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata,id=userdata0,rotation_rate=1,bootindex=1"