Loading disk.sh +28 −18 Original line number Diff line number Diff line Loading @@ -12,9 +12,9 @@ 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}") DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}") if (( NEW_SIZE < 6442450944 )); then if (( DATA_SIZE < 6442450944 )); then echo "ERROR: Please increase DISK_SIZE to at least 6 GB." && exit 83 fi Loading @@ -22,16 +22,26 @@ if [ -f "${DATA}" ]; then OLD_SIZE=$(stat -c%s "${DATA}") # Resize disk to new size if needed if [ "$DATA_SIZE" -gt "$OLD_SIZE" ]; then if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then echo "Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.." REQ=$((DATA_SIZE-OLD_SIZE)) # Check free diskspace SPACE=$(df --output=avail -B 1 "${IMG}" | tail -n 1) if (( REQ > SPACE )); then echo "ERROR: Not enough free space to resize virtual disk." && exit 84 fi if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then echo "ERROR: Could not allocate file for virtual disk." && exit 85 fi if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes.." fallocate -l "${NEW_SIZE}" "${DATA}" fi if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then echo "INFO: Shrinking existing disks is not supported yet!" echo "INFO: Creating backup of old drive in storage folder..." Loading @@ -39,7 +49,7 @@ if [ -f "${DATA}" ]; then mv -f "${DATA}" "${DATA}.bak" fi fi fi if [ ! -f "${DATA}" ]; then Loading @@ -47,19 +57,19 @@ 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 if (( DATA_SIZE > SPACE )); then echo "ERROR: Not enough free space to create virtual disk." && exit 86 fi # Create an empty file if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then rm -f "${DATA}" echo "ERROR: Could not allocate file for virtual disk." && exit 85 echo "ERROR: Could not allocate file for virtual disk." && exit 87 fi # Check if file exists if [ ! -f "${DATA}" ]; then echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 86 echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 88 fi # Format as BTRFS filesystem Loading Loading
disk.sh +28 −18 Original line number Diff line number Diff line Loading @@ -12,9 +12,9 @@ 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}") DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}") if (( NEW_SIZE < 6442450944 )); then if (( DATA_SIZE < 6442450944 )); then echo "ERROR: Please increase DISK_SIZE to at least 6 GB." && exit 83 fi Loading @@ -22,16 +22,26 @@ if [ -f "${DATA}" ]; then OLD_SIZE=$(stat -c%s "${DATA}") # Resize disk to new size if needed if [ "$DATA_SIZE" -gt "$OLD_SIZE" ]; then if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then echo "Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.." REQ=$((DATA_SIZE-OLD_SIZE)) # Check free diskspace SPACE=$(df --output=avail -B 1 "${IMG}" | tail -n 1) if (( REQ > SPACE )); then echo "ERROR: Not enough free space to resize virtual disk." && exit 84 fi if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then echo "ERROR: Could not allocate file for virtual disk." && exit 85 fi if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes.." fallocate -l "${NEW_SIZE}" "${DATA}" fi if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then echo "INFO: Shrinking existing disks is not supported yet!" echo "INFO: Creating backup of old drive in storage folder..." Loading @@ -39,7 +49,7 @@ if [ -f "${DATA}" ]; then mv -f "${DATA}" "${DATA}.bak" fi fi fi if [ ! -f "${DATA}" ]; then Loading @@ -47,19 +57,19 @@ 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 if (( DATA_SIZE > SPACE )); then echo "ERROR: Not enough free space to create virtual disk." && exit 86 fi # Create an empty file if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then rm -f "${DATA}" echo "ERROR: Could not allocate file for virtual disk." && exit 85 echo "ERROR: Could not allocate file for virtual disk." && exit 87 fi # Check if file exists if [ ! -f "${DATA}" ]; then echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 86 echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 88 fi # Format as BTRFS filesystem Loading