Fix size calculation for EFI image
CD creation fails with "disk full", because of rounding errors. The minimum size of data-allocation is a 'cluster', which is a power-of-two multiple of sectors. mkfs.msdos chooses minimum FAT and cluster size for image: FAT12<16G mkfs.msdos uses block-count where a block is 1024 B, but must be rounded up to track_size with 32 sectors. Round up each file to clusters before summing. A sub-directory entry needs 1 cluster minimum.
This commit is contained in:
parent
c949504c2e
commit
1a15968a7a
|
@ -61,6 +61,9 @@ debian-cd (3.1.18) UNRELEASED; urgency=medium
|
||||||
[ Helge Deller ]
|
[ Helge Deller ]
|
||||||
* Update hppa support. Closes: #744155
|
* Update hppa support. Closes: #744155
|
||||||
|
|
||||||
|
[ Philipp Hahn ]
|
||||||
|
* Fix size calculation for EFI image
|
||||||
|
|
||||||
-- Steve McIntyre <93sam@debian.org> Mon, 20 Apr 2015 12:36:57 +0100
|
-- Steve McIntyre <93sam@debian.org> Mon, 20 Apr 2015 12:36:57 +0100
|
||||||
|
|
||||||
debian-cd (3.1.17) unstable; urgency=medium
|
debian-cd (3.1.17) unstable; urgency=medium
|
||||||
|
|
|
@ -455,17 +455,38 @@ if [ -d boot$N/isolinux/grub ] && [ $BOOT_EFI -ne 0 ] ; then
|
||||||
>> $CDDIR/boot/grub/grub.cfg
|
>> $CDDIR/boot/grub/grub.cfg
|
||||||
|
|
||||||
# Stuff the EFI boot files into a FAT filesystem, making it as
|
# Stuff the EFI boot files into a FAT filesystem, making it as
|
||||||
# small as possible. 24KiB headroom seems to be enough;
|
# small as possible.
|
||||||
# (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
|
|
||||||
|
|
||||||
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
|
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
|
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
|
rm -f $CDDIR/boot/grub/efi.img
|
||||||
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
||||||
|
|
|
@ -481,17 +481,38 @@ if [ -d boot$N/isolinux/grub ] && [ $BOOT_EFI -ne 0 ] ; then
|
||||||
echo " CD$N/boot/grub/grub.cfg has $NUM_ENTRIES boot entries defined"
|
echo " CD$N/boot/grub/grub.cfg has $NUM_ENTRIES boot entries defined"
|
||||||
|
|
||||||
# Stuff the EFI boot files into a FAT filesystem, making it as
|
# Stuff the EFI boot files into a FAT filesystem, making it as
|
||||||
# small as possible. 24KiB headroom seems to be enough;
|
# small as possible.
|
||||||
# (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
|
|
||||||
|
|
||||||
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
|
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
|
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
|
rm -f $CDDIR/boot/grub/efi.img
|
||||||
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
||||||
|
|
|
@ -433,17 +433,38 @@ if [ -d boot$N/isolinux/grub ] ; then
|
||||||
>> $CDDIR/boot/grub/grub.cfg
|
>> $CDDIR/boot/grub/grub.cfg
|
||||||
|
|
||||||
# Stuff the EFI boot files into a FAT filesystem, making it as
|
# Stuff the EFI boot files into a FAT filesystem, making it as
|
||||||
# small as possible. 24KiB headroom seems to be enough;
|
# small as possible.
|
||||||
# (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
|
|
||||||
|
|
||||||
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
|
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
|
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
|
rm -f $CDDIR/boot/grub/efi.img
|
||||||
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
mkfs.msdos -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
||||||
|
|
Loading…
Reference in New Issue