After dd I cannot run grub2-mkconfig

I’ve made a fedora system in a virtual machine (virt manager, Q35 chipset, UEFI) using the live installer and GUI. Then, I converted the qcow2 image to raw and then I dd’d it to my /dev/sda. Made the following steps:

sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /run /mnt/run
sudo chroot /mnt

Then I figured I’d run grub2-mkconfig and be testing this system, but:

# grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
/usr/bin/grub2-editenv: error: cannot open `/boot/grub2/grubenv.new': No such file or directory.
/sbin/grub2-mkconfig: line 268: /boot/efi/EFI/fedora/grub.cfg.new: No such file or directory

# grub2-mkconfig -o /boot/grub2/grub.cfg
/usr/bin/grub2-editenv: error: cannot open `/boot/grub2/grubenv.new': No such file or directory.
/sbin/grub2-mkconfig: line 268: /boot/grub2/grub.cfg.new: No such file or directory

Edit: grub2-mkconfig -o /boot/grub2/grub.cfg is working on the virtual machine.

What am I missing to make this work?

You must be root to use grub2-mkconfig (either with sudo or logged in as root)
Your list of commands does not show that you ever shifted to become root or that you used sudo with the grub2-mkconfig command.

I did sudo chroot

In any case, I now tried sudo su and then chroot, same result.

What you are attempting sounds like it ought to work. I thought Fedora’s default install created separate partitions for /boot and /boot/efi though. You appear to have only mounted /boot. Have you configured the system differently?

1 Like

Here’s the official instruction:
The GRUB2 Bootloader – Installation and Configuration :: Fedora Docs

You missed step #9 and almost broke the configuration that shouldn’t be touched.

1 Like

When I do a chroot like that I always try and run a mount -a command after doing the chroot so I can be certain all the appropriate filesystem/partitions are mounted before doing any other commands.
I overlooked the missing /boot/efi in the steps posted by the OP above. :upside_down_face:

1 Like

I have only made a separate partition for /boot/efi.

Thanks. It gave me some weird errors (not being able to access /var/log/dnf.log I think?). But On the second attempt the guide took me there, it’s booting. Thanks for the help!

1 Like

I forgot that when using QEMU/KVM for a vm the default is to do a legacy installation and not uefi. Was your vm using legacy boot or uefi boot?

If uefi boot the /boot/efi partition should have already been part of the qcow2 (and raw) image

Yes, I did change it to UEFI in advance, thanks!