[CentOS] UEFI and PXE

Thu Apr 25 01:05:52 UTC 2019
Chris Adams <linux at cmadams.net>

Once upon a time, isdtor <isdtor at gmail.com> said:
> We have a working PXE setup. I've tried to adapt it to UEFI as per
> RHEL6 manual, but the client won't boot.

I have BIOS+UEFI PXE boot set up, although it took some doing.  I still
use SYSLINUX for BIOS, but GRUB2 plus Red Hat's secure boot shim for
UEFI.  I never could get SYSLINUX's UEFI support working very well or
reliably, and it didn't support secure boot at all last I looked.

I also feed most of the content out via HTTP (much faster than TFTP).
That includes generating menus on the fly from perl CGIs (I'm
old-fashioned that way :) ).

I'm using dnsmasq as my DHCP server, so I have this in its config (where
pxesrv.cmadams.net has IP

# EFI boot will set ARCH option (93)

# PXE boot

In my TFTP root, I then extract the following RPMs into subdirectories
(from Fedora 29 currently):

   syslinux-tftpboot shim-x64 grub2-efi-x64 grub2-efi-x64-modules

I put each in a subdirectory and then add symlinks to make it easier to
replace things with the contents of newer RPMs.  I'm including a script
I use that sets that up (and can be re-run at any time to download the
latest RPMs - this assumes the PXE server is Fedora though, but you
should be able to adapt it easily enough).

Since you already have a working BIOS PXE, I'll assume you know how to
make that config file.  The kernel/initrd lines take HTTP URLs just
fine, so that's much faster.

Here's what the output of my grub2.pl CGI looks like (I use gfxterm so I
can load a larger font that I set up locally in the TFTP root - you
should be able to just skip that line):

terminal_input console
loadfont /12x26.pf2
insmod gfxterm
set gfxmode=auto
terminal_output gfxterm
set timeout=-1

set timeout=-1

menuentry 'Install Fedora release 29 x86_64' {
        set root=(http,pxesrv.cmadams.net)
        linuxefi /pub/fedora/linux/releases/29/Server/x86_64/os/images/pxeboot/vmlinuz inst.root=http://pxesrv.cmadams.net/pub/fedora/linux/releases/29/Server/x86_64/os/ inst.stage2=http://pxesrv.cmadams.net/pub/fedora/linux/releases/29/Server/x86_64/os/ repo=http://pxesrv.cmadams.net/pub/fedora/linux/releases/29/Everything/x86_64/os quiet BOOTIF=$net_default_mac
        initrdefi /pub/fedora/linux/releases/29/Server/x86_64/os/images/pxeboot/initrd.img

Hope this helps - at least show you some ways to do things.  Here's my
tftpboot setup script:


# Set up a BIOS/UEFI PXE TFTP boot tree on a Fedora system
set -e

# Fetch and extract the RPMs
dnf download syslinux-tftpboot shim-x64 grub2-efi-x64 grub2-efi-x64-modules memtest86+
for rpm in *.rpm; do
	if [ ! -d $pkg ]; then
		mkdir $pkg
		cd $pkg
		rpm2cpio ../$rpm | cpio -dumi
		cd ..
		name=$(rpm -q --qf '%{name}' -p $rpm)
		rm -f $name
		ln -s $pkg $name
	rm $rpm

# BIOS setup
if [ ! -d bios ]; then
	mkdir bios
	cd bios
	ln -s ../syslinux-tftpboot/tftpboot/{ldlinux.c32,libutil.c32,lpxelinux.0,memdisk,menu.c32} .
	ln -s ../memtest86+/boot/memtest86+-* memtest-cur
	echo "ui menu.c32 http://pxesrv.cmadams.net/local/pxe.pl" > pxelinux.conf
	cd ..

# EFI setup
if [ ! -d EFI ]; then
	mkdir EFI
	cd EFI
	ln -s ../grub2-efi-x64-modules/usr/lib/grub fedora
	cd ..
	ln -s shim-x64/boot/efi/EFI/fedora/shimx64.efi .
	ln -s grub2-efi-x64/boot/efi/EFI/fedora/grubx64.efi .
	echo "sournce (http,pxesrv,cmadams.net)/local/grub2.pl" > grub.cfg

Chris Adams <linux at cmadams.net>