{"id":6262,"date":"2020-06-28T17:01:35","date_gmt":"2020-06-28T14:01:35","guid":{"rendered":"https:\/\/kifarunix.com\/?p=6262"},"modified":"2024-03-14T21:09:54","modified_gmt":"2024-03-14T18:09:54","slug":"how-to-fix-qemu-kvm-not-connected-error-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-fix-qemu-kvm-not-connected-error-on-ubuntu-20-04\/","title":{"rendered":"How to fix QEMU\/KVM Not Connected Error on Ubuntu 20.04"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to fix QEMU\/KVM Not connected error on Ubuntu 20.04. Maybe you have installed KVM hypervisor on Ubuntu 20.04 for you to run virtual machines on it as a regular, non-root, user. However for some reasons, when your try to run <code>virsh<\/code> command to even the <code>virt-manager<\/code>, display the virtual machine desktop management tool, you end up with such errors as Qemu\/KVM no connected. Let us see how to fix such error.<\/p>\n\n\n\n<p><em>Disclaimer: The tutorial outlines how i fix the issue myself. This is not an official fix for the issue. Use it ayor.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fixing QEMU\/KVM Not Connected Error<\/h2>\n\n\n\n<p>A sample of the errors you encounter when running KVM as a non-root user on Ubuntu 20.04 might include the ones sampled below;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"788\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/kvm-qemu-connection-error.png\" alt=\"\" class=\"wp-image-6263\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/kvm-qemu-connection-error.png?v=1593345563 1004w, https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/kvm-qemu-connection-error-768x603.png?v=1593345563 768w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>virsh -c qemu:\/\/\/system<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>error: failed to connect to the hypervisor\nerror: End of file while reading data: Input\/output error<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>virsh list --all<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>error: failed to connect to the hypervisor\nerror: End of file while reading data: Input\/output error<\/code><\/pre>\n\n\n\n<p>So you have done all that is required to run KVM as a non root user, by adding your standard user name to <code>libvirt<\/code> group, but still you cannot run KVM as a standard user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>id -nG<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>koromicha <strong>kvm<\/strong> netdev nm-openvpn <strong>libvirt<\/strong><\/code><\/pre>\n\n\n\n<p>All the required modules are loaded;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>lsmod | grep kvm<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>kvm_intel             282624  0\nkvm                   663552  1 kvm_intel<\/code><\/pre>\n\n\n\n<p>You have scoured through internet, but no suggested solution has so far fixed the issue with QEMU\/KVM not connected? Perhaps there is something you are not looking for?<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What About AppArmor?<\/h3>\n\n\n\n<p>According to <a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/wiki.ubuntu.com\/AppArmor\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu AppArmor wiki page<\/a>;<\/p>\n\n\n\n<p>AppArmor is a Mandatory Access Control (MAC) system which is a kernel (LSM) enhancement to confine programs to a limited set of resources. Its security model is to bind access control attributes to programs rather than to users.<\/p>\n\n\n\n<p>Its confinement is provided via profiles loaded into the kernel, typically on boot. AppArmor profiles can be in one of two modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>enforcement<\/code><\/strong> &#8211; Profiles loaded in enforcement mode will result in enforcement of the policy defined in the profile as well as reporting policy violation attempts (either via syslog or auditd).<\/li>\n\n\n\n<li><strong><code>complain<\/code><\/strong>&#8211; Profiles in complain mode will not enforce policy but instead report policy violation attempts.<\/li>\n<\/ul>\n\n\n\n<p>Well, so after checking the syslog logs;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo grep libvirt \/var\/log\/syslog | grep -i apparmor | grep -i denied<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Jun 28 14:53:27 koromicha kernel: [  334.660844] audit: type=1400 audit(1593345207.778:951): <strong>apparmor=\"DENIED\" operation=\"bind\" profile=\"libvirtd\" pid=12254 comm=\"libvirtd\" family=\"unix\" sock_type=\"dgram\" protocol=0 requested_mask=\"bind\" denied_mask=\"bind\" addr=\"@userdb-6228daaaf66b14dfd14d93ef46d962c3\"<\/strong>\nJun 28 14:54:19 koromicha kernel: [  386.034970] audit: type=1400 audit(1593345259.145:952): <strong>apparmor=\"DENIED\"<\/strong> operation=\"bind\" <strong>profile=\"libvirtd\"<\/strong> pid=14311 comm=\"libvirtd\" family=\"unix\" sock_type=\"dgram\" protocol=0 requested_mask=\"bind\" <strong>denied_mask=\"bind\"<\/strong> addr=\"@userdb-c861507740da1fa0c3356ad3b78bffe9\"\nJun 28 15:02:30 koromicha kernel: [  877.339057] audit: type=1400 audit(1593345750.437:968): apparmor=\"DENIED\" operation=\"bind\" profile=\"libvirtd\" pid=16175 comm=\"libvirtd\" family=\"unix\" sock_type=\"dgram\" protocol=0 requested_mask=\"bind\" denied_mask=\"bind\" addr=\"@userdb-7d70643a9f8da0342f6359907817b664\"\n...<\/code><\/pre>\n\n\n\n<p>From the kernel ring buffer messages;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dmesg| grep -i libvirt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[   12.737770] systemd[1]: Reached target Libvirt guests shutdown.\n[   36.451935] audit: type=1400 audit(1593344909.127:909): <strong>apparmor=\"DENIED\"<\/strong> operation=\"bind\" profile=\"libvirtd\" pid=1329 <strong>comm=\"libvirtd\"<\/strong> family=\"unix\" sock_type=\"dgram\" protocol=0 <strong>requested_mask=\"bind\" denied_mask=\"bind\" <\/strong>addr=\"@userdb-17950adb1cf7fdce327fb745a8f96166\"\n[   82.906690] audit: type=1400 audit(1593344956.066:911): apparmor=\"DENIED\" operation=\"bind\" profile=\"libvirtd\" pid=3295 comm=\"libvirtd\" family=\"unix\" sock_type=\"dgram\" protocol=0 requested_mask=\"bind\" denied_mask=\"bind\" addr=\"@userdb-5f105e043aa71b33f878838eb17ed07a\"\n...<\/code><\/pre>\n\n\n\n<p>This indicates that AppArmor for some reasons is restraining libvirtd from use use by the regular\/non-root users, irrespective of adding them to the group.<\/p>\n\n\n\n<p>Checking the AppArmor status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo aa-status<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\n6 processes have profiles defined.\n<strong>1 processes are in enforce mode.\n   \/usr\/sbin\/libvirtd (110108) libvirtd<\/strong>\n...<\/code><\/pre>\n\n\n\n<p>Is libvirtd using the AppArmor security driver?<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo virsh capabilities | less<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>..\n    &lt;secmodel&gt;\n      &lt;model&gt;apparmor&lt;\/model&gt;\n      &lt;doi&gt;0&lt;\/doi&gt;\n    &lt;\/secmodel&gt;\n..<\/code><\/pre>\n\n\n\n<p>You can cross examine the AppArmor <code>libvirtd<\/code> profile;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cat \/etc\/apparmor.d\/usr.sbin.libvirtd<\/code><\/pre>\n\n\n\n<p>And other files under, <code>\/etc\/apparmor.d\/libvirt\/<\/code> and <code>\/etc\/apparmor.d\/abstractions\/<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"fixkvmnotconnectederror\"><a href=\"#fixkvmnotconnectederror\">The Solution to the Problem<\/a><\/h3>\n\n\n\n<p>Well, I didn&#8217;t have much time to find a better solution than disabling the AppArmor enforcement for libvirtd;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo ln -s \/etc\/apparmor.d\/usr.sbin.libvirtd \/etc\/apparmor.d\/disable\/<\/code><\/pre>\n\n\n\n<p>Reboot the machine to effect the libvirt disablement changes;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl reboot -i<\/code><\/pre>\n\n\n\n<p>Once the system reboots, you should now be able to run KVM as a non root user;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1914\" height=\"517\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/qemu-kvm-connect.png\" alt=\"\" class=\"wp-image-6267\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/qemu-kvm-connect.png?v=1593351710 1914w, https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/qemu-kvm-connect-768x207.png?v=1593351710 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/06\/qemu-kvm-connect-1536x415.png?v=1593351710 1536w\" sizes=\"(max-width: 1914px) 100vw, 1914px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>virsh list --all<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code> Id   Name   State\n--------------------<\/code><\/pre>\n\n\n\n<p>And this is it on fixing QEMU\/KVM Not connected error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Further Reading<\/h3>\n\n\n\n<p><a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/gitlab.com\/apparmor\/apparmor\/-\/wikis\/Libvirt\" target=\"_blank\" rel=\"noreferrer noopener\">AppArmor: Libvirtd Wiki<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/wiki.ubuntu.com\/AppArmor\" target=\"_blank\" rel=\"noopener\">AppArmor Ubuntu Wiki<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-rename-kvm-virtual-machine-with-virsh-command\/\">How to Rename KVM Virtual Machine with virsh command<\/a><\/p>\n\n\n\n<p><a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-pfsense-firewall-on-kvm\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install pfSense Firewall on KVM<\/a><\/p>\n\n\n\n<p><a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/use-virtualbox-vms-on-kvm\/\" target=\"_blank\" rel=\"noreferrer noopener\">Use VirtualBox VMs on KVM<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to fix QEMU\/KVM Not connected error on Ubuntu 20.04. Maybe you have installed KVM hypervisor on Ubuntu 20.04<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,112,36],"tags":[1738,113,1739,1741,1744,1200],"class_list":["post-6262","post","type-post","status-publish","format-standard","hentry","category-howtos","category-kvm","category-virtualization","tag-fix-qemu-kvm-not-connected-error","tag-kvm","tag-kvm-libvirt-and-apparmor","tag-kvm-on-ubuntu-20-04","tag-libvirterror-virconnectopenauth-failed","tag-ubuntu-20-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/6262"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=6262"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/6262\/revisions"}],"predecessor-version":[{"id":21411,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/6262\/revisions\/21411"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=6262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=6262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=6262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}