Saturday, 10 October 2015

SOLUTION : GRUB NOT BOOTING ON DUAL BOOT WITH WINDOWS ON HP LAPTOPS


Well sometimes you buy hardware that has software made by morons. For example HP
laptops. I recently faced this situation with my HP lappy.
Now HP laptops are good pieces of hardware but my experiences say they usually
have very bad BIOS that does not allow you to tinker it much. One time another
HP laptop actually stopped booting when all I did was update the BIOS because
it just wanted to get updated from a 32-bit OS not a 64-bit one. Anyways my
 lappy also has a very stupid UEFI. Now this one has a hardon for
windows. What it does is if it finds windows efi file in your computer then it
will only ever boot from that file and will happily neglect any changes that
you make in the mean time. So our problem arises thusly:

You basically want to switch from windows and go the linuxy way of things and
one fine day decide to install it on your machine. After carefully searching
through the distro muck you select your favorite one and on you go forward in
your journey. But when the install is finished and the computer reboots. Well
long story short you will still boot into windows. As said above the damn thing
will only ever search for windows efi and will happily neglect your linux efi
entry. No matter how much h4x0r!n9 you do by changing efi file order it will
still boot into windows

But no worries like always where there is a will there is a way. So hop on for
one hell of a solution to this mess.



First of all I am assuming is that you have correctly installed windows
7/8/8.1/10 and a linux distro of your choice and now only problem left to
handle is to make the linux distro boot by default.

So boot into windows first. Now in Start/Start screen search for cmd.exe. Right
click and then select run as administrator. A command line window with
administrator privilages opens up. After this enter the following command into
it:

mountvol S: /S

what this does is it mounts a partition of your hard-drive basically the boot
partition of your hard-drive in which every OS's boot files are stored. Now to
see it on your explorer window restart it. A quick way is to give following
commands:

Taskkill /F /IM explorer.exe
explorer.exe

Now check 'My Computer' or 'This PC' (Win 8+) and you will see your boot
partition. Now go to folder S:\EFI\Microsoft\Boot\ where you will find your
boot file named 'bootmgfw.efi' till this file is present at this location your
machine will always create an 'OS boot manager' entry and will always boot into
Windows. So rename this file to something like 'windows.efi'.

Now you need to tell the windows loader to boot from your renamed EFI file so
execute this in your administrator command window:

bcdedit /set {bootmgr} path \EFI\Microsoft\Boot\windows.efi

If you have renamed the file to something else just give that name above
instead of windows.efi. Now reboot.

Quickly press F9 or whatever is the key combination for choosing boot order for
your machine is when the computer is restarting to open EFI file menu. Here
select the linux option (usually named after your distro example 'ubuntu').
This will boot you into your distro.

Now once there open a terminal and type:

sudo efibootmgr -v

this gives you list of EFI files that can boot your lappy. And the order in
which they boot( given in the line starting with BootOrder: ).

In the displayed list linux distro name should come first before windows if its
not so delete the windows entry. So if like windows is the first entry or it
can be 'OS boot Manager' then it will probably be numbered 0000 so type on
terminal:

sudo efibootmgr -b 0000 -B

Now if linux is at boot0001 and windows is at boot0002 change the boot order
using this:

sudo efibootmgr -o 0001,0002

After this all is done. You need to create an entry for grub to see your
windows. For this type:

sudo gedit /etc/grub.d/40_custom

and add the following block at the bottom

menuentry "Microsoft Windows 7" --class windows --class os {
  insmod part_gpt
  insmod fat
  insmod search_fs_uuid
  insmod chain
  set root='XXXXX'
  chainloader /EFI/Microsoft/Boot/windows.efi
}

where XXXXX is the output of

sudo grub-probe -t drive /boot/efi/EFI/Microsoft/Boot/windows.efi

Now finally type in terminal this:

sudo update-grub

This will add your boot entry to grub's boot menu and you are now done.

Phew....that was some loadful.

P.S. by Shivam Nema : This solution is the combined effort of lots of people. Firstly, Great Emerald in HP forums, Comments by geeks around the world and of course Siddarth Pant for his kind efforts to organizing all those efforts together and writing this very article. I thanks to all.

No comments:

Post a Comment