Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

2.6.2. VM Operations, Networking, and Management Tools

💡 First Principle: libvirt is an abstraction layer that provides a common API for managing different hypervisors (KVM, Xen, QEMU, VMware, LXC). virsh is the command-line client for libvirt. This means a script that uses virsh commands works across hypervisors that libvirt supports.

libvirt and virsh:
virsh list --all                   # List all VMs (running and stopped)
virsh start vm_name                # Start a VM
virsh shutdown vm_name             # Graceful shutdown (ACPI signal)
virsh destroy vm_name              # Force-stop (like pulling the power)
virsh reboot vm_name               # Reboot
virsh suspend vm_name              # Pause VM
virsh resume vm_name               # Unpause VM
virsh save vm_name /tmp/vm.state   # Save state to file
virsh restore /tmp/vm.state        # Restore from saved state
virsh dumpxml vm_name              # Show VM XML definition
virsh edit vm_name                 # Edit VM XML definition
virsh dominfo vm_name              # VM info (memory, CPUs, state)
virsh vcpuinfo vm_name             # CPU pinning information
virsh domstats vm_name             # Runtime statistics
VM Resources:
virsh setvcpus vm_name 4 --live    # Change CPU count while running
virsh setmem vm_name 4G --live     # Change memory while running
virsh attach-disk vm_name /dev/sdb vdb --live  # Attach disk hot
virsh detach-disk vm_name vdb --live           # Detach disk hot
VM Lifecycle Operations:
# Cloning (from a stopped VM)
virt-clone --original base_vm --name new_vm --auto-clone

# Snapshots
virsh snapshot-create-as vm_name snap1 "Before upgrade"
virsh snapshot-list vm_name
virsh snapshot-revert vm_name snap1
virsh snapshot-delete vm_name snap1

# Migration (live migration between hosts)
virsh migrate --live vm_name qemu+ssh://dest_host/system
VM Network Types:
Network TypeDescriptionUse Case
BridgedVM gets IP on same network as hostProduction VMs needing network presence
NATVMs share host's IP; host routes trafficDefault libvirt network; lab VMs
Host-only / IsolatedVMs communicate with each other and host onlyIsolated test networks
RoutedVMs have own subnet; host routes (no NAT)Advanced: requires router config
OpenNo network isolationDevelopment only
virsh net-list --all               # List networks
virsh net-start default            # Start default NAT network
virsh net-autostart default        # Auto-start network on boot
virsh net-define network.xml       # Define network from XML

virt-manager: The graphical front-end for libvirt, providing a GUI for creating and managing VMs. On the exam, it may appear as an alternative to virsh for scenarios where a GUI is available.

⚠️ Exam Trap: virsh shutdown sends an ACPI shutdown signal — the VM must have an ACPI-aware OS to respond to it (most modern Linux and Windows systems do). If the VM is unresponsive or the OS doesn't handle ACPI, use virsh destroy to force-stop. destroy in libvirt means "force stop," not "delete" — the VM definition and disk images remain.

Reflection Question: A junior admin runs virsh destroy production_db intending to delete the VM, panics when the VM stops, and believes they've deleted the production database. Are the VM's data and definition actually gone? What command would restart it?

Alvin Varughese
Written byAlvin Varughese
Founder18 professional certifications