This first article I will show you how to install KVM in Debian 9 and how to create a CentOS 7 Virtual Guest.
Now, an important thing to keep in mind is that depending on the Linux distribution you are using, the names of the packages to install could be different. This is really important, as you could find yourself in strange situations trying to install packages with the name from another distribution, wondering why that particular package is not in the repositories.
With this exercises, we will cover the
Virtualization competences, which is a great thing. I will show you everything using only the command line because while you are in the exam, the only available environment for you is the CLI. As I know that all those tasks are easier to accomplish using the GUI, you will need to know how to do them using only the command line! Below are the Virtualization competences listed:
Virtualization - 5%
- Configure a hypervisor to host virtual guests
- Access a VM console
- Configure systems to launch virtual machines at boot
- Evaluate memory usage of virtual machines
- Resize RAM or storage of VMs
Before stepping into installing KVM, you should be certain that your system has virtualization available and enabled. For this, you should look for
vmx (for Intel procs) or
svm (for AMD procs) inside the cpuinfo file:
Now, check if the proper kernel modules for virtualization have been loaded.
To install the Virtualization stack you will need to install the following packages from the repositories, at first:
Thus, in Debian 9, you will use the command:
Download the CentOS 7 iso file
Before creating a virtual machine, you will need to download the iso file of CentOS 7. I will show you how to download the iso file using the command line, but in order to do this, you will need to know the address/location of the file. I will use a mirror that is available in my country (Romania), but you should use one that is available to yours. You will find a list of available mirrors for your country at the following address: http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso
From all the mirrors listed, I will choose this one:
http://ftp.ines.lug.ro/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso. Now, in order to download the file, I will use the
wget command, as follows:
Now, to check that everything is in order, I will use the command:
And you will see that the CentOS iso file is there.
Now, in order to avoid any problems, you will have to copy your iso file from the
Downloads directory to the
/var/lib/libvirt/images/ directory. For this, you should run the command:
Prepare to create a new Virtual Guest
Configure the NAT and default Network
NAT is the most common method to share network connections. In order to do this, you must configure the host with the command:
This command will show you a
default network connection that is
inactive and has no
autostart. To change this, issue the commands:
and then check to see if everything is according to the plan:
The output should be as follows:
Now, if you run the command
you will see that there is an isolated bridge device available, but it uses NAT and has no physical interface added.
To be sure that everything will work as planning, you should uncomment the line
net.ipv4.ip_forward = 1 in the
Now, you should continue to create a Virtual Guest.
Create a new CentOS 7 Virtual Guest
To create a new virtual machine with KVM, you will need to use the
virt-install utility. This utility has several parameters that you will need to fill in order for the VM to be created correctly. Let’s see them. You can also read about them using the
man virt-install command.
NOTE: the – sign is actually two hyphens like - - but without the space between them!
- –name = the name of the virtual machine you are about to create
- –os-type = the type of the os, in our case Linux
- –os-variant = what variant of the os type is it, in our case rhel7
- –disk path = location of the disk image
- –disk size = the size of the disk image to be created - in GiB
- –disk bus = the
- –graphics = is the way to connect to the virtual machine - usually it is
- –vcpu = the number of virtual cpu’s
- –ram = the amount of RAM in megabytes
- –cdrom = the source path of the installation iso file
- –network = the bridge adapter to be used by the virtual machine
Before setting up a virtual guest, I will strongly advice to restart your Debian system, otherwise you will run into some very specific errors. Thus, run the command:
sudo shutdown -r now
The command to setup a CentOS Virtual Guest is as follows:
This command will automatically switch to the gui and virt-manager interface, showing you the installation options.
Now, I will not talk about how to use the
virsh command line, as I did this already in the former CentOS 7 KVM post. All the commands are the same, as they are
virsh specific, and are independent on the underlying distribution that you use.