[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#647607: live-build: binary_hdd partition size needs some thought



Tags: patch

Patch to correct.

Had to increase the percentage for filesystem overhead on ext
filesystems to 6% - 5% isn't quite enough in some cases - and fix the
losetup function so it handles the size of the partition as well as
the offset.
diff --git a/functions/losetup.sh b/functions/losetup.sh
index df3a97f..e29ec72 100755
--- a/functions/losetup.sh
+++ b/functions/losetup.sh
@@ -41,7 +41,7 @@ Losetup ()
 	PARTITION="${3:-1}"
 
 	${LB_ROOT_COMMAND} ${LB_LOSETUP} --read-only "${DEVICE}" "${FILE}"
-	FDISK_OUT="$(${LB_FDISK} -l -u ${DEVICE} 2>&1)"
+	FDISK_OUT="$(${LB_ROOT_COMMAND} ${LB_FDISK} -l -u ${DEVICE} 2>&1)"
 	Lodetach "${DEVICE}"
 
 	LOOPDEVICE="$(echo ${DEVICE}p${PARTITION})"
@@ -52,12 +52,12 @@ Losetup ()
 
 		${LB_ROOT_COMMAND} ${LB_LOSETUP} "${DEVICE}" "${FILE}"
 	else
-		SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")"
-		OFFSET="$(expr ${SECTORS} '*' 512)"
+		OFFSET="$(echo "$FDISK_OUT" | grep -m 1 "${LOOPDEVICE}" | awk '{print $2 * 512}')"
+		LENGTH="$(echo "$FDISK_OUT" | grep -m 1 "${LOOPDEVICE}" | awk '{print ($3 - $2 + 1) * 512}')"
 
-		Echo_message "Mounting %s with offset %s" "${DEVICE}" "${OFFSET}"
+		Echo_message "Mounting %s with offset %s and length of %s" "${DEVICE}" "${OFFSET}" "${LENGTH}"
 
-		${LB_ROOT_COMMAND} ${LB_LOSETUP} -o "${OFFSET}" "${DEVICE}" "${FILE}"
+		${LB_ROOT_COMMAND} ${LB_LOSETUP} -o "${OFFSET}" --sizelimit "${LENGTH}" "${DEVICE}" "${FILE}"
 	fi
 }
 
@@ -68,7 +68,7 @@ Calculate_partition_size ()
 
 	case "${FILESYSTEM}" in
 		ext2|ext3|ext4)
-			PERCENT="5"
+			PERCENT="6"
 			;;
 		*)
 			PERCENT="3"
diff --git a/scripts/build/lb_binary_hdd b/scripts/build/lb_binary_hdd
index aa6e497..17379d8 100755
--- a/scripts/build/lb_binary_hdd
+++ b/scripts/build/lb_binary_hdd
@@ -142,10 +142,12 @@ case "${LB_BINARY_FILESYSTEM}" in
 		;;
 esac
 
+# Partition sized to leave 64 x 512 byte sectors at the front and back of
+# the disk to allow for embedded bootloaders and GPT partitions.
 case "${LB_BUILD_WITH_CHROOT}" in
 	true)
-		Chroot chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
-		Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
+		Chroot chroot "parted -s -a none -- ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
+		Chroot chroot "parted -s -a none -- ${FREELO} mkpart primary ${PARTITION_TYPE} 64s -65s" || true
 
 		if [ "${LB_BOOTLOADER}" = "syslinux" ]
 		then
@@ -154,8 +156,8 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		;;
 
 	false)
-		parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE} || true
-		parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100% || true
+		parted -s -a none -- ${FREELO} mklabel ${PARTITION_TABLE_TYPE} || true
+		parted -s -a none -- ${FREELO} mkpart primary ${PARTITION_TYPE} 64s -65s || true
 
 		if [ "${LB_BOOTLOADER}" = "syslinux" ]
 		then

Reply to: