5.12 Managing and Configuring Virtual Machines with QEMU, KVM, and VIRSH

5.12 Managing and Configuring Virtual Machines with QEMU, KVM, and VIRSH


QEMU (Quick Emulator) and KVM (Kernel-based Virtual Machine) are powerful tools for virtualization on Linux systems. Combined with the management utility VIRSH, they offer extensive capabilities for creating, managing, and configuring virtual machines (VMs). This guide outlines the steps to install these packages and demonstrates common commands for managing VMs.

Installation: To install QEMU, KVM, and the libvirt utilities, follow these steps:

sudo dnf install libvirt qemu-kvm

Creating a Virtual Machine: You can create a virtual machine by defining its configuration in an XML file. Here's an example of creating a basic virtual machine named "TestMachine":

virsh define testmachine.xml

Managing Virtual Machines: Once VMs are defined, you can manage them using VIRSH commands:

  • List all active domains:

      virsh list
  • List all domains (active and inactive):

      virsh list --all
  • Start a virtual machine:

      virsh start testmachine
  • Reboot a virtual machine:

      virsh reboot testmachine
  • Force reset a virtual machine:

      virsh reset testmachine
  • Shut down a virtual machine:

      virsh shutdown testmachine
  • Forcefully power off a virtual machine:

      virsh destroy testmachine

Deleting Virtual Machines: To delete a virtual machine, first, shut it down and then undefine it:

  • Undefine a VM (keeping its data):

      virsh undefine testmachine
  • Undefine and remove all storage associated with the VM:

      virsh undefine --remove-all-storage testmachine

Automatic Start on Boot: You can configure a virtual machine to start automatically when the host machine boots:

  • Enable auto-start:

      virsh autostart testmachine
  • Disable auto-start:

      virsh autostart --disable testmachine

Checking and Modifying Resources: You can check and modify the resources allocated to a virtual machine:

  • Check virtual machine information:

      virsh dominfo testmachine
  • Modify resources (e.g., CPU):

      virsh setvcpus TestMachine 2 --config --maximum  # Set the maximum usable CPU to 2
      virsh setvcpus TestMachine 2 --config           # Set CPU to 2


With QEMU, KVM, and VIRSH, managing and configuring virtual machines on Linux systems becomes efficient and straightforward. These tools provide extensive capabilities for creating, starting, stopping, and modifying virtual machines, empowering users to build and manage virtualized environments effectively.

Congratulations! You've successfully completed Module 5 on service configuration. Well done on your learning journey so far!

Did you find this article valuable?

Support Vijay Kumar Singh by becoming a sponsor. Any amount is appreciated!