Follow symlinks while copying shim files

The shim EFI file on Ubuntu can be a symlink, as it may be in the alternatives system, so
previously, when calculating the size of the FAT32 partition, we would measure the size of the
symlink instead of the actual file and get "Disk full" errors when trying to copy the files into
the new FAT32 partition.

If we dereference the file on copy, we get the actual file and can calculate the size accurately.

```
lrwxrwxrwx. 1 root root   36 Jul 12 20:04 bootx64.efi -> /etc/alternatives/shimx64.efi.signed
```
This commit is contained in:
David Hewitt 2023-07-12 20:29:04 +00:00 committed by Luca Boccassi
parent d14306a799
commit 5bff71fea2
1 changed files with 3 additions and 1 deletions

View File

@ -185,12 +185,14 @@ gen_efi_boot_img(){
# USB flash drive, while grubx64.efi.signed is for hard drive.
# Therefore here gcdx64.efi.signed is used for amd64 and gcdaa64.efi.signed is
# for arm64.
# - Ubuntu's shim binary is in the alternatives system so it could be a symlink,
# so ensure we dereference it and copy the actual file
if [ -r ${_CHROOT_DIR}/usr/lib/grub/\$platform-signed/gcd\$efi_name.efi.signed -a \
-r ${_CHROOT_DIR}/usr/lib/shim/shim\$efi_name.efi.signed -a \
"${LB_UEFI_SECURE_BOOT}" != "disable" ]; then
cp -a ${_CHROOT_DIR}/usr/lib/grub/\$platform-signed/gcd\$efi_name.efi.signed \
${_CHROOT_DIR}/grub-efi-temp/EFI/boot/grub\$efi_name.efi
cp -a ${_CHROOT_DIR}/usr/lib/shim/shim\$efi_name.efi.signed \
cp -a --dereference ${_CHROOT_DIR}/usr/lib/shim/shim\$efi_name.efi.signed \
${_CHROOT_DIR}/grub-efi-temp/EFI/boot/boot\$efi_name.efi
fi
}