Menu

Duplicate tools

Jeremy S
2024-04-15
2025-07-03
  • Jeremy S

    Jeremy S - 2024-04-15

    Since upgrading to 0.14.2 on Archlinux, the tools are duplicated.

    My showtools entry in refind.conf is

    showtools mok_tool,reboot,shutdown,firmware,memtest

    but since upgrading, what shows up on the refind screen when booting is

    mok_tool,reboot,shutdown,memtest,mok_tool,about,shutdown,reboot,memtest

    I'm not the only archuser to have this issue:
    rEFInd - showtools option no longer working after updating to 0.14.2-1

    Oddly, the issue only occurs on two of my three Archlinux machines (laptop, home desktop, work desktop). I've compared config files and I don't see any differences that might suggest why two machines have this issue and one not...

     
  • Roderick W. Smith

    rEFInd 0.14.2 introduced some significant changes to the way it scans for disk-based tools. I did this for various reasons -- partly to simplify the code, partly to deal with changes in the names and locations of some tools (most notably, various memtest tools). One consequence, however, is that rEFInd may detect a slightly different set of tools, potentially increasing or decreasing the number of tools, depending on what's available on a system. That said, some of what you've reported seems strange, such as the replication of shutdown and reboot options. These are both built-in options, rather than disk-based tools, and so should not have been affected by changes in scanning code for disk-based tools.

    My suspicion is therefore that you may have multiple showtools options somewhere, such as in the main refind.conf file and in the configuration file for a theme, and you're looking at the definition that's overridden by a later one. You may want to look for that and, if there are multiple such lines, comment one of them out. Certainly I have not seen the symptoms you describe, or that are described in the Arch thread to which you linked. I even tried reproducing your showtools line, and the empty showtools line described in the thread. rEFInd 0.14.2 produced exactly the results it should have in my tests.

    As a general debugging tip, you may want to be sure that the hideui option is not active and check the paths to the tools that are reported. This may provide a clue about what's going on; the new code lists the path to each on-disk tool, which can help you figure out where it's located. This may help you locate duplicates.

    It would also be helpful for you to enable logging (setting log_level 1 should be adequate) and post the resulting refind.log file, or at least the "Scanning for Tools" section of that file. This should provide some clues about what's going on.

     
  • Jeremy S

    Jeremy S - 2024-04-16

    Only one showtools option in my configs:

    % grep -r showtools /boot
    /boot/EFI/refind/refind.conf:showtools  mok_tool,reboot,shutdown,firmware,memtest
    

    After commenting out hideui the two instances of mok_tool reported identical paths. The other tools did not report any paths. (Sorry for the glare.)
    moktool 1
    moktool 2

    Here is my current config:

    ########################
    # General Settings
    ########################
    timeout    10
    resolution 1920 1200
    showtools  mok_tool,reboot,shutdown,firmware,memtest
    scanfor    manual
    
    default_selection "Arch Linux"
    
    
    ########################
    # Theme Settings
    ########################
    #hideui           label,singleuser,safemode,hwtest,hints,arrows,editor,badges
    icons_dir        theme/icons
    banner           theme/banner.png
    banner_scale     noscale
    small_icon_size  144
    big_icon_size    256
    selection_big    theme/selection-big.png
    selection_small  theme/selection-small.png
    font             theme/source-code-pro-extralight-42.png
    log_level        1
    
    ########################
    # Permanent Entries
    ########################
    
    menuentry "Arch Linux" {
        icon      /EFI/refind/theme/icons/os_arch.png
        volume    "Arch Linux"
        loader    /vmlinuz-linux
        initrd    /initramfs-linux.img
        options   "root=LABEL=root ro rootfstype=ext4"
        graphics  on
        submenuentry "Boot using fallback initramfs" {
            initrd /initramfs-linux-fallback.img
        }
        submenuentry "Boot to terminal" {
            add_options "systemd.unit=multi-user.target"
        }
    }
    
    menuentry "Windows 11" {
        icon      /EFI/refind/theme/icons/os_win.png
        volume    "Windows 11"
        loader    /EFI/Microsoft/Boot/bootmgfw.efi
        graphics  on
    }
    
    # menuentry "HashTool" {
    #     icon      /EFI/refind/theme/icons/tool_hash.png
    #     volume    "HashTool"
    #     loader    /EFI/refind/HashTool.efi
    #     graphics  on
    # }
    

    Here is the log file. (The log file produced had every second character as a null character.... I had to strip them all with tr before it was readable.)

    ==========System information==========
    14:46:14 - rEFInd 0.14.2 built with GNU-EFI
    14:46:14 - rEFInd boot partition GUID: D4C510E1-AE84-4938-A898-BEFDD74A4F75
    14:46:14 - Platform: x86-64/X64/AMD64 (64-bit)
    14:46:14 - Log level is 1
    14:46:14 - Menu timeout is 10
    14:46:14 - Firmware: HP 264.00
    14:46:14 - EFI Revision 2.70
    14:46:14 - Secure Boot active
    14:46:14 - Shim is available
    14:46:14 - CSM is not available
    14:46:14 - Error 2; Unable to retrieve EFI variable capacity
    14:46:14 - System does not support text mode
    14:46:14 - System does not support UGA Draw graphics mode
    14:46:14 - System does support GOP graphics mode
    14:46:14 - Setting up Secure Boot (if applicable)
    
    ==========Loading drivers==========
    
    ==========Initializing basic features==========
    14:46:14 - Adjusting default_selection with PreviousBoot values
    14:46:14 - Entering InitScreen()
    14:46:14 - Setting watchdog timer
    14:46:14 - Setting screen resolution and mode
    14:46:14 - Setting volume icons....
    
    ==========Scanning for boot loaders==========
    
    ----------Scanning for user-configured boot stanzas----------
    14:46:14 - Adding manual loader for '\vmlinuz-linux'
    14:46:14 - Searching for an initrd to match '\vmlinuz-linux' on 'SYSTEM'
    14:46:14 - Located initrd is '\initramfs-linux.img'
    14:46:14 - Adding manual loader for '\EFI\Microsoft\Boot\bootmgfw.efi'
    
    ==========Scanning for tools==========
    14:46:14 - Scanning for tools 'MokManager.efi,HashTool.efi,HashTool-signed.efi,KeyTool.efi,KeyTool-signed.efi,mmx64.efi' in 'EFI\tools,EFI\refind'
    14:46:14 - 'EFI\refind\mmx64.efi' is a valid loader file
    14:46:14 - Adding tag for 'mmx64.efi' on 'SYSTEM'
    14:46:14 - Scanning for tools 'memtest86.efi,memtest86_x64.efi,memtest86x64.efi,memtest86+x64.efi' in 'EFI\tools,EFI\refind'
    14:46:14 - Scanning for tools 'MokManager.efi,HashTool.efi,HashTool-signed.efi,KeyTool.efi,KeyTool-signed.efi,mmx64.efi' in 'EFI\tools,EFI\refind'
    14:46:14 - 'EFI\refind\mmx64.efi' is a valid loader file
    14:46:14 - Adding tag for 'mmx64.efi' on 'SYSTEM'
    14:46:14 - Scanning for tools 'fwupx64.efi' in 'EFI\tools,EFI\refind'
    
    ==========Entering main loop==========
    
    ==========Launching 'Boot Arch Linux from SYSTEM'==========
    14:46:25 - Starting vmlinuz-linux
    14:46:25 - Using load options 'root=LABEL=root ro rootfstype=ext4 initrd=\initramfs-linux.img'
    14:46:25 - '\vmlinuz-linux' is a valid loader file
    14:46:25 - Launching 'vmlinuz-linux'
    
     
  • Jeremy S

    Jeremy S - 2024-04-18

    Yes, this is almost certainly the issue. I edited the showtools code in config.c by commenting out the SetMem call and then adding a loop to "manually" zero out the rest of the GlobalConfig.ShowTools array, and it fixed the issue.

    See here:
    https://github.com/loserMcloser/rEFInd/blob/86c7ab03db42001bfbe5c7e72654e568572e063f/refind/config.c#L669-L718

    Couple of side notes:
    * On my two machines where the issue occurs, secure boot is enabled and managed by rEFInd. My machine where the issue doesn't occur is older and does not use secure boot. So maybe something about secure boot is triggering the memory issue.
    * NUM_TOOLS is defined to be 24 in global.h, but the default showtools array in main.c is only zeroed out to a total of 21 items. Might want to add a few more zeros to that initial showtools array in main.c.

     
  • Jeremy S

    Jeremy S - 2024-04-18

    Also, isn't there an off-by-one error in the bound of that for loop in config.c ? Since i-1 is used as the index variable to set items in the GlobalConfig.ShowTools array, shouldn't

    for (i = 1; (i < TokenCount) && (i < NUM_TOOLS); i++) {
    

    instead be

    for (i = 1; (i < TokenCount) && (i <= NUM_TOOLS); i++) {
    

    ?

     
  • Jeremy S

    Jeremy S - 2024-04-18

    Sorry, last thing. Should note that my "fixed" code at
    https://github.com/loserMcloser/rEFInd/blob/86c7ab03db42001bfbe5c7e72654e568572e063f/refind/config.c#L669-L718
    is not actually an appropriate fix, because of the way that the TokenList index variable and the GlobalConfig.ShowTools index variable are tied together. If the SetMem command is commented out and one of the TokenList items triggers the final "unknown showtools flag" else block, the entry at position GlobalConfig.ShowTools[i-1] is not going to get overwritten with anything and will remain as it was initialized in the default GlobalConfig.ShowTools array in main.c.

    You might want to de-couple the GlobalConfig.ShowTools array index variable from the TokenList index variable in that for loop in config.c.

     
  • dakanji

    dakanji - 2024-04-18

    I handled the iteration as well as invalid entries differently in RefindPlus. The i-1 setup is not used. and there are separate iterators for TokenList and GlobalConfig.ShowTools.

    Additionally, a variable counts invalid items and this is added to the TokenList iterator. There is an issue otherwise as you noted indeed where if a user enters an invalid entry, things go out of shape.

    I have also dropped SetMem (not yet pushed) and now just zero things out manually there as well. This is done right off the top though. That is, everything is set to zero before assigning anything.

    PS: The link to rEFInd I posted is a mirror of the repo here without edits. Just more convenient on GitHub for linking to specific blocks of code

     

    Last edit: dakanji 2024-04-18
  • dakanji

    dakanji - 2024-04-18

    NUM_TOOLS is defined to be 24 in global.h, but the default showtools array in main.c is only zeroed out to a total of 21 items.

    Good catch!
    This could well be the mysterious memory issue as SetMem is used with a larger size.

    EDIT:
    ShowTools is set to NUM_TOOLS size here:
    https://github.com/dakanji/rEFInd/blob/94ba63b502c65933f4d8ef8871c5914d6dae4495/refind/global.h#L394

    So the sizing should not be an issue.
    That is, ShowTools by itself is OK and something else is manifesting.
    The issues with the iteration probably could be sorted but they are not quite critical.

     

    Last edit: dakanji 2024-04-19
  • Felipe Ignacio Gaspari

    Hi, I just registered at sourceforge to say this bug is a very sad thing. Please help.

     
    • Jeremy S

      Jeremy S - 2024-05-23

      @Felipe I have submitted a merge request to fix the issue, hopefully the author accepts it.

       
      • dakanji

        dakanji - 2024-07-25

        The MR works around the issue but does not fix the root cause.

        From my original comment, it is:

        Basically, the SetMem item is not taking ...

        Luckily, it seems someone else with an unrelated issue has stumbled on the root issue of SetMem being broken on recent GNUEFI builds and come up with a fix.

        SetMem basically needs to be refit_call3_wrapper(gBS->SetMem, ...) to work with recent GNUEFI builds.

        I posted a comment on the MR pointing to the thread with the fix.

         
        • Jeremy S

          Jeremy S - 2024-08-13

          Can confirm that refit_call3_wrapper(gBS->SetMem, ...) fixes the duplicate tools bug. I've closed my original merge request and opened a simpler one.

           
  • Albert Vaca

    Albert Vaca - 2025-01-02

    I'm also affected by this, maybe we can get a new release with the fix?

     
  • Alex Indigo

    Alex Indigo - 2025-02-16

    I see the same issue as well.

     
  • Swâmi Petaramesh

    Confirming the issue here, on 2 different machines.
    Issue which didn't exist in previous rEFInd releases.

    Strangely enough, if I have in refind.conf :
    showtools reboot, shutdown, memtest, bootorder, hidden_tags, windows_recovery, shell, firmware, about
    ...then the reboot and poweroff icons appear duplicated, and the firmware_upgrade icon appears even though it is not listed in wanted tools.

    But if I comment out the “showtools” line completely, then only the tools actually present on the system appears, AND there are no duplicates for reboot and poweroff.

    Same on the 2 machines (a several years old Asus and a 2 years old Lenovo Thinkpad)

     
  • Alexander Vorobyev

    Can confirm having this issue aswell

     
  • Panayotis Katsaloulis

    I tried the patch from the PR that was originally sent and I confirm too that I can see only one tool. In the PR it was mentioned that maybe this is not the optimal way to handle this and the patch was cancelled. I don't know if there's a better patch (I couldn't find it), neither in pending patches or accepted. So I think no more progress has been done. If the"proper" patch is not available yet, I could provide the binary that I compiled with the "wrong" patch, since it works for me -- although I strongly believe that properly solving it is the way to go.

     
    • Jeremy S

      Jeremy S - 2025-07-03

      @Panayotis Katsaloulis
      Both patches work, but the second version of the fix is much simpler and required less editing of the code:
      https://sourceforge.net/p/refind/code/merge-requests/55/

       
  • Albert Vaca

    Albert Vaca - 2025-07-03

    The patch works nicely. My worry is that this issue hasn't had any response by the refind author, even when there's a working patch that could be just merged and released with little effort. Is the project abandoned?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.