virsh CLI. By the end, you will be able to install dependencies, define VM domains via XML, control VM lifecycle, adjust resources, and clean up definitions—all from the command line. This workflow is fundamental for self-hosted virtualization and supports major cloud platforms like AWS, DigitalOcean, and Google Cloud.
Example: A single Linux server with 64 CPU cores and 1 TiB RAM can host dozens of isolated VMs, each with its own dedicated vCPU and memory allocation.
1. Installing Dependencies
Install QEMU, KVM, and Libvirt tools:- qemu-kvm: Hardware-accelerated virtualization
- libvirt: API and utilities for managing VMs
You may also need to start and enable the libvirtd service:
2. Defining a Virtual Machine Domain
Libvirt uses XML to describe VM configurations (called domains). Create a file namedtestmachine.xml:
- Name: TestMachine
- Memory: 1 GiB
- vCPUs: 1
- OS: Hardware VM on x86_64
3. Defining and Listing Domains
Register the domain with Libvirt:Omit
--all to list only running domains.4. VM Lifecycle Management
Use the following commands to control the VM. See the quick reference table below.resetsimulates pressing the reset button.
destroycuts power immediately—like unplugging the VM.
5. Deleting a Domain
Remove the domain definition only:--remove-all-storage will also delete associated disk images: