KVM Kernel-based virtual machine is a virtualization application developed for the Linux kernel that converts it to a higher system.
Before installation, login to our server to see if it supports CPU, let’s check the CPU information with the help of the following commands.
The output of this command means “CPU(s):” 0 does not support if it is 0, and if it is more than 1 or 1, it means it supports.
> egrep -c ‘(svm|vmx)’ /proc/cpuinfo
You can also use the command below to check whether the kernel modules are installed.
> lsmod | grep kvm
Then reboot the server.
You can also use the brctl show command to display the subsequent virtual interface (NIC).
Default is the directory where Virtual Machines (qcow2) are stored.
Note1: If you do not know the location of the disk in the qcow2 format, the following command (the command lists the corresponding VM disks with the directory where it is located) will tell you where it is.
> virsh domblklist Ubuntu18
Default is the directory where the installation iso is stored for Virtual Machine images.
Default is where Virtual Machine features (ram, cpu, disk, etc.) are stored in xml format.
Note2: The following command prints the features (ram, cpu, disk, etc.) where the machine is kept in xml format.
> virsh dumpxml Ubuntu18
You can view the existing virtual machines with the following two commands.
> virsh -c qemu:///system list
> virsh list –all
You can use virt interface to manage, create and delete Virtual Machines as GUI. The command is as follows.
Note 3: To do this, you must first connect to the server using the -X parameter (ssh -X email@example.com). You also need to have the Xming application for Windows (Putty must be enabled on x11) and the Xquartz application for Mac to be installed and running.
Note4: In the meantime, I have to give you another information. If you are a Linux user, that is, if your client machine is Linux, you can connect to the server and install File-Add Connection if you have a virt-manager on your client machine.
> sudo virt-manager
Or you can get the console of the server directly with the command below.
Note 5: To do this, you must first install the virt-viewer package on the user machine (ubuntu/debian for ’apt install virt-viewer’, Redhat/CentOS for ‘yum install virt-viewer’).
> sudo virt-viewer -c qemu:///system Ubuntu18
I will share a few commands below to manage the server through the commands.
Starts the server.
> virsh start Ubuntu18
Turns off the server.
> virsh shutdown Ubuntu18
Restarts the server.
> virsh reboot Ubuntu18
Used to change the properties of the server (changes the xml file).
> virsh edit Ubuntu18
When the host hosting the presentation is turned on, this is the option to automatically start vm as well.
> virsh autostart Ubuntu18
When the host hosting the presentation is turned on, this vm also disables the auto-start option.
> virsh autostart –disable Ubuntu18
Now let’s look at the virt-install command, which you can use to create a machine from the command line. You can use this example with the command below. I have used a lot of parameters but you don’t have to use all the parameters. Default values will be assigned instead of parameters you have not already used. You can then change these values. After executing the command, GUI will open and direct you to the installation.
> sudo virt-install –virt-type=kvm –name ubuntu-cli –ram 2048 –vcpus=2 –os-variant=Ubuntu16.04
–graphics spice –disk path=/var/lib/libvirt/images/ubuntu-cli.qcow2,size=40,bus=virtio,format=qcow2
Now let’s talk about “virt-clone” command. As the name suggests, it is the command used to get a clone. Its use is as follows. But you can get clone when VM is off, otherwise, it will give warning. You should get “Clone ‘Ubuntu18.clone’ created successfully.” Warning.
> virt-clone –original=Ubuntu18 –name=Ubuntu18.clone –file=/var/lib/libvirt/images/Ubuntu18.clone
The command below converts a vmdk in vmdk to qcow2 and runs it on your KVM host.
> qemu-img convert -O qcow2 ubuntu.vmdk ubuntu.qcow2
In our next article, we will look at how to make backups in the KVM environment and then restore and restore the backup we have made.
I hope it has been a useful article.