On starting my PC after it powered off due to low battery, I was met with a grub prompt as shown below
I didn’t have explanation for what had happened cause my PC hadn’t failed or given warning prior to this, but I made an update earlier which I suspected could be buggy or didn’t complete before I lost internet connectivity but nonetheless I had to fix this.
My working knowledge of grub2 was minimal since grub2 config is automatically installed and configured. Being a Fedoraproject user I found this good wiki resource on fedoraproject. I followed the wiki page and was able to fix the problem though not immediately, I hope my solution would help someone using lvm and device mapper device types, below is a sample of my df -h before the issue
Lets start working on fixing the issue, on the grub prompt run the command ls
Note: Below is how it appeared on my grub terminal, yours could be a little different especially if you aren’t using lvm
(hd0) (hd0,gpt1) (hd0,gpt2) (hd0,gpt3) (lvm/fedora-swap) (lvm/fedora-root) (lvm/fedora-home)
from the listed entries above you would need to find where your root file system in installed and also where your kernel (vmlinuz and initramfs) entries was installed, below are my own entry
Note if you don’t add the “/” at the back of the filesystem it would only give you the type of filesystem you are trying to access e.g ext2 or fat.
grub> ls (hd0,gpt2)/
grub> ls (lvm/fedora-root)/
Os root treeOnce you got the above previous entries you are good to go, just do the following
Note: first value passed to root is from ls result where our os tree reside, yours could be different based on device type
*linuxefi and initrdefi are for efi type, linux and initrd works for non efi.
*the root value is the device type for lvm, check the fedora wiki page for other scenario
grub> set root=(lvm/fedora-root)
grub> linuxefi (hd0,gpt2)/vmlinuz-4.9.4-201.fc25.x86_64 root=/dev/mapper/fedora-root rhgb quiet selinux=0
Once it has finish booting you can open a terminal and
grub2-mkconfig -o /boot/grub2/grub.cfg
Issue the grub2-install command to install grub2 to your hard drive and make use of your config:
grub2-install –boot-directory=/boot /dev/sda # Note: your drive may have another device name. Check for it with mount command output.
The command above is likely to fail for efi system, try the below if that happens
# dnf install grub2-efi-modules
# grub2-install –boot-directory=/boot /dev/sda.