You are not logged in.

#1 2020-08-16 23:24:01

freezeheat
Member
Registered: 2020-03-12
Posts: 14

[EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

UPDATE: I've updated the guide and moved it here

If anyone here had a problem with making a bootable USB with more than just one OS, especially with Windows, I've got a working example.

Features:

  • Hiren's Boot CD - the new one with UEFI support and windows 10 PE

  • Windows 7 64bit

  • Linux distros of your choice (iso files)

  • Can still use the rest of the space for general use even on Windows

Structure notes:

  • The first partition serves as both an EFI partition and a filesystem we can use and store files to.

  • Windows MBR boot process up to Windows 7 is only possible when the first block of the first partition has the boot files, since even if you do boot up from another partition the setup files won't be found(it looks for them in the first partition).

  • Windows 8 and later can be booted from anywhere, but they require their own partition, that's why you should calculate the partition size.

  • In general, multi-partitioned USB flash drives don't work well in Windows up to windows 7, that's why if you still wish to use the rest of the USB drive's space it must be present in the first partition, while the rest of the partitions cannot be accessed they are still accessible on boot when using GRUB2.

  • Both i386-pc and x86-64-efi targets are used so the USB drive will be detected in more systems(MBR and UEFI), but some systems will not detect it anyway(A BIOS update might be in order for a potential fix to that problem or it was that which caused it), using a USB V2,0 flash drive is also recommended for better compatibility(especially old systems).

NOTE: It's impossible to add any other partitions with Windows versions up to 7, the first partition must hold the setup files and it also must be your EFI and filesystem for them to work with systems which don't support multi-partitioned drives

First the preparation of your USB flash drive using 'GNU Parted':

1. Create a MBR(msdos) partition table
2. partition 1, EFI, flags=esp,boot, fs=fat32, Size should be calculated for more space (usb drive full capacity - the Hiren partition size)
3. partition 2, hiren, fs=ntfs, from the end of partition1 to 100%
4. Create the filesystems for each partition (mkfs commands), optionally set labels instead of using UUID lables(UUIDs are more unique and secure than labels which can get confused with your dedicated hard drive partitions' lables)
5. Mount&Copy win7 iso contents into partition 1, also make an 'iso' folder(or any other name - be sure to note it) to hold your iso files.
6. Mount&Copy Hiren iso contents into partition 2
7. Unmount partition 2 and keep partition 1 mounted(our EFI partition) for grub-install to work
8. grub-install --target=i386-pc --recheck --boot-directory=YOUR_EFI_PARTITION/boot dev/YOUR_DEVICE
9. grub-install --target=x86_64-efi --recheck --removable --efi-directory=YOUR_EFI_PARTITION --boot-directory=YOUR_EFI_PARTITION/boot
10. Copy iso's as is into the 1 partition, into the iso folder
11. Edit your own grub.cfg and copy it to YOUR_EFI_PARTITION/boot/grub/ directory.
.  11A. If you add linux images to your grub.cfg, make sure you use the initrd/linux commands that support that distro (google it).
   11B. If you didn't set any labels in step 4, run the 'lsblk' command in your shell to find the UUID for each partition
12. Unmount

Final result via 'parted' and structure:

### parted output
Model: Generic Flash Disk (scsi)
Disk /dev/sdb: 15.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  14.4GB  14.4GB  primary  fat32        boot, esp
 2      14.4GB  15.7GB  1363MB  primary  ntfs

### Directory structure
# ls of partition1/
total 2952
-rwxr-xr--  1 root root     122 Aug 16  2019 autorun.inf
drwxr-xr--  5 root root    8192 Aug 16  2019 boot
-rwxr-xr--  1 root root  383786 Aug 16  2019 bootmgr
-rwxr-xr--  1 root root  669568 Aug 16  2019 bootmgr.efi
drwxr-xr--  4 root root    8192 Aug 16  2019 EFI
drwxr-xr--  2 root root    8192 Aug 16  2019 iso
drwxr-xr--  4 root root    8192 Jan  2  2020 myfiles
-rwxr-xr--  1 root root  106768 Aug 16  2019 setup.exe
drwxr-xr-- 10 root root   16384 Aug 16  2019 sources
drwxr-xr--  5 root root    8192 Aug 16  2019 support
drwxr-xr--  3 root root    8192 Aug 16  2019 upgrade
drwxr-xr--  8 root root    8192 Jan  4  2020 xp

# ls of partition1/iso
total 1131200
-rwxr-xr-- 1 root root 1158348800 Aug 16  2019 lubuntu-18.04.3-desktop-amd64.iso

# ls of partition1/boot/grub
total 80
drwxr-xr-- 2 root root  8192 Aug 16  2019 fonts
-rwxr-xr-- 1 root root  1712 Aug 16  2019 grub.cfg
-rwxr-xr-- 1 root root  1024 Aug 16  2019 grubenv
drwxr-xr-- 2 root root 24576 Aug 16  2019 i386-pc
drwxr-xr-- 3 root root  8192 Aug 16  2019 themes
drwxr-xr-- 2 root root 24576 Aug 16  2019 x86_64-efi

For clarification, the 'grub-install' commands for the above USB flash drive and the mount point of partition 2 is '/mnt/usb'

grub-install --target=i386-pc --recheck --boot-directory=/mnt/usb/boot /dev/sdb
grub-install --target=x86_64-efi --recheck --removable --efi-directory=/mnt/usb/ --boot-directory=/mnt/usb//boot

grub.cfg file:

# insmod ntfs for NTFS filesystem
# insmod ntldr for MBR boots for Windows
# ntldr, Windows until XP ntldr /ntldr, Windows 7+ 'ntldr /bootmgr'
# linux /vmlinuz + initrd /initrd, each distro has different options
# loopback is used to mount ISO files (only supported types)
# search --set-root --fs-uuid, to find partition by UUID.
# search --set-root --label, find partition by Label.
# use 'blkid' in your shell to find the uuid's in the system.
# the 'boot' command is implicitly added when you choose an entry from the menu, it's used when you finish configuring everything and can be done from GRUB's command line.
# set pager=1, this will allow behavior like using the 'less' command in UNIX
# For windows to work with multiboot os(not for USB booting), remember to hide partitions with parttool:
# parttool (device,partition) hidden+\- boot+\-
# boot+ enables bootable+active, hidden+ hides the partition

part1="1234-ABCD"
part2="1A2B3C4D5E6F7G8H"

menuentry "Windows 7 64bit (MBR ONLY)" {
    insmod ntfs
    insmod ntldr
    search --no-floppy --set=root --fs-uuid ${part1}
    ntldr /bootmgr
}

menuentry "Lubuntu 18.04 LTS 64bit" {
    search --no-floppy --set=root --fs-uuid ${part1}
    loopback loop /iso/lubuntu-18.04.3-desktop-amd64.iso
    linux (loop)/casper/vmlinuz iso-scan/filename=/iso/lubuntu-18.04.3-desktop-amd64.iso boot=casper noeject noprompt splash --
    initrd (loop)/casper/initrd
}

menuentry "Hiren's Boot - Windows 10 PE (MBR)" {
    insmod ntfs
    insmod ntldr
    search --no-floppy --set=root --fs-uuid ${part2}
    ntldr /bootmgr
}

menuentry "Hiren's Boot - Windows 10 PE (UEFI)" {
    insmod ntfs
    insmod chain
    search --no-floppy --set=root --fs-uuid ${part2}
    chainloader /EFI/Boot/bootx64.efi # or chainloader +1, (+1 is block based)
}

You can obviously use more variables and improve the menu with all sorts of stuff.
NOTE: Make sure you choose the right menu entry for your boot method, if you use UEFI for a BIOS(MBR) or an BIOS(MBR) for a UEFI it obviously won't work

Last edited by freezeheat (2022-03-06 23:49:22)

Offline

#2 2020-08-17 01:51:05

GaKu999
Member
From: US/Eastern
Registered: 2020-06-21
Posts: 696

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

Hmp this is mostly Windows...anyways you could also do a Hybrid MBR with GPT partitions and is even well documented in the wiki...with a little need of touch of course.

The best part is being capable of making it work anywhere and having the benefit of partitioning the device with GPT, just made a live multiboot with GRUB2 and updated my desktop setup to have it as well.

PS:

$ dd if=/dev/sda skip=8 bs=128 count=1
Hah!IdontNeedEFI<gibberish>

lol tongue

Btw something makes me think that this is dwelling in the realm of piracy...
I don't think MS wants people to use their OS as livesticks for free...


My reposSome snippets

Heisenberg might have been here.

Offline

#3 2020-08-17 03:54:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

@freezeheat, since this is an instructional (as opposed to support request), this would be better suited to the wiki or your blog, rather than being buried in the forums.

Offline

#4 2020-08-17 10:10:47

freezeheat
Member
Registered: 2020-03-12
Posts: 14

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

GaKu999 wrote:

Hmp this is mostly Windows...anyways you could also do a Hybrid MBR with GPT partitions and is even well documented in the wiki...with a little need of touch of course.

The best part is being capable of making it work anywhere and having the benefit of partitioning the device with GPT, just made a live multiboot with GRUB2 and updated my desktop setup to have it as well.

PS:

$ dd if=/dev/sda skip=8 bs=128 count=1
Hah!IdontNeedEFI<gibberish>

lol tongue

Btw something makes me think that this is dwelling in the realm of piracy...
I don't think MS wants people to use their OS as livesticks for free...

This is essentially made for older systems that can't boot GPT or have trouble with Hybrid setups yet still supports MBR and UEFI, I tested it on a netbook from 2005 and it booted properly.
The whole point is to have a multi-boot on a USB stick that can support most systems and still retain the ability to use the USB stick as normal(Access from OS's that don't support multi-partitioned drives), I didn't try the Hybrid MBR since it seemed way too much trouble and  from what I see it won't allow you to install Windows 7 for example or for OSs that don't support multi-partitioned drives to detect the USB drive's filesystem.

I don't know if you have truly old systems to try your usb stick on, but maybe I should try the Hybrid MBR solution in the wiki (https://wiki.archlinux.org/index.php/Mu … T/MBR_boot).

Last edited by freezeheat (2020-08-17 10:19:53)

Offline

#5 2020-08-17 10:12:23

freezeheat
Member
Registered: 2020-03-12
Posts: 14

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

fukawi2 wrote:

@freezeheat, since this is an instructional (as opposed to support request), this would be better suited to the wiki or your blog, rather than being buried in the forums.

According to @GaKu999 it seems that the Wiki already has something more complex and thorough, link: https://wiki.archlinux.org/index.php/Mu … T/MBR_boot

Offline

#6 2020-08-17 22:40:16

GaKu999
Member
From: US/Eastern
Registered: 2020-06-21
Posts: 696

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

Well taking old boxes into account it’s hard to say...the hybrid MBR should still be visible to the BIOS, and the bios only needs to load GRUB, not to be aware or include drivers for GPT...
The rest it’s up to GRUB...

But I may be saying gibberish, it’s hard to get a working ye o’l box for me...so I have no ways to know...

Try a dummy hybrid MBR on a usb and see if something from 2005 is capable of reading/booting it?
If GRUB2 appears and you can do insmod part_gpt I don’t see what could go wrong...but again, lack of testing...


My reposSome snippets

Heisenberg might have been here.

Offline

#7 2020-08-19 10:05:21

scrouthtv
Member
Registered: 2019-10-15
Posts: 38

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

I would advise against manually editing grub.cfg. instead, I additionally installed osprober and ran grub-mkconfig -o /boot/grub.cfg (or wherever you're grub.cfg is located).
osprober auto detects any additional OSs and adds them to your grub.cfg

Offline

#8 2020-08-19 13:05:32

GaKu999
Member
From: US/Eastern
Registered: 2020-06-21
Posts: 696

Re: [EXAMPLE] GRUB2 Multiboot with Windows UEFI/BIOS

scrouthtv wrote:

I would advise against manually editing grub.cfg. instead, I additionally installed osprober and ran grub-mkconfig -o /boot/grub.cfg (or wherever you're grub.cfg is located).
osprober auto detects any additional OSs and adds them to your grub.cfg

That is totally unrelated to the purpose of this thread and I manually edit my grub.cfg and use LVM for my root filesystems.

Autogeneration is good to get a headstart but once you know the inner workings of GRUB there’s no need to autogenerate...


My reposSome snippets

Heisenberg might have been here.

Offline

Board footer

Powered by FluxBB