How to Create a EFI/UEFI GRUB2 Multiboot USB drive to boot ISO images

ahmadnurhadirmw - For this Tutorial, there are some Assumptions:
  1. You can format your usb drive (did you do a backup?)
  2. Your USB drive is the /dev/sdb device (You can check yours with sudo fdisk -l or using Gparted)
  3. Your USB drive will be mounted at /mnt
  4. You are using a Ubuntu distro (any Ubuntu flavour) - Could be a live session (LiveCD)
  5. You are logged with the first user (setted at installation or live session default)
  6. You are not afraid of Linux Command Interface

First Step: Format USB drive

To create a EFI firmware compatible boot drive, you need a GPT partition table and at least one FAT32 partition. Do as follows...
sudo apt-get install gdisk
sudo sgdisk --zap-all /dev/sdb
You probably need to remove and insert the USB drive again at this point for the kernel to update information about it...
sudo sgdisk --new=1:0:0 --typecode=1:ef00 /dev/sdb
sudo mkfs.vfat -F32 -n GRUB2EFI /dev/sdb1
We are done with Step One, you can check modifications with sudo parted -l or with Gparted.

Second Step: Copy files and Set directory structure

Let's mount the usb drive...
sudo mount -t vfat /dev/sdb1 /mnt -o uid=1000,gid=1000,umask=022
To make life easier, I created a pack with all necessary files for you to modify as you need. If you don't trust my files, create yours using this page as reference. Link to Download is: http://webativo.com/uploads/files/usb-pack_efi.zip

Extract the zip file and paste those inner files using Command Line Interface or a file manager you like.
cd ~/Downloads/
unzip usb-pack_efi.zip
rsync -auv usb-pack_efi/ /mnt
The most important files are bootia32.efi to boot on 32bit machines, bootx64.efi to boot on 64bit machines and grub.cfg to setup grub to load ISOs or chainload to other paths.

In the end, you might get a directory tree like this:
How to Create a EFI/UEFI GRUB2 Multiboot USB drive to boot ISO images

Third Step: Install GRUB2 on the drive

sudo grub-install --removable --boot-directory=/mnt/boot --efi-directory=/mnt/EFI/BOOT /dev/sdb
PS: Grub2 installation might throw some error messages, just ignore it.
PS: If you have problems to copy and paste content on /mnt, you can use sudo to do it

Fourth Step: Setup ISOs to be loaded

Put (copy) the .iso files you want to load in /mnt/iso/ and setup grub.cfg like the existing examples...

Note that the most important variable to set is isofile. There is lots of examples on the web about how to configure grub2 menu. Use # to comment those lines you don't want to use, e.g. to hide a configuration of absent .iso at /iso.

Last Step: Configure firmware and Test

First and most important, deactivate secure boot on your computer's firmware. Search on the web if you don't know how.

To boot the USB drive you can set your machine firmware to search first for the USB device (boot order). Or you can choose what drive to boot as soon as you turn on your computer. Each manufacturer has its own keys to do it. Search for your machine's manual if needed.

Post a Comment

0 Comments