Unverified Commit 6ff05815 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Add full preallocation (writing zeroes)

parents 11e6b6b2 d94d6480
Loading
Loading
Loading
Loading
+36 −10
Original line number Diff line number Diff line
@@ -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,12 +45,22 @@ if [ -f "${DATA}" ]; then
        echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 84
      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

  if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then

@@ -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 [ "$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

+29 −3
Original line number Diff line number Diff line
@@ -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,11 +115,37 @@ if (( SYSTEM_SIZE > SPACE )); then
  echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87
fi

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: System disk has the wrong size: ${SIZE}" && exit 90
fi

PART="$TMP/partition.fdisk"

{	echo "label: dos"