{"id":147,"date":"2013-12-02T02:11:13","date_gmt":"2013-12-02T02:11:13","guid":{"rendered":"http:\/\/blog.ignoranthack.me\/?p=147"},"modified":"2014-04-19T14:45:56","modified_gmt":"2014-04-19T14:45:56","slug":"moving-forward-by-going-slightly-backwards-and-to-the-right-uefi-booting-on-freebsd","status":"publish","type":"post","link":"http:\/\/blog.ignoranthack.me\/?p=147","title":{"rendered":"Moving forward by going slightly backwards and to the right, UEFI booting on #FreeBSD"},"content":{"rendered":"<p>The FreeBSD Foundation has been working towards the future of booting in x86 and catching up to our friends in Linux-land by sponsoring work on a UEFI enabled boot loader.\u00a0 This work was taken on by Benno Rice (benno@freebsd.org) and Ed Maste (emaste@freebsd.org).<\/p>\n<p>So far, it appears that one can indeed boot FreeBSD as I will demonstrate on my Thinkpad T520.<\/p>\n<p>Starting with the <a href=\"http:\/\/svnweb.freebsd.org\/base\/projects\/uefi\/\">UEFI project branch<\/a>, one must build a 64bit version of libstand in tree.<\/p>\n<blockquote><p>cd uefi\/lib\/libstand &amp;&amp; make<\/p><\/blockquote>\n<p>Modify the makefile in sys\/boot\/amd64<\/p>\n<blockquote><p>Index: amd64\/efi\/Makefile<br \/>\n===================================================================<br \/>\n&#8212; amd64\/efi\/Makefile\u00a0\u00a0 \u00a0(revision 258775)<br \/>\n+++ amd64\/efi\/Makefile\u00a0\u00a0 \u00a0(working copy)<br \/>\n@@ -77,8 +77,8 @@<br \/>\nLIBEFI=\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0${.OBJDIR}\/..\/..\/efi\/libefi\/libefi.a<br \/>\nCFLAGS+=\u00a0\u00a0 \u00a0-I${.CURDIR}\/..\/..\/common<\/p>\n<p>-DPADD=\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0${LIBFICL} ${LIBEFI} ${LIBSTAND}<br \/>\n-LDADD=\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0${LIBFICL} ${LIBEFI} ${LIBSTAND}<br \/>\n+DPADD=\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0${LIBFICL} ${LIBEFI} ..\/..\/..\/..\/lib\/libstand\/libstand.a<br \/>\n+LDADD=\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0${LIBFICL} ${LIBEFI} ..\/..\/..\/..\/lib\/libstand\/libstand.a<\/p>\n<p>.include &lt;bsd.prog.mk&gt;<\/p><\/blockquote>\n<p>Now you can build loader.efi and get it to link against the 64bit version of libstand:<\/p>\n<blockquote><p>cd sys\/boot &amp;&amp; make<\/p><\/blockquote>\n<p>UEFI will look for a FAT formatted partition with the &#8220;efi&#8221; signature on it.\u00a0 FreeBSD&#8217;s gpart can create this partition for you, so do the following foo:<\/p>\n<blockquote><p>gpart create -s gpt da0<\/p>\n<p>gpart add -t efi da0<\/p>\n<p>gpart add -t freebsd-ufs da0<\/p>\n<p>$ gpart show da0<br \/>\n=&gt;\u00a0\u00a0\u00a0\u00a0 34\u00a0 2013117\u00a0 da0\u00a0 GPT\u00a0 (983M)<br \/>\n34\u00a0\u00a0 131072\u00a0\u00a0\u00a0 1\u00a0 efi\u00a0 (64M)<br \/>\n131106\u00a0 1882045\u00a0\u00a0\u00a0 2\u00a0 freebsd-ufs\u00a0 (919M)<\/p>\n<p>newfs -t msdosfs \/dev\/da0p1<\/p>\n<p>newfs \/dev\/da0p2<\/p><\/blockquote>\n<p>Mount the fat formatted partition, create the EFI directory structure(this is mandatory) and copy the loader.efi binary into place as bootx64.efi<\/p>\n<blockquote><p>mount -t msdosfs \/dev\/da0p1 \/mnt<\/p>\n<p>mkdir -p \/mnt\/efi\/boot<\/p>\n<p>cp uefi\/sys\/boot\/amd64<\/p><\/blockquote>\n<p>Because the kernel currently needs to be aware of the new style UEFI memory map, you can&#8217;t run stock -current in this configuration.\u00a0 You&#8217;ll need to use a kernel from the projects\/uefi branch when constructing your bootable device.\u00a0 I used a 1G usb thumbdrive for this test, so mount the UFS partition and use it as a DESTDIR for your installworld\/installkernel:<\/p>\n<blockquote><p>make -s buildworld<\/p>\n<p>make -s buildkernel<\/p>\n<p>mount \/dev\/da0p2 \/mnt<\/p>\n<p>DESTDIR=\/mnt make -s installworld<\/p>\n<p>DESTDIR=\/mnt make -s installkernel<\/p>\n<p>DESTDIR=\/mnt make -s distribution<\/p><\/blockquote>\n<p>Setup an \/etc\/fstab on this stick:<\/p>\n<blockquote><p>\/dev\/da0p2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ufs\u00a0\u00a0\u00a0\u00a0 rw,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/p><\/blockquote>\n<p>At this point, your USB disk is ready for its first booting attempt.<\/p>\n<p><a href=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_BIOS.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-medium wp-image-157\" alt=\"EFI_BIOS\" src=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_BIOS-300x225.jpg\" width=\"300\" height=\"225\" srcset=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_BIOS-300x225.jpg 300w, http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_BIOS-1024x768.jpg 1024w, http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_BIOS-624x467.jpg 624w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-158 alignleft\" alt=\"EFI_LOADER1\" src=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER1-300x225.jpg\" width=\"300\" height=\"225\" srcset=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER1-300x225.jpg 300w, http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER1-1024x768.jpg 1024w, http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER1-624x467.jpg 624w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I have to toggle UEFI\/Legacy BIOS mode in my laptop.\u00a0 For your entertainment, here it is.\u00a0 This has the convient side effect of not booting from my other disk devices in my laptop as they do not have the &#8220;proper&#8221; fat formatted EFI partition on them.\u00a0 This actually yeilds a pretty quick boot to the loader.<\/p>\n<p>Amazing!\u00a0 It did!\u00a0 Sort of.<\/p>\n<p>Now we have the entertainment of trying to figure out how to get here to multiuser.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER2.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-159 alignright\" alt=\"EFI_LOADER2\" src=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER2-300x225.jpg\" width=\"300\" height=\"225\" srcset=\"http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER2-300x225.jpg 300w, http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER2-1024x768.jpg 1024w, http:\/\/blog.ignoranthack.me\/wp-content\/uploads\/2013\/12\/EFI_LOADER2-624x467.jpg 624w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>With a &#8220;show&#8221; we find out that the loader has selected the EFI partition &#8220;part6&#8221; as the boot device.\u00a0 &#8220;lsdev&#8221; shows us all the partitions that we could boot from, but I have chosen well in this example and can easily see that the one I really want is tagged with a &#8220;(removable)&#8221;.<\/p>\n<p>In this case executing a &#8220;set currdev=part7&#8221; sets up the loader to boot and executing &#8220;boot&#8221; will get this system into multiuser.<\/p>\n<p>Many thanks to the folks at the FreeBSD Foundation for these initial steps into UEFI.\u00a0 The project branch in subversion is publicly available and I highly encourage folks to engage the community to get this closer to production grade.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The FreeBSD Foundation has been working towards the future of booting in x86 and catching up to our friends in Linux-land by sponsoring work on a UEFI enabled boot loader.\u00a0 This work was taken on by Benno Rice (benno@freebsd.org) and Ed Maste (emaste@freebsd.org). So far, it appears that one can indeed boot FreeBSD as I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_share_on_mastodon":"0"},"categories":[2],"tags":[],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts\/147"}],"collection":[{"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147"}],"version-history":[{"count":10,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":160,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions\/160"}],"wp:attachment":[{"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}