It was noticed that the script uefi-mkconfig runs for about a minute or longer on some machines.
The reason appeared to be the cleanup of old existing items on line 212:
# Clear old entries for regeneration
## 256..512 is because entry IDs are actually in hexadecimal format
for entry_number in {256..512}; do
# Wipe only boot entries with UMC stamp
if [[ "$(efibootmgr -u | grep Boot$(printf %04X $entry_number))" == *"UMC "* ]]; then
efibootmgr -q -B -b $(printf %04X $entry_number)
fi
done
this code invokes the external efibootmgr command 256 times with grepping one line. The command runs slowly on old BIOSes, so it takes long to clean up items (while most of numbers in the range don't match any item in fact).
This is performance issue and might be optimized in the way that efibootmgr is just called once and then result is processed, also no reason to check whole range, finding only existing items could be performed much faster with regex, for example the list of items can be obtained with
where first regex looks for Boot0NNN* UMC.... in the line where NNN is hex number of 100-200 and the second regex extracts the number to be then used with the efibootmgr command for item removal.
By the way, second issue with similar behavior can be found on line (31)[https://github.com/Biosias/uefi-mkconfig/blob/a02cd817d70a53e76d1b93a282f3e483e1efc315/uefi-mkconfig#L31], the difference is that while cycle runs several times as number of EFI itmes is usually under 20. However, with adding more items the time this cycle takes would also increase, might be better to also call the efibootmgr just once and then parse the output with regex.
It was noticed that the script
uefi-mkconfig
runs for about a minute or longer on some machines.The reason appeared to be the cleanup of old existing items on line 212:
this code invokes the external
efibootmgr
command 256 times with grepping one line. The command runs slowly on old BIOSes, so it takes long to clean up items (while most of numbers in the range don't match any item in fact). This is performance issue and might be optimized in the way thatefibootmgr
is just called once and then result is processed, also no reason to check whole range, finding only existing items could be performed much faster with regex, for example the list of items can be obtained withwhere first regex looks for
Boot0NNN* UMC....
in the line whereNNN
is hex number of100-200
and the second regex extracts the number to be then used with theefibootmgr
command for item removal.By the way, second issue with similar behavior can be found on line (31)[https://github.com/Biosias/uefi-mkconfig/blob/a02cd817d70a53e76d1b93a282f3e483e1efc315/uefi-mkconfig#L31], the difference is that
while
cycle runs several times as number of EFI itmes is usually under 20. However, with adding more items the time this cycle takes would also increase, might be better to also call theefibootmgr
just once and then parse the output with regex.