I got a grub-rescue prompt and it was not fun but I learnt a lot

Here’s me on a weekend thinking I can upgrade a core server from Ubuntu 18.04 to 20.04.

This is normally quite a risky undertaking depending on the complexity of the server, but doable. It’s a lot of fun too, e.g. if you are the Systems Administrator’s kind.

So I proceed, and at some stage a weird message about GRUB pops up. This particular VM host is Proxmox.

The message is detailed at the end of this article, but safe to say, the next few hours were quite harrowing because seeing your production server look like this:

>grub rescue

is not fun at all.

Most of the articles for >grub uses the ls and set prefix commands. Generally the remedies are for >grub and not >grub rescue as my case.

Here are common ‘this will sort it out’ advice,. things like:

ls
ls (hd0,msdos1)/boot/grub/i386-pc
set prefix=(hd0,msdos1)/boot/grub

However, in my case, I got a weird cannot find i386-pc file problem. Nothing I did with those commands helped me.

In the end I had to boot Ubuntu Desktop, go to a terminal, and follow various recovery procedures, most of which didn’t work. For example:

grub-install --root-directory=/mnt /dev/sda

The below StackExchange article got me in the right direction, but not the suggested answer, one further below.

https://askubuntu.com/questions/1183951/grub-file-filters-not-found-after-ubuntu-19-10-upgrade

Solution

First boot from Ubuntu Desktop ISO, then go to terminal

$ sudo mount /dev/sda1 /mnt
$ sudo grub-install --root-directory=/mnt /dev/sda

Here is where trouble begin:

| The GRUB boot loader was previously installed to a disk that is no longer present, or whose unique identifier has changed for some reason. It is │ 
│ important to make sure that the installed GRUB core image stays in sync with GRUB modules and grub.cfg. Please check again to make sure that GRUB is │ 
│ written to the appropriate boot devices. │ 
│ │ 
│ If you're unsure which drive is designated as boot drive by your BIOS, it is often a good idea to install GRUB to all of them. │ 
│ │ 
│ Note: it is possible to install GRUB to partition boot records as well, and some appropriate partitions are offered here. However, this forces GRUB │ 
│ to use the blocklist mechanism, which makes it less reliable, and therefore is not recommended. │ 
│ │ 
│ GRUB install devices: │ 
│ │ 
│ [ ] /dev/sda (161061 MB; QEMU_HARDDISK) │ 
│ [ X ] - /dev/sda1 (86972 MB; /) │ 
│

Incidentally, I selected the 86972 disk only as that’s the actual size of the disk. Perhaps next time I will select both 🙂 as doing that set me back a few hours and caused a lot of stress.

I hope this doesn’t happen to you but if it does, do not panic.

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top