How UEFI Shell Runs Startup Scripts Automatically
This article provides an overview of UEFI Shell startup scripts,
focusing on the standard startup.nsh file and the mechanics
behind its automated execution. Readers will learn what these scripts
are, their primary use cases in low-level system management, and the
exact sequence the Unified Extensible Firmware Interface (UEFI) Shell
follows to detect, delay, and execute commands prior to booting an
operating system.
What Is a UEFI Startup Script?
A UEFI startup script is a plain-text file containing a sequence of
UEFI Shell commands executed in order, analogous to a .bat
file in Windows or a .sh script in Unix-like environments.
These scripts traditionally use the .nsh file
extension.
The primary startup script recognized by the UEFI Shell is named
startup.nsh. System administrators, firmware developers,
and hardware manufacturers use startup.nsh to automate
tasks before an operating system loads. Typical use cases include:
- Flashing motherboard BIOS or hardware component firmware.
- Running hardware diagnostics and stress tests.
- Configuring UEFI variables and non-volatile memory settings.
- Launching custom bootloaders or provisioning operating system installations.
How UEFI Shell Executes Startup Scripts Automatically
When a system boots into the UEFI Shell—either via a boot menu, direct firmware configuration, or a designated bootable USB drive—it follows a defined process to locate and run the script.
1. File System Enumeration
Upon initialization, the UEFI Shell probes all storage controllers
and detects mounted file systems formatted with supported formats
(predominantly FAT32). It maps these partitions as logical devices,
designated as FS0:, FS1:, FS2:,
and so on.
2. Locating the Script
The shell searches the root directory of these mapped file systems
for a file named startup.nsh. The search order generally
begins with FS0: and progresses sequentially through the
remaining file systems until the file is located.
3. Execution Delay and User Interrupt
Once startup.nsh is detected, the UEFI Shell initiates a
brief countdown timer (typically five seconds by default). A prompt
appears on the screen:
Press ESC in 5 seconds to skip startup.nsh or any other key to continue.
- If the user presses the ESC key during the countdown, the shell aborts the script and drops directly to an interactive command prompt.
- If any other key is pressed, or if the countdown timer expires without input, the shell immediately begins executing the script.
4. Command Processing
The shell reads the script sequentially, executing each command line
by line. Scripts support basic logic, loops, conditional branching (such
as if statements), and exit codes. Once the script
finishes, the shell either exits to an operating system loader (if
instructed by commands such as exit or by calling an
.efi executable) or drops the user into an interactive
shell prompt.