1. Introduction

From system recovery to firmware updates and system configuration, creating a bootable flash for the EFI shell can be useful in many ways. Bootable USB drives are particularly valuable when we have a system whose EFI shell is not readily accessible.

In this tutorial, we’ll go over the steps needed to create a bootable flash for the EFI shell.

2. Formatting the Flash Drive

To prepare a USB drive for the EFI shell, we must first ensure the drive uses the FAT filesystem. We can do this by formatting the USB drive to either FAT16 or FAT32. In this article, we’ll format to FAT32.

To format a USB drive in a Linux terminal, we’ll start by getting the drive’s path using lsblk:

$ lsblk -p
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
/dev/loop0    7:0    0 63.5M  1 loop /snap/core20/1950
/dev/loop2    7:2    0 53.3M  1 loop /snap/snapd/19457
/dev/loop3    7:3    0 53.2M  1 loop /snap/snapd/18933
/dev/loop4    7:4    0 91.9M  1 loop /snap/lxd/24061
/dev/loop5    7:5    0 63.5M  1 loop /snap/core20/1974
/dev/sda      8:0    0   40G  0 disk
└─/dev/sda1   8:1    0   40G  0 part /
/dev/sdb      8:16   0   10M  0 disk
/dev/sdc      8:32   1 14.5G  0 disk
└─/dev/sdc1   8:33   1 14.5G  0 part

From the list returned by lsblk, we can see that our flash’s path is /dev/sdc1. We know this because the /dev/sdc1 is the only block device with a value of 1 under the RM column, meaning it is a removable device. Also, the size matches what we already know about the flash.

Now that we know our flash’s path, we’ll unmount it:

$ sudo umount /dev/sdc1

Before formatting our USB drive, we must ensure it doesn’t contain any important files. The formatting process will delete all files from the device.

Once unmounted, we’ll format the flash to FAT32 using mkfs:

$ sudo mkfs.vfat -F 32 /dev/sdc1
mkfs.fat 4.1 (2017-01-24)

Once the system is done formatting the USB drive, we can download the bootloader to the USB drive.

3. Downloading the EFI Bootloader to the Flash

To download the bootloader executable to our flash, we’ll mount the flash again:

$ sudo mount /dev/sdc1 /media/usb

Then we’ll cd to the mount point, /media/usb:

$ cd /media/usb

Once in the mount point, we’ll create a directory, efi/boot/, on the USB drive:

$ sudo mkdir -p efi/boot/

Next, we’ll cd into the efi/boot directory:

$ cd efi/boot/

When in the efi/boot directory, we’ll download the EFI bootloader from TianoCore’s Github repository using wget:

$ sudo wget -q -O BOOTX64.efi https://github.com/tianocore/edk2/raw/edk2-stable201903/ShellBinPkg/UefiShell/X64/Shell.efi

The command above will download the bootloader for Intel 64-bit architectures to the flash and save it with the name BOOTX64.efi.

Here’s what we would have done if we were using a 32-bit Intel system:

$ sudo wget -q -O BOOTIA32.efi https://github.com/tianocore/edk2/blob/UDK2018/ShellBinPkg/UefiShell/Ia32/Shell.efi

Here, the EFI shell bootloader will also be downloaded to the USB drive but named BOOTIA32.efi.

If we want the EFI shell bootloader for an ARMHF architecture, we’ll run the following:

$ sudo wget -q -O BOOTIARM.efi https://github.com/tianocore/edk2/blob/UDK2018/ShellBinPkg/UefiShell/Arm/Shell.efi

But if we were working with an ARMx64 system, we’ll use the following:

$ sudo wget -q -O BOOTIAA64.efi https://github.com/tianocore/edk2/blob/UDK2018/ShellBinPkg/UefiShell/AArch64/Shell.efi

After downloading the bootloader to the efi/boot/ directory of our flash, we can boot an EFI shell from the flash.

4. Conclusion

In this article, we looked at the steps involved in creating a bootable USB drive for an EFI shell from a Linux terminal. We talked about how to unmount a flash and format it to FAT32. Then, we discussed remounting a FAT32 flash and downloading EFI bootloaders of various architectures to it.

Comments are closed on this article!