##// END OF EJS Templates
Merge branch 'rootfs-size-calculation-improvement' of https://github.com/stylesuxx/rpi2-gen-image into stylesuxx-rootfs-size-calculation-improvement
Jan Wagner -
r44:5a2f6de119e2 Fusion
parent child
Show More
@@ -864,35 +864,42 rm -f $R/var/lib/urandom/random-seed
864 rm -f $R/etc/machine-id
864 rm -f $R/etc/machine-id
865 rm -fr $R/etc/apt/apt.conf.d/10proxy
865 rm -fr $R/etc/apt/apt.conf.d/10proxy
866
866
867 # Calculate size of the chroot directory
867 # Calculate size of the chroot directory in KB
868 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'` / 1024)
868 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`)
869
869
870 # Calculate required image size
870 # Calculate the amount of needed 512 Byte sectors
871 IMAGE_SIZE=`expr $(expr ${CHROOT_SIZE} / 1024 + 1) \* 1024`
871 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
872 BOOT_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
873 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS})
872
874
873 # Calculate number of sectors for the partition
875 # The root partition is EXT4
874 IMAGE_SECTORS=`expr $(expr ${IMAGE_SIZE} \* 1048576) / 512 - 133120`
876 # This means more space than the actual used space of the chroot is used.
877 # As overhead for journaling and reserved blocks 20% are added.
878 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
879
880 # Calculate required image size in 512 Byte sectors
881 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS} + ${ROOT_SECTORS})
875
882
876 # Prepare date string for image file name
883 # Prepare date string for image file name
877 DATE="$(date +%Y-%m-%d)"
884 DATE="$(date +%Y-%m-%d)"
878
885
879 # Prepare image file
886 # Prepare image file
880 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=1M count=1
887 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
881 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=1M count=0 seek=${IMAGE_SIZE}
888 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
882
889
883 # Write partition table
890 # Write partition table
884 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
891 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
885 unit: sectors
892 unit: sectors
886
893
887 1 : start= 2048, size= 131072, Id= c, bootable
894 1 : start= ${TABLE_SECTORS}, size= ${BOOT_SECTORS}, Id= c, bootable
888 2 : start= 133120, size= ${IMAGE_SECTORS}, Id=83
895 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
889 3 : start= 0, size= 0, Id= 0
896 3 : start= 0, size= 0, Id= 0
890 4 : start= 0, size= 0, Id= 0
897 4 : start= 0, size= 0, Id= 0
891 EOM
898 EOM
892
899
893 # Set up temporary loop devices and build filesystems
900 # Set up temporary loop devices and build filesystems
894 VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
901 VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
895 EXT4_LOOP="$(losetup -o 65M --sizelimit `expr ${IMAGE_SIZE} - 64`M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
902 EXT4_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
896 mkfs.vfat "$VFAT_LOOP"
903 mkfs.vfat "$VFAT_LOOP"
897 mkfs.ext4 "$EXT4_LOOP"
904 mkfs.ext4 "$EXT4_LOOP"
898
905
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant