{"id":2312,"date":"2017-03-03T23:17:15","date_gmt":"2017-03-03T21:17:15","guid":{"rendered":"http:\/\/possiblelossofprecision.net\/?p=2312"},"modified":"2022-01-29T23:19:25","modified_gmt":"2022-01-29T21:19:25","slug":"updating-bios-firmware-via-ipxe","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=2312","title":{"rendered":"Updating BIOS firmware via iPXE"},"content":{"rendered":"<p>These days mainboards usually come with some sort of wizbang tool that allow the user to update the BIOS from a USB drive or straight via network. Except, of course, that one single mainboard that absolutely needs a new BIOS version on a late Friday afternoon. And obviously the manufacturer only provides a flash tool for DOS and the mainboard is not supported by <a href=\"https:\/\/www.flashrom.org\">flashrom <\/a> yet.<br \/>\nIn those cases booting <a href=\"http:\/\/www.freedos.org\/\">FreeDOS<\/a> can be really handy. <a href=\"https:\/\/possiblelossofprecision.net\/?p=491\">Booting FreeDOS via PXE<\/a> is not that hard and it can also be booted <a href=\"http:\/\/ipxe.org\/cmd\/sanboot\">via iPXE<\/a> quite easily. If you do boot it via PXE, the easiest way to access the mainboard manufacturer&#8217;s flash tool and the new BIOS firmware from within FreeDOS is probably to include it in the PXE image file (see <a href=\"https:\/\/possiblelossofprecision.net\/?p=491#4-manipulating-the-image\">here<\/a>). With iPXE however there&#8217;s a much more elegant way&#8230;<\/p>\n<p><!--more--><\/p>\n<h2>Minimal iPXE script to boot FreeDOS<\/h2>\n<p>While a comprehensive tutorial on how to set up a dhcp, tftp and iPXE server would go beyond the scope of this post, here&#8217;s a short outline of the necessary steps involved.<br \/>\nFirst, we need to configure the dhcp server so that the iPXE firmware is handed out to legacy PXE clients, and an iPXE boot configuration file is handed out to actual iPXE clients. With the <a href=\"https:\/\/www.isc.org\/downloads\/dhcp\/\">ISC dhcp server<\/a> this can be done by handing out different configurations based on the <em>DHCP user class<\/em> (see also <a href=\"http:\/\/ipxe.org\/howto\/dhcpd\">http:\/\/ipxe.org\/howto\/dhcpd<\/a>):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n  if exists user-class and option user-class = &quot;iPXE&quot; {\r\n      filename &quot;http:\/\/my.web.server\/freedos.ipxe&quot;;\r\n  } else {\r\n      filename &quot;undionly.kpxe&quot;;\r\n  }\r\n<\/pre>\n<p>Of course the tftp server now needs to be configured to hand out <code>undionly.kpxe<\/code> which is part (at least on RHEL and Fedora) of the <code>ipxe-bootimgs<\/code> package. A very basic installation could look like this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndnf install tftp-server ipxe-bootimgs\r\ncp \/usr\/share\/ipxe\/undionly.kpxe \/var\/lib\/tftpboot\/\r\nsystemctl enable tftp.service\r\nsystemctl start tftp.service\r\n<\/pre>\n<p>Copying <code>undionly.kpxe<\/code> to <code>\/var\/lib\/tftpboot\/<\/code> is necessary since the tftp daemon is started in <a href=\"https:\/\/linux.die.net\/man\/8\/tftpd\">secure mode<\/a> per default which disables following symlinks.<\/p>\n<p>A minimalistic <code>freedos.ipxe<\/code> boot configuration file could be<\/p>\n<pre class=\"brush: plain; title: freedos.ipxe; notranslate\" title=\"freedos.ipxe\">\r\n#!ipxe\r\n\r\n:freedos\r\nkernel memdisk raw\r\ninitrd http:\/\/www.freedos.org\/download\/download\/FD12FLOPPY.zip\r\nboot || goto failed\r\n\r\n:failed\r\necho Booting failed, dropping to shell\r\ngoto shell\r\n<\/pre>\n<p>The <code>memdisk<\/code> kernel is part of the <code>syslinux-tftpboot<\/code> package. Creating a symlink to <code>\/tftpboot\/memdisk<\/code> in the same directory in which the <code>freedos.ipxe<\/code> boot configuration file lives should be sufficient.<\/p>\n<div id=\"attachment_2327\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a data-rokbox href=\"wordpress\/wp-content\/uploads\/2017\/04\/iPXE_booting_FreeDOS.png\" data-rokbox-album=\"p2312\" data-rokbox-caption=\"iPXE booting FreeDOS\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2327\" src=\"wordpress\/wp-content\/uploads\/2017\/04\/iPXE_booting_FreeDOS.png\" alt=\"\" \/><\/a><p id=\"caption-attachment-2327\" class=\"wp-caption-text\">iPXE booting FreeDOS<\/p><\/div>\n<h2>Creating a payload image<\/h2>\n<p>Instead of <a href=\"https:\/\/wiki.archlinux.org\/index.php\/Flashing_BIOS_from_Linux#FreeDOS\">manipulating the FreeDOS floppy image<\/a> to include the mainboard manufacturer&#8217;s flash tool and the BIOS update file, we&#8217;re going to create a separate payload image and attach it to FreeDOS as an <strong>additional hard disk<\/strong>.<\/p>\n<p>First, we&#8217;ll create an empty 32MB file (which could be bigger if one needed more space) and partition it with the first partition starting at <a href=\"https:\/\/www.thomas-krenn.com\/en\/wiki\/Partition_Alignment\">LBA Address 63<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntruncate payload.img --size 32MB\r\nsfdisk payload.img &lt;&lt; EOF\r\n63,,b\r\nEOF\r\n<\/pre>\n<p>Next, set up the resulting <code>payload.img<\/code> file as loop device and create a filesystem:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nlosetup \/dev\/loop0 payload.img\r\nmkfs.vfat \/dev\/loop0p1 \r\n<\/pre>\n<p>If there&#8217;s no separate device for the first partition (e.g. <code>\/dev\/loop0p1<\/code> you might want to pass a <code>max_part<\/code> option to the loop kernel module module so that loop devices are partitionable:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmodprobe -r loop\r\nmodprobe loop max_part=16\r\n<\/pre>\n<p>Now you can mount the partition and copy the necessary files (flash tool and BIOS firmware)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmount \/dev\/loop0p1 \/mnt\/ \r\ncp &lt;necessary files&gt; \/mnt\/\r\numount \/mnt\r\nlosetup -d \/dev\/loop0 \r\n<\/pre>\n<h2>Attaching the payload image as additional hard drive<\/h2>\n<p>The only thing left to do is to attach the newly created payload image as an additional hard disk to FreeDOS:<\/p>\n<pre class=\"brush: plain; highlight: [4]; title: freedos.ipxe; notranslate\" title=\"freedos.ipxe\">\r\n#!ipxe\r\n\r\n:freedos\r\nsanhook payload.img || goto failed\r\nkernel memdisk raw\r\ninitrd http:\/\/www.freedos.org\/download\/download\/FD12FLOPPY.zip\r\nboot || goto failed\r\n\r\n:failed\r\necho Booting failed, dropping to shell\r\ngoto shell\r\n<\/pre>\n<p>Don&#8217;t forget to copy the <code>payload.img<\/code> to the host handing out the <code>freedos.ipxe<\/code> iPXE boot configuration file.<\/p>\n<div id=\"attachment_2328\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a data-rokbox href=\"wordpress\/wp-content\/uploads\/2017\/04\/FreeDOS_with_additional_harddisk.png\" data-rokbox-album=\"p2312\" data-rokbox-caption=\"FreeDOS booting with additional hard disk\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2328\" src=\"wordpress\/wp-content\/uploads\/2017\/04\/FreeDOS_with_additional_harddisk.png\" alt=\"\" \/><\/a><p id=\"caption-attachment-2328\" class=\"wp-caption-text\">FreeDOS bootin with additional hard disk attached via <em>sanhook<\/em><\/p><\/div>\n<p>After booting up FreeDOS you can find the contents of the payload image file under <code>C:<\/code> (or <code>D:<\/code> if you booted the FreeDOS cdrom images instead of the floppy image).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>These days mainboards usually come with some sort of wizbang tool that allow the user to update the BIOS from a USB drive or straight via network. Except, of course, that one single mainboard that absolutely needs a new BIOS version on a late Friday afternoon. And obviously the manufacturer only provides a flash tool for DOS and the mainboard&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=2312\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,58,85],"class_list":["post-2312","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-fedora","tag-hardware","tag-pxe"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2312"}],"version-history":[{"count":24,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2312\/revisions"}],"predecessor-version":[{"id":2338,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2312\/revisions\/2338"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}