14

I had Windows 8.1 and Kali Linux installed in an extended partition. For some reason, I only formatted the partition where Windows was installed and re-installed. Now it only boot into Windows and doesn't show grub.

I'm using a live USB and tried to reinstall grub:

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

and getting the error:

grub-install :command not found
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

3 Answers3

8

To add to the answer provided by user @kirill-a and flesh it out a bit more:

Here is what I did recently to restore the GRUB boot loader on a Windows 8 and Debian 8 dual-boot machine, after a Windows 8 reinstallation cleared the previous GRUB boot loader entry from the beginning of the disk.

REPAIR GRUB2: Live USB/CD 'chroot' method on linux:

These instructions apply generally to an unencrypted, non-LVM disk on Debian-based distros, minor changes are needed in directory names and utilities used under RHEL/SUSE-based and possibly Arch-based distros.

Start with a bootable Live USB or CD of the distro of your choice.

  1. Use lsblk to determine the kernel name descriptor (i.e. /dev/xxyN) of the block device with a missing or damaged GRUB boot loader.

All the following actions are to be done as root (use su or sudo).

  1. Create a temporary mount point for the installed Linux:

    mkdir -p /mnt/linux
    

    (the -p option creates the parent directory /mnt if it doesn't already exist)

  2. Using /dev/xxyN from previous lsblk command:

    mount /dev/xxyN /mnt/linux
    
  3. The following command is only necessary if you have a separate /boot partition; /dev/xxyN here is representing the kernel name descriptor of your /boot partition.

    mount /dev/xxyN /mnt/linux/boot
    
  4. Then:

    mount -t proc none /mnt/linux/proc
    mount -t sysfs sys /mnt/linux/sys
    mount -o bind /dev /mnt/linux/dev
    mount -t devpts pts /mnt/linux/dev/pts
    chroot /mnt/linux /bin/bash
    grep -v rootfs /proc/mounts > /etc/mtab
    grub-install /dev/xxy
    

    (Here, dev/xxy = the device name and number on which to install the GRUB boot loader , e.g., /dev/sda, not including the root partition number as in /dev/sda1)

  5. If you wanted to make any other changes/customizations to GRUB, now is the time to edit the /etc/default/grub file, and save.

    grub-mkconfig -o /boot/grub/grub.cfg
    
  6. Reboot and verify.

Note: There are several additional steps to this procedure if your GRUB2 boot loader resides on a linux system with an LVM LV root and/or an encrypted root volume. Feel free to message me here, I have these additional instructions written down and have applied them successfully several times to an LVM LV on an ssd which contains a root volume encrypted with the kernel dm-crypt module.

muru
  • 72,889
nomadrc
  • 576
  • This did not work for me until I logged in as root. I was using Debian 10 Buster live media – Matt Minga Feb 10 '21 at 20:11
  • This is an old thread, but I found it useful. However, I had to mount /sys/firmware/efi/efivars to get grub-install to complete without the warning "EFI variables are not supported on this system." – Dan Meigs Mar 16 '22 at 19:17
3

You need to chroot to your installed system and reinstall grub from there:

mount /dev/sda(number of partition with kali) /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt bash
grub-install --boot-directory=/mnt/boot /dev/sda
update-grub
exit
reboot 
kirill-a
  • 2,923
2

My answer is for grub2-install and grub2-mkconfig commands.

I was also getting command not found error on my Photon OS Linux box.

There were configuration files under /boot/grub2. So I was thinking that the grub2 package is already installed, but for some reason grub2-* commands are not working.

However, it turned out that grub2 package was not installed. Running below command fixed the issue.

yum install grub2 -y

For grub-install command, you will need to install grub package instead of grub2.

AdminBee
  • 22,803
ramtech
  • 121