Lines 101-137
make_esp_device() {
Link Here
|
101 |
# Check if /EFI/BOOT/BOOTxx.EFI is the FreeBSD boot1.efi |
101 |
# Check if /EFI/BOOT/BOOTxx.EFI is the FreeBSD boot1.efi |
102 |
# If it is, remove it to avoid leaving stale files around |
102 |
# If it is, remove it to avoid leaving stale files around |
103 |
efibootfile="${mntpt}/EFI/BOOT/${efibootname}.efi" |
103 |
efibootfile="${mntpt}/EFI/BOOT/${efibootname}.efi" |
104 |
if [ -f "${efibootfile}" ]; then |
|
|
105 |
isboot1=$(strings "${efibootfile}" | grep "FreeBSD EFI boot block") |
106 |
|
104 |
|
107 |
if [ -n "${isboot1}" ] && [ "$kbfree" -lt "${loadersize}" ]; then |
105 |
if cmp -s "${efibootfile}" "${file}"; then |
108 |
echo "Only ${kbfree}KB space remaining: removing old FreeBSD boot1.efi file /EFI/BOOT/${efibootname}.efi" |
106 |
echo "The current /EFI/BOOT/${efibootname}.efi has not changed." |
109 |
rm "${efibootfile}" |
107 |
else |
110 |
rmdir "${mntpt}/EFI/BOOT" |
108 |
if [ -f "${efibootfile}" ]; then |
111 |
else |
109 |
isboot1=$(strings "${efibootfile}" | grep "FreeBSD EFI boot block") |
112 |
echo "${kbfree}KB space remaining on ESP: renaming old boot1.efi file /EFI/BOOT/${efibootname}.efi /EFI/BOOT/${efibootname}-old.efi" |
110 |
|
113 |
mv "${efibootfile}" "${mntpt}/EFI/BOOT/${efibootname}-old.efi" |
111 |
if [ -n "${isboot1}" ] && [ "$kbfree" -lt "${loadersize}" ]; then |
|
|
112 |
efibootfilesize=$(stat -f %z "${efibootfile}") |
113 |
efibootfilesize=$((efibootfilesize / 1024)) |
114 |
|
115 |
# XXX Is there a chance we remove our only loader? |
116 |
if [ "$((kbfree + efibootfilesize))" -lt "${loadersize}" ]; then |
117 |
# This code is the same as in the block below... |
118 |
# once this piece is explained, I'll clean up. |
119 |
umount "${mntpt}" |
120 |
rmdir "${mntpt}" |
121 |
echo "Failed to update the EFI System Partition ${dev}" |
122 |
echo "Insufficient space remaining for ${file}" |
123 |
echo "Run e.g. \"mount -t msdosfs ${dev} /mnt\" to inspect it for files that can be removed." |
124 |
die |
125 |
else |
126 |
echo "Only ${kbfree}KB space remaining: removing old FreeBSD boot1.efi file /EFI/BOOT/${efibootname}.efi" |
127 |
rm "${efibootfile}" |
128 |
rmdir "${mntpt}/EFI/BOOT" |
129 |
fi |
130 |
else |
131 |
echo "${kbfree}KB space remaining on ESP: renaming old boot1.efi file /EFI/BOOT/${efibootname}.efi /EFI/BOOT/${efibootname}-old.efi" |
132 |
mv "${efibootfile}" "${mntpt}/EFI/BOOT/${efibootname}-old.efi" |
133 |
echo "Copying loader to /EFI/BOOT on ESP" |
134 |
cp -p "${file}" "${efibootfile}" |
135 |
fi |
114 |
fi |
136 |
fi |
115 |
fi |
|
|
116 |
|
137 |
|
117 |
if [ ! -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then |
138 |
if [ ! -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then |
118 |
umount "${mntpt}" |
139 |
umount "${mntpt}" |
119 |
rmdir "${mntpt}" |
140 |
rmdir "${mntpt}" |
120 |
echo "Failed to update the EFI System Partition ${dev}" |
141 |
echo "Failed to update the EFI System Partition ${dev}" |
121 |
echo "Insufficient space remaining for ${file}" |
142 |
echo "Insufficient space remaining for ${file}" |
122 |
echo "Run e.g \"mount -t msdosfs ${dev} /mnt\" to inspect it for files that can be removed." |
143 |
echo "Run e.g \"mount -t msdosfs ${dev} /mnt\" to inspect it for files that can be removed." |
123 |
die |
144 |
die |
|
|
145 |
fi |
124 |
fi |
146 |
fi |
125 |
|
147 |
|
126 |
mkdir -p "${mntpt}/EFI/freebsd" |
148 |
mkdir -p "${mntpt}/EFI/freebsd" |
127 |
|
149 |
|
128 |
# Keep a copy of the existing loader.efi in case there's a problem with the new one |
150 |
if cmp -s "${mntpt}/EFI/freebsd/loader.efi" "${file}"; then |
129 |
if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then |
151 |
echo "The current /EFI/freebsd/loader.efi has not changed." |
130 |
cp "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi" |
152 |
else |
131 |
fi |
153 |
# Keep a copy of the existing loader.efi in case there's a problem with the new one |
|
|
154 |
if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then |
155 |
cp -p "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi" |
156 |
fi |
132 |
|
157 |
|
133 |
echo "Copying loader to /EFI/freebsd on ESP" |
158 |
echo "Copying loader to /EFI/freebsd on ESP" |
134 |
cp "${file}" "${mntpt}/EFI/freebsd/loader.efi" |
159 |
cp -p "${file}" "${mntpt}/EFI/freebsd/loader.efi" |
|
|
160 |
fi |
135 |
|
161 |
|
136 |
if [ -n "${updatesystem}" ]; then |
162 |
if [ -n "${updatesystem}" ]; then |
137 |
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi") |
163 |
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi") |
Lines 159-169
make_esp_device() {
Link Here
|
159 |
echo "Existing UEFI FreeBSD boot entry found: not creating a new one" |
185 |
echo "Existing UEFI FreeBSD boot entry found: not creating a new one" |
160 |
fi |
186 |
fi |
161 |
else |
187 |
else |
162 |
# Configure for booting from removable media |
188 |
# Configure for booting from removable media |
163 |
if [ ! -d "${mntpt}/EFI/BOOT" ]; then |
189 |
if [ ! -d "${mntpt}/EFI/BOOT" ]; then |
164 |
mkdir -p "${mntpt}/EFI/BOOT" |
190 |
mkdir -p "${mntpt}/EFI/BOOT" |
165 |
fi |
191 |
fi |
166 |
cp "${file}" "${mntpt}/EFI/BOOT/${efibootname}.efi" |
192 |
if [ ! -f "${mntpt}/EFI/BOOT/${efibootname}.efi" ]; then |
|
|
193 |
cp -p "${file}" "${mntpt}/EFI/BOOT/${efibootname}.efi" |
194 |
fi |
167 |
fi |
195 |
fi |
168 |
|
196 |
|
169 |
umount "${mntpt}" |
197 |
umount "${mntpt}" |