[SOLVED] Unable to overwrite Windows Boot Manager with GRUB in external drive with dual boot setup

I’ll try this right now. :wink:

Also, can you share some answer from my post #4. Maybe I could use that reference? Thank you.

This.

I hope I’m not misunderstanding you again… I was about to explain that your firmware will not have efibootentry of the External disk efi bootentry if you remove the disk and booted without it.

But then I realized you may not be talking about the bios firmware cmos efientries.:joy:
Maybe it related to the main issue to skip entries and is no longer relevant?

So, if it is important and still relevant, would you want to explain further?
Cheers.

2 Likes

The BCD entries in Windows that boot linux? Oh no, I never use this method. That’s sacrilegious :rofl: to me. Maybe @AgentS or @calvous can explain? Haven’t seen @calvous for some time.

1 Like

CAVEAT

I’ve only tested (long ago) personally with one entry to skip.
If multiple skips are required, I am not sure if separate lines will do the job.
If it doesn’t, you can try with one line and separated by space like…

GRUB_OS_PROBER_SKIP_LIST="A46E8F586E8F21E2@/dev/sda1" "xxxxxxxxxxxxxxxxx@/dev/sda3" "xxxxxxxxxxxxxxxx@/dev/sda4"
2 Likes

Using GRUB_OS_PROBER_SKIP_LIST worked (but I tried it multiple lines in my case). Thank you so much :grin:

About my 4th post (a reference from here)

Maybe I could try the suggested workaround? Could you verify if it’s possible (and how)? Thank you again :slightly_smiling_face:

1 Like

I would suggest you do not. Again, what do we want to achieve here? If we do not want Windows to be default, at efibootmgr, we can do that. If bios-legacy, just do ‘grub-install’ at the OS we want to be default. If we do not want windows to thrash linux bootloaders, in uefi, have separate $esp’s. And finally, we have this method The Simple First Start Method to get back our bootloader either in bios-legacy or in uefi.

But entirely up to you to try it out. And you have that link to get it back if you find (most likely) it serves no point.

Cheers.

2 Likes

I just realized, I could just use os-prober to detect other OSes bootloaders in my drives :sweat_smile: But the only problem right now, executing sudo update-grub does not add the Windows bootloader to the entry. Maybe there’s an option that manually adds an entry like contrast to what GRUB_OS_PROBER_SKIP_LIST does?

It does for me. It was reported that for some here it did not, like for you. Some suggested to mount the windows partition first before doing ‘update-grub’ and the windows entry will be found.

I also suspect (‘suspect’ because I don’t have this problem and I had hiberfile disabled in windows) that disabling hiberfile in windows should also do the job.

powercfg /h off

As admin in windows command prompt.

Finally there is a custom entry for windows that will boot it.
For uefi, “chainloader /EFI/Microsoft/Boot/bootmgfw.efi”
For bios-legacy, “ntldr /bootmgr”

So if you really have a problem, let me know and we’ll write out the custom entry and put it in the grub.cfg.

2 Likes

Oh… forget to point out an important point.
A bios-legacy grub can never boot a uefi windows.
A uefi grub can never boot a bios-legacy windows.

Hope you are not doing this. But if you are, you have to boot using the bootup key (F8 ~ F12) when you start computer and select it.

The manual entries I was talking about are

menuentry "Windows UEFI "  {
	insmod part_gpt
	insmod fat
	insmod chain
	set root='(hd0,gpt1)'
	chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}


menuentry "Windows bios-legacy" {
  insmod ntfs
  search --set=root --fs-uuid xxxxxxxxxxxxxxx
  ntldr /bootmgr
}

And create /boot/grub/custom.cfg and put entry into it.

ps: it’s late here and I’ll be logging off soon.
Will write later if you have more.
Good night.

2 Likes

I’ll try it and see if it all worked.

Thank you so much, and good night to you too :grin:

Just adding the RTFM
From Grub manual

On EFI systems for fixed disk install you have to mount EFI System Partition. If you mount it at /boot/efi then you don’t need any special arguments:

grub-install

Otherwise you need to specify where your EFI System partition is mounted:

grub-install --efi-directory=/mnt/efi

For removable installs you have to use --removable and specify both –boot-directory and –efi-directory:

grub-install --efi-directory=/mnt/usb --boot-directory=/mnt/usb/boot --removable
2 Likes

I think if you mean only EFI system partition is mounted, then the value for --boot-directory should be: --boot-directory=/mnt/usb/EFI/Boot (I’m not really sure :thinking:)? Please correct me if I’m wrong cause I’ll try this right now :slightly_smiling_face:

EDIT

Because if --efi-directory is /mnt/usb, given the value /mnt/usb/boot for --boot-directory could possibly N/A (does not exist)? Or should I mount both the root and system partition and use: --boot-directory=/mnt/boot?

OR, what does /mnt/usb/boot refers to? :confused:

These identifiers are examples.
IIUC after booting from your external Manjaro installation, confirm you have the correct $esp mounted at /boot/efi.
If not (if the internal $esp was used), unmount internal $esp and mount external $esp at /boot/efi.
Then

sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro-ext  --boot-directory=/boot --recheck --debug --removable
1 Like

I got it now thank you :slightly_smiling_face:

1 Like

@gohlip I tried everything as well as the “workaround” from stackexchange. Although the workaround does replaced the Windows Boot Manager with GRUB (which answered the title of my original post), the problem changed to something else…

What I did was:

  1. Mount the external drive’s ESP and renamed the /EFI/Microsoft directory to /EFI/Windows (by doing this will overwrite the Windows bootloader with GRUB :heavy_check_mark:).
  2. Created the the file /boot/grub/custom.cfg with the Windows menu entry:
menuentry "Microsoft Windows (UEFI)"  {
	insmod part_gpt
	insmod fat
	insmod chain
	search --set=root --fs-uuid D2B27159B27142D1
	chainloader /EFI/Windows/Boot/bootmgfw.efi
}

(this will add the Windows entry to the GRUB menu :heavy_check_mark:)
3. Now I have both Manjaro’s GRUB as the default bootloader of my external drive and a Windows entry in the menu. I could boot to Manjaro normally, but unfortunately, not on Windows :sweat:

It gives me an error if I boot into Windows saying:

error: file '/EFI/Windows/Boot/bootmgfw.efi' not found.

Press any key to continue...

But then, I tried to rename /EFI/Windows back to /EFI/Microsoft, and Windows Boot Manager resets back as the default bootloader.

Everything still works fine though. I can still boot to Windows, and into Manjaro with live media.

P.S
As long as I could boot into Manjaro and Windows in my external drive as a portable device (without any live media, etc.), then that is fine for me.

Any additional possible solution to this?

Have you tried to change the UEFI boot order with efibootmgr ?
Post

efibootmgr -v
ls -lR /boot/efi
1 Like

Hmm, I think I found the solution now… There was just a mistake in setting the root partition in /boot/grub/custom.cfg. I placed the UUID of the Windows partition, when it should be the EFI system partition :grin:

I verified it in the GRUB prompt and I have successfully booted into Windows. Yay! :smile: Right now, I’m going to edit the custom.cfg file to see if I can boot Windows directly if I choose the Windows entry.

I’ll post the result in detail later :wink:

Morning, everybody.
Looks like many manjaro users have OCD!:rofl:
I’ll write later. Morning’s not a good time.
See you later. Ciao.

2 Likes

See this part if it helps.
Instead of renaming windows directory, I moved the directory higher up.
Then create the custom.cfg for it.
Also note we copied the grub efi to the replaced windows efi file. I think you did not do that.
Note the windows entry is then actually grub entry.
Do you need to do something so drastic?
That link OP had no choice. His Lenovo is tied in to Microsoft.

1 Like

First of, thank you @SGS, @gohlip, and @AgentS for your time! I deeply appreciate you guys :yum:

Workaround

This is the overall workaround to my original post. Credits to the guy who posted it at stackexchange (see here). It is for a Windows and Linux setup that for some reasons, GRUB bootloader is unable to overwrite Windows’ bootloader (specifically, in UEFI boot). Not the best fix you’d expect, but this could save you tons of hours.

I’ll break this down in three easy steps (newbie friendly :smile:):

Basically, we will; rename the Windows bootloader directory which resides in ESP, we will also create a file that contains the GRUB menu entry of the Windows bootloader with the correct path, then reinstall and update the GRUB (that’s all we really need to do here).

#1

Using live installation media, mount the / (root) partition and ESP (EFI System Partition) of the drive where Windows and Linux is installed.

Here’s my drive setup for example:

$ sudo fdisk -l
Disk /dev/sdb: 298.1 GiB, 320072932352 bytes, 625142446 sectors
Disk model: Storage Device  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DB966007-BD1D-4E70-BD62-5EF4A6D2FA28

Device         Start       End   Sectors  Size Type
/dev/sdb1       2048    264191    262144  128M EFI System
/dev/sdb2     264192 134481919 134217728   64G Microsoft basic data
/dev/sdb3  134481920 612558847 478076928  228G Linux filesystem
/dev/sdb4  612558848 625142412  12583565    6G Linux swap
$ lsblk -f
sdb                                                                          
├─sdb1 vfat     SYSTEM   08C8-F2D7                                           
├─sdb2 ntfs     WINDOWS  D2B27159B27142D1                                    
├─sdb3 ext4     LINUX    7e8a9b28-100c-47da-95d1-de662c3bd15f                
└─sdb4 swap     SWAP     db1a0d00-4800-43f0-a025-a866bc5c5912

In my case I got /dev/sdb1 as the ESP and /dev/sdb3 as the root partition:

Write down the ESP’s UUID, in my case it’s 08C8-F2D7 (we’ll need this in step #2).

sudo mount /dev/sdb3 /mnt
sudo mount /dev/sdb1 /mnt/boot/efi
sudo manjaro-chroot /mnt

We perform manjaro-chroot so we can just update the GRUB later.

#2

Rename the Windows bootloader directory to something else:

sudo mv /boot/efi/EFI/Microsoft /boot/efi/EFI/Windows

This will set the GRUB as default bootloader. You can rename it back to use the Windows bootloader again (:heavy_check_mark:).

Next, create the file for the Windows bootloader GRUB menu entry with the updated path:

- Create the file
sudo touch /boot/grub/custom.cfg
- Open the file (with any text editor)
sudo xdg-open /boot/grub/custom.cfg
- Put the entry into the file and save
menuentry "Microsoft Windows (UEFI)" --class windows  {
	insmod part_gpt
	insmod fat
	insmod chain
	search --set=root --fs-uuid XXXX-XXXX
	chainloader /EFI/Windows/Boot/bootmgfw.efi
}

You need to replace XXXX-XXXX with the correct UUID of the ESP. In my case it is:

search --set=root --fs-uuid 08C8-F2D7
#3

Last step, simply reinstall and update the GRUB:

sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --boot-directory=/boot --bootloader-id=Manjaro --removable --recheck --debug
sudo update-grub

Reboot and enjoy :grin:

Cheers! :beers: