Last day my workstation (which runs Linux Mint 18.2 Sonya) crashed while upgrading Grub2 (the default Linux boot loader). After a hard reset it and I found myself grub console. After rebooting twice, I realized that something had gone wrong. Grub is one of the things I’ve never bothered to look into, since I’m mostly doing development and not system administration. And experimenting with tenfold of Linux distributions doesn’t appeal to me any longer.
I had quite a lot of work that had to be done, so I reached out for my pack of USB memory sticks and hoped there would be a recovery boot option. After being through 5 different sticks; the only dire option was to trying to boot up the computer via the grub console or reinstalling everything.
First step – orientation – ls and cat
I needed to figure out which one of my harddrive contained my filesystem to boot to. I figured out that the ls command in grub can give a lot of information.
The hd0 stands for harddrive 0, or /dev/sda. The last digit stands for which partition; and the slash in the end means that I’d like to list all the files and directories in the root of that partition. In this case /dev/sda1. After a few adjustments on the harddrive number and the partition number, I finally found my root directory (the volume to boot up on). Harddrive 1 and partition 2. (hd1, 2). Which also translates into /dev/sdb2 I verified that it indeed was the volume by:
grub> cat (hd1,2)/etc/issue
Linux Mint Sonya 18.2 \n \l
Second – Inform grub about your root filesystem
So I found the root filesystem, which I needed to tell grub about. I declared the root in grub:
I also needed to declare the linux kernel and the initrd image (temporary root filesystem which the system boots upon). They are located in the /boot directory. However, grub2 can work with symlinks and there are usually a symlink to both vmlinuz and initrd.img in the root directory. So I declared these for grub:
grub> linux /vmlinux root=/dev/sdb2
grub> initrd /initrd.img
The root argument is needed so the kernel knows which one is the root filesystem. In this specific case the disk was the second disk (number 2) and partition 2 which translates to /dev/sdb2.
Third – Boot time
Lastly I crossed my fingers and hope that the machine finally would boot up. By telling grub to boot:
The first time I ran the boot command it didn’t work at all. I’d forgotten the root argument for the kernel. After adding that, the machine booted up and I could finally run grub-update to fix the corrupt grub installation.
Hope it helps anyone who’s experiencing the same issue. It is at least a quick guide for myself for next time :)