Biosias / uefi-mkconfig

grub-mkconfig inspired script for automatically managing uefi entries for booting linux kernel directly without bootloader
Apache License 2.0
10 stars 3 forks source link

performance issue during cleanup of existing items #10

Closed glorg closed 4 months ago

glorg commented 4 months ago

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

efibootmgr -u|grep -Po '[Bb]oot0(1[0-9a-fA-F]{2}|200)\W{1,2}UMC'|grep -Po '[0-9a-fA-F]{4}'

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.

Biosias commented 4 months ago

Hello @glorg everything should be fixed in #12 PR. Could you please test the code in its branch?

I've minimized calling efibootmgr to the absolute minimum needed. So it should work faster.

Biosias commented 4 months ago

Is fixed in next version