Skip to content

Instantly share code, notes, and snippets.

@alexanderzjs
Created May 19, 2022 07:34
Show Gist options
  • Save alexanderzjs/121b8f56d4437c7f59f103aff5dd8994 to your computer and use it in GitHub Desktop.
Save alexanderzjs/121b8f56d4437c7f59f103aff5dd8994 to your computer and use it in GitHub Desktop.
Multiboot USB with grub2 x86_64 UEFI

Multiboot USB with grub2 (Please star it if it helps you!!!)

This gist is for x86_64 (amd64) architecture and UEFI boot mode!

Suppose you have 3 partitions: 1. EFI partition (FAT32); 2. macOS partition (Mac OS Extended); 3. WinPE and multiple Linux distros partition (FAT32).

First of all, you need to install grub2 to your EFI partition. You can go to GNU grub2's official website for documentations. Basically, grub-install.exe --no-floppy --target=x86_64-efi --boot-directory=X:\grub --efi-directory=X:\ will work.

  1. EFI partition should have: a. grub2's files: bootx64.efi (in X:\EFI\Boot folder), grub folder (X:\grub folder) including grub.cfg (if grub.cfg is not there, create an empty one manually); b. WinPE's boot files: bcd and bootx64.efi (X:\EFI\microsoft folder) (bcd file needs to be modified according to your WinPE's boot.sdi and boot.wim)

  2. macOS patition should have your macOS image file.

  3. WinPE and multiple Linux distros partition should have different folders to include the ISOs (only some Debian based distros like Debian and Kali needs separate bootloaders and they can be downloaded from their corresponding mirror sites, e.g. https://mirrors.XXX.debain.org/debian/dists/Debian11.1/main/installer-amd64/current/images/hd-media/).

#加载模块
insmod cat
insmod gzio
insmod ext2
insmod fat
insmod ntfs
insmod font
insmod part_gpt
insmod loopback
insmod efi_gop
insmod efi_uga
insmod video_bochs
insmod video_cirrus
insmod all_video

set default=0
set timeout=60 
loadfont /boot/grub/unicode.pf2
set gfxpayload=keep

menuentry "Windows 10 PE x86_64" {
    search --no-floppy --fs-uuid --set=root 67E3-17ED # This is the UUID of EFI partition
    chainloader /EFI/microsoft/boot/bootx64.efi
}

menuentry "macOS Mojave" {
    search --no-floppy --label "Install macOS Mojave" --set root # This is the label of macOS partition
    chainloader /System/Library/CoreServices/boot.efi
}

menuentry "Kubuntu Rhino Rhino Remix x86_64" {
    search --no-floppy --fs-uuid --set=root 034F-A211 # This is the UUID of the third partition, you can also use the label of your third partition
    set iso_file=/ubuntu/kubuntu-rolling-rhino-amd64.iso
    loopback loop ${iso_file}
    linux (loop)/casper/vmlinuz iso-scan/filename=${iso_file} boot=casper file=/cdrom/preseed/kubuntu.seed quiet splash
    initrd (loop)/casper/initrd.gz
}

menuentry 'Kali Rolling XFCE Linux x86_64' {
    search --no-floppy --label "LIVEUSB" --set root # This is the label of the third partition, you can also use the UUID of your third partition
    set iso_file=/kali/kali-linux-2022.2-installer-amd64.iso
    loopback loop ${iso_file}
    linux /kali/vmlinuz findiso=${iso_file}
    initrd /kali/initrd.gz
}

menuentry "Fedora Rawhide KDE x86_64" {
    search --no-floppy --fs-uuid --set=root 034F-A211 # This is the UUID of the third partition, you can also use the label of your third partition
    set iso_file=/ubuntu/Fedora-KDE-Live-x86_64-Rawhide-20220512.iso
    loopback loop ${iso_file}
    linux (loop)/isolinux/vmlinuz iso-scan/filename=${iso_file} root=live:CDLABEL=Fedora-KDE-Live-rawh-20220512-n- rd.live.image splash=silent
    initrd (loop)/isolinux/initrd.img
}

menuentry "OpenSUSE Tumbleweed KDE x86_64" {
    search --no-floppy --fs-uuid --set=root 034F-A211 # This is the UUID of the third partition, you can also use the label of your third partition
    set iso_file=/opensuse/openSUSE-Tumbleweed-KDE-Live-x86_64-Snapshot20220507.iso
    loopback loop ${iso_file}
    linux (loop)/boot/x86_64/loader/linux boot=isolinux iso-scan/filename=${iso_file} root=live:CDLABEL=openSUSE_Tumbleweed_KDE_Live splash=silent
    initrd (loop)/boot/x86_64/loader/initrd
}

menuentry "Arch Linux x86_64" {
    search --no-floppy --fs-uuid --set=root 034F-A211 # This is the UUID of the third partition, you can also use the label of your third partition
    set iso_file=/archlinux/archlinux-2022.05.01-x86_64.iso
    loopback loop ${iso_file}
    linux (loop)/arch/boot/x86_64/vmlinuz-linux img_dev=/dev/disk/by-uuid/034F-A211 img_loop=${iso_file}
    initrd (loop)/arch/boot/x86_64/initramfs-linux.img (loop)/arch/boot/intel-ucode.img
}

menuentry "Gentoo Linux x86_64" --class gentoo {
    search --no-floppy --fs-uuid --set=root 034F-A211 # This is the UUID of the third partition, you can also use the label of your third partition
    set iso_file=/gentoo/install-amd64-minimal-20220508T170538Z.iso
    loopback loop ${iso_file}
    linux (loop)/boot/gentoo root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/image.squashfs cdroot isoboot=${iso_file} splash=silent
    initrd (loop)/boot/gentoo.igz
}

menuentry "Reboot" --class windows --class os {
    reboot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment