thin: A Trivial EFI Utility

by Roderick W. Smith, rodsmith@rodsbooks.com

Originally written: 4/17/2012

I'm a technical writer and consultant specializing in Linux technologies. This Web page is provided free of charge and with no annoying outside ads; however, I did take time to prepare it, and Web hosting does cost money. If you find this Web page useful, please consider making a small donation to help keep this site up and running. Thanks!

Donate $1.00 Donate $2.50 Donate $5.00 Donate $10.00 Donate another value
Donate with PayPal

The rEFIt boot manager comes in both source code and binary versions; however, the binaries are delivered in a proprietary Apple "fat" binary format that includes both 32- and 64-bit versions in one file. This is handy for Apple users, but these "fat" binaries are non-standard; they don't work on UEFI-based PCs. Unfortunately, the source code for some of the rEFIt ancillary programs is difficult to compile under Linux, so if you want to use those programs on a UEFI-based PC, you're in a bit of a bind. I found myself in this bind when I wanted to experiment with the Linux filesystem drivers provided with rEFIt. (These drivers enable Linux ReiserFS and ext2 filesystems to be read from EFI.)

Fortunately, rEFIt's author has documented the "fat" binary format here. Using this information, I wrote thin, which takes an Apple "fat" EFI binary and extracts the two (theoretically up to five) single-architecture program files that make it up.

thin is a very small program; it's a quick hack, but one that might be of interest to some other people, so I'm making it available on this page. Without further ado, then, here's the download link:

thin.tgz

Included in that package is the single source file (thin.c), an x86-64 binary for Linux (thin), and a copy of the GNU GPLv3. If you want to compile the program for another architecture, you can do so with the following command:

gcc -o thin thin.c

I make no promises that it will compile on anything but a Linux system, but it will probably compile on most Unix-like systems with few or no changes. To use the program, pass it the name of the original "fat" EFI binary file. The result is a few status lines and two new files:

$ ./thin fsw_ext2.efi
fsw_ext2.efi is 107984 bytes in size
Saving file for CPU type 7; offset = 48, length = 39424
Saving new file to 'fsw_ext2_ia32.efi'
Saving file for CPU type 1000007; offset = 39472, length = 68512
Saving new file to 'fsw_ext2_x64.efi'

As noted by the Saving new file to... lines, the result is two new files, both with filenames based on the original file's name. You can use the basename_ia32.efi file on x86 (aka IA32; 32-bit) systems, and the basename_x64.efi file on x86-64 (aka AMD64 or x64; 64-bit) systems.

Please remember that thin is a quick hack. It includes minimal error checking. Although it checks that the input file is in Apple's "fat" EFI binary format, it could do strange things if you feed it a file with a peculiar name or a file that's been damaged in some way.


copyright © 2012 by Roderick W. Smith

If you have problems with or comments about this Web page, please e-mail me at rodsmith@rodsbooks.com. Thanks.

Return to my main Web page.