Hello there and welcome to yet another video
In this video, we are going to demonstrate how to install KVM on Ubuntu 24.04
And towards the tail end of this video, we'll also demonstrate how you can create a virtual
machine once the installation of KVM is complete. Now KVM is an acronym for Kernel-Based Virtual Machine and this is an open source virtualization
technology that is integrated into the Linux kernel. KVM allows users to create and run multiple guest machines which can either be Windows
or Linux. Now to get started, ensure you have the following prerequisites
So first ensure you have Ubuntu 24.04 already installed. So we have our instance here
And just to confirm, I'm going to run the command cart xe osrelease
So you can see we are running Ubuntu 24.04. So the other thing you need is that you need at least two vCPUs, 4GB of RAM and a stable
internet connectivity. Now with the prerequisites out of the way. Now let's get started with the installation
So first ensure that your local package index is updated and to do so run the command sudo
apt update and hit enter. So this will refresh the local cache and as you can see we are done
Alright now the next step is to ensure that virtualization is enabled
So you can check for if virtualization is enabled using the following command
So you can run the command egrep with hyphen C flag like that. Okay
Then here you can search for either vmx that's for this is for Intel processors. Okay
Or you can search for svm for AMD processors. Alright. So I'm going to close the parentheses. Alright
Then I'm going to search in the proc CPU info file. Okay
So I'm going to hit enter. So here we get the output 8
So if you get an output that is greater than zero know that virtualization is enabled
So here we have 8 and we have confirmed that virtualization is enabled
So the other way of confirming if virtualization is enabled is by running the command KVM hyphen OK
So if this is a fresh system you're going to see this error and you're going to be informed
that you need to install CPU the CPU checker package. Alright. So that is what you're going to do exactly
So run the command sudo apt install CPU checker. Like that. Alright
So here there is a hyphen. So CPU hyphen checker. Then hit enter
So this is going to install all the tools required to run the KVM OK command
Alright so we are done. Let me clear the screen. Okay. So as we've mentioned you can also check if virtualization is enabled by running the command
KVM hyphen. Okay like that. So as you can see the output informs us that KVM acceleration can be used. Alright
So we have confirmed that our system is good and for virtualization and we can go ahead
and install KVM. Alright. Now I'm going to clear the screen again
Now in the third step we are going to install KVM using the following command
So do apt install. So here the first package is Kemu. KVM. Alright
Then virtmanager. Don't worry I'm going to explain what these are. Alright
Then libvirt. Demon system
Then virtinst. Then libvirt hyphen clients. Alright
Then bridgeutils. Hyphen utils. Alright. Okay
So these are the packages that are needed by KVM. Alright. So at this point I'm going to hit enter
So I'm going to hit enter. So here I'll be prompted to proceed with the installation
So I'm just going to type Y and hit enter. So this might take some time
So just give it a minute or so for the installation to proceed. Alright
So at this moment I'm going to pause the video and I'll be back when the installation is complete
And there we go. So we have managed to install all the packages required for KVM to function
Let me clear the screen. Okay. Alright. So let's review the command once more
So this is the command we ran earlier on. Alright. So let's review what these packages are and what they do
So the first package here is KVM. So this is an open source emulator and virtualization package that provides the hardware emulation. Alright
Next we have the virtmanager here. So virtmanager is a graphical interface that helps you to manage virtual machines using
the libvirtdaemon. And this one here, the libvirtdaemon package. So this is a package that provides the configuration files that are required to run the libvirtdaemon
So next here we have the virtinst. So this is a set of command line utilities for provisioning and modifying virtual machine. Alright
Then we have the libvirtclients. So this is a set of server side, sorry, it's a set of client side libraries and APIs that
are used for managing and controlling virtual machines and hypervisors from the command line. Okay
Then finally we have bridgeutils. So bridgeutils is a set of tools that allows you to create and manage bridge devices. Alright
So I'm just going to press Ctrl C to cancel out since we have already installed the packages. Alright
So now I'm going to start and enable the virtualization daemon. Alright
So run the command sudo systemctl enable the double hyphen. Now libvirtd
Okay so libvirtd is the virtualization daemon as I've just explained. Okay so I'm going to hit enter. Okay
Now to start it run the command sudo systemctl start libvirtd and hit enter
Okay now we are going to check whether the libvirtd daemon is running and to do so I'm
simply going to say sudo systemctl. So this time around I'll check the status like that and I'm going to hit enter
So on your screen we can see that the KVM daemon is active and running. Alright
So this is good news and it means that we can now proceed with installing the KVM
Alright or rather we can now go ahead and start creating virtual machines
Alright now one other thing we need to do is to add the currently logged in user to
the KVM and libvirtd groups so that you can create and manage virtual machines without
any problem. Okay so now what we're going to do we're going to add the currently logged in user which
is Linux Techie to the KVM group and to do so simply use the user mode command like this
So sudo user mode hyphen a with a capital G. Alright so here we are adding the currently logged in user to the KVM group
So this is the command for adding the currently logged in user which is defined with a dollar
sign user variable to the KVM group. So just hit enter. Alright then still on the same we are going to add the currently logged in user to the
libvirtd group. Okay so run sudo user mode hyphen a G. Then we are adding the user to the libvirtd like that
And hit enter. And you can confirm this by running the command groups then the user
In my case this is Linux Techie. So you can see the user belongs to several groups and among them is KVM and libvirtd
Okay alright so now let me clear the screen. Now if you're planning to access the KVM virtual machines outside your Ubuntu 24.04 system
then you need to map the VM's interface to a network bridge
So in this section we are going to see how to create a bridge interface and this will
allow you to communicate or will allow you will allow the access of the virtual machine
externally to other systems. Alright so now to do so you need to create a yaml configuration file which are going
to see shortly. So now I'm going to create the yaml file so I'm going to use the nano text editor and
I'll create this in the net plan directory as you can see
So I'm going to call the yaml file let's say 01 netconfig.yaml like that
Okay so I'm going to hit enter. So this is how the yaml file looks like
So I'm going to copy these lines of code and I'm going to include this in the description
So I'm going to copy all of this. I'm going to copy this and I'm going to paste it here
So as you can see we are using network manager as our renderer
So ens33 that's my active network interface. So we have disabled DHCP for IPv4 and IPv6
So we are creating a bridge called br0 okay and we have specified the interface as ens33
so we are using our active network interface as the bridge interface alright
So this is the IP address and CIDR for the bridge interface
So here we have specified 192.168.2.130. So make sure that this corresponds to your network addressing scheme
So in my network this is my network addressing scheme okay and this is the default gateway 192.168.2.12
So this is the IP address of my router okay and here below we have the name servers
So I've specified Google's DNS as my preferred name server alright. So basically this is how the configuration for the bridge network looks like alright
So now I'm going to save this. So I'm going to press ctrl-o and I'll be prompted to write the changes
So I'm going to hit enter and to exit I'm going to press ctrl-x alright
So I have successfully defined the bridge network configuration okay. So now to apply the changes I'm going to run the command sudo netplan apply like that alright
So hit enter alright. So you might see such a notification that permissions for the YAML file are to open alright
So now what you need to do you are going to clear the screen
So we are going to head back to the netplan directory and I'm going to run cd forward
slash etsy netplan alright. So these are the configuration files
So I'm going to use the chmod command like that chmod. Then I'm going to assign the permission of 600 alright
So what this means is that only the owner of the file can read and write alright and
the group and other users do not have any permissions. So I'm going to grant these permissions to the YAML files like that okay
Then I'm going to hit enter. So there's a dot here so I'm going to grant this permission to all the YAML files alright
Then I'm going to repeat the command so I'm going to run sudo netplan apply then I'm going
to hit enter alright. So as you can see our changes have applied alright
Now I'm going to go back to the home directory and clear the screen
So one thing you'll notice is that the active network interface icon here will disappear
and the reason for this is because now our bridge interface has taken effect alright
So now let's check our IP configuration so I'm going to run the command IP address and
hit enter. So here you can see our active interface is ens33 so at this time it has no active IP
address and instead we have the bridge network here br0 which has been assigned the IP address 192.168.130
So this is the bridge network that will allow you to access the virtual machines
So let's ping the bridge interface and see so I'm going to run ping hyphen 3 192.168.2.130
hit enter and as you can see we are getting a positive ping response alright
So I'm going to clear the screen. OK so now that we have the bridge interface configured and active the next step is to
launch the KVM virtual machines manager and to do so simply run the command sudo vart
manager like that on the screen and hit enter. So on your screen you get this graphical interface for the virtual machine manager
alright so this is where we are OK. So this will allow us to now create virtual machines
So now I'm going to demonstrate how you can create a virtual machine
So to get started with creating a virtual machine you can come here click on file then
select new virtual machine alright. Alternatively you can just right click here and select new
So once you do that you'll see this virtual machine wizard here that allows you to create
a virtual machine. So here you'll see a list of options alright
So I have already downloaded an ISO image for Debian 12 OK
So I'm going to go with this option alright. So I'm going to click forward
So here I'm prompted to select the ISO image. So I'm going to click on browse alright
Then I'm going to head over to browse local. So this will allow me to navigate to where I have downloaded the ISO image
So I have it in my downloads folder. So here is the ISO image for Debian 12 alright
So I'm going to select open. So as you can see the ISO image path has been selected
So ensure that this is the same for your case. And here you can see the operating system has automatically been detected
So I'm going to click forward. So here you might see this notification that the emulator may not have such permissions
for the path to the ISO image. So to correct this I'm going to click yes to give it permission
So I'm going to select yes. So here you're going to choose your memory and CPU settings
So I'm going to leave this by default. So I'm going to leave this the way they are and I'm going to click forward
Otherwise if your system has more resources you can add more memory and CPUs
So for here I'm going to click forward. So in this step you're going to adjust the disk image size for the virtual machine
So once again I'm going to leave this default since I'm already satisfied with the selections
So I'm going to click forward. And here you're going to specify the name for your virtual machine
So I'm going to leave it the way it is. So you're going to get also the memory, the CPUs here for the network selection
You can see that it's using the bridge device. So you can see the virtual machine is already using the bridge network which we have just created
So here I'm going to click finish. And as you can see the creation of the virtual machine is underway
All right and here we go. So as you can see this is the Debian 12 installation page or pop-up
So as you can see this is what you would see when you're installing Debian 12
And as you can see we have a list of options and the first one is graphical install
So I'm going to hit enter. So what you're going to do we're just going to continue with the installation
So at this point I'm going to pause the video. I'm going to go all the way until Debian 12 is installed
And once installed we are going to see whether we can access the system
We're going to see whether we can connect to the system using the IP address
All right to test whether the bridge network is working or not
So at this point we have successfully installed KVM and we have also created a virtual machine
So I'm going to pause the video this moment and continue all the way until Debian 12 is installed
So finally the installation of Debian 12 VM is complete. So what I'm going to do I'm going to click continue to reboot the virtual machine so
that I can log into it. So I'm going to pause the video once again and I'll join you shortly once I've successfully
logged in into the Debian 12 virtual machine. So the virtual machine has successfully rebooted
So I'm going to go ahead and click on user and I'm going to provide the password. OK
So this will usher us into the Debian 12 desktop background as you shall see shortly
OK so here we go. All right so now our point of concern is to check whether the virtual machine has the
correct IP address and whether we can reach it from our host system
So here I'm going to just complete the wizard by clicking next
So I'll skip this and click start using Debian. OK so now I'm going to go to activities
And I'm going to search for terminal. OK. All right so here we are
So I'm going to check the IP address by running the command IP address like that
OK so as you can see we have the loopback address and we have the active network interface
which is ENP1S0. So as you can see this is our IPv4 address
So in our case we have 192.168.2.107 as the IP address of the virtual machine
So we are going to check whether we can access this from the Ubuntu host system
So once again I'm going back to the terminal here and I'm going to clear the screen
So I'm going to attempt to ping the virtual machine. So I'm going to run the ping command as follows
So 192.168.2.107. Then I'm going to hit enter. And there you see we can access the virtual machine externally
And it can also be accessed by any other system within their local area network
All right. So that's it guys for this lecture. So in this lecture I demonstrated how to install KVM on Ubuntu 24.04
And we have also seen how you can create and run a virtual machine
All right so that's it guys for this video. I hope you found it insightful
So please leave a like and subscribe to our channel for more of these videos
So for us it's bye-bye and see you in the next lecture