1

With a triple boot system on BIOS/Legacy disk, I tested a solution to avoid the Windows Boot Manager menu triggered by the Linux GRUB (see here) and make the Windows systems start directly from the GRUB without passing by WBM. I discovered that "a priori" the Windows systems needs the WBM and can not be started without (source). So I search a solution to make each system have its own WBM but I do not know how to achieve this. I searched from the web but I did not find some relevant informations.


Remind : I have a perfectly working virtual triple boot (in my case : Windows 10 Home 21H1/Windows 7 Pro/Debian 11) and I want to make GRUB run directly all the Windows systems without group them in one entry which run the Windows Boot Manager.

The workaround solution which worked for me (thanks to Tom Yan ; see bellow) was to reboot on the Linux system, change the partition's type of the first Windows partition to prevent the second Windows partition to see it (see how bellow), reboot, to fully reinstall the second Windows system (I reinstall because I did not find a solution to add a WBM on an installed system), power off, boot on a Live session (in my case, I used the Clonezilla tool) since the Linux system is unreachable from the WBM freshed installed, finalize in undoing the type modification on the first partition (see how bellow) and in a Linux chrooted environment, install and update grub to replace the bootloader of the MBR (see too how bellow).

Nota : I prepend on some commands with the assigning of LC_ALL=C (environment variable) because I am french and some return's outputs too, and I found this trick practical and elegant :)

To change the partition's type :

root@host:~# LC_ALL=C fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK   
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: dos
Disk identifier: 0xf1e6f539

Device Boot Start End Sectors Size Id Type /dev/sda1 2048 42008575 42006528 20G 7 HPFS/NTFS/exFAT /dev/sda2 * 42008576 71710719 29702144 14.2G 7 HPFS/NTFS/exFAT /dev/sda3 71710720 83884031 12173312 5.8G 83 Linux

Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 sectors Disk model: QEMU HARDDISK
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: dos Disk identifier: 0xcdb5e72f

Device Boot Start End Sectors Size Id Type /dev/sdb1 * 2 2097119 2097118 1024M c W95 FAT32 (LBA) root@host:~# LC_ALL=C fdisk /dev/sda

Welcome to fdisk (util-linux 2.36.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help): t Partition number (1-3, default 3): 1 Hex code or alias (type L to list all): L

00 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
01 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 02 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 03 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- 04 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
05 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
06 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 07 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
... Hex code or alias (type L to list all): 83

Changed type of partition 'HPFS/NTFS/exFAT' to 'Linux'.

Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors Disk model: QEMU HARDDISK
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: dos Disk identifier: 0xf1e6f539

Device Boot Start End Sectors Size Id Type /dev/sda1 2048 42008575 42006528 20G 83 Linux /dev/sda2 * 42008576 71710719 29702144 14.2G 7 HPFS/NTFS/exFAT /dev/sda3 71710720 83884031 12173312 5.8G 83 Linux

Command (m for help): w The partition table has been altered. Syncing disks.

To undo type's modification from a Live session :

root@CZ-LIVE:~# LC_ALL=C fdisk /dev/sda

Welcome to fdisk (util-linux 2.37.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help): t Partition number (1-3, default 3): 1 Hex code or alias (type L to list all): L

00 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
01 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 02 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 03 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- 04 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
05 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
06 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 07 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
... Hex code or alias (type L to list all): 07

Changed type of partition 'Linux' to 'HPFS/NTFS/exFAT'.

Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors Disk model: QEMU HARDDISK
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: dos Disk identifier: 0xf1e6f539

Device Boot Start End Sectors Size Id Type /dev/sda1 2048 42008575 42006528 20G 7 HPFS/NTFS/exFAT /dev/sda2 * 42008576 71710719 29702144 14,2G 7 HPFS/NTFS/exFAT /dev/sda3 71710720 83884031 12173312 5,8G 83 Linux

Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.

To install GRUB from a Linux chrooted environment of a Live session :

root@CZ-LIVE:~# lsblk -lo NAME,FSTYPE,LABEL,UUID
NAME FSTYPE LABEL   UUID
sda                 
sda1 ntfs   W10H    7A42F6E942F6A8D1
sda2 ntfs   W7P     964843B148438EC5
sda3 ext4           a696a4ab-3120-4028-bd87-c2aaa40499bd                 
...     
root@CZ-LIVE:~# mount /dev/sda3 /mnt/
root@CZ-LIVE:~# for f in /dev /proc /sys /run ; do mount -B $f /mnt$f ; done
root@CZ-LIVE:~# chroot /mnt/
root@CZ-LIVE:/# grub-install /dev/sda
Installation pour la plate-forme i386-pc.
Installation terminée, sans erreur.
root@CZ-LIVE:/# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.10.0-19-amd64
Found initrd image: /boot/initrd.img-5.10.0-19-amd64
Found linux image: /boot/vmlinuz-5.10.0-16-amd64
Found initrd image: /boot/initrd.img-5.10.0-16-amd64
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and  
 create new boot entries.
Found Windows on /dev/sda1
Found Windows on /dev/sda2
done
root@CZ-LIVE:/# 
exit
root@CZ-LIVE:~# for f in /run /sys /proc /dev ; do umount -l /mnt$f ; done

Nota : we can see that update-grub found two Windows partitions.

From this point, we can see all the Windows system entries from the GRUB menu :

root@host:~# gawk '/^(menuentry|submenu)/ { printf '\
' gensub( /[^\x27]+\x27([^\x27]+)\x27.+/ , "\\1" , "g" ) ; '\
' uuid = gensub( '\
' /.+([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).*/ '\
' , "\\1" , "g" ) ; '\
' if ( uuid != $0 ) { printf " [" uuid "]" } printf "\n" }' \
  /boot/grub/grub.cfg
Debian GNU/Linux [a696a4ab-3120-4028-bd87-c2aaa40499bd]
Advanced options for Debian GNU/Linux [a696a4ab-3120-4028-bd87-c2aaa40499bd]
Windows 7 Pro (on /dev/sda2)
Windows 10 Home (on /dev/sda1)

Nota : in this config I manually modified /boot/grub/grub.cfg to customize the title entries, because GRUB "a priori" has no solution to see the inner system editions ; furthermore it is not advised to modify here because is will be overwritten by the next update-grub, but rather we must modify from the /etc/grub.d/30_os-prober file

That's all the folks :D

For me this a big workaround solution as I suppose it is possible to add a WBM without affecting the data on a Windows partition and especially to not have to reinstall it. If I find a simpler way to achieve this or more automate it, I will complete this post. Maybe have you a better approach ?

1 Answers1

0

Assuming the case of UEFI, you would need to make sure that the Windows installations do not share one EFI system partition (ESP).

If you have to stick to the orthodox / conventional Windows Setup, you'll need to temporarily "hide" the ESP(s) of existing Windows installation(s) (and the one for Linux) by e.g. changing the partition type (GUID) to a non-ESP one (i.e., any one but C12A7328-F81F-11D2-BA4B-00A0C93EC93B) with fdisk or gdisk. Make sure you change them back once the new installation is complete though, otherwise you'll probably break (in a somewhat "permanent" way) the booting of the existing ones.

Or you could avoid Windows Setup and instead adopt a more "manual" approach to install, namely by using bcdboot and dism.

Note that since Windows / WBM is bossy, every time you boot any of the installations it will register (again) its EFI/Microsoft/Boot/bootmgfw.efi to the UEFI firmware if it notices that the WBM UEFI boot entry is not pointing to itself. On most (if not all) UEFI firmware this will cause the WBM UEFI boot entry become the first one in the boot order (after changing which WBM the entry points to). Therefore, you'll need to remove EFI/Microsoft/Boot/bootmgfw.efi on each of the Windows ESPs and make grub chainload their EFI/Boot/bootx64.efi (which is an identical file at different path) instead. (So you probably need to avoid os-prober as well, and write your own grub conf or grub conf snippet instead.)

What's even more annoying is that, Windows will "repair" the ESP every time there is a cumulative update. So basically you'll have to perform the deletion like every month for all of the installations after the update is done. (You'll need to explcitly boot grub instead by getting to the UEFI boot menu or Windows' Advanced Startup, and then delete the file from Linux.)

For the case of BIOS/legacy Windows installations, just make sure you temporarily hide all the existing Windows partitions. (They probably all have type code 0x7 and you just need to change it to e.g. 0x83, which makes Windows Setup ignore them.)

P.S. If your machine have multiple drives and you can have it like one Windows per drive (drive, not partition), you probably don't have to deal with the EFI/Microsoft/Boot/bootmgfw.efi hassle mentioned above, since AFAIK most UEFI firmware supports multiple WBM UEFI boot entries when each of the WBMs is on a different drive (again, drive, not ESP). Still make sure you do the ESP hiding before starting a new installation. (Windows Setup will try its best to make your installations share one ESP / WBM, even when they are not on the same drive.)

Tom Yan
  • 10,996