{"id":311,"date":"2022-02-20T20:42:48","date_gmt":"2022-02-20T20:42:48","guid":{"rendered":"http:\/\/10.171.10.16:10000\/?p=311"},"modified":"2022-02-20T20:42:50","modified_gmt":"2022-02-20T20:42:50","slug":"adding-efi-support-to-our-pxe-server","status":"publish","type":"post","link":"https:\/\/dannypayne.me\/?p=311","title":{"rendered":"Adding EFI support to our PXE server"},"content":{"rendered":"\n<p>In this post I&#8217;m going to cover the process needed to add UEFI support to our PXE server. <br>Up until this point, we&#8217;ve only been able to boot and access our PXE server on BIOS devices, Gen 1 Hyper-V VMs, and BIOS mode VMWare VMs.<br><br>This post assumes you&#8217;ve either followed or have a similar setup to the one mentioned in my first post on this, <a href=\"http:\/\/10.171.10.16:10000\/?p=248\" target=\"_blank\" rel=\"noreferrer noopener\">HERE<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"getting-started\">Getting started<\/h3>\n\n\n\n<p>As mentioned above, we&#8217;re going to add EFI support to our PXE server. We&#8217;re going to accomplish this with a few files and resources:<br>&#8211; grubx64.efi (found online or within an ISO)<br>&#8211; grubia32.efi (found online or within an ISO)<br>&#8211; grub.cfg (created by us, more on this later)<br><br>To begin, we want to obtain the <strong>grubia32.efi<\/strong> and <strong>grubx64.efi<\/strong> files and put it in the <code>\/var\/lib\/tftpboot<\/code> location. <br>In the first post in this series, you&#8217;ll remember we copied the AlmaLinux install files to our <code>\/srv\/networkboot<\/code> location &#8211; I&#8217;m going to copy the files from that location:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">[root@COLO-PXE ~]# cp -v \/srv\/networkboot\/almalinux\/8.5\/EFI\/BOOT\/{grubia32.efi,grubx64.efi} \/var\/lib\/tftpboot\/\r\n'\/srv\/networkboot\/almalinux\/8.5\/EFI\/BOOT\/grubia32.efi' -> '\/var\/lib\/tftpboot\/grubia32.efi'\r\n'\/srv\/networkboot\/almalinux\/8.5\/EFI\/BOOT\/grubx64.efi' -> '\/var\/lib\/tftpboot\/grubx64.efi'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"prepare-router-for-efi-booting\">Prepare router for EFI booting<\/h3>\n\n\n\n<p>When we initially built our PXE server, I ran through how to set the DHCP options to enable PXE booting, however this was only for BIOS\/Legacy clients. To enable PXE booting for EFI clients, we&#8217;ll need to do the following:<\/p>\n\n\n\n<p>On PFSense, we\u2019re going to want to navigate to\u00a0<strong>Services\u00a0<\/strong>>\u00a0<strong>DHCP Server<\/strong>\u00a0>\u00a0<em><strong>&lt;Network name><\/strong><\/em>.<br>Scroll to the bottom of the page and find\u00a0<strong>Network Booting<\/strong>. Click\u00a0<strong>Display Advanced<\/strong>. <br>In the <strong>UEFI 32 bit file name<\/strong> box, enter  <strong>grubia32.efi<\/strong><br>In the <strong>UEFI 64 bit file name<\/strong> box, enter <strong>grubx64.efi<\/strong><br>Scroll to the bottom of the page and <strong>Save<\/strong> the changes we&#8217;ve made. We&#8217;re now ready to continue. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"646\" height=\"268\" src=\"http:\/\/10.171.10.16:10000\/wp-content\/uploads\/2022\/02\/311-1.png\" alt=\"\" class=\"wp-image-327\" srcset=\"https:\/\/dannypayne.me\/wp-content\/uploads\/2022\/02\/311-1.png 646w, https:\/\/dannypayne.me\/wp-content\/uploads\/2022\/02\/311-1-300x124.png 300w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"building-grub-cfg\">Building grub.cfg<\/h3>\n\n\n\n<p>At this point, we&#8217;ve copied our efi bootloaders, but we now need to build our <code>grub.cfg<\/code> file &#8211; unfortunately our <code>pxelinux<\/code> menu files won&#8217;t work with EFI. <br>First, we need to create the <code>grub.cfg<\/code> file and then open it, I&#8217;m using <code>vi<\/code> in this example:<\/p>\n\n\n\n<pre title=\"\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">[root@COLO-PXE ~]# touch \/var\/lib\/tftpboot\/grub.cfg\n[root@COLO-PXE ~]# vi \/var\/lib\/tftpboot\/grub.cfg<\/code><\/pre>\n\n\n\n<p>In this example, I&#8217;m going to provide a simple <code>grub.cfg<\/code> that lets us boot the AlmaLinux installation media, and also Gparted, both over EFI:<\/p>\n\n\n\n<pre title=\"\/var\/lib\/tftpboot\/grub.cfg\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">set default=0\nset timeout=30\n\n\rmenuentry 'Boot from next volume' {\r\n        exit\r\n}\r\n\r\nmenuentry 'Boot AlmaLinux 8.5 x64 with Network Repo'{\r\n        linuxefi almalinux\/8.5\/pxeboot\/vmlinuz inst.repo=ftp:\/\/10.179.1.10\/almalinux\/8.5 devfs=nomount\r\n        initrdefi almalinux\/8.5\/pxeboot\/initrd.img\r\n}\r\n\r\nmenuentry 'GParted Live'{\r\n        linuxefi gparted\/vmlinuz boot=live config components union=overlay username=user noswap noeject locales=en_US keyboard-layouts=en_US.UTF-8 fetch=ftp:\/\/10.179.1.10\/gparted\/filesystem.squashfs\r\n        initrdefi gparted\/initrd.img\r\n}\r<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"so-what-s-actually-happening\">So what&#8217;s actually happening? <\/h4>\n\n\n\n<p>This took me some time to work out and understand. We&#8217;re basically doing the following:<br>&#8211; Setting our default boot option number <br>&#8211; Setting our menu timeout <br>&#8211; Adding an exit option (which is our default boot option) <br>&#8211; Adding a menu entry for our first bootable item (AlmaLinux 8.5 media)<br>&#8211; Setting the EFI equivalent of the <code>PXELINUX<\/code> <code>APPEND<\/code> line<br>&#8211; Setting the EFI equivalent of the <code>PXELINUX<\/code> <code>KERNEL<\/code> line<br>&#8211; Adding a menu entry for our second bootable item (GParted Live) <br>&#8211; Setting the EFI equivalent of the <code>PXELINUX<\/code> <code>APPEND<\/code> line<br>&#8211; Setting the EFI equivalent of the <code>PXELINUX<\/code> <code>KERNEL<\/code> line<br> <\/p>\n\n\n\n<p>You&#8217;ll notice that the <code>linuxefi<\/code> and <code>initredfi<\/code> lines are similar to what I initially set up in my post about adding more entries to our boot menu, <a href=\"http:\/\/10.171.10.16:10000\/?p=280#build-pxe-menu\">HERE<\/a>. We can reuse most of these lines but some will need some changing to follow the above format. <\/p>\n\n\n\n<p>Now that we&#8217;ve got this, we can try booting:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/10.171.10.16:10000\/wp-content\/uploads\/2022\/02\/311-almalinux-boot.gif\" alt=\"\" class=\"wp-image-319\"\/><figcaption>AlmaLinux<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/10.171.10.16:10000\/wp-content\/uploads\/2022\/02\/311-gparted-boot.gif\" alt=\"\" class=\"wp-image-320\"\/><figcaption>GParted Live<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"adding-more-entries-to-grub-cfg\">Adding more entries to grub.cfg<\/h3>\n\n\n\n<p>Now that we understand the basics of the <code>grub.cfg<\/code> menu, we can add some more entries and customise it a little. Sources are <a rel=\"noreferrer noopener\" href=\"https:\/\/www.gaztronics.net\/server\/network-boot.php\" target=\"_blank\">HERE<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/snippets.cacher.io\/snippet\/e69ce7f307639326cf06\" target=\"_blank\">HERE<\/a> &#8211; these two links massively helped with this process. <br>Below is a copy of a menu that contains a couple of submenus with more bootable options. This also has some colours set for the text:<\/p>\n\n\n\n<pre title=\"\/var\/lib\/tftpboot\/grub.cfg\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">set default=0\r\nset timeout=20\r\nfunction load_video {\r\n  insmod efi_gop\r\n  insmod efi_uga\r\n  insmod video_bochs\r\n  insmod video_cirrus\r\n  insmod all_video\r\n}\r\n\r\nload_video\r\nset gfxpayload=keep\r\ninsmod net\r\ninsmod efinet\r\ninsmod tftp\r\ninsmod gzio\r\ninsmod part_gpt\r\ninsmod ext2\r\n\r\r\nset menu_color_normal=white\/black\r\nset menu_color_highlight=white\/cyan\r\n\r\nmenuentry 'Boot from next volume' {\r\n\techo \"System booting to next volume...\"\r\n    exit\r\n}\r\n\r\nmenuentry \"Shutdown system\" {\r\n\techo \"System shutting down...\"\r\n\thalt\r\n}\r\n \r\nmenuentry \"Reboot system\" {\r\n\techo \"System rebooting...\"\r\n\treboot\r\n}\r\n\r\nsubmenu \"AlmaLinux -->\" {\r\n\tmenuentry 'Boot AlmaLinux 8.5 x64 with Network Repo'{\r\n        linuxefi almalinux\/8.5\/pxeboot\/vmlinuz inst.repo=ftp:\/\/10.179.1.10\/almalinux\/8.5 devfs=nomount\r\n        initrdefi almalinux\/8.5\/pxeboot\/initrd.img\r\n\t}\r\n}\r\n\r\nsubmenu \"Tools -->\" {\r\n    menuentry \"NT Password and Registry Editor\"{\r\n        linuxefi ntpasswd\/vmlinuz rw vga=1\r\n\t\tinitrdefi ntpasswd\/initrd.cgz,ntpasswd\/scsi.cgz\r\n    }\r\n\r\n    menuentry \"GParted Live\"{\r\n        linuxefi gparted\/vmlinuz boot=live config components union=overlay username=user noswap noeject locales=en_US keyboard-layouts=en_US.UTF-8 fetch=ftp:\/\/10.179.1.10\/gparted\/filesystem.squashfs\r\n        initrdefi gparted\/initrd.img\r\n    }\r\n\r\n    menuentry \"Clonezilla Live\"{\r\n        linuxefi clonezilla\/vmlinuz boot=live username=user union=overlay config components quiet noswap edd=on nomodeset nodmraid keyboard-layouts=en locales=en_US.UTF-8 ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" ocs_live_batch=no net.ifnames=0 nosplash noprompt fetch=ftp:\/\/10.179.1.10\/clonezilla\/filesystem.squashfs\r\n        initrdefi clonezilla\/initrd.img\r\n    }\r\n\r\n    menuentry \"Rescuezilla Live\"{\r\n        linuxefi rescuezilla\/vmlinuz boot=casper quiet splash fastboot toram root=\/dev\/ram0 ramdisk_size=15000000 ip=dhcp url=http:\/\/10.179.1.10\/networkboot\/rescuezilla\/rescuezilla-2.3.1-64bit.impish.iso\r\n        initrdefi rescuezilla\/initrd.lz\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"so-what-s-actually-happening-part-2\">So what&#8217;s actually happening? Part 2 <\/h4>\n\n\n\n<p>Much the same as our first menu, I&#8217;m not 100% sure what&#8217;s going on here and it&#8217;s taken me some time to sort of understand, however for the parts I do know:<br>&#8211; Setting our default boot option number <br>&#8211; Setting our menu timeout <br>&#8211; Creating a module group, and then inserting the dynamic modules to support different video types<br>&#8211; Inserting more dynamic modules (not 100% what these are but I presume they&#8217;re important!)<br>&#8211; Setting menu colours for normal text and highlighted text<br>&#8211; Adding menu entries for boot to next volume, shutdown and reboot<br>&#8211; Creating submenu for AlmaLinux containing it&#8217;s boot entry<br>&#8211; Creating submenu for Tools and their entries <\/p>\n\n\n\n<p>That was lots of text, so let&#8217;s test our menu and see if we can boot from it successfully:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/10.171.10.16:10000\/wp-content\/uploads\/2022\/02\/311-almalinux-boot2.gif\" alt=\"\" class=\"wp-image-322\"\/><figcaption>AlmaLinux<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/10.171.10.16:10000\/wp-content\/uploads\/2022\/02\/311-rescuezilla-boot.gif\" alt=\"\" class=\"wp-image-323\"\/><figcaption>Rescuezilla<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/10.171.10.16:10000\/wp-content\/uploads\/2022\/02\/311-reboot-shutdown.gif\" alt=\"\" class=\"wp-image-324\"\/><figcaption>Reboot + shutdown<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"wrapping-up\">Wrapping up<\/h3>\n\n\n\n<p>In this post I&#8217;ve covered the process of enabling UEFI PXE booting on our router, copying the files to allow for UEFI booting, and creating a couple of grub menus to allow us to select and boot from our stored images, with submenu support to allow us to keep our menu tidy and organised. <br>In the next post, I&#8217;m going to cover adding Windows support to both the legacy <code>PXELINUX<\/code> and <code>grub.cfg<\/code> menu. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;m going to cover the process needed to add UEFI support to our PXE server. Up until&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/dannypayne.me\/?p=311\">Read more<span class=\"screen-reader-text\">Adding EFI support to our PXE server<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":328,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-homelab","excerpt","zoom","full-without-featured","even","excerpt-0"],"jetpack_featured_media_url":"https:\/\/dannypayne.me\/wp-content\/uploads\/2022\/02\/311-2.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/posts\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dannypayne.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=311"}],"version-history":[{"count":10,"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":329,"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/posts\/311\/revisions\/329"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dannypayne.me\/index.php?rest_route=\/wp\/v2\/media\/328"}],"wp:attachment":[{"href":"https:\/\/dannypayne.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dannypayne.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dannypayne.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}