Accidentally wiped grub (need to reinstall)

I just accidentally did sudo rm -rf /boot/efi/EFI. I don't want to talk about it... I now need to reinstall grub but I can't figure out how. I'm still in the system and I would like to shutdown soon-ish, quick help would be a godsend. The fedora docs give this command dnf reinstall shim-\* grub2-efi-\* grub2-common but that's not helpful to me. I tried to do sudo rpm-ostree install --allow-inactive shim-\* grub2-efi-\* grub2-common but that did nothing. ujust regenerate-grub also did nothing. Most promising felt sudo bootupctl validate but that failed with this output
[TRACE bootupd] executing cli
Running as unit: bootupd.service
[TRACE bootupd] executing cli
[TRACE bootupd::bootupd] Gathering status for installed component: EFI
[DEBUG bootupd::efi] Unmounting
[TRACE bootupd::bootupd] Remaining known components: 1
[TRACE bootupd::component] No CoreOS aleph detected
[DEBUG bootupd::blockdev] Found parent devices: ["/dev/sdb"]
[DEBUG bootupd::blockdev] Found esp partitions: ["/dev/sdb1"]
[DEBUG bootupd::efi] Reusing existing mount point "/boot/efi"
[DEBUG bootupd::efi] Unmounting
[TRACE bootupd::efi] Unmounted
error: opening EFI dir /boot/efi: No such file or directory (os error 2)
[TRACE bootupd] executing cli
Running as unit: bootupd.service
[TRACE bootupd] executing cli
[TRACE bootupd::bootupd] Gathering status for installed component: EFI
[DEBUG bootupd::efi] Unmounting
[TRACE bootupd::bootupd] Remaining known components: 1
[TRACE bootupd::component] No CoreOS aleph detected
[DEBUG bootupd::blockdev] Found parent devices: ["/dev/sdb"]
[DEBUG bootupd::blockdev] Found esp partitions: ["/dev/sdb1"]
[DEBUG bootupd::efi] Reusing existing mount point "/boot/efi"
[DEBUG bootupd::efi] Unmounting
[TRACE bootupd::efi] Unmounted
error: opening EFI dir /boot/efi: No such file or directory (os error 2)
Solution:
just a summary if anyone ends up in the same situation as me you need to run dnf install grub2-efi grub2-efi-modules shim-\* in a fedora distrobox container then copy the /boot/efi/EFI/fedora from the container into your host after that you need to download the gen_grub_cfgstub script and run it like so sudo ./gen_grub_cfgstub "/boot/grub2" "/boot/efi/EFI/fedora"...
Jump to solution
108 Replies
nagito || Knight of Emilia
the bootupd logs look promising
Absolpega
AbsolpegaOP•2mo ago
they're the most promising, i wouldn't call them promising they're confusing it errors with /boot/efi not existing but when i do sudo ls /boot/efi it does exist
nagito || Knight of Emilia
bootupd is what updates/installs grub
Absolpega
AbsolpegaOP•2mo ago
i know i just don't know what to do next
nagito || Knight of Emilia
weeeell if you can somehow install the grub binaries i can give ya the grub config file bootupd uses a static config which itself uses the blscfg command to load the OSTree entries this file doesn't need to change problem is only fedora's grub has blscfg so you gotta make sure to install that i once used a fedora distrobox to do this
Absolpega
AbsolpegaOP•2mo ago
i see doing a second install and then transplanting the executables might also work
nagito || Knight of Emilia
also this setup needs another little config file alongside grub.cfg has to be called bootuuid.cfg & this is what it contains for me set BOOT_UUID="db2880d5-2031-4064-aa94-50b9b594701c" it's just the UUID of OSTree's boot partition
Absolpega
AbsolpegaOP•2mo ago
is that the partition mounted on /boot?
nagito || Knight of Emilia
yeah should be it's where the kernel & initrd are
nagito || Knight of Emilia
this is grub.cfg
nagito || Knight of Emilia
oh i see the partition can also be labelled boot & grub will find it though UUID is better probably $prefix refers to the install folder for grub
Absolpega
AbsolpegaOP•2mo ago
hold on so you're suggestion to make a fedora container but from then i don't understand exactly run the dnf command?
nagito || Knight of Emilia
as in where the majority of it is yeah basucally that was my silly idea you use a rootful distrobox install the grub cli tools in there & use grub2-ibstall with the correct args to install grub also mount the esp & boot in there of course i don't know the args off the top of my head but i know --target should be x86_64-efi there's also --efi-directory as i recall
Absolpega
AbsolpegaOP•2mo ago
sudo grub2-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Fedora /dev/sdb i have it tried that before directly
nagito || Knight of Emilia
hiw did it end?
Absolpega
AbsolpegaOP•2mo ago
grub2-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesn't exist. Please specify --target or --directory. it's proofed against people doing this it only works for bios boot /usr/lib/grub/i386-pc/ has everything you'd expect
nagito || Knight of Emilia
hmm that just seems to indicate the target for efi doesn't exist on the grub partition there;s this file as well {"installed":{"BIOS":{"meta":{"timestamp":"2025-06-17T16:35:00Z","version":"grub2-tools-1:2.12-32.fc42.x86_64"},"filetree":null,"adopted-from":null}},"pending":null,"static-configs":{"timestamp":"1970-01-01T00:00:00Z","version":"0.2.26"}} it's bootupd.json nottice how it says version & then the package name might need that package to get the propper tools
Absolpega
AbsolpegaOP•2mo ago
been there, done that
nagito || Knight of Emilia
i mean grub2-tools
Absolpega
AbsolpegaOP•2mo ago
i was booting with uefi before this is i'm pretty sure intentional yea didn't change the output and it was also already installed
nagito || Knight of Emilia
hmm i recall there being a separate efi modules package for efo
Absolpega
AbsolpegaOP•2mo ago
yea i think i installed that too (and again it was already installed) i really think this is intentional it might even be this way on regular fedora
nagito || Knight of Emilia
Fedora Docs
The GRUB2 Bootloader – Installation and Configuration
GRUB2 is the latest version of GNU GRUB, the GRand Unified Bootloader. A bootloader is the first software program that runs when a computer starts. It is responsible for loading…
Absolpega
AbsolpegaOP•2mo ago
No description
nagito || Knight of Emilia
hmm fukes gitta be somewhere on the filesystem after package install lemme go & poke it also i think bazzite has some restore script somewhere for grub
Absolpega
AbsolpegaOP•2mo ago
sudo fd modinfo.sh / only found the bios boot one
nagito || Knight of Emilia
hmm if i install the packages from the instructions i get the wrong arch aarch64-efi
Absolpega
AbsolpegaOP•2mo ago
yea you might be running a little different hardware lol
nagito || Knight of Emilia
nope i'm on x86
Absolpega
AbsolpegaOP•2mo ago
well i just ran sudo dnf install shim-\* grub2-efi-\* grub2-common in the fedora container and there now is a /boot/efi/EFI in the container so i'm just gonna try transplanting that
nagito || Knight of Emilia
used this to get the modules udo dnf install grub2-efi grub2-efi-x64-modules shim-\*
Absolpega
AbsolpegaOP•2mo ago
yea i have those too now not sure which method is less sketchy
nagito || Knight of Emilia
i'd try the CLI should work now probably
Absolpega
AbsolpegaOP•2mo ago
well i decided on the transplant and now bootupd is happy only thing i can do now is probably reboot pray for me
nagito || Knight of Emilia
good luck
Absolpega
AbsolpegaOP•2mo ago
grub shell :( well at least i don't have any important files on my gaming desktop
nagito || Knight of Emilia
good
Absolpega
AbsolpegaOP•2mo ago
probably just gonna reinstall
nagito || Knight of Emilia
is it the grub shell or just grub rescue if it isn't rescue that's good grub is installed
Absolpega
AbsolpegaOP•2mo ago
uuuuhh what's the difference i'm only used to systemd-boot with UKI
nagito || Knight of Emilia
the prompt has rescue in it
Absolpega
AbsolpegaOP•2mo ago
not the case
nagito || Knight of Emilia
& there's no introduction text about the bash like shell & styff
Absolpega
AbsolpegaOP•2mo ago
ok it's the shell
nagito || Knight of Emilia
can you run blscfg does the command exist
Absolpega
AbsolpegaOP•2mo ago
yep
nagito || Knight of Emilia
if yes good now just gotta look at the static config for what needs to be done for blscfg to be happy & find the entries setting root to the correct partition might be enough i think you just gotta set set boot=(hd0,gptX) X being the partition number you can see them all with ls ls (hd0,gptX)/ will show you the files on there may beed to run normal after blscfg
Absolpega
AbsolpegaOP•2mo ago
should root be the ext2 or btrfs partition
nagito || Knight of Emilia
root only really determines the root partition as in what partition is listed when you ls / don't think that matters here i think you just gotta set boot to the ext4 partition
Absolpega
AbsolpegaOP•2mo ago
it's ext2 and that's the one that's mounted on /boot gpt1 is mounted on /boot/efi gpt2 is mounted on /boot gpt3 is mounted on / (not exactly but you know what i mean)
nagito || Knight of Emilia
i think grub can't tell the difference between ext versions
Absolpega
AbsolpegaOP•2mo ago
maybe
nagito || Knight of Emilia
the ext2 driver reads ext3 & 4 just fine they're backwards compatible
Absolpega
AbsolpegaOP•2mo ago
wait so this current problem is because it couldn't find the grub cfg right? so i'm just setting boot so it can find it also after setting it how do i make it boot
nagito || Knight of Emilia
no not quite you are setting boot so that the blscfg command can find the boot entries this is what grub.cfg does it's all it needs to do on blscfg supporting distros
Absolpega
AbsolpegaOP•2mo ago
i set it and what do i do now?
nagito || Knight of Emilia
the actual loader entries are stored in /loader/entries/ostree-1.conf on the boot partition blscfg needs to read these ostree-1 & ostree-2 respectiveky those correspont to the grub entries
Absolpega
AbsolpegaOP•2mo ago
i see (i also see they're there)
nagito || Knight of Emilia
have you tried blscfg & then normal after setting boot
Absolpega
AbsolpegaOP•2mo ago
it just put me back
nagito || Knight of Emilia
oh i noticed something in grub,cfg it sets root=$boot so yeah you probably need to set root
Absolpega
AbsolpegaOP•2mo ago
same thing as before except just set root instead of set boot?
nagito || Knight of Emilia
yeah
Absolpega
AbsolpegaOP•2mo ago
that did something blscfg is now complaining
Absolpega
AbsolpegaOP•2mo ago
no menu context error: ../../grub-core/commands/menuentry.c:96: no menu context. i don't think the transplant worked...
nagito || Knight of Emilia
oh an AI is telling me something interesting
A common cause is an incorrect blsdir setting in the /boot/grub2/grubenv file, which can point to a wrong directory like /root/boot/loader/entries instead of the correct /boot/loader/entries. Removing or correcting the blsdir line in grubenv resolves the issue, as the system then searches the correct location. Additionally, ensure that the insmod blscfg and blscfg lines are present in /boot/grub2/grub.cfg.
you probably need a blsdir variable as well grubenv is just a way of setting variables in a way that grub can save them
Absolpega
AbsolpegaOP•2mo ago
i can always do btrfs surgery to separate the system and home to reinstall bazzite while saving everything
nagito || Knight of Emilia
fun fact grubenv is the one file that grub can write to & tools in linux can also write to it so you can do cool dynamic rebooting into distros it can also save/hold the last selected/booted entry the save_env command saves variables to grubenv
Absolpega
AbsolpegaOP•2mo ago
my grubenv doesn't have anything related
nagito || Knight of Emilia
ai says the blsdir
Absolpega
AbsolpegaOP•2mo ago
just menu_auto_hide=2, boot_success=1, boot_indeterminat=0
nagito || Knight of Emilia
variable has to be /loader/entries which is the folder entries sit in set that & see if blscfg is happy
Absolpega
AbsolpegaOP•2mo ago
blscfg didn't complain this time but normal just brought me back
nagito || Knight of Emilia
i could reboot & poke around
Absolpega
AbsolpegaOP•2mo ago
well anyways i need to log off now your support has been 10/10 thank you very much, you are a godsend at this stage i can always return to this i also have alternative ways of recovering the system and i don't need to recover it at all i feel pretty good leaving this here and again thank you so much
nagito || Knight of Emilia
i got less bad news & bad news less bad news i literally just needed
root=(hd0,5)
blscfg
root=(hd0,5)
blscfg
root is my ostree boot partition bad news this seemingly HAS to be in a config file for some very strange reason if you can put a config file on a fkash drive you could try loading that with configfile gudder news you can in fact load the file with configfile if your firmware has an EFI shell built in that has a built in text editor you can use it to make the file it's SUCH a dumb situation with such a simple fix the editor in uefi shell is edit could also just boot the local install just enough to be able to write the file after all ain't nothin stopping you from just entering the commands to boot it is just 2 commands though they're both kinda long the grub shell support tab completion so it's not that much typing
Absolpega
AbsolpegaOP•2mo ago
what config file should i put that in? i'm currently in windows so i'm free to edit any file
nagito || Knight of Emilia
just a random text file which will act as grub's config when you load it using configfile you can just put it in /grub2/grub.cfg if you can so it loads at boot as in configfile /path/to/file loads a file you can start the path with (hdX,gptX) of course & of course set root in the file to whatever your boot partition is
Absolpega
AbsolpegaOP•2mo ago
@nagito || Knight of Emilia i got further and i can now boot with configfile (hd2,gpt2)/grub2/grub.cfg i don't know if maybe it can't find the grub.cfg because of the transplant also the current grub.cfg is the original static one you sent me i must've ran mkconfig before understanding how bls worked
nagito || Knight of Emilia
what do you get if you echo $prefix the file needs to go in $prefix/grub.cfg to auto load not that suprised grub doesn't auto find the config because of the way it was installed usually the cli lets you set the preffix maybe just moving the binaries doesn't change the prefix or something though it can clearly find all it's modules which are also in $prefix this sort of transplanting isn't that unexpected by grub fun fact on UEFI you can just smash all of grub including the config file into 1 binary grub-mkimage is grub's tool that does this sort of thing fedora probably calls it grub2-mkimage not sure why dustris do the spread out way also the config file/modules aren't the only thing you can bake in you can do arbitrary files
Absolpega
AbsolpegaOP•2mo ago
so is there a way to manually change the prefix?
nagito || Knight of Emilia
yeah what IS the prefix though
Absolpega
AbsolpegaOP•2mo ago
time to reboot the prefix is (hd2,gpt1)/EFI/fedora
nagito || Knight of Emilia
oh yeah i read that that's the "normal" one for fedora usually a file sits there telling it to load the other standard file it's written in the docs we read i believe
Absolpega
AbsolpegaOP•2mo ago
i think it's baked into the grub executable
nagito || Knight of Emilia
the prefix yes the config no not in your case
nagito || Knight of Emilia
see says here that's normal i do wonder what the "shim" config looks like
Absolpega
AbsolpegaOP•2mo ago
i have shim.efi and shimx64.efi in $prefix
nagito || Knight of Emilia
yeah don't know if shim refers to that seems to refer to the "default" grub.cfg that loads the standard not using EFI currently so i can't test on my own right now it's probably fine to put the static file in $prefix/grub.cfg now that i think of it /EFI/steamos/grub.cfg is a thing on Steam OS as well in that case only that config exists as i recall but fedora has the shim"to load the default fedora file to support both BIOS & UEFI i guess the shim.efi seens ti be secure boot related
Absolpega
AbsolpegaOP•2mo ago
i think from now on it's just fighting rpm-ostree i need to reinstall the grub base packages you use overrides to override base packages but there's this thing called inactive overrides where if the override package is the same as the original base package it does nothing so no reinstall happens i'll probably have to downgrade and then upgrade back for it to actually reinstall
nagito || Knight of Emilia
the difference between shell & rescue is rescuse is entered when the $prefix & thus modules in there can't be found
Absolpega
AbsolpegaOP•2mo ago
ok that would require much more work than i thought rpm-ostree override replace is such a pain to use
nagito || Knight of Emilia
it lets you set the prefix manually & boot
Absolpega
AbsolpegaOP•2mo ago
it requires local rpm files
nagito || Knight of Emilia
yeeeeeeah
Absolpega
AbsolpegaOP•2mo ago
and i need to reinstall grub2-common and all the other grub packages are dependents of it i have found this tho https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/gen_grub_cfgstub it's the script used to generate the stub
nagito || Knight of Emilia
yeah see essentially it's just
cat << EOF > "${EFI_HOME}"/grub.cfg.stb
search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)${GRUB_DIR}
export \$prefix
configfile \$prefix/grub.cfg
EOF
cat << EOF > "${EFI_HOME}"/grub.cfg.stb
search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)${GRUB_DIR}
export \$prefix
configfile \$prefix/grub.cfg
EOF
Absolpega
AbsolpegaOP•2mo ago
i get that
nagito || Knight of Emilia
or specifically just
search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)${GRUB_DIR}
export \$prefix
configfile \$prefix/grub.cfg
search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)${GRUB_DIR}
export \$prefix
configfile \$prefix/grub.cfg
Absolpega
AbsolpegaOP•2mo ago
GRUB_HOME i know is /boot/grub2 and i'm assuming EFI_HOME is /boot/efi/EFI/fedora/
nagito || Knight of Emilia
yeah since that contains the grub.cfg generated
Absolpega
AbsolpegaOP•2mo ago
that did fix it
nagito || Knight of Emilia
as i thought it would
Absolpega
AbsolpegaOP•2mo ago
thank you again so much
Solution
Absolpega
Absolpega•2mo ago
just a summary if anyone ends up in the same situation as me you need to run dnf install grub2-efi grub2-efi-modules shim-\* in a fedora distrobox container then copy the /boot/efi/EFI/fedora from the container into your host after that you need to download the gen_grub_cfgstub script and run it like so sudo ./gen_grub_cfgstub "/boot/grub2" "/boot/efi/EFI/fedora" DO NOT use grub-mkconfig if you did, you will have to find the original static one that uses blscfg
nagito || Knight of Emilia
see the search command in grub.cfg notice how that looks for the UUID an interesting thing it can do is look for files & if a device contains a specific file set the chosen variable to that device

Did you find this page helpful?