{"id":4288,"date":"2015-04-06T10:16:17","date_gmt":"2015-04-06T17:16:17","guid":{"rendered":"http:\/\/www.graphics-muse.org\/wp\/?p=4288"},"modified":"2015-04-06T10:16:17","modified_gmt":"2015-04-06T17:16:17","slug":"networking-with-qemu-and-kvm-speedup","status":"publish","type":"post","link":"https:\/\/www.graphics-muse.org\/wp\/?p=4288","title":{"rendered":"Networking with QEMU and KVM speedup"},"content":{"rendered":"<h3>Networking in QEMU<\/h3>\n<p>I&#8217;ve recently had a need to test UEFI booting for a disk image.\u00a0 I stumbled upon <a href=\"http:\/\/www.tianocore.org\/ovmf\/\">OVMF<\/a>, a bios that will handle UEFI booting.\u00a0 It works pretty well but doesn&#8217;t remember its config sometimes.\u00a0 But that&#8217;s not why I&#8217;m writing this.<\/p>\n<p>In my disk image I need dual network interfaces that are on specific networks.\u00a0 I don&#8217;t need <em>tap<\/em> interfaces.\u00a0 I can live with the slower <em>user-mode<\/em> interfaces.\u00a0 But I needed to put them on separate networks.\u00a0 So I did this.<\/p>\n<blockquote>\n<pre>-netdev user,id=user0,dhcpstart=192.168.20.20,hostfwd=tcp::5555-:22 -device e1000,netdev=user0<\/pre>\n<pre>-netdev user,id=user1,dhcpstart=192.168.50.50,hostfwd=tcp::5556-:22 -device e1000,netdev=user1<\/pre>\n<\/blockquote>\n<p>I googled till I was blue to figure out how to do this.\u00a0 You can set the <strong>dhcpstart<\/strong> address but<em> qemu_system_x86-64<\/em> spews the following message:<\/p>\n<pre style=\"padding-left: 30px;\">device 'user' could not be initialized<\/pre>\n<p>It doesn&#8217;t say why, but after fiddling with it for a long time it became obvious that this was a configuration error.\u00a0 There just doesn&#8217;t seem to be any explanation as to what configuration is wrong.<\/p>\n<p>Finally I found <a href=\"https:\/\/www.centos.org\/forums\/viewtopic.php?f=16&amp;t=44259#p188536\">a site with an example<\/a>.\u00a0 The key appears to be that you have to <strong>include the host&#8217;s network address<\/strong> on the network that interface will be in.\u00a0 Without this specification there is no mapping of the guest interface to a host interface.\u00a0 Here is what the correct configuration should look like.<\/p>\n<blockquote>\n<pre>-netdev user,id=user0,net=192.168.20.0\/24,dhcpstart=192.168.20.20,hostfwd=tcp::5555-:22 -device e1000,netdev=user0<\/pre>\n<pre>-netdev user,id=user1,net=192.168.50.0\/24,dhcpstart=192.168.50.50,hostfwd=tcp::5556-:22 -device e1000,netdev=user1<\/pre>\n<\/blockquote>\n<p>Now both interfaces will come up on the assigned networks.\u00a0 The <em>hostfwd<\/em> option is used to map host ports to guest ports, with the larger number (the first one) mapping to the guest&#8217;s port.\u00a0 Here I&#8217;m mapping ports to the ssh port on the guest.\u00a0 Since I&#8217;m using user-mode networking this is required otherwise the default firewall in the guest prevents me from accessing it from the host.<\/p>\n<h3>KVM Speedup<\/h3>\n<p>Another thing I discovered when running qemu_system_x86_64 is that it was slow on my Fedora 21 box.\u00a0 The reason is simple:\u00a0 you can&#8217;t run this command manually with KVM speedups (which are significant) if you&#8217;re already running <em>libvirtd<\/em>.\u00a0 You can go through the hoops of tying the two together, but for a quick solution to run a qemu session with full virtualization to get much better performance without dealing with libvirtd just shutoff libvirtd.<\/p>\n<pre style=\"padding-left: 30px;\">sudo service libvirtd stop<\/pre>\n<p>That&#8217;s using archaic <em>service<\/em> format instead of the ugly <em>sysctl<\/em> interface (that you very little, systemd) but it works.\u00a0 Again, this is for Fedora.\u00a0 Your distro mileage will vary.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Networking in QEMU I&#8217;ve recently had a need to test UEFI booting for a disk image.\u00a0 I stumbled upon OVMF, a bios that will handle UEFI booting.\u00a0 It works pretty well but doesn&#8217;t remember its config sometimes.\u00a0 But that&#8217;s not why I&#8217;m writing this. In my disk image I need dual network interfaces that are [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[35,8,5,295],"tags":[595,634,598,528,298,239,139,597,596,641],"class_list":{"0":"post-4288","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-fedora","7":"category-hardware","8":"category-linux","9":"category-virtualization","10":"tag-bios","11":"tag-fedora","12":"tag-kernel-based-virtual-machine","13":"tag-kvm","14":"tag-libvirtd","15":"tag-qemu","16":"tag-ssh-port","17":"tag-tuntap","18":"tag-unified-extensible-firmware-interface","19":"tag-virtualization","20":"czr-hentry"},"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pe9t8-17a","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4288"}],"version-history":[{"count":2,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4288\/revisions"}],"predecessor-version":[{"id":4290,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4288\/revisions\/4290"}],"wp:attachment":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}