How to Manually Set the BootNow UEFI Variable in FreeBSD
This article details manually setting the value of the BootNow UEFI variable. This allows setting the action BootIt UEFI should take upon booting if a native BootNow utility is not available or is not supported by the operating system.
Note: For systems that support both hexadecimal (hex) and octal numbers with printf, you can use whichever format you prefer. For systems that only support one format you will need to use that format. For example, if using the sh or csh shell, which don't support the hex format with printf, octal must be used.
While the BootNow UEFI variable can be set directly from the terminal by running the command, in most cases, creating a shell script containing the command will make creating, editing, testing, and using the feature much easier. A script could be created to handle multiple boot scenarios or individual scripts could be created for different scenarios, for example.
The BootNow variable value consists of a 4-byte command value followed by a boot item description and auto-run filename. For commands that don't use the description or auto-run filename strings, the strings should consist of just the terminating zeros (zero length strings).
BootNow Command Hex and Octal Values (4-byte/32-bit):
Note: Only the first two bytes of the four bytes are used for the command value and should be specified least significant byte first (as shown in the table below). The remaining two bytes should be zero.
Command | Hex | Octal |
Boot Current Menu Item | \xFB\xFF\x00\x00 | \373\377\000\000 |
Boot Next Menu Item | \xFE\xFF\x00\x00 | \376\377\000\000 |
Shutdown System | \xFD\xFF\x00\x00 | \375\377\000\000 |
None (no action after booting) | \xFC\xFF\x00\x00 | \374\377\000\000 |
Boot Item by Description (max. 50 chars) | \xFF\xFF\x00\x00 | \377\377\000\000 |
Boot Item by Index (starting with 1); example: 3 | \x03\x00\x00\x00 | \003\000\000\000 |
After the command bytes, the remainder of the string consists the boot item description and the auto-run filename. If neither of these is used, the remainder of the string will be two terminating zeros for those strings:
Hex: \x00\x00
Octal: \000\000
Specifying a Description (Boot Item Name)
When booting an item by description, the description text immediately follows the command value and should consist of ASCII characters and be terminated by the zero character. There is a length limit of 50 characters (including the terminating zero character). If no description text is being used, the description portion should consist of only the terminating zero character. If unfamiliar with ASCII character values, using an ASCII chart that shows hex/octal character values will be helpful. (See end of article for printf example to test string output.)
Specifying an Auto-Run Filename
When using an auto-run filename, the filename text immediately follows the terminating zero character of the description text and should consist of ASCII characters and be terminated by the zero character. If no auto-run filename is being used, the filename portion should consist of only the terminating zero character. If unfamiliar with ASCII character values, using an ASCII chart that shows hex/octal character values will be helpful. (See end of article for printf example to test string output.)
Command Value Examples:
- Boot menu item 1 (first menu item):
Hex: \x01\x00\x00\x00\x00\x00
Octal: \001\000\000\000\000\000
- Boot menu item 9:
Hex: \x09\x00\x00\x00\x00\x00
Octal: \011\000\000\000\000\000
- Boot menu item 12:
Hex: \x0C\x00\x00\x00\x00\x00
Octal: \014\000\000\000\000\000
- Boot current menu item, auto-run filename "myscript.tbs":
Hex: \xFB\xFF\x00\x00\x00\x6D\x79\x73\x63\x72\x69\x70\x74\x2E\x74\x62\x73\x00
Octal: \373\377\000\000\000\155\171\163\143\162\151\160\164\056\164\142\163\000
- Boot "test" menu item:
Hex: \xFF\xFF\x00\x00\x74\x65\x73\x74\x00\x00
Octal: \377\377\000\000\164\145\163\164\000\000
- Boot "Windows 10" menu item:
Hex: \xFF\xFF\x00\x00\x57\x69\x6E\x64\x6F\x77\x73\x20\x31\x30\x00\x00
Octal: \377\377\000\000\127\151\156\144\157\167\163\040\061\060\000\000
Setting the BootNow UEFI Variable Value
Once the variable value has been determined, you can use the printf and efivar commands to set the UEFI BootNow variable. This command can be run directly from a terminal or from a shell script.
Note: If the efivar utility is not available you will need to install the package for it before continuing.
Note: The efivar utility requires elevated permission (run from a root account or use su or sudo). If creating and using a script for the command, the script will need to be run elevated.
In the command usage below, substitute "full command value" with the desired command value as detailed above. The command should all be on one line (command may wrap if terminal width is narrow).
printf "full command value" | efivar --name 81686ef9-7f6f-42e3-9371-696de9bf6299-BootNow --write
Example using Hex Characters (boot "Windows 10" menu item):
sudo printf "\xFF\xFF\x00\x00\x57\x69\x6E\x64\x6F\x77\x73\x20\x31\x30\x00\x00" | efivar --name 81686ef9-7f6f-42e3-9371-696de9bf6299-BootNow --write
Example using Octal Characters (boot "Windows 10" menu item):
sudo printf "\377\377\000\000\127\151\156\144\157\167\163\040\061\060\000\000" | efivar --name 81686ef9-7f6f-42e3-9371-696de9bf6299-BootNow --write
Restarting the System
Once the command or script has been run to set the UEFI BootNow variable, the system is ready to be restarted. This can be done by manually when ready, or, if a script was created, the script can automatically run a restart command such as reboot or shutdown -r now after setting the variable.
Testing Hex/Octal String Output:
When creating the hex/octal text for a boot item description or filename, it can be helpful to use the printf command in a terminal to see the output generated. This command does not require elevated permission and can easily be edited. For cleaner output while testing, it can also be helpful to append a new line character (\n).
For example, output "Windows 10" text and print a new line (using octal):
printf "\127\151\156\144\157\167\163\040\061\060\n"