Fix size calculation for EFI image

Backport fix from master
This commit is contained in:
Steve McIntyre 2016-04-19 23:49:27 +01:00
parent fccf852167
commit e9c12ce0cd
2 changed files with 29 additions and 7 deletions

1
debian/changelog vendored
View File

@ -24,6 +24,7 @@ debian-cd (3.1.13-deb7u1) UNRELEASED; urgency=low
+ Switch references to d-i.debian.org to use https instead of http.
Closes: #809698. Also use --ca-directory /etc/ssl/ca-debian/ with wget
to ensure this works.
+ Fix size calculation for EFI image
-- Steve McIntyre <93sam@debian.org> Mon, 17 June 2013 15:44:32 +0100

View File

@ -420,17 +420,38 @@ if [ -d boot$N/isolinux/grub ] ; then
>> $CDDIR/boot/grub/grub.cfg
# Stuff the EFI boot files into a FAT filesystem, making it as
# small as possible. 24KiB headroom seems to be enough;
# (x+31)/32*32 rounds up to multiple of 32.
# This is the same as in efi-image, but we need to redo it here in
# the case of a multi-arch amd64/i386 image
# small as possible.
size=0
sector_bytes=512 # -S
cluster_sectors=4 # -s
cluster_bytes=$((sector_bytes * cluster_sectors))
clusters=2 # 1 cluster for each sub-directory
for file in $CDDIR/efi/boot/boot*.efi; do
size=$(($size + $(stat -c %s "$file")))
[ -f "$file" ] || continue
clusters=$(($clusters + (($(stat -c %s "$file") + $cluster_bytes - 1) / $cluster_bytes)))
done
reserved_sectors=1 # boot-sector -R
reserved_bytes=$(($reserved_sectors * $sector_bytes))
fat_copies=2 # -f
if [ "$clusters" -le $(((1 << 12) - 2)) ]; then
fat_entry_bytes=3/2 # -F
elif [ "$clusters" -le $(((1 << 16) - 2)) ]; then
fat_entry_bytes=2 # -F
else
fat_entry_bytes=4 # -F
fi
fat_bytes=$((($clusters * $fat_entry_bytes + $sector_bytes - 1) / $sector_bytes * $sector_bytes))
root_entries=512 # -r
root_entry_bytes=32
root_bytes=$(($root_entries * root_entry_bytes))
size=$(($reserved_bytes + $fat_copies * $fat_bytes + $root_bytes + $clusters * $cluster_bytes))
blocks=$((($size / 1024 + 55) / 32 * 32 ))
track_sectors=32
track_bytes=$((sector_bytes * $track_sectors))
tracks=$((($size + $track_bytes - 1) / $track_bytes))
block_bytes=1024
blocks=$(($tracks * $track_bytes / $block_bytes))
rm -f $CDDIR/boot/grub/efi.img
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null