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
Solution:Jump to 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"...108 Replies
the bootupd logs look promising
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 existbootupd is what updates/installs grub
i know
i just don't know what to do next
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 thisi see
doing a second install and then transplanting the executables might also work
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 partitionis that the partition mounted on /boot?
yeah
should be
it's where the kernel & initrd are
this is grub.cfg
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
hold on so you're suggestion to make a fedora container
but from then i don't understand exactly
run the dnf command?
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 recallsudo grub2-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Fedora /dev/sdb
i have it
tried that before directlyhiw did it end?
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 expecthmm 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 toolsbeen there, done that
i mean
grub2-toolsi was booting with uefi before
this is i'm pretty sure intentional
yea
didn't change the output
and it was also already installed
hmm
i recall there being a separate efi modules package
for efo
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
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…

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
sudo fd modinfo.sh / only found the bios boot onehmm
if i install the packages from the instructions
i get the wrong arch
aarch64-efi
yea you might be running a little different hardware lol
nope
i'm on x86
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 thatused this to get the modules
udo dnf install grub2-efi grub2-efi-x64-modules shim-\*yea i have those too now
not sure which method is less sketchy
i'd try the CLI
should work now probably
well i decided on the transplant and now bootupd is happy
only thing i can do now is probably reboot
pray for me
good luck
grub shell :(
well at least i don't have any important files on my gaming desktop
good
probably just gonna reinstall
is it the grub shell or just grub rescue
if it isn't rescue that's good
grub is installed
uuuuhh what's the difference
i'm only used to systemd-boot with UKI
the prompt has rescue in it
not the case
& there's no introduction text
about the bash like shell & styff
ok it's the shell
can you run
blscfg
does the command existyep
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 blscfgshould root be the ext2 or btrfs partition
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 partitionit'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)
i think grub can't tell the difference between ext versions
maybe
the ext2 driver reads ext3 & 4 just fine
they're backwards compatible
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
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
i set it
and what do i do now?
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
i see
(i also see they're there)
have you tried
blscfg & then normal
after setting bootit just put me back
oh
i noticed something in grub,cfg
it sets
root=$boot
so yeah
you probably need to set rootsame thing as before except just set root instead of set boot?
yeah
that did something
blscfg is now complaining
hmm
no menu context
error: ../../grub-core/commands/menuentry.c:96: no menu context.
i don't think the transplant worked...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 themi can always do btrfs surgery to separate the system and home to reinstall bazzite while saving everything
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 grubenvmy grubenv doesn't have anything related
ai says the blsdir
just
menu_auto_hide=2, boot_success=1, boot_indeterminat=0variable has to be
/loader/entries
which is the folder entries sit in
set that & see if blscfg is happyblscfg didn't complain this time
but normal just brought me back
i could reboot & poke around
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
i got less bad news & bad news
less bad news
i literally just needed
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 typingwhat config file should i put that in?
i'm currently in windows so i'm free to edit any file
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@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 workedwhat 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 filesso is there a way to manually change the prefix?
yeah what IS the prefix though
time to reboot
the prefix is
(hd2,gpt1)/EFI/fedoraoh 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
i think it's baked into the grub executable
the prefix yes
the config no
not in your case

see says here that's normal
i do wonder what the "shim" config looks like
i have shim.efi and shimx64.efi in $prefix
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 relatedi 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
the difference between shell & rescue is rescuse is entered when the $prefix & thus modules in there can't be found
ok that would require much more work than i thought
rpm-ostree override replace is such a pain to useit lets you set the prefix manually & boot
it requires local rpm files
yeeeeeeah
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
yeah see
essentially it's just
i get that
or specifically just
GRUB_HOME i know is /boot/grub2
and i'm assuming EFI_HOME is /boot/efi/EFI/fedora/
yeah
since that contains the grub.cfg generated
that did fix it
as i thought it would
thank you again so much
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"
DO NOT use grub-mkconfig
if you did, you will have to find the original static one that uses blscfgsee 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