8
July
2024
17:37

Installing the boot-repair utility on Debian

8 July 2024 17:37

Installing boot-repair on Debian is very different from Ubuntu.

What is this message about?

When running from a bootable LiveCD or bootable Linux flash drive, it is possible boot recovery linux operating system installed on the hard drive using the utility boot-repair. At the same time, boot correction is possible both in Ubuntu and Debian OS. This article is about the latter option.

What is the purpose of the boot-repair utility?

When installing Windows in parallel (side by side) with Linux or executing the command bcdedit /fixmbr from Windows Recovery Environment as written at the beginning of this article, the Linux boot loader gets corrupted and when you turn on the PC, instead of the Grub2 menu, Windows immediately starts.

"update-grub" command used when restoring grub2, but does not help here:
sudo mount /dev/sda5 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc
#sudo mount /dev/sdaX /mnt/boot
sudo chroot /mnt
sudo update-grub
exit
sudo umount /mnt/dev
sudo umount /mnt/sys
sudo umount /mnt/proc
#sudo umount /mnt/boot#if a separate section boor
sudo umount /mnt/

The reason is that on a system with mbr, the GRUB2 bootloader writes a reference to itself to the boot sector(which is currently occupied by the Windows boot loader), so the effect of update-grub no.

The solution is to use the boot-repair utility

There is a peculiarity when installing boot-repair in Debian. Incorrect installation steps boot-repair in Debian:
PPA repository shouldn't add via the command add-apt-repository:
sudo add-apt-repository ppa:yannubuntu/boot-repair this method is intended for Ubuntu

The correct way to install boot-repair on Debian is:

1) if add-apt-repository does not start, install the package

sudo apt install python3-launchpadlib

2) using add-apt-repository, delete the PPA if it was installed previously (steps 1-2 can be skipped if it’s a clean installation)

sudo add-apt-repository --remove ppa:yannubuntu/boot-repair

3) install wget

sudo apt install wget

4) download the GPG key

wget -O- https://sourceforge.net/projects/boot-repair/files/key.gpg | sudo tee /etc/apt/keyrings/boot-repair.gpg;

5) add the repository to the boot-repair.list file in the /etc/apt/sources.list.d/ folder

echo 'deb [signed-by=/etc/apt/keyrings/boot-repair.gpg] https://ppa.launchpadcontent.net/yannubuntu/boot-repair/ubuntu noble main' | sudo tee /etc/apt/sources.list.d/boot-repair.list;

6) installation boot-repair

sudo apt update && sudo apt install -y boot-repair

Steps 3-6 are described in the instructions on the page https://sourceforge.net/p/boot-repair/home/Home/ author of the program yannubuntu.

After installing boot-repair, I ran the utility in the terminal boot-repair as administrator (sudo). When choosing the first option - a simple recovery, after a few minutes the program installed the Linux bootloader on the hard drive and reinstalled Grub2, after which the choice of OS in the Grub2 menu became available the next time the PC was turned on.


Notes on using boot-repair

(Additions from 2026):

1) before using boot-repair on a laptop with a low-resolution screen, you need to resize the display so that the window becomes smaller and fits within the screen boundaries:

xrandr | grep "connected" | awk '{print $1}'
xrandr --output LVDS --scale 1.2x1.2

2) if boot-repair is run from a bootable LiveCD, then its boot method is UEFI or boot should exactly match the disk partitioning style for recovery. For example, to restore the boot menu of a hard drive partitioned using the BIOS method, you need to press ESC and select “General USB Disk”. And for a hard drive with UEFI partitioning (GPT), you need to press ESC and select "USB Disk UEFI".

3) When performing boot-repair to reinstall grub, a text instruction will be displayed on the screen. You need to execute the commands from this instruction in a terminal window one by one manually.

4) For the BIOS boot type, it is highly desirable to have a partition /boot at the beginning of the disk (ext4 format, named /dev/sda1, 300 MB in size), which will contain the grub2 bootloader files and the vmlinuz, initrd and memtest86 kernel files (in total, 2 kernels and grub2 occupy 270 MB, one kernel and grub2 - 170 MB). Since if Linux OS is installed by the second system, then the Linux boot partition (for example, /dev/sda7) is located very far from the beginning of the disk. At the same time, the first boot may proceed normally, but if the laptop's power is turned off, mbr and grub may fail to load, because The BIOS will not be able to transfer control to the grub bootloader at the end of the disk.

5) To edit the UEFI BIOS menu when using GPT disk partitioning, you can use the utility efibootmgr.
In this case, the operating system must be loaded in UEFI mode (or from a LiveCD flash drive in UEFI mode).
This utility allows you to edit the menu built into the UEFI BIOS and change the boot delay time.



Related publications