Reinstall grub on a different drive?

5,756

Thanks Raman Sailopal and cas for the help, but it didn't fit my case.
Here are the exact steps to follow, assuming /dev/sda4 is linux root, /dev/sdb2 is your EFI partition (located in /boot/efi), and your linux/initrd files are /boot/vmlinuz-linux & /boot/initramfs.img
Burn a live usb of ubuntu (16.04?) with amd64 architecture, boot on it and paste these commands:

sudo os-prober
efibootmgr

Install os-prober or efibootmgr if it isn't installed yet:

sudo apt-get install os-prober
sudo apt-get install efibootmgr

Grub in efi mode is probably not installed, install it too

sudo apt-get install grub-efi-amd64-signed

Then, install grub:

sudo mount -t ext4 /dev/sda4 /mnt
sudo mount -t vfat /dev/sdb2 /mnt/boot/efi
grub-install --target=x86_64-efi --efi-directory=/mnt/boot/efi --boot-directory=/mnt/boot --bootloader-id=grub

Don't try to use grub-mkconfig, it will not work.
Instead, boot from your newly grub bootloader, you will have a grub shell, paste these commands:

set root=(hd0,4)
linux /boot/vmlinuz-linux root=/dev/sda4
initrd /boot/initramfs.img
boot

After that, you should be on linux, mount your efi partition if it's not already, install grub/os-prober/efibootmgr, and run these:

sudo os-prober
grub-install --target=x86_64-efi --efi-directory=/boot/efi --boot-directory=/boot --bootloader-id=grub
grub-mkconfig -o /boot/grub/grub.cfg

Reboot, and grub is back.

Share:
5,756

Related videos on Youtube

Random Coder 99
Author by

Random Coder 99

Updated on September 18, 2022

Comments

  • Random Coder 99
    Random Coder 99 over 1 year

    I dismantled my PC & reassembled it, after that GRUB disappeared.
    I have two disks: a SSD (sdb, GPT) and a HDD (sda, MBR):

    • sda1: "part" (128MB)
    • sda2: windows, ntfs
    • sda3: windows again, ntfs (added this partition after installing grub & arch)
    • sda4: arch linux /

    • sdb1: windows's recovery (ntfs)

    • sdb2: /boot/efi (vfat)
    • sdb3: "part" again, 16MB
    • sdb4: windows again (main windows partition, it is installed here)

    I usually booted on my SSD, and I had windows boot loader & arch_grub
    Now I only have windows boot loader, but grub's files are still there, there's grubx64.efi in /boot/efi/EFI/arch_grub, and grubenv, grub.cfg, x86_64-efi in /boot
    (I installed windows in UEFI mode, and I guess I installed arch too in UEFI mode, I used architect)

    So basically grub is in /boot which is on my HDD (and /boot/efi is on my SSD), everything worked fine until now. I tried to use boot-repair on an ubuntu live usb, but I had the error "arch does not have grub-amd64-efi-signed package installed"

    I think I can still boot on arch with grub's command line but what will I do then ? I already have every needed files, therefore grub-install will be useless

    • Alessio
      Alessio almost 7 years
      if you can get arch to boot at all via the grub command line, you should be able to run update-grub and it will re-generate the grub.cfg to match the current drive setup. You may also need to run efibootmgr again so that it also matches the new drive layout. You're runing Arch, so see wiki.archlinux.org/index.php/GRUB/EFI_examples
    • Random Coder 99
      Random Coder 99 almost 7 years
      Sorry but I'm lost, I can't find a manual page for efibootmgr, so I don't know which arguments I have to enter. Also, I have a MSI B250M Pro-VDH, and every single file of grub is okay, so if I replace the bootx64.efi by grubx64.efi, it will boot directly on grub ? Is that a bad idea ?
    • Random Coder 99
      Random Coder 99 almost 7 years
      Nevermind, found a manual page. If I redo grub config & add a boot entry with efibootmgr, will it be okay ? wiki.archlinux.org/index.php/…
  • Random Coder 99
    Random Coder 99 almost 7 years
    grub-install may install grub files to another folder, they will be redundant. If I just regenerate grub's config & use efibootmgr as cas said, it will work I guess ?
  • Random Coder 99
    Random Coder 99 almost 7 years
    I have tried that: pastiebin.com/5981bee6233ec your answer doesn't work with efi and for my case
  • Raman Sailopal
    Raman Sailopal almost 7 years
    Shouldn't grub-mkconfig -o be to /mnt/boot and not /boot?
  • Random Coder 99
    Random Coder 99 almost 7 years
    When i executed grub-mkconfig I was already on arch (said it in the comments)