CAUTION!
The these instructions are for older systems using IDE mode only.
How to Repair or Re-install GRUB using the chroot command
Guide Overview
The purpose of this guide is to teach you how to Repair or Re-install GRUB using the chroot command.
A typical example of the need for this is when you install or re-install Windows in dual boot system. Windows will over write your boot sector, causing you to loose GRUB.
Tools Needed
Live USB or Bootable CD Installation Media
Computer with failed or broken GRUB boot menu
Instructions
Step1
Boot the computer using the Live Media and mount the Linux system partition.
Using your USB or CD media, boot the computer. DO NOT use the install option. Select the “Try Without Installing” or similar option, depending on your flavour.
Determine which device is your computer’s root system. It is most likely an ext4 partition. Your Windows will be on an ntfs partition. A simple method is to start gparted from the Live menu. It is pre-installed on almost all installation media.
If it is an SATA or IDE drive, it will appear as something similar to this /dev/sdxn where x is the drive letter, and n is the partition number. On my old computer, for example, it is /dev/sda2. Newer SSD drives may appear as something like this /dev/nvme0n1p2.
Now determine your mount point. Open a terminal on your live desktop. Most live systems will have a directory called /mnt. You can confirm this with the command ls /mnt. If /mnt does not exist, the create it with the command sudo mkdir /mnt.
You can now mount your system partition using the following command:
sudo mount -t ext4 /dev/sdxn /mnt
Substitute the correct drive letter and partition number for your installation. The -t switch tells the mount command that it is an ext4 partition. If you are typing it by hand, don’t forget the spaces!
Step2
Tell grub where to find the information it needs to repair your system, using the --bind switch with the mount command. Then change your root directory.
You are going to bind the directories that grub needs to the /mnt directory. Enter the following series of commands:
sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /sys /mnt/sys
You can copy and paste them as a block. The && at the end of the line tells your shell to execute the next command in line only if that command is successful.
Now, use the chroot command to make the /mnt directory our new root.
sudo chroot /mnt
Any commands you enter, from this point, will act directly on your computers Linux system root.
Step3
Install, check, and update grub.
Enter each of the following commands, one at a time, to re-install and update grub.
NOTE: You are installing grub in the boot sector of your hard drive. NOT in a partition. Only use the drive letter. Do not add the partition number.
Normally it would be the first drive in the computer, that is /dev/sda. If you had grub installed on another drive, then you must use that drive letter.
grub-install /dev/sda
grub-install --recheck /dev/sda
update-grub
You have now reset your grub menu.
Step4
Exit the chroot shell, unmount our binds and system partition, and restart the computer.
To return to your original root, simply type the exit command.
Then unbind the directories and unmount the system partition using the following sequence:
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt
NOTE: Everything is done in reverse order. We want to make sure that everything is unmounted cleanly.
Now shut down the computer using the power off menu from the install media. Remove the USB or CD and restart the computer.
Your grub menu should appear, as normal.
Cheers!
Naught
Edited by NickAu, 04 March 2021 - 10:54 PM.