From ecaf2c27457cc77bb35a2778803ca4636f8a31b5 Mon Sep 17 00:00:00 2001 From: Chris Landa Date: Sat, 5 Mar 2016 14:07:32 +0100 Subject: Make the rootfs partition 20% bigger than the used size of the chroot directory --- rpi2-gen-image.sh | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/rpi2-gen-image.sh b/rpi2-gen-image.sh index ff677d2..1343d55 100755 --- a/rpi2-gen-image.sh +++ b/rpi2-gen-image.sh @@ -830,35 +830,42 @@ rm -f $R/var/lib/urandom/random-seed rm -f $R/etc/machine-id rm -fr $R/etc/apt/apt.conf.d/10proxy -# Calculate size of the chroot directory -CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'` / 1024) +# Calculate size of the chroot directory in KB +CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`) -# Calculate required image size -IMAGE_SIZE=`expr $(expr ${CHROOT_SIZE} / 1024 + 1) \* 1024` +# Calculate the amount of needed 512 Byte sectors +TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) +BOOT_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) +ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS}) -# Calculate number of sectors for the partition -IMAGE_SECTORS=`expr $(expr ${IMAGE_SIZE} \* 1048576) / 512 - 133120` +# The root partition is EXT4 +# This means more space than the actual used space of the chroot is used. +# As overhead for journaling and reserved blocks 20% are added. +ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512) + +# Calculate required image size in 512 Byte sectors +IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS} + ${ROOT_SECTORS}) # Prepare date string for image file name DATE="$(date +%Y-%m-%d)" # Prepare image file -dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=1M count=1 -dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=1M count=0 seek=${IMAGE_SIZE} +dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} +dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} # Write partition table -sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <