Using Linux Mint 19 64 bits as host OS. It's quite safe to assume that similar distros and releases, like Ubuntu for example, will behave the same.
We will need:
- A USB of 16GB.
- ISO images of Windows, in this case Windows 7 and Windows 10 64 bits.
The process
Install grub-efi-amd64 for GRUB EFI compatibility
sudo apt install -y grub-efi-amd64
Format the USB with msdos partition table. The partitions' size have to be enough to hold the unpacked ISOs. In this case, let's just divide the USB in two halves ~8GB each. Both partitions have to be FAT formatted. Mark the first partition as bootable.
Mount the USB first partition. Take a note of: wich device is, i.e. /dev/sdc1, and the path it is mounted on, i.e. /media/foo/WIN7/. From now on, I will use those two examples for the guide.
Install GRUB:
dirs=(bin dev etc lib lib64 proc sbin sys usr)
for dir in "${dirs[@]}"; do
mkdir /media/foo/WIN7/$dir && sudo mount --bind /$dir /media/foo/WIN7/$dir
done
sudo chroot /media/foo/WIN7/
# chroot environment
# first we install grub efi
grub-install --force --removable --target=x86_64-efi --efi-directory=/ /dev/sdc1
# now we install grub 386
grub-install --force --removable --target=i386-pc --boot-directory=/ /dev/sdc
# exit the chroot
exit
WARNING!! Be very careful with the next command, since you could remove binded directories. Use tab completion for the paths instead of typing them.
for dir in "${dirs[@]}"; do
sudo umount /media/foo/WIN7/$dir && rm -rf /media/foo/WIN7/$dir
done
- Mount the ISOs, and copy their contents to each USB's partitions: Windows 7 into the first partition (you will get the message that boot directory already exists, just merge them), and Windows 10 into the second partition.
GRUB configuration:
NOTE: Windows 7 will boot on BIOS only and Windows 10 in EFI only
Create under /media/foo/WIN7/grub the file grub.cfg and put the following content there:
set root='(hd0,1)'
configfile /boot/grub/grub.cfg
Create under /media/foo/WIN7/boot/grub the file grub.cfg and put the following content there:
menuentry 'Windows 7 installer BIOS' {
insmod ntldr
ntldr /bootmgr
}
menuentry 'Windows 10 64 bits installer EFI' {
set root='(hd0,2)'
chainloader /efi/boot/bootx64.efi
}
We are now ready to test if the USB works properly, just boot your machine with the USB attached, and depending on the BIOS/EFI you will have different options to select between BIOS or EFI, or just the option to boot from USB in older machines.