KVM (Kernel Based Virtual Machine) is a virtualization software. With the help of KVM you can create Virtual Machines. It is also one of the best alternate of VirtualBox. Generally we use KVM for our POC and Test environment.
Summary
We have already written about the installation of KVM with complete details in this article. It has all the manual steps with detail explaination. Since Ubuntu 20.04 LTS to Ubuntu 24.04 LTS the installation method is same. So we have created a bash script for installing KVM on Ubuntu Linux for all these versions.
This bash script will help you to install the KVM and it can be executed in the following Ubuntu version system.
- Ubuntu 24.04 LTS
- Ubuntu 22.04 LTS
- Ubuntu 20.04 LTS
We should prefer to create automation script for almost all the tasks. It will reduce the effort and time. And also you will gain concepts and knowledge of automation. Keep doing such practice, it helps a lot.
Install KVM On Ubuntu 24.04 LTS (Bash Script)
We will install KVM through simple automation way. Means, we will create a bash script which you can use whenever you need.
About install_kvm.sh bash script
- The bash script will check if the Operating System has Virtual Technology is compatible.
- Then install all the packages for KVM
- At the end install virt-manager for managing VM through Graphical User Interface.
Steps to install KVM on Ubuntu 24.04 LTS
- Create a new file called install_kvm.sh . (we prefer vi/vim or gedit)
- Copy the given below content into the file, save and exit.
- Give permission to the file by using the command
chmod +x install_kvm.sh
- Now run the script
./install_kvm.sh
#!/bin/bash
# Author: Sharad Chhetri
# Blog: https://sharadchhetri.com
# Description: Install KVM on Ubuntu
# Resources: Ubuntu 24.04 LTS, Ubuntu 22.04 LTS, Ubuntu 20.04 LTS
#
_cpu_count=$(egrep -c '(vmx|svm)' /proc/cpuinfo)
echo '## Check Virtualisation Technology ##'
if [ "$_cpu_count" -lt 1 ]
then
echo "Checked CPU, Virtualization Technology does not support."
exit 1
else
echo "Checked CPU, Virtualization Technology support in this Operating System"
fi
sudo apt -y update
echo '## Install packages ##'
sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon libvirt-daemon-system qemu qemu-kvm qemu-system
echo '## Add user ##'
sudo adduser `id -un` libvirt
sudo adduser `id -un` kvm
echo '### List VM ###'
virsh list --all
echo '#### Install virt-manager for GUI ###'
sudo apt -y install virt-manager
Virt-Manager GUI
Now open the Virt-Manager from Dash Home. Through virt-manager you create,delete and manage the VM easily in Graphical User Interface.