Thursday, June 29, 2017

HP and Windows - A Jealous Affair

I bought my HP laptop 3.5 years ago. It came pre-installed with Windows 8. As a primary Linux user, I installed Ubuntu with a intention of dual-booting with using Ubuntu primarily. However, HP always showed only Windows in the bootup, and by default it goes into Windows - never letting me sign in. Boot-repair-disk helped me fix this issue. Nevertheless, every time Windows upgraded, it broke the fix, and made the computer go into Windows by default. I tried to stop Windows upgrade after fixing this several times using Boot-repair-disk, as I got fed up with this. However, Windows upgrade worked on its own for "critical system/security updates". I was unable to turn these off. Guess what? These automated updates broke my boot as usual, leaving Windows the only option. 

It was not even possible to change the boot to Ubuntu, or to bring the menu at start up. By that time, I got to know that this was a bug (or a feature?) from HP that Windows was hard-coded. I also did not have this issue in my other new laptop. Why I did not completely uninstall Windows? Sometimes I need it: printer, a few wifi configurations, and some docx, pptx files sent by others - these are the reasons behind my occasional usage of Windows. But every time I go to WIndows, it breaks my grub, leaving it as the only option to log in to.

By this time, Boot-repair-disk stopped working. However, I have an earlier version stored in my pen drive, which luckily works well. So I assume that a later "fix" in Boot-repair-disk broke it. Even efibootmgr did not work as expected. All I was able to do was to change the option for the next boot. Not forever! Eventually, I had to follow this work-around to get this running.

First, find your current status:
$ sudo efibootmgr
[sudo] password for pradeeban:
BootCurrent: 0002
Timeout: 0 seconds
BootOrder: 0003,3003,0000,0002,0004,2001,2002,2003
Boot0000* rEFInd Boot Manager
Boot0002* ubuntu
Boot0003* Windows Boot Manager
Boot0004* ubuntu
Boot0005* EFI USB Device (General UDisk)
Boot2001* USB Drive (UEFI)
Boot2002* Internal CD/DVD ROM Drive (UEFI)
Boot3000* Internal Hard Disk or Solid State Disk
Boot3001* Internal Hard Disk or Solid State Disk
Boot3003* Internal Hard Disk or Solid State Disk

Now, ideally you should be able to do the below:
$ sudo efibootmgr -o 0002,0004,3003,0000,2001,2002,0003
BootCurrent: 0002
Timeout: 0 seconds
BootOrder: 0002,0004,3003,0000,2001,2002,0003
Boot0000* rEFInd Boot Manager
Boot0002* ubuntu
Boot0003* Windows Boot Manager
Boot0004* ubuntu
Boot0005* EFI USB Device (General UDisk)
Boot2001* USB Drive (UEFI)
Boot2002* Internal CD/DVD ROM Drive (UEFI)
Boot3000* Internal Hard Disk or Solid State Disk
Boot3001* Internal Hard Disk or Solid State Disk
Boot3003* Internal Hard Disk or Solid State Disk

But, unfortunately, it was not working as expected. Rather, I had to follow a work-around of changing the boot order just for the next boot:
$ sudo efibootmgr -n 0002

Now add this below line to /etc/rc.local to repeat this same action every time Ubuntu loads:
sudo efibootmgr -n 0002

After this work-around, the grub loads successfully, and I can choose Ubuntu (among the many other options) easily as before. I did not log in to Windows after this fix. I am sure Windows will find a way to easily break this work-around once I log in to it.

Currently this work around makes sure that every time I log in to Ubuntu, Ubuntu sets the next boot to be Ubuntu/grub option. However, if I log in using the Windows entry in the grub, this bit won't be set. So the next time, it will log in to Windows directly, and thus breaking this cycle. However, when that happens, I just need to use Esc -> F9 sequence to just log in to Ubuntu once. After that, Ubuntu will be back as long as I keep using only it. In other words, Ubuntu boot will be fine as long as I do not log in to Windows.

You do not see Ubuntu upgrades breaking my Windows boot. Windows is such a jealous affair.

No comments:

Post a Comment

You are welcome to provide your opinions in the comments. Spam comments and comments with random links will be deleted.