Gen Post - UEFI Shell - How to access and basic uses

patkim

Cyborg Agent
As requested by some of you. Some details on UEFI Shell

UEFI enables accessing at least FAT file system as well as running efi applications. UEFI Shell is an element of UEFI and it can be sort of considered as a command prompt (a small OS / efi app that runs on top of UEFI) that can run a number of shell commands. These commands can be informative, file system level, boot related, config related, device related and so on.
Most desktop motherboards with UEFI firmware at least mid-range to high end have UEFI shell built-in in the UEFI. Some laptop firmware’s also have it. Others simply have a pointer or link to it in the boot order, where it expects shell.efi file (efi application) on the EFI partition or similar.

If your UEFI does not have built-in shell, how to boot to it.
  1. Download shell.efi (I assume 64 bit here, note that UEFI, efi apps and OS all must match bitness and architecture) from edk2/Shell.efi at UDK2018 · tianocore/edk2
  2. Rename the file as bootx64.efi
  3. Create a FAT formatted pen drive, (ideally GPT, but MBR should work)
  4. Create \EFI\Boot folder therein and place this bootx64.efi at \EFI\Boot
Go to boot menu and select this pen drive to boot.
UEFI is designed to have a fallback boot whereby it will also look for bootx64.efi (on 64 bit implementation) at \EFI\Boot on pen drive or EFI partition, if there’s no defined boot order entry.
This method also confirms if your Firmware supports UEFI booting or not in reality! More applicable for those systems that had something called hybrid efi boards.
Shell will look something similar to this.

1.png


Here it by default does FAT partition mapping and is at the Shell prompt. Now if you notice, there’s fs0 partition mapping. So just like we type C: in command prompt on Windows I can type fs0: and access the partition mapped to fs0:

2.png


Detailed list of shell commands is available in the Shell specifications. Note that not all commands are available in all shell implementations. In shell just type ‘help’ and list of all commands will be displayed. Use -b switch to pause at the screen break!

Few things I do with shell are

  1. Add/modify boot entries (bcfg command)
  2. Have access to various file systems. While UEFI generally supports FAT, there are drivers available for all other filesystems, here Free Software EFI Drivers (Drivers only support Read-only)
  3. Also ntfs R/W driver (experimental) is available at Release 1.1 · pbatard/ntfs-3g-old
  4. It’s a built-in fallback mechanism to boot to shell still giving you control in case your Windows or Linux gets corrupted.
  5. Windows 10 UEFI install with install.wim > 4 GB without need of Rufus or any third-party tool, simply using shell and NTFS driver
You can save Shell.efi on EFI partition and create a boot entry to it as well. This is what I have done.
I always have UEFI Shell to boot to as yet another boot option. This is how my boot options look like.

3.png

Shell environment can also be used to flash firmware. Generally more common in enterprise environment. Scripts are possible using .nsh scripting files on Shell. Command names are inherited from Windows and Linux but they are essentially UEFI Shell commands, neither Windows nor Linux!

Help is available by simply typing Help <command> -b
-b switch is useful to pause at the screen break!

How to boot to Shell if you want to enable secure boot? Well for built-in shell there’s no issue but if you want to boot to shell.efi when secure boot is ON, you need to create your own self-signed certificate. Use private key to sign shell.efi and push public certificate in UEFI Secure Boot db database (If your UEFI supports such interface to update db, some simply don’t)

Further reading - *www.uefi.org/sites/default/files/resources/UEFI_Shell_2_2.pdf
Refer section 5 for list of shell command details.
To experiment with Shell you can use VMWare Player. Free for non-commercial. Just create a UEFI VM and it will have boot to shell as option in boot order in its Virtual UEFI.
 
Top Bottom