##// END OF EJS Templates
Make the rootfs partition 20% bigger than the used size of the chroot directory
Chris Landa -
r41:ecaf2c27457c
parent child
Show More
@@ -830,35 +830,42 rm -f $R/var/lib/urandom/random-seed
830 830 rm -f $R/etc/machine-id
831 831 rm -fr $R/etc/apt/apt.conf.d/10proxy
832 832
833 # Calculate size of the chroot directory
834 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'` / 1024)
833 # Calculate size of the chroot directory in KB
834 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`)
835 835
836 # Calculate required image size
837 IMAGE_SIZE=`expr $(expr ${CHROOT_SIZE} / 1024 + 1) \* 1024`
836 # Calculate the amount of needed 512 Byte sectors
837 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
838 BOOT_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
839 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS})
838 840
839 # Calculate number of sectors for the partition
840 IMAGE_SECTORS=`expr $(expr ${IMAGE_SIZE} \* 1048576) / 512 - 133120`
841 # The root partition is EXT4
842 # This means more space than the actual used space of the chroot is used.
843 # As overhead for journaling and reserved blocks 20% are added.
844 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
845
846 # Calculate required image size in 512 Byte sectors
847 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS} + ${ROOT_SECTORS})
841 848
842 849 # Prepare date string for image file name
843 850 DATE="$(date +%Y-%m-%d)"
844 851
845 852 # Prepare image file
846 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=1M count=1
847 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=1M count=0 seek=${IMAGE_SIZE}
853 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
854 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
848 855
849 856 # Write partition table
850 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
857 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
851 858 unit: sectors
852 859
853 1 : start= 2048, size= 131072, Id= c, bootable
854 2 : start= 133120, size= ${IMAGE_SECTORS}, Id=83
855 3 : start= 0, size= 0, Id= 0
856 4 : start= 0, size= 0, Id= 0
860 1 : start= ${TABLE_SECTORS}, size= ${BOOT_SECTORS}, Id= c, bootable
861 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
862 3 : start= 0, size= 0, Id= 0
863 4 : start= 0, size= 0, Id= 0
857 864 EOM
858 865
859 866 # Set up temporary loop devices and build filesystems
860 867 VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
861 EXT4_LOOP="$(losetup -o 65M --sizelimit `expr ${IMAGE_SIZE} - 64`M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
868 EXT4_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
862 869 mkfs.vfat "$VFAT_LOOP"
863 870 mkfs.ext4 "$EXT4_LOOP"
864 871
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant