top of page
Search

KVM Virtualization Installation: Linux

Updated: Aug 26, 2024

KVM (Kernel-based Virtual Machine) is an open-source virtualization technology integrated into the Linux kernel. It allows a host machine to run multiple, isolated virtual environments called virtual machines (VMs). Here are the key aspects of KVM.


Setting Up KVM


Step 1: Check CPU virtualization:


To check if your CPU supports hardware virtualization, you can use the egrep command to search for the appropriate CPU flags in the /proc/cpuinfo file.

egrep -c '(vmx|svm)' /proc/cpuinfo

If your CPU supports hardware virtualization, you will see vmx or svm listed in the output. For example:

vmx is the flag for Intel processors. svm is the flag for AMD processors.

vmx
VMX
VMX 

or

SVM
SVM
SVM
  • Verify KVM support:

sudo kvm-ok

Step 2: Install KVM Packages


  • Install KVM, QEMU, libvirt, and virt-manager. These tools will help you create and manage virtual machines:

sudo apt-get update
sudo apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

Step 3: Add Your User to the libvirt Group


  • To use KVM without root privileges, add your user to the libvirt group.

sudo usermod -aG libvirt $(whoami)
newgrp libvirt

Step 4: Start and Enable the libvirt Service


  • Ensure that the libvirt service is running and enabled to start at boot

sudo systemctl start libvirtd
sudo systemctl enable libvirtd

Step 5: Verify Installation


  • Verify that KVM modules are loaded and the installation is correct.

lsmod | grep kvm

Step 6: Create a Virtual Machine


  • You can create a virtual machine using virt-manager (GUI) or virt-install (CLI).

Using virt-manager (GUI):

Using virt-manager (GUI)
  • Click on the Create a new virtual machine button and follow the wizard to set up your new VM.


Using virt-install (CLI):

virt-install \
--name myvm \
  --ram 2048 \
  --disk path=/var/lib/libvirt/images/myvm.img,size=20 \
  --vcpus 2 \
  --os-type linux \
  --os-variant ubuntu20.04 \
  --network bridge=virbr0 \
  --graphics vnc \
  --cdrom /path/to/ubuntu-20.04.iso
  • --name: The name of the VM.

  • --ram: Amount of RAM.

  • --disk: Disk path and size.

  • --vcpus: Number of CPU cores.

  • --os-type and --os-variant: The type and variant of the OS.

  • --network: Network configuration.

  • --graphics: Graphics type (VNC in this case).

  • --cdrom: Path to the installation ISO file.


Step 7: Managing Virtual Machines


  • You can manage your VMs using virsh (CLI) or virt-manager (GUI).\


Using virsh (CLI):


  • Start a VM:

virsh start myvm
  • Stop a VM:

virsh shutdown myvm
  • List all VMs:

virsh list --all

Using virt-manager (GUI):


  • Open virt-manager and you can start, stop, and manage VMs through the graphical interface.

By following these steps, you can set up and manage KVM virtualization on your Linux system. KVM provides a powerful and flexible way to run multiple virtual machines on a single physical machine, leveraging the capabilities of your hardware.


Done


 
 
 

Comments


bottom of page