This guide explains how to create a KVM virtual machine using Qcow2 image in Linux. QCOW, stands for QEMU copy-on-write, is the default storage format for virtual disks of QEMU/KVM instances.
Some Linux distributions especially RHEL provides customized Qcow2 images, so we can instantly create and run new virtual machines with Red Hat Enterprise Linux OpenStack Platform, or KVM hypervisor.
Table of Contents
Create A KVM Virtual Machine Using Qcow2 Image
We can import Qcow2 images in three different ways;
- using virt-install command,
- using Virt-manager gui application,
- using Cockpit web console.
1. Import Qcow2 images using virt-install command
Virt-install is a command line tool to create KVM, Xen and Linux container guests. It is part of the Virt-manager package.
If you haven't installed Virt-manager yet, refer the guide attached in "Virt-manager" in the next section below.
To create new KVM VM using Qcow2 image, run:
$ virt-install --name CentOS_8_Server --memory 2048 --vcpus 1 --disk /home/sk/CentOS_8_Server.qcow2,bus=sata --import --os-variant centos8 --network default
Replace "/home/sk/CentOS_8_Server.qcow2"
with your actual path where you have saved the Qcow2 image.
This command will create a CentOS 8 KVM instance with 2GB RAM, 1 vCPU with Qcow2 virtual disk.
Once the VM is created, it will automatically open in Virt-viewer application. Virt-viewer is also part of the VIrt-manager package.
Start using the new VM!
To launch the same VM next time, run:
$ virsh --connect qemu:///system start centos8
Replace "centos8" with your VM's name.
You can view the list of available VMs using command:
$ virsh list --all
2. Import Qcow2 images using Virt-manager
Virt-manager is a graphical user interface application used for creating and managing virtual machines through libvirt. Refer the following guide to learn how to install and use Virtual-manager.
Once Virt-manager is installed, launch it from Dash or Menu.
Navigate to File -> New Virtual Machine. Virt-manager will have an "Import existing disk image" option in the first window when creating a new virtual machine. Choose it and click Forward button.
Choose the actual path of Qcow2 image and then choose the operating system's variant you want to install. In my case, I chose CentOS 8.
Choose Memory and CPU settings for the new VM:
Check the "Customize configuration before install" option and click Finish.
Now you will see VM's configuration window. Click on "VirtIO Disk 1" setting from the left pane. On the right side pane, choose "SATA" as DISK BUS value under Advanced Settings. Click Apply to enable the changes.
Next configure Network settings for the VM. To do so, click "NIC :xx:xx:xx" option and select the Network Source, Device model etc. Click Apply to save the changes.
Finally, click "Begin Installation" on the top bar to start loading the new VM.
You will be redirected to the Virtual machine's graphical console.
Start using the newly created VM!
3. Import Qcow2 images using Cockpit Web console
Cockpit is a web-based server administration tool for managing remote Linux machines via a web-browser.
Not just physical machines, we can also manage virtual machines via Cockpit. For more details, refer the following guide to learn how to manage KVM VMs via Cockpit:
Log in to your Cockpit web console. Then click on "Virtual Machines" tab on the left pane.
Click "Import VM" option to import the existing Qcow2 virtual disk image.
Enter the Virtual machine name, choose the Qcow2 image file location, choose the memory size and click "Import" option. Make sure you've unchecked the box that says - "Immediately Start VM". Because, we need to do configure Disk and Network settings.
After importing the machine, you can adjust CPU, Memory and Network settings as per your requirement. First, we need to configure the Disk Bus Type.
To do so, Click on the "Disks" tab and click "Edit".
Choose the bus type. The default is hypervisor dependent. For KVM, the default value is virtio. You need to select a valid bus type. I select the bus type as "sata" and click Save.
Next go to Network Interfaces tab, click "Edit", choose Interface Type and Source and finally click Save.
Once everything is good, click "Run" to start the virtual machine:
Go to the Consoles tab and see if the newly created VM is running!
Conclusion
In this guide, we learned how to create a KVM virtual machine using Qcow2 image with Virt-install, Virt-manager and Cockpit in Linux.