Factor out common code for calculating ESP size
Use it for both x86 and arm64
This commit is contained in:
parent
95f79b7af9
commit
15ab1a98d2
|
@ -81,58 +81,26 @@ if [ -d boot$N/grub ] ; then
|
||||||
echo " Adding EFI boot code for $ARCH on CD$N"
|
echo " Adding EFI boot code for $ARCH on CD$N"
|
||||||
|
|
||||||
# Move GRUB files to the right place.
|
# Move GRUB files to the right place.
|
||||||
mkdir -p $CDDIR/efi/boot
|
mkdir -p $CDDIR/EFI/boot
|
||||||
mcopy -i boot$N/grub/efi.img ::efi/boot/bootaa64.efi $CDDIR/efi/boot/bootaa64.efi
|
mcopy -n -s -i boot$N/isolinux/grub/efi.img '::efi/*' $CDDIR/EFI
|
||||||
mkdir -p $CDDIR/boot/grub
|
mkdir -p $CDDIR/boot/grub
|
||||||
mv boot$N/grub/* $CDDIR/boot/grub/
|
mv boot$N/grub/* $CDDIR/boot/grub/
|
||||||
rmdir boot$N/grub
|
rmdir boot$N/grub
|
||||||
|
|
||||||
# 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 image
|
|
||||||
|
|
||||||
# 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.
|
# small as possible.
|
||||||
|
|
||||||
sector_bytes=512 # -S
|
# First, work out how many blocks we need
|
||||||
cluster_sectors=4 # -s
|
blocks=$(calculate_efi_image_size $CDDIR)
|
||||||
cluster_bytes=$((sector_bytes * cluster_sectors))
|
|
||||||
|
|
||||||
clusters=2 # 1 cluster for each sub-directory
|
|
||||||
for file in $CDDIR/efi/boot/boot*.efi; do
|
|
||||||
[ -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))
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
# Now make a new image to contain the files
|
||||||
rm -f $CDDIR/boot/grub/efi.img
|
rm -f $CDDIR/boot/grub/efi.img
|
||||||
mkfs.msdos -v -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
mkfs.msdos -v -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
||||||
|
|
||||||
|
# And copy them into place
|
||||||
mmd -i "$CDDIR/boot/grub/efi.img" ::efi
|
mmd -i "$CDDIR/boot/grub/efi.img" ::efi
|
||||||
mmd -i "$CDDIR/boot/grub/efi.img" ::efi/boot
|
mcopy -o -s -i "$CDDIR/boot/grub/efi.img" $CDDIR/EFI/* \
|
||||||
mcopy -o -i "$CDDIR/boot/grub/efi.img" $CDDIR/efi/boot/boot*.efi \
|
"::efi"
|
||||||
"::efi/boot"
|
|
||||||
|
|
||||||
# Ugh - different code here depending on the version of xorriso we've got
|
# Ugh - different code here depending on the version of xorriso we've got
|
||||||
if [ $XORRISO_VER -le 10202 ] ; then
|
if [ $XORRISO_VER -le 10202 ] ; then
|
||||||
|
|
|
@ -479,40 +479,14 @@ if [ -d boot$N/isolinux/grub ] && [ $BOOT_EFI -ne 0 ] ; then
|
||||||
# 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.
|
# small as possible.
|
||||||
|
|
||||||
sector_bytes=512 # -S
|
# First, work out how many blocks we need
|
||||||
cluster_sectors=4 # -s
|
blocks=$(calculate_efi_image_size $CDDIR)
|
||||||
cluster_bytes=$((sector_bytes * cluster_sectors))
|
|
||||||
|
|
||||||
clusters=4 # 1 cluster for each sub-directory
|
|
||||||
for file in $CDDIR/EFI/*/*; do
|
|
||||||
[ -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))
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
# Now make a new image to contain the files
|
||||||
rm -f $CDDIR/boot/grub/efi.img
|
rm -f $CDDIR/boot/grub/efi.img
|
||||||
mkfs.msdos -v -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
mkfs.msdos -v -C "$CDDIR/boot/grub/efi.img" $blocks >/dev/null
|
||||||
|
|
||||||
|
# And copy them into place
|
||||||
mmd -i "$CDDIR/boot/grub/efi.img" ::efi
|
mmd -i "$CDDIR/boot/grub/efi.img" ::efi
|
||||||
mcopy -o -s -i "$CDDIR/boot/grub/efi.img" $CDDIR/EFI/* \
|
mcopy -o -s -i "$CDDIR/boot/grub/efi.img" $CDDIR/EFI/* \
|
||||||
"::efi"
|
"::efi"
|
||||||
|
|
|
@ -157,3 +157,42 @@ xorriso_version() {
|
||||||
print ver[1]*10000+ver[2]*100+ver[3]
|
print ver[1]*10000+ver[2]*100+ver[3]
|
||||||
}'
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Work out how many blocks we need for a FAT filesystem to hold all
|
||||||
|
# the EFI boot files
|
||||||
|
calculate_efi_image_size() {
|
||||||
|
CDDIR=$1
|
||||||
|
|
||||||
|
sector_bytes=512 # -S
|
||||||
|
cluster_sectors=4 # -s
|
||||||
|
cluster_bytes=$((sector_bytes * cluster_sectors))
|
||||||
|
|
||||||
|
clusters=4 # 1 cluster for each sub-directory
|
||||||
|
for file in $CDDIR/EFI/*/*; do
|
||||||
|
[ -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))
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
echo $blocks
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue