Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164714757
D46677.id143353.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D46677.id143353.diff
View Options
diff --git a/tools/boot/install-boot.sh b/tools/boot/install-boot.sh
--- a/tools/boot/install-boot.sh
+++ b/tools/boot/install-boot.sh
@@ -101,37 +101,63 @@
# Check if /EFI/BOOT/BOOTxx.EFI is the FreeBSD boot1.efi
# If it is, remove it to avoid leaving stale files around
efibootfile="${mntpt}/EFI/BOOT/${efibootname}.efi"
- if [ -f "${efibootfile}" ]; then
- isboot1=$(strings "${efibootfile}" | grep "FreeBSD EFI boot block")
- if [ -n "${isboot1}" ] && [ "$kbfree" -lt "${loadersize}" ]; then
- echo "Only ${kbfree}KB space remaining: removing old FreeBSD boot1.efi file /EFI/BOOT/${efibootname}.efi"
- rm "${efibootfile}"
- rmdir "${mntpt}/EFI/BOOT"
- else
- echo "${kbfree}KB space remaining on ESP: renaming old boot1.efi file /EFI/BOOT/${efibootname}.efi /EFI/BOOT/${efibootname}-old.efi"
- mv "${efibootfile}" "${mntpt}/EFI/BOOT/${efibootname}-old.efi"
+ if cmp -s "${efibootfile}" "${file}"; then
+ echo "The current /EFI/BOOT/${efibootname}.efi has not changed."
+ else
+ if [ -f "${efibootfile}" ]; then
+ isboot1=$(strings "${efibootfile}" | grep "FreeBSD EFI boot block")
+
+ if [ -n "${isboot1}" ] && [ "$kbfree" -lt "${loadersize}" ]; then
+ efibootfilesize=$(stat -f %z "${efibootfile}")
+ efibootfilesize=$((efibootfilesize / 1024))
+
+ # XXX Is there a chance we remove our only loader?
+ if [ "$((kbfree + efibootfilesize))" -lt "${loadersize}" ]; then
+ # This code is the same as in the block below...
+ # once this piece is explained, I'll clean up.
+ umount "${mntpt}"
+ rmdir "${mntpt}"
+ echo "Failed to update the EFI System Partition ${dev}"
+ echo "Insufficient space remaining for ${file}"
+ echo "Run e.g. \"mount -t msdosfs ${dev} /mnt\" to inspect it for files that can be removed."
+ die
+ else
+ echo "Only ${kbfree}KB space remaining: removing old FreeBSD boot1.efi file /EFI/BOOT/${efibootname}.efi"
+ rm "${efibootfile}"
+ rmdir "${mntpt}/EFI/BOOT"
+ fi
+ else
+ echo "${kbfree}KB space remaining on ESP: renaming old boot1.efi file /EFI/BOOT/${efibootname}.efi /EFI/BOOT/${efibootname}-old.efi"
+ mv "${efibootfile}" "${mntpt}/EFI/BOOT/${efibootname}-old.efi"
+ echo "Copying loader to /EFI/BOOT on ESP"
+ cp -p "${file}" "${efibootfile}"
+ fi
fi
- fi
- if [ ! -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then
- umount "${mntpt}"
- rmdir "${mntpt}"
- echo "Failed to update the EFI System Partition ${dev}"
- echo "Insufficient space remaining for ${file}"
- echo "Run e.g \"mount -t msdosfs ${dev} /mnt\" to inspect it for files that can be removed."
- die
+ if [ ! -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then
+ umount "${mntpt}"
+ rmdir "${mntpt}"
+ echo "Failed to update the EFI System Partition ${dev}"
+ echo "Insufficient space remaining for ${file}"
+ echo "Run e.g \"mount -t msdosfs ${dev} /mnt\" to inspect it for files that can be removed."
+ die
+ fi
fi
mkdir -p "${mntpt}/EFI/freebsd"
- # Keep a copy of the existing loader.efi in case there's a problem with the new one
- if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then
- cp "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi"
- fi
+ if cmp -s "${mntpt}/EFI/freebsd/loader.efi" "${file}"; then
+ echo "The current /EFI/freebsd/loader.efi has not changed."
+ else
+ # Keep a copy of the existing loader.efi in case there's a problem with the new one
+ if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then
+ cp -p "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi"
+ fi
- echo "Copying loader to /EFI/freebsd on ESP"
- cp "${file}" "${mntpt}/EFI/freebsd/loader.efi"
+ echo "Copying loader to /EFI/freebsd on ESP"
+ cp -p "${file}" "${mntpt}/EFI/freebsd/loader.efi"
+ fi
if [ -n "${updatesystem}" ]; then
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi")
@@ -159,11 +185,13 @@
echo "Existing UEFI FreeBSD boot entry found: not creating a new one"
fi
else
- # Configure for booting from removable media
- if [ ! -d "${mntpt}/EFI/BOOT" ]; then
- mkdir -p "${mntpt}/EFI/BOOT"
- fi
- cp "${file}" "${mntpt}/EFI/BOOT/${efibootname}.efi"
+ # Configure for booting from removable media
+ if [ ! -d "${mntpt}/EFI/BOOT" ]; then
+ mkdir -p "${mntpt}/EFI/BOOT"
+ fi
+ if [ ! -f "${mntpt}/EFI/BOOT/${efibootname}.efi" ]; then
+ cp -p "${file}" "${mntpt}/EFI/BOOT/${efibootname}.efi"
+ fi
fi
umount "${mntpt}"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 4, 7:53 AM (21 h, 54 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35952786
Default Alt Text
D46677.id143353.diff (5 KB)
Attached To
Mode
D46677: boot: Check current loader file before overwriting
Attached
Detach File
Event Timeline
Log In to Comment