@@ -864,35 +864,42 rm -f $R/var/lib/urandom/random-seed | |||
|
864 | 864 | rm -f $R/etc/machine-id |
|
865 | 865 | rm -fr $R/etc/apt/apt.conf.d/10proxy |
|
866 | 866 | |
|
867 | # Calculate size of the chroot directory | |
|
868 |
CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'` |
|
|
867 | # Calculate size of the chroot directory in KB | |
|
868 | CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`) | |
|
869 | 869 | |
|
870 | # Calculate required image size | |
|
871 | IMAGE_SIZE=`expr $(expr ${CHROOT_SIZE} / 1024 + 1) \* 1024` | |
|
870 | # Calculate the amount of needed 512 Byte sectors | |
|
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 | |
|
874 | IMAGE_SECTORS=`expr $(expr ${IMAGE_SIZE} \* 1048576) / 512 - 133120` | |
|
875 | # The root partition is EXT4 | |
|
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 | 883 | # Prepare date string for image file name |
|
877 | 884 | DATE="$(date +%Y-%m-%d)" |
|
878 | 885 | |
|
879 | 886 | # Prepare image file |
|
880 |
dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs= |
|
|
881 |
dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs= |
|
|
887 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} | |
|
888 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} | |
|
882 | 889 | |
|
883 | 890 | # Write partition table |
|
884 |
sfdisk -q |
|
|
891 | sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM | |
|
885 | 892 | unit: sectors |
|
886 | 893 | |
|
887 |
1 : start= |
|
|
888 |
2 : start= |
|
|
889 | 3 : start= 0, size= 0, Id= 0 | |
|
890 | 4 : start= 0, size= 0, Id= 0 | |
|
894 | 1 : start= ${TABLE_SECTORS}, size= ${BOOT_SECTORS}, Id= c, bootable | |
|
895 | 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83 | |
|
896 | 3 : start= 0, size= 0, Id= 0 | |
|
897 | 4 : start= 0, size= 0, Id= 0 | |
|
891 | 898 | EOM |
|
892 | 899 | |
|
893 | 900 | # Set up temporary loop devices and build filesystems |
|
894 | 901 | VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" |
|
895 |
EXT4_LOOP="$(losetup -o 65M |
|
|
902 | EXT4_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" | |
|
896 | 903 | mkfs.vfat "$VFAT_LOOP" |
|
897 | 904 | mkfs.ext4 "$EXT4_LOOP" |
|
898 | 905 |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant