Broadly speaking, you need to install an EFI-mode boot loader for Linux on the USB drive you've prepared. This boot loader should be stored as EFI/BOOT/bootx64.efi
on the EFI System Partition (ESP), which is a FAT partition on the disk. There's a chance that the disk you've prepared lacks an ESP, so you may need to create it. (Even an ordinary FAT partition is usually sufficient, so if the disk has a FAT partition, you might not need a separate ESP.)
The tricky thing about this is that the boot loader you write to the disk must be properly configured to boot the installation on the disk. GRUB taken from the Ubuntu installation .iso
file won't work without changes, because it's configured to boot the Ubuntu installer, not the installation you've created on the USB drive. Thus, you must know enough about the boot loader to know how to configure it, and enough about your installation to know what values to put in the boot loader's configuration file.
Unfortunately, GRUB 2 is a very difficult boot loader to configure; its configuration file format is rather complex, and is usually created by specialized scripts. Even the binary may need to be modified for your specific situation, since the main configuration file (grub.cfg
) is normally located on the Ubuntu root (/
) or /boot
partition, meaning that the binary must be modified for your particular installation.
I've written a page on EFI boot loaders for Linux that covers many alternatives, most of which are easier to configure than GRUB 2. My own rEFInd is likely to be the easiest to set up and configure, since it tries to auto-detect Linux kernels when it starts, and it can usually figure out what options to pass to the kernel to get the system booted. Thus, configuration file changes needed to boot with rEFInd are minimal, and sometimes non-existent.
One big caveat in this is Secure Boot. If you want the computer to boot with Secure Boot active, you must provide either Shim (shimx64.efi
) or PreLoader (preloader.efi
) as the boot loader (renamed to EFI/BOOT/bootx64.efi
), with your follow-on boot loader renamed appropriately for Shim or PreLoader. Furthermore, depending on the boot loader in question, you might need to add keys or hashes to the firmware whenever you boot your disk on a new computer. In this case, it's probably worth going to the hassle of using GRUB 2 on the new computer, since Ubuntu provides all the pieces necessary to get a computer to boot Ubuntu without messing with keys or hashes.
Best Answer
There is a bug in grub 2.04 so ensure you have a prior or later version.
Well, the basics for adding an ISO file to grub are the same for an UEFI as for a BIOS machine: edit
/etc/grub.d/40_custom
and add amenuentry
item (GParted is used in this example) to the bottom of the file:Now we're going to add a variable containing the directory where we stored the ISO (so far, so good: no differences with BIOS machines):
I'm using
/opt
to store these as I don't like creating directories in the root of my machine and according to the Linux File System Hierarchy that's where optional software should reside anyway.Before we add the
loopback
variable, we need to find out on which hard disk the file is stored, so we do a:df --output=source /opt/Live-ISOs/gparted-live-0.31.0-1-amd64.iso | tail -1
and the output on my machine is:/dev/sdb2
.However grub uses (
hdX,Y
) notation and this is where the difference between UEFI and BIOS machines comes in! So now reboot your machine, go into the grub menu and press C: This will bring you to the grub command prompt with different commands than you're used to but the only one that you need is:ls
.On my machine the output is:
Huh? 4 drives? I only have 3! And it's not
(hd1,4)
line on a BIOS but(hd1,gpt3)
in UEFI and(hd0)
has no partitions at all!Well, apparently when part of the NVRAM is used as storage and shows up as
(hd0)
you need to start numbering your drives at 1! Whereas all the information you find on booting ISO files says you have to start numbering from 0 (on BIOS machines this is always true, this is not necessarily the case on some UEFI machines ! )So the value for
loopback
becomes(hd2,gpt2)$GPartedISOFile
as the ISO file on my machine was/dev/sdb2
(second drivehd2
, second partitiongpt2
):Another difference is that the
linux
andinitrd
on BIOS machines are calledlinuxefi
andinitrdefi
on UEFI machines, which gives us our final result:So now save that file, and update grub with:
After all of the above, reboot, go into the grub menu, choose
GParted Live ISO
and you can now easily boot your ISO without having to hunt for a USB stick ever again!:-)
CloneZilla Live example (for this question )