Use KVM high performance to create virtual images in Linux systems

1. Introduction

This article uses KVM on Debian12 system to implement virtual image management through graphical interface and command line. KVM is an open source virtualization technology embedded in the Linux kernel. It can transform a Linux system into a hypervisor, allowing the host computer to run multiple isolated virtual environments.

Compared with other commercial virtual machines, KVM has unique advantages in cost, performance, security, and cross-platform. KVM is part of the Linux system. It has everything Linux has and KVM also has it. KVM uses a combination of security-enhanced Linux (SELinux) and secure virtualization (sVirt) to enhance the security and isolation of virtual machines. KVM can use any storage supported by Linux, including some local disks and network-attached storage (NAS), and can also take advantage of multipath I/O to enhance storage and provide redundancy. KVM inherits the performance of Linux and scales as the number of clients and requests increases to meet load requirements. KVM virtualizes the most demanding application workloads and is the foundation of many enterprise virtualization setups, such as data centers and private clouds.

2.KVM component installation

KVM components can be installed on any modern Linux system to achieve virtualization. The Debian system, which is known for its stability, is used as the experimental target.

If you want to keep the same as the experimental environment in this article, you can go here to download the latest Debian system: Debian — The Universal Operating System

Log in to the Debian system and enter the following command to first check whether the CPU supports virtualization:

# egrep 'vmx|svm' /proc/cpuinfo

The result information returned by the command is as follows:

If the word “vmx” in the picture appears, it means virtualization is supported.

KVM requires many packages to be installed. The core components are roughly as follows:

# apt install qemu-system-x86 libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon libguestfs-tools libosinfo-bin qemu-system virt-manager

The installation names of these component packages may be different on different Linux systems. If you are using Debian 12, you can directly copy the above command for installation. The installation process may take a while, and there are still many dependent packages.

After the KVM component is installed, you first need to configure the network. First enter the following command to view the current network status:

# virsh net-list --all

If the status is: inactive, it means that the network status is not active, as shown in the figure:

Then enter the following command to activate the network:

# virsh net-start --network default

Check the status again. If the status changes to active, it means the network activation is successful, as shown in the figure:

After completing the network activation, you can officially start installing the virtual image.

3. Use the graphical interface to install the image

To install a virtual system image under the graphical interface, you need to find “Virtual System Manager” in the software list and open it, as shown in the figure:

After clicking the icon, the main interface of the virtual system manager will open. Compared with commercial software such as VMware, the interface of open source KVM is very simple, as shown in the figure:

Click the computer icon on the upper left to start creating a virtual image, as shown in the figure:

In most cases here, ISO image installation is usually used. Just default to the first one. The following architectures are usually selected: x86_64. Click the “Forward” button in the lower right corner to enter the next step, as shown in the figure:

What I uploaded here is the ISO image of Windows 11. Select the ISO image location through the browse button, check the box to automatically detect the media, and click the “Forward” button to enter the next step, as shown in the figure:

Here you mainly set the memory size and number of CPUs. Note that the memory size unit here is MB. If you set it in GB units, the virtual system will fail to start due to insufficient memory. After the configuration is completed, click the “Forward” button to proceed to the next step, as shown in the figure:

Here we mainly allocate hard disk space for the virtual image. You can set the size according to the actual size. The default size unit of the hard disk here is GB. Click the “Forward” button to enter the next step, as shown in the figure:

Here you can see all the options set in the previous steps. After confirming that there is no problem, click the “Finish” button to return to the main interface. Then you need to configure the boot options. By default, CDROM is placed at the front of the boot sequence, as shown in the figure:

Click “apply” in the lower right corner to make the settings take effect. Click the Start Virtual Machine button on the previous interface and you will see the familiar Windows installation interface, as shown in the figure:

4. Command line installation image

The complete installation image command is as follows:

# virt-install --name windows11_command --vcpus=4 --ram=4096 --disk path=/var/lib/libvirt/images/windows11_command.qcow2,size=5 --cdrom=/home/Win11_22H2_Chinese_Simplified_x64v2 .iso --network bridge=virbr0 --graphics vnc --os-variant win11 --noautoconsole

Command description:

–name: Specify the virtual machine name

–vcpus: Set the number of vCPUs

–ram: set memory size

–disk: Set virtual disk size and save path

–cdrom: Specify ISO image path

–network: Use the default network in NAT mode

–graphics vnc: Set to use VNC access

–os-variant: Specify operating system type

–noautoconsole: Do not automatically open the console

After the command is successfully executed, as shown in the figure:

At this time, return to the virtual system manager and you can see that the image just created through the command is already running, as shown in the figure:

5. Summary

Finally, let’s summarize some of the unique advantages of KVM compared to other commercial virtual machines:

  • Lower cost – KVM is open source and free, and you only need to invest in the hardware cost of the running platform when using it. Other commercial virtual machines require payment of licensing fees.

  • Higher performance – KVM is kernel-level virtualization with extremely low performance overhead. Compared with commercial hosted virtualization, KVM has better performance.

  • Better security – KVM leverages Linux’s security mechanisms to provide more reliable isolation. Other commercial virtual machines expose more attack surfaces.

  • More flexible environment – KVM can run on a variety of standard server hardware, making it more flexible. Other commercial virtual machines have certain limitations on server hardware.

  • Wider platform support – KVM supports a variety of operating systems as virtual machine platforms. Other commercial virtual machines do not have completely consistent virtualization support for different operating systems.

  • More powerful cluster functions – KVM can be integrated with OpenStack to obtain powerful virtualization cluster management functions.

  • Open source community support – KVM has an active open source community providing support and new features.

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS entry skill treeLinux introductionFirst introduction to Linux36307 people are learning the system