Skip to content

Commit b3c0dc4

Browse files
book: Add "Running on Hardware" page
This page describes how to format a USB to run an EFI application on real hardware.
1 parent 316deea commit b3c0dc4

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

Diff for: book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Creating a UEFI Application](tutorial/app.md)
66
- [Building](tutorial/building.md)
77
- [Running in a VM](tutorial/vm.md)
8+
- [Running on Hardware](tutorial/hardware.md)
89
- [How-to](how_to/introduction.md)
910
- [Using Protocols](how_to/protocols.md)
1011
- [Drawing to the Screen](how_to/drawing.md)

Diff for: book/src/tutorial/hardware.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Running on Hardware
2+
3+
To run on real hardware you'll need a specially-prepared USB drive.
4+
5+
## Preparation
6+
7+
The general steps to prepare the drive are:
8+
9+
1. Partition the drive using [GPT].
10+
2. Create a partition.
11+
3. Set the partition type GUID to
12+
`C12A7328-F81F-11D2-BA4B-00A0C93EC93B`. That marks it as an EFI
13+
System partition. (On many UEFI implementations this is not strictly
14+
necessary, see note below.)
15+
4. Format the partition as [FAT].
16+
5. Mount the partition.
17+
6. Create the directory path `EFI/BOOT` on the partition. (FAT is case
18+
insensitive, so capitalization doesn't matter.)
19+
7. Copy your EFI application to a file under `EFI/BOOT`. The file name
20+
is specific to the architecture. For example, on x86_64 the file name
21+
must be `BOOTX64.EFI`. See the [boot files] table for other
22+
architectures.
23+
24+
The details of exactly how to do these steps will vary depending on your OS.
25+
26+
Note that most UEFI implementations do not strictly require GPT
27+
partitioning or the EFI System partition GUID; they will look for any
28+
FAT partition with the appropriate directory structure. This is not
29+
required however; the UEFI Specification says "UEFI implementations may
30+
allow the use of conforming FAT partitions which do not use the ESP
31+
GUID."
32+
33+
### Example on Linux
34+
35+
**Warning: these operations are destructive! Do not run these commands
36+
on a disk if you care about the data it contains.**
37+
38+
```sh
39+
# Create the GPT, create a 9MB partition starting at 1MB, and set the
40+
# partition type to EFI System.
41+
sgdisk \
42+
--clear \
43+
--new=1:1M:10M \
44+
--typecode=1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \
45+
/path/to/disk
46+
47+
# Format the partition as FAT.
48+
mkfs.fat /path/to/disk_partition
49+
50+
# Mount the partition.
51+
mkdir esp
52+
mount /path/to/disk_partition esp
53+
54+
# Create the boot directory.
55+
mkdir esp/EFI/BOOT
56+
57+
# Copy in the boot executable.
58+
cp /path/to/your-executable.efi esp/EFI/BOOT/BOOTX64.EFI
59+
```
60+
61+
## Booting the USB
62+
63+
Insert the USB into the target computer. Reboot the machine, then press
64+
the one-time boot key. Which key to press depends on the vendor. For
65+
example, Dell uses F12, HP uses F9, and on Macs you hold down the Option
66+
key.
67+
68+
Once the one-time boot menu appears, select your USB drive and press enter.
69+
70+
[GPT]: https://en.wikipedia.org/wiki/GUID_Partition_Table
71+
[FAT]: https://en.wikipedia.org/wiki/File_Allocation_Table
72+
[boot files]: ../concepts/gpt.html#system-partition

0 commit comments

Comments
 (0)