{"id":2510,"date":"2021-05-03T18:39:10","date_gmt":"2021-05-04T02:39:10","guid":{"rendered":"http:\/\/wonghoi.humgar.com\/blog\/?p=2510"},"modified":"2022-03-17T22:30:42","modified_gmt":"2022-03-18T06:30:42","slug":"qemu-for-windows-host-quirks","status":"publish","type":"post","link":"https:\/\/wonghoi.humgar.com\/blog\/2021\/05\/03\/qemu-for-windows-host-quirks\/","title":{"rendered":"Qemu for Windows Host Quirks"},"content":{"rendered":"\n<p>I&#8217;m trying to cross compile my router&#8217;s firmware as I made a few edits override the update DDNS update frequency. Turns out it doesn&#8217;t work on the latest Linux so I&#8217;d need to run an older Ubuntu just to keep it happy. <\/p>\n\n\n\n<p><span class=\"has-inline-color has-dark-gray-color\">RANT: Package servers keep pulling the rug on outdated linux frustrates the hell out of me. Very often developers didn&#8217;t make a whole installer for it so we are often wedged between downloading a package at the mercy of its availability from package managers and their servers or compiling the damn source code! <\/span><\/p>\n\n\n\n<p>With the promise that Qemu might have less overhead than Hyper-V or VirtualBox (indeed it observably is), I tried installing Qemu on Windows host and it turned out to be a frustrating nightmare. <\/p>\n\n\n\n<p><span class=\"has-inline-color has-dark-gray-color\">RANT: Linux is not free in the sense of free beer. The geniuses did the most sophisticated work for free but users pay time and energy cleaning after them (aka a support network dealing with daily frustrations) to make these inventions usable. There&#8217;s a company that does the clean up to make BSD (same umbrella as Linux\/Unix) usable and made a lot of money: it&#8217;s called Apple Computers (since Steve Jobs&#8217; return). <\/span><\/p>\n\n\n\n<p>qemu is just the core components. System integration (simplifying common use cases) is practically non-existent. Think of them as the one who produced an ASIC (chip) and the end-user happens to be the application engineers. There&#8217;s a few tutorials on qemu Linux hosts for moderately complex scenarios, but you are pretty much on your own trying to piece it altogether for Windows because there are some conceptual and terminology differences. The man page <code>--help<\/code> for the qemu&#8217;s Windows host&#8217;s VM engine was blindly copied from the Linux hosts counterpart, so it tells you about <code>qemu-bridge-helper<\/code> which is missing.<\/p>\n\n\n\n<p>I stupidly went down the rabbit hole and drained my time on qemu. So I documented the quirks to help the next poor sap who has to get <em>qemu running on Windows 10 host efficiently over Bridged-Adapter (VirtualBox lingo) networking mode<\/em>. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Preparation work to get HAXM accelerator set up<ul><li>Release VT-d (hardware assisted virtualizations) so HAXM can acquire it<ul><li>You&#8217;ll need to remove Hyper-V completely as it will hoard VT-d&#8217;s control<ul><li><em>Windows Sandbox<\/em> and <em>Windows Subsystem for Linux (WSL2) <\/em>uses Hyper-V. If you just unchecked Hyper-V in Windows Optional Features leaving any of these 2 on, Hyper-V is still active (it only removes the icons)<\/li><\/ul><\/li><\/ul><\/li><li>HAXM v7.6.6 not recognized by qemu on clean install. Install v7.6.5 first, then remove it and install v7.6.6. Likely they forgot a step in v7.6.6&#8217;s installer<\/li><li>Turn on optimization by: <code>-accel hax<\/code><\/li><\/ul><\/li><li>Command line qemu engine<ul><li><code>qemu-system-{architecture name}.exe<\/code> is what runs the show<\/li><li><code>qemu-system-{architecture name}<span style=\"text-decoration: underline;\">w<\/span>.exe<\/code> is the silent version of the above engine. Won&#8217;t give you a clue if something fails (like invalid parameters)<\/li><li><code>qemu-img create -f<\/code> {format such as vhd\/qcow2} {hard drive image name} {size like 10G}<\/li><\/ul><\/li><li>QtEmu sucks, and they lack any better GUIs out there!<ul><li>It&#8217;s basically a rudimentary command line&#8217;s GUI wrapper<\/li><li>It only has <em>user<\/em> mode (SLIRP) networking (default)<\/li><li>It&#8217;s not maintained actively so it doesn&#8217;t keep up with the parameter syntax changes (i.e. can generate invalid combinations)<\/li><li>Since it uses the silent (with a <span style=\"text-decoration: underline;\"><code>w<\/code><\/span> suffix) engine, likely to avoid a lingering command window, it also won&#8217;t tell you shit and why if something fails. It just ignores you when you press the start button unless all the stars align (you got everything right)<\/li><\/ul><\/li><li>Basic command line parameters<ul><li>Set aside 10G for the VM: <code>-m 10G<\/code><\/li><li>1 core if unspecified. Number of available threads (in hyper-threaded system) show up as # of processors. It&#8217;s referring to logical processors, not physical cores.<ul><li>Windows: <code>-smp %NUMBER_OF_PROCESSORS%<\/code><\/li><li>Linux: <code>-smp $(nproc)<\/code><\/li><\/ul><\/li><li>Attach virtual hard drive: <code>-hda<\/code> {virtual hard drive file name}<\/li><li>Attach optical drive (iso): <code>-cdrom<\/code> {iso file}<\/li><\/ul><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>I typically want <em>Bridged-Adapter<\/em> option from VirtualBox, which means the virtual NIC plugs into the same router as the host and just appears as another computer on the same network as host. This is broken into a few components in qemu and you have to manage them separately. Great for learning about how <em>Bridged-Adapter<\/em> really works, but a lot of swearwords coming from people who just want to get basic things done.<\/p>\n\n\n\n<p>Networking in QEMU is another can of worms if you deviate from the default SLIRP (user mode). I figured out how to work it, but the network bridge is faulty and it keeps crashing my windows with BSOD on bridge.sys with varying error tag. I have short glimpse of it working if I move very fast. Looks like the TAP driver is corrupting the memory as the bridge became very erratic that I see error messages deleting it and have persistent BSOD when the bridge starts after the VM hanged at the TAP bridge on boot. <\/p>\n\n\n\n<p>I listed the steps below to show what should have been done to get the Bridge-Adapter (VirtualBox) equivalent function if there are no bugs in the software, but hell I&#8217;m throwing qemu for Windows to trash as it&#8217;s half-baked. <\/p>\n\n\n\n<p>First, of all, you need to install OpenVPN to steal its TAP-Win32 virtual network card. It&#8217;s not VMware or Virtualbox that it&#8217;s part of the package. Qemu didn&#8217;t care to tightly integrate or test this driver properly.<\/p>\n\n\n\n<p>Then you&#8217;ll need to bridge the &#8220;TAP-Windows Adapter (V#) for OpenVPN&#8221; with the network interface you want it to piggy back on.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"864\" height=\"520\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/image.png\" alt=\"\" class=\"wp-image-2523\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/image.png 864w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/image-300x181.png 300w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/image-768x462.png 768w\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" \/><\/figure>\n\n\n\n<p>The name of the TAP adapter is what you enter as <code>ifname=<\/code> parameter of the tap interface in qemu command line. You have to tell qemu specifically which interface you want to engage in. I named the virtual network card as &#8216;TAP&#8217; above. After bridging it looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"378\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Bridge_TAP_Example-1.png\" alt=\"\" class=\"wp-image-2522\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Bridge_TAP_Example-1.png 836w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Bridge_TAP_Example-1-300x136.png 300w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Bridge_TAP_Example-1-768x347.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/figure>\n\n\n\n<p>You are not done yet! The bridged network (seen as one logical interface) is confused and it won&#8217;t be able to configure with your physical network card&#8217;s DHCP client. You&#8217;ll have to go to the properties of the Network Bridge and configure the IPv4 with static IP. <\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"731\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Network-Bridge-Properties.png\" alt=\"\" data-id=\"2526\" data-full-url=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Network-Bridge-Properties.png\" data-link=\"https:\/\/wonghoi.humgar.com\/blog\/?attachment_id=2526\" class=\"wp-image-2526\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Network-Bridge-Properties.png 520w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Network-Bridge-Properties-213x300.png 213w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"582\" height=\"647\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Internet-Protocol-Version-4-TCP_IPv4-Properties.png\" alt=\"\" data-id=\"2525\" data-full-url=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Internet-Protocol-Version-4-TCP_IPv4-Properties.png\" data-link=\"https:\/\/wonghoi.humgar.com\/blog\/?attachment_id=2525\" class=\"wp-image-2525\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Internet-Protocol-Version-4-TCP_IPv4-Properties.png 582w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/05\/Internet-Protocol-Version-4-TCP_IPv4-Properties-270x300.png 270w\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>You can use <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">ipconfig \/all<\/code> to find out the relevant adapters acquired DHCP settings and enter it as static IP. Coordinate with the network administrator (can be yourself) to make sure you own that IP address so you won&#8217;t run into IP conflict if you reboot and somebody took your IP.<\/p>\n\n\n\n<p>After these are all set up the parameter to add to qemu call is:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-nic tap,ifname=TAP<\/pre>\n\n\n\n<p>There are complicated settings like <code>-net nic<\/code> and <code>-netdev -device<\/code>.  These are old ways to do it and have bloated abstractions. <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">-nic<\/code> switch combined them into one switch.<\/p>\n\n\n\n<p>Then welcome to the world of Windows 10 <code>bridge.sys<\/code> crashing frequently and you might get a short window of opportunity that it boots and <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">ifconfig<\/code> acquire the IP address settings from your router (or network the physical adapter is on)&#8217;s DHCP server. <\/p>\n\n\n\n<p>It&#8217;s like a damn research project finding out something is technically feasible but definitely not ready for production. Welcome to the FOSS jungle!<\/p>\n\n\n\n<p>Postscript: I put Hyper-V back and realized it&#8217;s insanely slow with Linux Mint as it does not support hardware graphics acceleration. It&#8217;s night and day of a difference. Qemu is fast, but it crashes on Windows 10 if I bridge the adapters!<\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_2510\" class=\"pvc_stats all  \" data-element-id=\"2510\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to cross compile my router&#8217;s firmware as I made a few edits override the update DDNS update frequency. Turns out it doesn&#8217;t work on the latest Linux so I&#8217;d need to run an older Ubuntu just to keep &hellip; <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2021\/05\/03\/qemu-for-windows-host-quirks\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_2510\" class=\"pvc_stats all  \" data-element-id=\"2510\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[39,4],"tags":[],"class_list":["post-2510","post","type-post","status-publish","format-standard","hentry","category-linux","category-windows"],"_links":{"self":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/2510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/comments?post=2510"}],"version-history":[{"count":27,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/2510\/revisions"}],"predecessor-version":[{"id":3805,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/2510\/revisions\/3805"}],"wp:attachment":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/media?parent=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}