UEFI: Difference between revisions

[unchecked revision][unchecked revision]
Line 254:
 
====Linux, root not required====
This approach uses '''parted''', '''mformat''', and '''mcopy''' and can be performed with user privileges. First, use parted to create primary and secondary GPT headers, and a single EFI partition spanning the same range as the approach above.
<source lang="bash">
$ parted /path/to/uefi.img -s -a minimal mklabel gpt
$ parted /path/to/uefi.img -s -a minimal mkpart EFI FAT16 2048s 93716s
$ parted /path/to/uefi.img -s -a minimal toggle 1 boot
</source>
 
Now create a new temporary image file that will contain the EFI partition data and use mformat to format it with FAT16.
TODO - this section needs updating
<source lang="bash">
You can also get a few tools that do not rely on having certain features in a Linux kernel. Instead, we make use of dd, mtools and parted rather than gdisk and loopback devices. These can be automated into a relatively brief makefile:
dd if=/dev/zero of=$(TEMP_IMG)/tmp/part.img bs=512 count=$(FAT_SECTORS)91669
mformat -i $(TEMP_IMG)/tmp/part.img -h 32 -t 32 -n 64 -c 1 ::
</source>
 
Use mcopy to copy any UEFI applications you want to test to the file system.
<source lang="bash">
$ mcopy -i /tmp/part.img /path/to/main.efi
FAT_SECTORS:=65536
$ ...
DISK_SECTORS:=69632
</source>
DISK_START:=2048
DISK_END:=67584
 
Finally, write the partition image into the main disk image.
TEMP_IMG := temp.img
<source lang="bash">
PARTED := /usr/sbin/parted
$ dd if=/tmp/part.img of=/path/to/uefi.img bs=512 count=91669 seek=2048 conv=notrunc
PARTED_PARAMS := -s -a minimal
 
partition.img: $(FILES)
dd if=/dev/zero of=$(TEMP_IMG) bs=512 count=$(FAT_SECTORS)
mformat -i $(TEMP_IMG) -h 32 -t 32 -n 64 -c 1 ::
mcopy -i $(TEMP_IMG) $(FILES) ::
cp $(TEMP_IMG) $@
rm $(TEMP_IMG)
 
hd.img: partition.img
dd if=/dev/zero of=$(TEMP_IMG) bs=512 count=$(DISK_SECTORS)
$(PARTED) $(TEMP_IMG) $(PARTED_PARAMS) mklabel gpt
$(PARTED) $(TEMP_IMG) $(PARTED_PARAMS) mkpart EFI FAT16 $(DISK_START)s $(DISK_END)s
$(PARTED) $(TEMP_IMG) $(PARTED_PARAMS) toggle 1 boot
dd if=$(BUILDROOT)/partition.img of=$(TEMP_IMG) bs=512 obs=512 count=$(FAT_SECTORS) seek=$(DISK_START) conv=notrunc
cp $(TEMP_IMG) $@
rm $(TEMP_IMG)
</source>
 
''uefi.img'' is now a disk image containing primary and secondary GPT tables, containing a single partition of type EFI, containing a FAT16 file system, containing one or more UEFI applications.
 
====FreeBSD, root required====
Anonymous user