Efi Grub reinstall

If you have some problematic computer like HP Pavilion 17, Windows or windows-based malwares can destroy boot. If so, you need to install and configure via liveUSB, because boot-repair, etc. may not work with HP.

The process:
1. Boot using liveUSB, open Terminal and mount efi-partition under /mnt and open /mnt as an administrator and copy /mnt/EFI/Microsoft/Boot to /mnt/EFI/Microsoft/Boot2 and rename /mnt/EFI/Microsoft/Boot/bootmgfw.efi and /mnt/EFI/Microsoft/Boot/bootmgr.efi files.

2. Copy /mnt/EFI/ubuntu/grubx64.efi (copy twice) and /mnt/EFI/ubuntu/grub.cfg files to the /mnt/EFI/Microsoft/Boot folder and rename grubx64.efi as bootmgr.efi and bootmgfw.efi.

3. Umount /mnt

4. Chroot to your linux-system (eg. /dev/sda7)

sudo mount /dev/sda7 /mnt
sudo mount –bind /dev /mnt/dev
sudo mount –bind /sys /mnt/sys
sudo mount –bind /proc /mnt/proc
sudo chroot /mnt
nano /etc/resolv.conf
… the contents
…. save and quit
Ctrl o
Ctrl x
apt-get update
apt-get install grub-efi-amd64
mount /dev/sda2 /boot/efi ### if the efi partition is /dev/sda2
apt-get install –reinstall grub-efi

sudo umount /mnt/dev
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt

Now you should be able to boot into your linux-system.

For getting Windows to boot also, you need to make an /etc/grub.d/40_custom file, whose contents is

#! /bin/sh
exec tail -n +3 $0

menuentry ”Windows” {
insmod part_gpt
insmod chain
set root='(hd0,gpt2)’
chainloader /EFI/Microsoft/Boot2/bootmgfw.efi

Notice that the path is /EFI/Microsoft/Boot2 !

After making run
sudo update-grub

WordPress shows the commands wrong, so read this

Useful links: