{"id":218,"date":"2014-07-19T22:18:32","date_gmt":"2014-07-19T22:18:32","guid":{"rendered":"http:\/\/blog.ignoranthack.me\/?p=218"},"modified":"2014-07-19T22:18:32","modified_gmt":"2014-07-19T22:18:32","slug":"using-qemu-user-to-chroot-and-bootstrap-other-architectures-on-freebsd","status":"publish","type":"post","link":"http:\/\/blog.ignoranthack.me\/?p=218","title":{"rendered":"Using qemu-user to chroot and bootstrap other architectures on #FreeBSD"},"content":{"rendered":"<p>My last post spawned enough feedback that I thought I would dump some notes here for those interested in building a chroot on FreeBSD that allows you to test and prototype architectures, e.g. ARMv6 on AMD64.<\/p>\n<p>The FreeBSD buildsys has many targets used for many things, the two we care about here are <strong>buildworld<\/strong> and <strong>distribution.\u00a0 <\/strong>We will also be changing the output architecture through the use of TARGET and TARGET_ARCH command line variables.\u00a0 I&#8217;ll assume csh is your shell here, just for simplicity.\u00a0 You&#8217;ll need 10stable or 11current to do this, as it requires the binary activator via binmiscctl(8) which has not appeared in a release version of FreeBSD yet.<\/p>\n<p>Checkout the FreeBSD source tree somewhere, your home directory will be fine and start a buildworld.\u00a0 This will take a while, so get a cup of tea and relax.<\/p>\n<p style=\"padding-left: 30px;\"><strong>make -s -j &lt;number of cpus on your machine&gt; buildworld TARGET=mips TARGET_ARCH=mips64 MAKEOBJDIRPREFIX=\/var\/tmp<\/strong><\/p>\n<p>Some valid combinations of TARGET\/TARGET_ARCH are:<\/p>\n<p style=\"padding-left: 30px;\"><strong>mips:mips<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>mips:mip64<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>arm:armv6<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>sparc64:sparc64<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>powerpc:powerpc<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>powerpc:powerpc64<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>i386:i386<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>amd64:amd64<\/strong><\/p>\n<p>Once this is done, you have an installable tree in \/var\/tmp.\u00a0 You need to be root for the next few steps, <strong>su<\/strong> now and execute these steps:<\/p>\n<p style=\"padding-left: 30px;\"><strong>make -s installworld TARGET=mips TARGET_ARCH=mips64 MAKEOBJDIRPREFIX=\/var\/tmp DESTDIR=\/opt\/test<\/strong><\/p>\n<p><strong>DESTDIR<\/strong> is where you intend on placing the installed FreeBSD system.\u00a0 I chose \/opt\/test here only because I wanted to be FAR away from anything in my running system.\u00a0 Just to be clear here, this will crush and destroy your host computer without DESTDIR set.<\/p>\n<p>Next, there are some tweaks that have to be done by the buildsys, so run this command as root:<\/p>\n<p style=\"padding-left: 30px;\"><strong>make -s distribution TARGET=mips TARGET_ARCH=mips64 MAKEOBJDIRPREFIX=\/var\/tmp DESTDIR=\/opt\/test<\/strong><\/p>\n<p>Now we need to install the emulator tools (QEMU) to allow us to use the chroot on our system.\u00a0 I suggest using emulators\/qemu-user-static for this as Juergen Lock has set it up for exactly this purpose.\u00a0 It will install <em>only <\/em>the tools you need here.<\/p>\n<p>Once that is installed, via pkg or ports, setup your binary activator module for the architecture of your chroot.\u00a0 Use the listed options on the <a href=\"https:\/\/wiki.freebsd.org\/QemuUserModeHowTo\">QEMU user mode wiki page<\/a> for the architecture you want.\u00a0 I know the arguments are not straight forward, but there should be examples for the target that you are looking for.<\/p>\n<p>For this mips\/mips64 example:<\/p>\n<p style=\"padding-left: 30px;\"><strong>binmiscctl add mips64elf &#8211;interpreter &#8220;\/usr\/local\/bin\/qemu-mips64-static&#8221; <\/strong><br \/>\n<strong>&#8211;magic &#8220;x7fx45x4cx46x02x02x01x00x00x00x00x00x00x00x00x00x00x02x00x08&#8221; <\/strong><br \/>\n<strong>&#8211;mask &#8220;xffxffxffxffxffxffxffx00xffxffxffxffxffxffxffxffxffxfexffxff&#8221; <\/strong><br \/>\n<strong>&#8211;size 20 &#8211;set-enabled<\/strong><\/p>\n<p>Copy the binary qemu that you setup in this step *into* the chroot environment:<\/p>\n<p style=\"padding-left: 30px;\"><strong>mkdir -p \/opt\/tmp\/usr\/local\/bin<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>cp \/usr\/local\/bin\/qemu-mips64-static \/opt\/tmp\/usr\/local\/bin\/<\/strong><\/p>\n<p>Mount devfs into the chroot:<\/p>\n<p style=\"padding-left: 30px;\"><strong>mount -t devfs devfs \/opt\/tmp\/dev<\/strong><\/p>\n<p>Want to try building ports in your chroot?\u00a0 Mount the ports tree in via nullfs:<\/p>\n<p style=\"padding-left: 30px;\"><strong>mkdir \/opt\/tmp\/usr\/ports<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>mount -t nullfs \/usr\/ports \/opt\/tmp\/usr\/ports<\/strong><\/p>\n<p>And now, through the QEMU and FreeBSD, you can simply chroot into the environment:<\/p>\n<p style=\"padding-left: 30px;\"><strong>chroot \/opt\/tmp<\/strong><\/p>\n<p>Hopefully, you can now &#8220;do&#8221; things as though you were running on a MIPS64 or whatever architecture machine you have as a target.<\/p>\n<p>arm:armv6, mips:mips, mips:mips64 are working at about %80-90 functionality.\u00a0 powerpc:powerpc64 and powerpc:powerpc are still a work in progress and need more work.\u00a0 sparc64:sparc64 immediately aborts and probably needs someone with an eye familiar with the architecture to give QEMU a look.\u00a0 If you are interested in further development of the qemu-user targets, please see<a href=\"https:\/\/github.com\/seanbruno\/qemu-bsd-user\/tree\/bsd-user\"> my github repo<\/a> and clone away.<\/p>\n<p>If you are looking to see what needs to be done, Stacey Son has kept an excellent log of open item on the <a title=\"Playing nice with others.  git(1) and patches on #FreeBSD\" href=\"https:\/\/wiki.freebsd.org\/QemuUserModeToDo\">FreeBSD Wiki<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My last post spawned enough feedback that I thought I would dump some notes here for those interested in building a chroot on FreeBSD that allows you to test and prototype architectures, e.g. ARMv6 on AMD64. The FreeBSD buildsys has many targets used for many things, the two we care about here are buildworld and [&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":[3,2],"tags":[],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts\/218"}],"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=218"}],"version-history":[{"count":2,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":220,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=\/wp\/v2\/posts\/218\/revisions\/220"}],"wp:attachment":[{"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ignoranthack.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}