Virtualization is the process of creating a virtual environment that runs on top of an existing operating system. It allows multiple operating systems to run on a single physical machine, thereby maximizing hardware utilization and improving system efficiency. KVM (Kernel-based Virtual Machine) is a virtualization solution that is integrated with the Linux kernel. In this tutorial, we will show you how to install and configure virtualization software on Fedora with KVM.
How to install and configure virtualization
Check Hardware Support
First, you need to ensure that your hardware supports virtualization. To check if your CPU supports hardware virtualization, run the following command:
$ egrep -c '(vmx|svm)' /proc/cpuinfo
If the output is greater than 0, your CPU supports virtualization.
Install KVM Packages
To install KVM packages, run the following command:
$ sudo dnf install @virtualization
This command installs all the necessary packages required to run KVM on Fedora.
Configure Network Bridge
By default, KVM uses NAT (Network Address Translation) for networking. This means that all virtual machines share the same IP address as the host machine. To avoid this, we will configure a network bridge that allows the virtual machines to have their own IP addresses.
To create a network bridge, run the following command:
$ sudo nmcli connection add type bridge autoconnect yes con-name br0 ifname br0
This command creates a network bridge named br0.
Next, we need to add a physical network interface to the bridge. To do this, run the following command:
$ sudo nmcli connection modify eno1 master br0
Replace eno1 with the name of your physical network interface.
Create Virtual Machine
To create a virtual machine, you can use the virt-manager GUI or the virt-install command-line tool.
To use the virt-manager GUI, run the following command:
$ sudo virt-manager
This will open the virt-manager GUI. From here, you can create a new virtual machine by clicking on the “Create a new virtual machine” button.
To use the virt-install command-line tool, run the following command:
$ sudo virt-install \
--name myvm \
--ram 2048 \
--disk path=/var/lib/libvirt/images/myvm.img,size=20 \
--vcpus 2 \
--os-type linux \
--os-variant fedora33 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location http://ftp.fi.muni.cz/pub/linux/fedora/linux/releases/33/Everything/x86_64/os/
This command creates a new virtual machine named myvm with 2 vCPUs and 2GB of RAM. It uses a 20GB virtual disk stored in /var/lib/libvirt/images/myvm.img. The virtual machine is connected to the br0 network bridge and uses the Fedora 33 operating system.
Access Virtual Machine
Access the virtual machine, you can use the virt-viewer GUI or the virsh console command-line tool.
Use the virt-viewer GUI, right-click on the virtual machine in the virt-manager window and select “Open”.
To use the virsh console command-line tool, run the following command:
$ sudo virsh console myvm
This command connects to the virtual machine’s console.
Conclusion
KVM is a powerful virtualization solution that is integrated with the Linux kernel. It allows you to run multiple operating systems on a single physical machine, thereby maximizing hardware utilization and improving system efficiency. In this tutorial, we showed you how to install and configure KVM on