Ubuntu 20.04 LTS - can't make a bootable USB flash drive
I'm trying to create a bootable USB drive for 20.04. If I do a 20.04 downloaded image, I can boot the drive properly. However, if I extract all the 20.04 content to a directory, then recreate the ISO and dd that to the drive, the resulting drive won't boot. My zbook just beeps and goes back to the boot menu. The command for creating the ISO I got from several articles. But I'm certain it has to be the created ISO itself. Any ideas?
Solution 1:
There are many ways to make a Bootable USB Flash Drive
The following method extracts the contents of the ISO to a partition
Making a Grub2 booter that uses Persistent partitions is easy.*
- Boot Installed Ubuntu or Live USB.
- Insert Target USB.
- Start GParted.
- Create a GPT partition table on Target USB.
- Create a 1MB BIOS boot partition on the left, formatted as unformatted.
- Add a 300MB FAT32 EFI boot partition next to it.
- Add an ext4 root partition large enough for the Ubuntu ISO's contents, (~ 3GB for 20.04).
- Create an ext4 partition labeled casper-rw
- Add a NTFS data partition if desired.
- Apply all operations.
- Flag partition 1 bios_grub.
- Flag Partition 2 boot, esp
- Close GParted.
-
Open the ISO's folder as Administrator, open the ISO using Archive Manager.
-
Extract the ISO's contents to the Target's root partition.
-
Drag and drop the boot and EFI folders from Archive Manager window to the EFI boot partition.
-
Edit sdx2/boot/grub/grub.cfg adding set root=(hd0,3) after the first line that starts with
menuentry
. -
Add a space and the word "persistent" after ---.
set timeout=5 menuentry "Ubuntu persistent" { set root=(hd0,3) set gfxpayload=keep linux /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --- persistent initrd /casper/initrd }
-
Install grub, if in BIOS mode or booted from USB drive run:
sudo mount /dev/sdx2 /mnt sudo grub-install --boot-directory=/mnt/boot /dev/sdx
-
If in UEFI mode on installed system, boot into the Target drive and run the above.
*Booting based on mkusb by sudodus
Another method to make a bootable USB is to boot ISO files directly
BIOS/UEFI Template Image for Booting ISO Files
Solution 2:
tl;dr When you recreate the ISO from the extracted files, you are not (correctly) transferring either the BIOS bootblock, nor the EFI System Partition, or ESP, to the newly created USB drive. Therefore, the system will not be able to boot from this disk.
Problem
Loading the bootloader
The system firmware does not to know how to boot the operating system on the drive, and instead passes on that responsibility to a small program called the bootloader. It is stored on the disk in a specified location where the firmware can find it easily. The location where the bootloader is stored is dependent on the method used by the firmware to boot the disk. There are two different boot methods in use today on x86-64 platforms, the modern EFI and legacy BIOS boot.
I assume your HP Z-Book is new enough to be both x86-64, and support EFI boot. You will be able to enable legacy BIOS support in the system firmware's setup utility, though this may differ on other laptops, and could be subject to change for newer laptops.
EFI System Partition (ESP)
x86-64 EFI-based firmware loads the bootloader by looking for a file called /efi/boot/bootx64.efi
(case does not matter) on a special, FAT32-formatted partition with type 0xEF
or EFI System Partition (ESP)
on the selected boot disk. Some BIOSes can (apparently) also boot from NTFS file systems.
Most Linux distributions, Ubuntu included, now distribute an El Torrito-compliant disk image. This means the same disk can be booted by a legacy BIOS, or modern EFI-based firmware, in their respective boot modes. When you extract or mount the disk (i.e. from GNOME Files, the file manager), the EFI partition is maintained as a separate efi.img
file, but this is actually not how the disk is arranged on a CD/DVD burned from this ISO file.
Therefore, the system firmware does not recognise this file as a valid EFI System Partition when it is copied to your USB drive. The drive is rejected by the firmware, because it does not believe the disk to be bootable.
Resolving the problem
You can create an EFI System Partition using GNOME Disks, GParted, or command-line tools such as gdisk
. The new partition must have the ESP type, and must be formatted as FAT32.
The contents of efi.img
must be extracted to a folder called efi
on the target disk, such that bootx64.efi
appears at the path /efi/boot/bootx64.efi
on the root of the disk.
The rest of the ISO may be extracted to the same partition, and this is what tools such as Rufus does. However, an extra step is often required for most Linux distributions: the file system label is often used to identify the disk from which to boot, and therefore, the file system's label must match that which came on the ISO file. Otherwise (with, for example, Ubuntu), the kernel will not be able to locate the SquashFS root file system to continue booting.