Problems reinstalling grub

So i am dual booting fedora 36 and windows 11, but a couple of days ago, i stopped being able to boot into fedora 36. I got some help from this forum and typed the following commands in a live usb of fedora:

  1. sudo /bin/bash
  2. mount /dev/nvme0n1p6 /mnt
  3. mount --bind /boot /mntroot/boot
  4. mount --bind /boot/efi /mnt/root/boot/efi
  5. for dir in proc sys dev run; do mount -o bind "/$dir" "/mnt/root/$dir" ; done
  6. chroot /mnt/root
    Then i tried reinstalling grub:
  7. dnf reinstall grub*
    Which gave me some Curl errors.

After this i tried some other commands i found for reinstall grub, but none of them worked.
Also after this command, which gave me the error, the last command i will type is:
8. grub2-mkconfig -o /etc/grub2-efi.cfg
And then, assuming i am able to boot into fedora, i will do a dnf upgrade to make sure everything is up to date.
So how do i reinstall grub?

1 Like

You are supposed to create the grub config file in /boot not /etc. It goes something like this # grub2-mkconfig -o /boot/grub2/grub.cfg. Also I think the curl errors are maybe due to network issues. Make sure your internet is working. I think you should check out the documentation and check out the section “restoring the boot loader from live disk”.
If you are having any issues, feel free to ask.

1 Like

/etc/grub2-efi.cfg is a symbolic link to /boot/grub2/grub.cfg – or it should be. Therefore, you can specify either one as output.

I seriously doubt about the first commands:
Assuming it’s no BTRFS, I would do:
mount /dev/nvme0n1p6 /mnt/root
Only if separate boot partition: mount /dev/nvme0n1p? /mnt/root/boot with ? is index of boot partition
mount /dev/nvme0n1p? /mnt/root/boot/efi with ? the index of the EFI partition

Steps 3 and 4 bind directories of the live system to the installation, which makes no sense. In contrast, in step 5 it makes sense.

The name server config file /etc/resolv.conf could be a symbolic link to a file in /run. This fails in a chroot environment. You can try to create a classical /etc/resolv.conf containing "nameserver <yourdnsserverip>"or “nameserver” and check whether the curl errors disappear.

What is exactly happening when you try to boot Fedora and what could have caused the boot failure?

The command to recreate grub.cfg is grub2-mkconfig -o /boot/grub2/grub.cfg, provided it is included by /boot/efi/EFI/fedora/grub.cfg using the correct uuid of the boot partition.

Ive managed to install grub now, but i am having problems with grub2-mkconfig -o /boot/grub2/grub.cfg
Which gives me the error:

/usr/sbin/grub2-probe: error: cannot find a device for / (is / dev mounted?).

What is it i need to mount here?

Please consider this thread, especially towards the end, how to properly reinstall GRUB.

Did you mount / on /mnt/root while using the live disk because I think for some reason it was not there.

Im a bit confused. Didnt i do that with the command mount /dev/nvme0n1p6 /mnt?
If not, what exactly is it i need to mount to what?
Sorry for this dumb, question, as you can probably tell, i know very little about linux.

Its okay we all were beginner once. So are you sure the one you used to mount is the / partition and if it is then try to chroot into it again and I would suggest to follow the documentation and change the disk index likewise. And this is a dumb question on my part :sweat_smile: and don’t get offended did you followed the commands as is I mean you do have a nvme storage device right? and partition 6 is the one with / partition. Try this

# mkdir -p /mnt/root
# mount /dev/nvmep? /mnt/root
# mount -o bind /dev /mnt/root/dev
# mount -o bind /proc /mnt/root/proc
# mount -o bind /sys /mnt/root/sys
# mount -o bind /run /mnt/root/run 
# mount -o bind /sys/firmware/efi/efivars /mnt/root/sys/firmware/efi/efivars
# mount <efi system partition> /mnt/root/boot/efi 

on the second command enter partition for your nvme drive and if you are using uefi then mount your efi partition.

Instead of mount /dev/nvme0n1p6 /mnt/root shouldnt it be mount /dev/nvme0n1p6 /mnt? because there is no root folder inside the mnt folder.
When i try the first command i get mount point does not exist.
The root folder is in the nvme0n1p6 i think.

If not, could this be the problem? When i used the chroot command i wasnt able to chroot to /mnt i had to chroot to /mnt/root.

Yeah you actually have to create the folder before you use that command and that’s exactly what this
mkdir -p /mnt/root command does , it creates the directory inside /mnt where you mount everything else. And you have to chroot into /mnt/root as you have used it to mount the / partition.

Okay. But that means inside the root folder i created with the command mkdir -p /mnt/root there is another folder called root, because everything on the nvme0n1p6 is inside a folder called root. So when i mount for example /dev i should mount it to /mnt/root/root/dev right?
Thats atleast the only thing that works.

And thanks for all the help so far.

I don’t understand exactly what you are saying but if I am not wrong you are talking about the /root directory on nvme drive OK so in Linux this “/” is called root partition and /root is a directory on it it’s not the same thing it’s different. So you don’t have to do that just use the above command. If you somehow mistakenly created a root directory inside /mnt/root then that might be the reason why you are seeing it. If that is the case then I guess it might work but it seems unnecessary in my opinion.

On the nvme0n1p6 partition there is one folder where everything is inside, and when i mount that partition on the /mnt/root, the root folder on the nvme0n1p6 gets put inside the /mnt/root so i am not able to mount and bind for example /boot to /mnt/root/boot, because the only folder inside /mnt/root is a folder called root. Inside that folder is all the folders i need to bind and mount to.
So to not get an error i have to mount /boot to /mnt/root/root/boot.
Could this be why i get the error with the
grub2-mkconfig -o /boot/grub2/grub.cfg

I don’t know why everything on nvme is inside root folder but I guess you are right that it might be the reason why grub config error occurred. I think this directory somehow got created because “/” is where the filesystem’s root is present and you can’t have it like this root/. I suggest try deleting that directory and retry or you can just reboot with the live disk if it’s not persistent.

Okay, that did it. I got all the commands to work, and createdbthe grub.cfg file, but after rebooting i just got booted into windows again. Did i do something wrong, here are the commands i ran:

sudo /bin/bash
# mkdir -p /mnt/root
# mount /dev/nvme0n1p6 /mnt/root
# mount -o bind /dev /mnt/root/dev
# mount -o bind /proc /mnt/root/proc
# mount -o bind /sys /mnt/root/sys
# mount -o bind /run /mnt/root/run 
# mount -o bind /sys/firmware/efi/efivars /mnt/root/sys/firmware/efi/efivars
# mount  /dev/nvme0n1p5 /mnt/root/boot/efi 
# chroot /mnt/root
# dnf reinstall grub*
# grub2-mkconfig -o /boot/grub2/grub.cfg

Then i rebooted again, but just got booted into windows, without any grub bootloader to choose OS.
Is there anything im missing here?

You didn’t see anything about windows on grub config output. If that’s the case then make sure you have os-prober installed and sometimes os-prober doesn’t work if you didn’t mount the windows c drive when you are in chroot. Enter the chroot again and just run lsblk find the windows partition and check the label or size from the output. Since you are on windows you can see the size or disk lable of c drive then on chroot just use that to find the right one and you don’t need to reinstall grub if you installed it without errors just recreate the grub config while in chroot. Also when you are in chroot you don’t need to mount the windows partition to /mnt/root just mount it in /mnt or if you prefer any other directory inside it just remember to mount it on /mnt while in chroot. I think you are pretty close to fixing it. :smile:

Thanks a lot for all the help, i really appreciate it.
I might not reply more today, because it might take some time to do this, but i will reply if i get it to work, or if i encounter any problems i am not able to solve.

It’s okay I understand fixing things can get tiring. You can take your time. :grinning:

Please look at what /etc/grub2-efi.cfg actually is before stating that the command given is incorrect.

Using it is not an error since it is a symlink to the file located at /boot/grub2/grub.cfg.