diff --git a/run/disk.sh b/run/disk.sh index a8960a0..86b9c08 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -29,7 +29,7 @@ if [ -f "${DATA}" ]; then echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.." - if [ "$ALLOCATE" != "Y" ]; then + if [ "$ALLOCATE" = "N" ]; then truncate -s "${DATA_SIZE}" "${DATA}"; @@ -45,10 +45,20 @@ if [ -f "${DATA}" ]; then echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 84 fi - if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - echo "ERROR: Could not allocate a file for the virtual disk." && exit 85 - fi + if [ "$ALLOCATE" = "Z" ]; then + GB=$(( (REQ + 1073741823)/1073741824 )) + echo "INFO: Writing ${GB} GB of zeroes, please wait.." + + dd if=/dev/zero of="${DATA}" seek="${OLD_SIZE}" count="${REQ}" bs=1M iflag=count_bytes oflag=seek_bytes + + else + + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + echo "ERROR: Could not allocate a file for the virtual disk." && exit 85 + fi + + fi fi fi @@ -66,7 +76,7 @@ if [ ! -f "${DATA}" ]; then # Create an empty file - if [ "$ALLOCATE" != "Y" ]; then + if [ "$ALLOCATE" = "N" ]; then truncate -s "${DATA_SIZE}" "${DATA}" @@ -80,16 +90,25 @@ if [ ! -f "${DATA}" ]; then echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 86 fi - if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - rm -f "${DATA}" - echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 - fi + if [ "$ALLOCATE" = "Z" ]; then + echo "INFO: Writing ${DISK_SIZE} of zeroes, please wait.." + + dd if=/dev/zero of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes + + else + + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + rm -f "${DATA}" + echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 + fi + + fi fi # Check if file exists if [ ! -f "${DATA}" ]; then - echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 88 + echo "ERROR: Virtual disk does not exist ($DATA)" && exit 88 fi # Format as BTRFS filesystem @@ -97,6 +116,13 @@ if [ ! -f "${DATA}" ]; then fi +# Check the filesize +SIZE=$(stat -c%s "${DATA}") + +if [[ SIZE -ne DATA_SIZE ]]; then + echo "ERROR: Virtual disk has the wrong size: ${SIZE}" && exit 89 +fi + AGENT="${STORAGE}/${BASE}.agent" [ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1 diff --git a/run/install.sh b/run/install.sh index b50a911..2e98307 100644 --- a/run/install.sh +++ b/run/install.sh @@ -106,7 +106,7 @@ unzip -q -o "$BOOT".zip -d $TMP echo "Install: Creating partition table..." SYSTEM="$TMP/sys.img" -SYSTEM_SIZE="4954537983" +SYSTEM_SIZE=4954537983 # Check free diskspace SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) @@ -115,9 +115,35 @@ if (( SYSTEM_SIZE > SPACE )); then echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 fi -if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then +if [ "$ALLOCATE" != "Z" ]; then + + # Cannot use truncate here because of swap partition + + if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then + rm -f "${SYSTEM}" + echo "ERROR: Could not allocate a file for the system disk." && exit 88 + fi + +else + + GB=$(( (SYSTEM_SIZE + 1073741823)/1073741824 )) + echo "INFO: Writing ${GB} GB of zeroes, please wait.." + + dd if=/dev/zero of="${SYSTEM}" count="${SYSTEM_SIZE}" bs=1M iflag=count_bytes + +fi + +# Check if file exists +if [ ! -f "${SYSTEM}" ]; then + echo "ERROR: System disk does not exist ($SYSTEM)" && exit 89 +fi + +# Check the filesize +SIZE=$(stat -c%s "${SYSTEM}") + +if [[ SIZE -ne SYSTEM_SIZE ]]; then rm -f "${SYSTEM}" - echo "ERROR: Could not allocate a file for the system disk." && exit 88 + echo "ERROR: System disk has the wrong size: ${SIZE}" && exit 90 fi PART="$TMP/partition.fdisk"