{"id":22002,"date":"2024-03-29T15:22:57","date_gmt":"2024-03-29T12:22:57","guid":{"rendered":"https:\/\/kifarunix.com\/?p=22002"},"modified":"2024-03-29T15:23:01","modified_gmt":"2024-03-29T12:23:01","slug":"how-to-install-kvm-on-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-install-kvm-on-ubuntu-24-04\/","title":{"rendered":"How to Install KVM on Ubuntu 24.04"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to install KVM on Ubuntu 24.04. KVM (<a href=\"https:\/\/www.linux-kvm.org\/page\/Main_Page\" target=\"_blank\" rel=\"noreferrer noopener\">Kernel-based Virtual Machine<\/a>) is an opensource, virtualization tool for Linux systems with Intel-VT\u00a0or\u00a0AMD-V based-processors hardware virtualization extensions.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-kvm-on-ubuntu-24-04\">Installing KVM on Ubuntu 24.04<\/a><ul><li><a href=\"#check-virtualization-support\">Check Virtualization Support<\/a><\/li><li><a href=\"#installing-kvm-on-ubuntu-24-04-1\">Installing KVM on Ubuntu 24.04<\/a><\/li><li><a href=\"#start-libvirt-daemon-libvirtd\">Start libvirt Daemon (libvirtd)<\/a><\/li><li><a href=\"#add-user-to-libvirt-group\">Add User to Libvirt Group<\/a><\/li><li><a href=\"#launch-kvm-virtual-machine-manager\">Launch KVM Virtual Machine Manager<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-kvm-on-ubuntu-24-04\">Installing KVM on Ubuntu 24.04<\/h2>\n\n\n\n<p>To be able to run and use KVM on your Ubuntu 24.04, there are few items that the system must meet.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-virtualization-support\">Check Virtualization Support<\/h3>\n\n\n\n<p>KVM runs on systems equipped with Intel or AMD processors. You need to verify if this support is already enabled on your system by executing the command below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep --color -iE 'vmx|svm' \/proc\/cpuinfo<\/code><\/pre>\n\n\n\n<p> The command looks for the CPU flags;&nbsp;<strong>Intel vmx (Virtual Machine Extension)<\/strong>&nbsp;or&nbsp;<strong>AMD svm (Secure virtual Machine)<\/strong>.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch pti tpr_shadow flexpriority ept vpid fsgsbase bmi1 avx2 bmi2 invpcid rdseed clflushopt vnmi md_clear flush_l1d arch_capabilities\n<strong>vmx flags<\/strong>\t: vnmi invvpid ept_x_only flexpriority tsc_offset vtpr vapic ept vpid unrestricted_guest ple\nflags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch pti tpr_shadow flexpriority ept vpid fsgsbase bmi1 avx2 bmi2 invpcid rdseed clflushopt vnmi md_clear flush_l1d arch_capabilities\n<strong>vmx flags<\/strong>\t: vnmi invvpid ept_x_only flexpriority tsc_offset vtpr vapic ept vpid unrestricted_guest ple\n<\/code><\/pre>\n\n\n\n<p>From the output above, you can see that my system is using Intel processor.<\/p>\n\n\n\n<p>If the command output is empty, find out how to enable virtualization on your respective machine BIOS.<\/p>\n\n\n\n<p>Similarly, you can use the command below to check Virtualization support.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lscpu | grep Virtualization<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Virtualization:                  VT-x\nVirtualization type:             full\n<\/code><\/pre>\n\n\n\n<p>You can also use the cpu-checker, <strong>kvm-ok<\/strong>, command to check if the system has virtualization support enabled.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install cpu-checker<\/code><\/pre>\n\n\n\n<p>The above provides the <strong>kvm-ok<\/strong> command, which you can use to check the virtualization support by running;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kvm-ok<\/code><\/pre>\n\n\n\n<p>Such an output confirms that the virtualization support is on.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>INFO: \/dev\/kvm exists\nKVM acceleration can be used\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-kvm-on-ubuntu-24-04-1\">Installing KVM on Ubuntu 24.04<\/h3>\n\n\n\n<p>If your system meets the above requirements, you can then proceed to install KVM by executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install virt-manager qemu-system libvirt-daemon-system qemu-utils<\/code><\/pre>\n\n\n\n<p>The packages installed above are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>virt-manager<\/strong><\/code>: Virt-Manager is a graphical user interface (GUI) tool for managing virtual machines through libvirt-daemon.<\/li>\n\n\n\n<li><strong><code>qemu-system<\/code><\/strong>&nbsp;is an open source virtualizer that provides hardware emulation for the KVM hypervisor. It acts as a virtual machine monitor together with the KVM kernel modules, and emulates the hardware for a full system such as a PC and its associated peripherals.<\/li>\n\n\n\n<li><strong><code>libvirt-daemon-system<\/code><\/strong>&nbsp;provides API libraries that enables GUI apps such as virt-manager to communicate with libvirtd daemon, a system service&nbsp;<strong><code>libvirtd<\/code><\/strong>&nbsp;, and a&nbsp;<strong><code>virsh<\/code><\/strong>&nbsp;CLI tool.<\/li>\n<\/ul>\n\n\n\n<p>If you are running an headless server with no GUI, then it suffices to just run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install qemu-system libvirt-daemon-system virtinst qemu-utils<\/code><\/pre>\n\n\n\n<p>Once the installation is done, check if KVM modules are loaded;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lsmod | grep -i kvm<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>kvm_intel             487424  0\nkvm                  1437696  1 kvm_intel\nirqbypass              12288  1 kvm\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"start-libvirt-daemon-libvirtd\">Start libvirt Daemon (libvirtd)<\/h3>\n\n\n\n<p>According to man pages,&nbsp;<em>the libvirtd program is the server side daemon component of the libvirt virtualization management system. This daemon runs on host servers and performs required management tasks for virtualized guests. This includes activities such as starting, stopping and migrating guests between host servers, configuring and manipulating networking, and managing storage for use by guests. The libvirt client libraries and utilities connect to this daemon to issue tasks and collect information about the configuration and resources of the host system and guests<\/em>.<\/p>\n\n\n\n<p>Thus, start and enable this service to run on system boot;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now libvirtd<\/code><\/pre>\n\n\n\n<p>Check the status;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status libvirtd<\/code><\/pre>\n\n\n\n<p><em>By default, the libvirtd daemon listens for requests on a local Unix domain socket. Using the\u00a0<strong><code>-l | --listen<\/code><\/strong>\u00a0command line option, the libvirtd daemon can be instructed to additionally listen on a TCP\/IP socket. The TCP\/IP socket to use is defined in the libvirtd configuration file<\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"add-user-to-libvirt-group\">Add User to Libvirt Group<\/h3>\n\n\n\n<p>If you are launching virt-manager as standard user, you may be prompted to enter your administrator password to run it,\u00a0<strong>\u201csystem policy prevents management of local virtualized systems\u201d<\/strong>.<\/p>\n\n\n\n<p>To fix this, add the standard user to&nbsp;<strong><code>libvirt<\/code><\/strong>&nbsp;and&nbsp;<strong><code>kvm<\/code><\/strong>&nbsp;group (<em>Replace USERNAME with your user account<\/em>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG libvirt,kvm <strong>USERNAME<\/strong><\/code><\/pre>\n\n\n\n<p>Next, log the user out completely, if they were logged in when you executed the command above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"launch-kvm-virtual-machine-manager\">Launch KVM Virtual Machine Manager<\/h3>\n\n\n\n<p>If you are running a desktop system, then you can launch the Virtual Machine manager from your applications or command line;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1279\" height=\"802\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/03\/launching-kvm-manager-kde-ubuntu-24.04.png\" alt=\"\" class=\"wp-image-22004\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/03\/launching-kvm-manager-kde-ubuntu-24.04.png?v=1711714423 1279w, https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/03\/launching-kvm-manager-kde-ubuntu-24.04-768x482.png?v=1711714423 768w\" sizes=\"(max-width: 1279px) 100vw, 1279px\" \/><\/figure>\n\n\n\n<p>To launch it from command line;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>virt-manager<\/code><\/pre>\n\n\n\n<p>You can now start creating virtual machines and run them over KVM!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1276\" height=\"798\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/03\/kvm-virtual-manager.png?v=1711714441\" alt=\"\" class=\"wp-image-22005\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/03\/kvm-virtual-manager.png?v=1711714441 1276w, https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/03\/kvm-virtual-manager-768x480.png?v=1711714441 768w\" sizes=\"(max-width: 1276px) 100vw, 1276px\" \/><\/figure>\n\n\n\n<p>If QEMU\/KVM is not connected, log out the user from the SSH session as well as from the desktop and re-login and relaunch the virtual manager.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to install KVM on Ubuntu 24.04. KVM (Kernel-based Virtual Machine) is an opensource, virtualization tool for Linux systems<\/p>\n","protected":false},"author":10,"featured_media":22008,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[36,121,112],"tags":[7429,113],"class_list":["post-22002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-virtualization","category-howtos","category-kvm","tag-install-kvm-ubuntu-24-04","tag-kvm","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/22002"}],"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\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=22002"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/22002\/revisions"}],"predecessor-version":[{"id":22009,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/22002\/revisions\/22009"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/22008"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=22002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=22002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=22002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}