mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 21:40:01 +08:00
Allow disk resizing
This commit is contained in:
parent
2bebca6c58
commit
ac023cc6ec
95
disk.sh
95
disk.sh
@ -7,52 +7,65 @@ SYSTEM="$IMG/$BASE.system.img"
|
|||||||
[ ! -f "$BOOT" ] && echo "ERROR: Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
[ ! -f "$BOOT" ] && echo "ERROR: Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
||||||
[ ! -f "$SYSTEM" ] && echo "ERROR: Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
[ ! -f "$SYSTEM" ] && echo "ERROR: Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
||||||
|
|
||||||
|
DATA="${IMG}/data.img"
|
||||||
DISK_SIZE=$(echo "${DISK_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
DISK_SIZE=$(echo "${DISK_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
|
|
||||||
|
[ -f "$IMG/data$DISK_SIZE.img" ] && mv -f "$IMG/data$DISK_SIZE.img" "${DATA}"
|
||||||
|
|
||||||
NEW_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
|
NEW_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
|
||||||
|
|
||||||
DATA="$IMG/data$DISK_SIZE.img"
|
if (( NEW_SIZE < 6442450944 )); then
|
||||||
|
echo "ERROR: Please increase DISK_SIZE to at least 6 GB." && exit 83
|
||||||
if [ ! -f "$DATA" ]; then
|
|
||||||
|
|
||||||
# Check free diskspace
|
|
||||||
SPACE=$(df --output=avail -B 1 "$IMG" | tail -n 1)
|
|
||||||
if (( NEW_SIZE > SPACE )); then
|
|
||||||
echo "ERROR: Not enough free space to create virtual disk." && exit 87
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create an empty file
|
|
||||||
if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then
|
|
||||||
rm -f "${DATA}"
|
|
||||||
echo "ERROR: Could not allocate file for virtual disk." && exit 88
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file exists
|
|
||||||
if [ ! -f "$DATA" ]; then
|
|
||||||
echo "ERROR: Virtual DSM data-image does not exist ($DATA)" && exit 83
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Format as BTRFS filesystem
|
|
||||||
mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Resizing requires mounting a loop device which in turn requires
|
if [ -f "${DATA}" ]; then
|
||||||
# the container to be privileged, so we must disable it for now.
|
|
||||||
#
|
OLD_SIZE=$(stat -c%s "${DATA}")
|
||||||
# OLD_SIZE=$(stat -c%s "${DATA}")
|
|
||||||
#
|
# Resize disk to new size if needed
|
||||||
# if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
|
|
||||||
# echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes"
|
if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
|
||||||
#
|
|
||||||
# if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then
|
if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then
|
||||||
# fallocate -l "${NEW_SIZE}" "${DATA}"
|
echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes.."
|
||||||
# btrfs filesystem resize "${NEW_SIZE}" "${DATA}"
|
fallocate -l "${NEW_SIZE}" "${DATA}"
|
||||||
# fi
|
fi
|
||||||
#
|
|
||||||
# if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then
|
if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then
|
||||||
# btrfs filesystem resize "${NEW_SIZE}" "${DATA}"
|
|
||||||
# fallocate -l "${NEW_SIZE}" "${DATA}"
|
echo "INFO: Shrinking existing disks is not supported yet!"
|
||||||
# fi
|
echo "INFO: Creating backup of old drive in storage folder..."
|
||||||
# fi
|
|
||||||
|
mv -f "${DATA}" "${DATA}.bak"
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "${DATA}" ]; then
|
||||||
|
|
||||||
|
# Check free diskspace
|
||||||
|
SPACE=$(df --output=avail -B 1 "${IMG}" | tail -n 1)
|
||||||
|
|
||||||
|
if (( NEW_SIZE > SPACE )); then
|
||||||
|
echo "ERROR: Not enough free space to create virtual disk." && exit 84
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create an empty file
|
||||||
|
if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then
|
||||||
|
rm -f "${DATA}"
|
||||||
|
echo "ERROR: Could not allocate file for virtual disk." && exit 85
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if file exists
|
||||||
|
if [ ! -f "${DATA}" ]; then
|
||||||
|
echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 86
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Format as BTRFS filesystem
|
||||||
|
mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
KVM_DISK_OPTS="\
|
KVM_DISK_OPTS="\
|
||||||
-device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \
|
-device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user