Grub Boot repair

Posted on Wed 19 August 2020 in dev-journal

One of my servers had a failure over the weekend and caused some corruption of the boot loader. This is the first time I have experienced this with a setup built on LVM and LUKS, which provided a little extra complexity to solve the problem.

This time, the Ubuntu Boot Repair tool was used because in the process of trying to fix this problem manually I had caused further issues.

The error:

symbol grub_calloc not found grub rescue

One of the problems I ran into seemed to be the way that I was using LVM when decrypting and mounting my root partition.

device-mapper: create ioctl on xubuntu--vg-root failed: Device or resource busy

Here is what worked:

# STEP 1: boot into live cd

# create rescue folder
sudo mkdir -p /rescue/boot

# in this case the root partition was encrypted
sudo cryptsetup open --type=luks vg0-root /dev/sda5
sudo mount /dev/mapper/vg0-root /rescue/boot
sudo mount /dev/sda1 /rescue/boot

sudo mount --bind /dev /rescue/dev &&
sudo mount --bind /dev /rescue/dev &&
sudo mount --bind /dev/pts /rescue/dev/pts &&
sudo mount --bind /proc /rescue/proc &&
sudo mount --bind /sys /rescue/sys


# chroot 
sudo chroot /rescue
grub-install /dev/sda
grub-install --recheck /dev/sda
update-grub

sudo umount -a
# STEP 2: run the rescue utility
# From the Boot-Repair live cd
sudo mkdir -p /rescue/boot

sudo cryptsetup open --type=luks vg0-root /dev/sda5
sudo mount /dev/mapper/vg0-root /rescue/boot
sudo mount /dev/sda1 /rescue/boot

# at this point you have the encrypted volumes mounted. Now run the Boot Repair utility

The second step may not be necessary for you. I had done something wrong in the process before I discovered how to fix it so my entire boot partition had problems. After getting the device decrypted and mounted the utility was able to walk me through the process of fixing the VM so it would boot again.