Skip to content

bootctl: install with shim #27234

Open
Open

Description

@lnussel

Component

bootctl

Is your feature request related to a problem? Please describe

Systemd-boot right now installs itself (bootctl install) like this in the
ESP (star marks boot entry):

\EFI\BOOT\BOOTX64.EFI    <-- systemd-boot
\EFI\systemd\systemd-bootx64.efi  *

To make systemd-boot usable on real hardware with secure boot enabled, it would have to be signed by the MS 3rd party CA. That's probably not going to happen so the way to do that would be make sd-boot bootable by shim.

Describe the solution you'd like

Assuming systemd-boot is signed with a vendor certificate, the
way to install both shim and systemd-boot would be what is outlined
in https://github.com/rhboot/shim/blob/main/README.fallback

for removable media:

\EFI\BOOT\BOOTX64.EFI    <-- shim
\EFI\BOOT\MokManager.efi
\EFI\BOOT\grubx64.efi    <-- systemd-boot

for an installed system:

\EFI\BOOT\BOOTX64.EFI    <-- shim
\EFI\BOOT\MokManager.efi
\EFI\BOOT\fallback.efi
\EFI\vendor\BOOT.CSV
\EFI\vendor\shim.efi     *
\EFI\vendor\MokManager.efi
\EFI\vendor\grubx64.efi  <-- systemd-boot

(Yeah, for now systemd-boot would have to name itself after grub as
that's hardcoded in shim).

So my question is would you accept patches to bootctl that (eg via
build time option) installs systemd-boot as outlined above if shim
is installed?

If so, a way would be to eg have the shim package symlink it's files
into /usr/lib/systemd/boot/efi/. Bootctl already installs *.efi from
there. We'd need a hack to the systemd-boot -> grub renaming though.

The other alternative would be to either not use bootctl install
at all, or have some script mangle what it did to retrofit shim.

Thoughts? :-)

Describe alternatives you've considered

No response

The systemd version you checked that didn't have the feature you are asking for

No response

Activity

  1. added
    RFE 🎁
    on Apr 12, 2023
  2. YHNdnzj commented on Apr 12, 2023

    @YHNdnzj
    Member

    IMO this should not be handled by bootctl. The use of shim (and where it gets installed) is distinct across distros, and thus they shall provide their own tools to tackle with this.

  3. Yukigamine commented on Apr 12, 2023

    @Yukigamine

    IMO this should not be handled by bootctl. The use of shim (and where it gets installed) is distinct across distros, and thus they shall provide their own tools to tackle with this.

    If you can point me to a tool in Arch that will automatically stick a copy of systemd-boot64.efi into grubx64.efi, I'm all ears.

    I ended up here looking for exactly the kind of solution that OP proposed. Because shim is hardcoded to look for grubx64.efi and PreLoader is hardcoded to look for loader.efi there are limited options when it comes to automating updates.

    If bootctl supported specifying additional paths/names as an optional parameter, it would be a reasonably clean solution.

  4. YHNdnzj commented on Apr 12, 2023

    @YHNdnzj
    Member

    If you can point me to a tool in Arch that will automatically stick a copy of systemd-boot64.efi into grubx64.efi, I'm all ears.

    Well, bootctl install basically does two things: install the boot loader to esp/EFI/systemd/ and esp/EFI/BOOT/, plus adding an EFI boot entry. Since you're using shim/preloader, you don't need sd-boot to be installed to the mentioned destinations nor the boot entry since it's chainloaded by shim. So a simple cp will work for you IIUC?

  5. YHNdnzj commented on Apr 12, 2023

    @YHNdnzj
    Member

    If bootctl supported specifying additional paths/names as an optional parameter, it would be a reasonably clean solution.

    I actually think this makes more sense than adding a build option. It has more use cases, for both end users and distro maintainers, while still retaining the default behavior of installing to the aforementioned places.

  6. lnussel commented on Apr 13, 2023

    @lnussel
    ContributorAuthor

    Command line options are not useful for the distro unless there's also support for a global config file to enable the settings by default. So just calling bootctl install works out of the box.

    With shim the EFI boot entry must not point to sd-boot but shim. So bootctl install would need to know what path to put.
    Regarding distro differences that's why I had the idea to symlink shim files into /usr/lib/systemd/boot/efi/ so bootctl can just pick them up and do the right thing.

    Anyway another idea that came to my mind was to have a script eg /usr/lib/systemd/boot/install (or even scripts in .d) that when present gets executed by bootctl install instead of the builtin code. bootctl could pass some env vars with settings, like mount point of the efi partition. That script could be shipped by the shim package. So if no shim is installed, bootctl would just use it's built in code.

  7. alexojegu commented on Oct 19, 2024

    @alexojegu

    A configuration file would be great, something like /etc/systemd/boot.conf:

    [Boot]
    shim=yes
    

    So that bootctl update has the same behavior as now, but renaming systemd-boot64.efi to grubx64.efi. To bootctl install I see two options:

    • Create EFI boot entry pointing to grubx64.efi (It would be the same behavior as now).
    • Create EFI boot entry pointing to shimx64.efi (It could be simplified but it would be more risky).

    About the path, just keep using the same one as now /ESP/EFI/systemd/ (At least in Arch Linux, I don't know if it is a build option). For more exotic configurations the user or distribution will be responsible.

  8. Nowa-Ammerlaan commented on Oct 20, 2024

    @Nowa-Ammerlaan

    You don't actually have to rename systemd-boot to grub, shim loads the efi file it is given as an argument before it loads the hardcoded grubx64.efi. Like this:

    nowa@nowa-gentoo-pc ~ % efibootmgr -u
    BootCurrent: 0000
    Timeout: 0 seconds
    BootOrder: 0000,0006,0004,0008,0007
    Boot0000* Linux Boot Manager    HD(1,GPT,7ae430c6-07e8-3b4e-a796-b2a28706b3fb,0x800,0x100800)/\EFI\SYSTEMD\SHIMX64.EFI\EFI\systemd\systemd-bootx64.efi
    ...
    

    This I think is much cleaner.

  9. alexojegu commented on Oct 20, 2024

    @alexojegu

    Thanks @Nowa-Ammerlaan, I tried it but don't work with my hardware (It is 8 years old).

    BootCurrent: 0003
    Timeout: 1 seconds
    BootOrder: 0003,0001,0002,0000
    Boot0000* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi\EFI\Systemd\systemd-bootx64.efi
    ...
    

    https://wiki.gentoo.org/wiki/Shim#systemd-boot

    ... if the firmware supports it ...

  10. Nowa-Ammerlaan commented on Oct 20, 2024

    @Nowa-Ammerlaan

    Thanks @Nowa-Ammerlaan, I tried it but don't work with my hardware (It is 8 years old).

    Mine is also about that old, how did you create this entry? The correct way is:

    efibootmgr --create --disk ... --part ... \EFI\systemd\shimx64.efi --unicode \EFI\systemd\systemd-bootx64.efi
    

    The way efibootmgr -u prints the result makes it look identical to:

    efibootmgr --create --disk ... --part ... \EFI\systemd\shimx64.efi\EFI\systemd\systemd-bootx64.efi
    

    but that will not work.

    ... if the firmware supports it ...

    This is almost always the case (and if it is not then that is a serious UEFI bug). Windows also relies on passing arguments to the Windows boot loader via UEFI entry.

  11. alexojegu commented on Oct 20, 2024

    @alexojegu

    I tried to create it again before replying, this was the command:

    efibootmgr --disk /dev/sda --part 1 --create --label "Linux Secure Boot" --loader '\EFI\Systemd\shimx64.efi' --unicode '\EFI\Systemd\systemd-bootx64.efi'
    
  12. alexojegu commented on Oct 20, 2024

    @alexojegu

    I created the entry again now, by mistake, and when I deleted it... see this:

    # efibootmgr --disk /dev/sda --part 1 --create --label "Linux Secure Boot" --loader '\EFI\Systemd\shimx64.efi' --unicode '\EFI\Systemd\systemd-bootx64.efi'
    efibootmgr: ** Warning ** : Boot0000 has same label Linux Secure Boot
    BootCurrent: 0003
    Timeout: 1 seconds
    BootOrder: 0004,0003,0001,0002,0000
    Boot0000* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi\EFI\Systemd\systemd-bootx64.efi
    ...
    Boot0003* Temporal	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\systemd-bootx64.efi
    Boot0004* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi\EFI\Systemd\systemd-bootx64.efi
    
    # efibootmgr -u
    BootCurrent: 0003
    Timeout: 1 seconds
    BootOrder: 0004,0003,0001,0002,0000
    Boot0000* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi\EFI\Systemd\systemd-bootx64.efi
    ...
    Boot0003* Temporal	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\systemd-bootx64.efi
    Boot0004* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi\EFI\Systemd\systemd-bootx64.efi
    
    # efibootmgr -B -b 0004
    BootCurrent: 0003
    Timeout: 1 seconds
    BootOrder: 0003,0001,0002,0000
    Boot0000* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi5c004500460049005c00530079007300740065006d0064005c00730079007300740065006d0064002d0062006f006f0074007800360034002e00650066006900
    ...
    Boot0003* Temporal	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\systemd-bootx64.efi
    

    Some times \EFI\Systemd\systemd-bootx64.efi is converted to 5c004500460049005c00530079007300740065006d0064005c00730079007300740065006d0064002d0062006f006f0074007800360034002e00650066006900

  13. Nowa-Ammerlaan commented on Oct 20, 2024

    @Nowa-Ammerlaan

    Some times \EFI\Systemd\systemd-bootx64.efi is converted to 5c004500460049005c00530079007300740065006d0064005c00730079007300740065006d0064002d0062006f006f0074007800360034002e00650066006900

    That's the same, just presented differently. Note the difference between the output of efibootmgr and efibootmgr -u.

    If it still does not work I recommend upgrading the UEFI (if there is an update available). Note also that sometimes this is case-sensitive (even though it shouldn't be due to the FAT file system).

  14. alexojegu commented on Oct 20, 2024

    @alexojegu

    Yeah, the latest BIOS update for this Dell model is from 2021 and is installed.

    On a couple of occasions after displaying 5c004500460049005c00530079007300740065006d0064005c00730079007300740065006d0064002d0062006f006f007400780036003400 2e00650066006900, like now, when I reboot the Dell logo has disappeared (although everything seems to continue working correctly) and I have to reset the BIOS to defaults to get it to display again.

  15. arvidjaar commented on Oct 20, 2024

    @arvidjaar
    Contributor

    @alexojegu Show

    hexdump -C /sys/firmware/efi/efivars/Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c
    

    or whatever your boot entry number is.

  16. alexojegu commented on Oct 20, 2024

    @alexojegu

    This entry:

    efibootmgr -u
    ...
    Boot0000* Linux Secure Boot	HD(1,GPT,ad9b31dc-84c8-417f-b634-0cfd86589be8,0x800,0x300000)/\EFI\Systemd\shimx64.efi\EFI\Systemd\systemd-bootx64.efi
    

    Has this hexdump:

    # hexdump -C /sys/firmware/efi/efivars/Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c 
    00000000  07 00 00 00 01 00 00 00  64 00 4c 00 69 00 6e 00  |........d.L.i.n.|
    00000010  75 00 78 00 20 00 53 00  65 00 63 00 75 00 72 00  |u.x. .S.e.c.u.r.|
    00000020  65 00 20 00 42 00 6f 00  6f 00 74 00 00 00 04 01  |e. .B.o.o.t.....|
    00000030  2a 00 01 00 00 00 00 08  00 00 00 00 00 00 00 00  |*...............|
    00000040  30 00 00 00 00 00 dc 31  9b ad c8 84 7f 41 b6 34  |0......1.....A.4|
    00000050  0c fd 86 58 9b e8 02 02  04 04 36 00 5c 00 45 00  |...X......6.\.E.|
    00000060  46 00 49 00 5c 00 53 00  79 00 73 00 74 00 65 00  |F.I.\.S.y.s.t.e.|
    00000070  6d 00 64 00 5c 00 73 00  68 00 69 00 6d 00 78 00  |m.d.\.s.h.i.m.x.|
    00000080  36 00 34 00 2e 00 65 00  66 00 69 00 00 00 7f ff  |6.4...e.f.i.....|
    00000090  04 00 5c 00 45 00 46 00  49 00 5c 00 53 00 79 00  |..\.E.F.I.\.S.y.|
    000000a0  73 00 74 00 65 00 6d 00  64 00 5c 00 73 00 79 00  |s.t.e.m.d.\.s.y.|
    000000b0  73 00 74 00 65 00 6d 00  64 00 2d 00 62 00 6f 00  |s.t.e.m.d.-.b.o.|
    000000c0  6f 00 74 00 78 00 36 00  34 00 2e 00 65 00 66 00  |o.t.x.6.4...e.f.|
    000000d0  69 00                                             |i.|
    000000d2
    

    And it tries to load grubx64.efi. I am using shim-15.8-3 signed by Fedora (x86_64):
    https://koji.fedoraproject.org/koji/buildinfo?buildID=2423319

  17. Nowa-Ammerlaan commented on Oct 20, 2024

    @Nowa-Ammerlaan

    Yeah, the latest BIOS update for this Dell model is from 2021 and is installed.

    I vaguely remember reading at some point that some older Dell boards indeed have an issue where arguments are not actually passed on to the EFI executable. Perhaps that is what is going on here. You could try to directly load some kernel image and try to pass a kernel cmdline to it.

  18. arvidjaar commented on Oct 20, 2024

    @arvidjaar
    Contributor

    Has this hexdump:

    It's OK. I was surprised that efibootmgr did not show File(...), but apparently it was removed from efivars because it violated UEFI specs. Resulting in even more confusion over where path ends and parameters start.

  19. alexojegu commented on Oct 20, 2024

    @alexojegu

    You are right @Nowa-Ammerlaan, after a quick search I can find several references to Dell boards that do not pass arguments to the EFI executable (mostly older ones, but there is also one on the Gentoo forums from 2024).

    So finally I think I will have to use a pacman hook to copy systemd-bootx64.efi to grubx64.efi on upgrade, instead of just using bootctl update.

  20. demitriusbelai commented on Nov 5, 2024

    @demitriusbelai

    @alexojegu I don't remember why I put a null terminator in args. I guess BIOS was putting some dirty at the end of args. I am working with a Dell OptiPlex 3080. I guess it worth a try. Here the command I used:

    printf '\linux.efi\0' | iconv -t ucs-2 | efibootmgr --create-only --disk /dev/nvme0n1 --part 1 --label 'Arch' --loader '\EFI\Arch\shimx64.efi' --append-binary-args -
    

    For reference, fwupd also adds a null terminator:

    # hexdump -C /sys/firmware/efi/efivars/Boot0006-8be4df61-93ca-11d2-aa0d-00e098032b8c 
    00000000  07 00 00 00 01 00 00 00  5e 00 4c 00 69 00 6e 00  |........^.L.i.n.|
    00000010  75 00 78 00 20 00 46 00  69 00 72 00 6d 00 77 00  |u.x. .F.i.r.m.w.|
    00000020  61 00 72 00 65 00 20 00  55 00 70 00 64 00 61 00  |a.r.e. .U.p.d.a.|
    00000030  74 00 65 00 72 00 00 00  04 01 2a 00 01 00 00 00  |t.e.r.....*.....|
    00000040  00 08 00 00 00 00 00 00  00 d0 07 00 00 00 00 00  |................|
    00000050  a3 1f 75 ba cd c0 3a 46  86 ba 6c 58 9a f3 57 f8  |..u...:F..lX..W.|
    00000060  02 02 04 04 30 00 5c 00  45 00 46 00 49 00 5c 00  |....0.\.E.F.I.\.|
    00000070  61 00 72 00 63 00 68 00  5c 00 73 00 68 00 69 00  |a.r.c.h.\.s.h.i.|
    00000080  6d 00 78 00 36 00 34 00  2e 00 65 00 66 00 69 00  |m.x.6.4...e.f.i.|
    00000090  00 00 7f ff 04 00 5c 00  66 00 77 00 75 00 70 00  |......\.f.w.u.p.|
    000000a0  64 00 78 00 36 00 34 00  2e 00 65 00 66 00 69 00  |d.x.6.4...e.f.i.|
    000000b0  00 00                                             |..|
    000000b2
    

    I'm currently booting directly into the Linux kernel, but I'm looking to switch to systemd-boot with Shim. I've been researching how to make this migration.

  21. alexojegu commented on Nov 8, 2024

    @alexojegu

    Thank you very much @demitriusbelai, it's working!!!

  22. mreilaender commented on Dec 8, 2024

    @mreilaender

    Currently on a similar setup on Manjaro and I can confirm that:

    efibootmgr --disk /dev/sda --part 1 --create --label "Linux Secure Boot" --loader '\EFI\Systemd\shimx64.efi' --unicode '\EFI\Systemd\systemd-bootx64.efi'
    

    doesn´t pass the systemd argument to shim but instead shim looks for grubx64.efi. I'm on a Lenovo ThinkPad T14 Gen 1.

    Can u not simply add something like:

    bootctl update <installation-path>
    

    U would be able to name it whatever u want and would solve the problem of having to rename systemd with some script ...

  23. schaarsc commented on May 22, 2025

    @schaarsc

    In case of issues you may try '\EFI\SYSTEMD\SYSTEMD-BOOTX64.EFI ' (worked for me)

    • all upper case
    • white space at the end
  24. Greek64 commented on Oct 19, 2025

    @Greek64
    * white space at the end
    

    Space did it for me.
    I remember having to do a similar trick once for the kernel commandline inside a EFI, where the last argument was malformed due to some extra garbage being appended, so I inserted a second quiet to the end of the arguments that would be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFE 🎁sd-boot/sd-stub/bootctl

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions