diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
index 57055cc..0d662cc 100755
--- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
+++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
@@ -22,24 +22,23 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
 	exit 1
 fi
 
-# this value is in blocks. Normally a block has 512 bytes.
-BUFFER_SIZE=32768
 BOOT_DEV_NAME=${BOOT_DEV##*/}
+LAST_PART_NAME="$(lsblk -l -o NAME "${BOOT_DEV}" | tail -1)"
+LAST_PART="/dev/${LAST_PART_NAME}"
+
 DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
-ALL_PARTS_SIZE=0
-for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"/"${BOOT_DEV_NAME}"*; do
-	PART_SIZE=$(cat "${PARTITION}"/size)
-	ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
-done
+LAST_PART_SIZE="$(cat /sys/class/block/"${LAST_PART_NAME}"/size)"
+LAST_PART_START="$(cat /sys/class/block/"${LAST_PART_NAME}"/start)"
+
+# The GUID partition table stores its backup in the last 33 blocks of the table.
+# Therefore the last partition ends 33 before the end of the disk if expanded.
+GPT_BACKUP_SIZE=33
 
-MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
-if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
+if [ $((LAST_PART_START + LAST_PART_SIZE + GPT_BACKUP_SIZE)) -lt "${DISK_SIZE}" ]; then
 	echo "Disk is practically already full, doing nothing." >&2
 	exit 0
 fi
 
-LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
-
 # Transform the partition table as follows:
 #
 # - Remove any 'last-lba' header so sfdisk uses the entire available space.
