virsh — Virtualization Shell for Managing VMs

virsh is a command-line interface for managing virtual machines via libvirt, typically used with KVM, QEMU, and other virtualization technologies. It supports operations like VM lifecycle management, storage, network, snapshots, and resource monitoring.


Key Features

  • Lifecycle Management: Start, stop, suspend, and destroy VMs.

  • Persistent and Transient VMs: Manage both runtime and saved configurations.

  • Storage and Networking: Control virtual disks, volumes, and virtual networks.

  • Snapshots: Create and revert to VM snapshots.

  • Remote Management: Manage VMs on remote hosts over SSH or TLS.

  • Interactive and Non-interactive Use: Run commands or enter an interactive shell.


Basic Syntax

virsh [options] <command> [args]

Example:

virsh start vm-name

Common and Essential Subcommands

1. VM Lifecycle Management

  • List VMs (running or all)

  • Start / Shutdown / Destroy / Reboot

  • Suspend / Resume

  • Autostart on Boot


2. Domain and Resource Info

  • Get VM Information

  • CPU and Memory Statistics


3. VM Configuration and XML

  • Dump or Edit XML Configuration

  • Define or Undefine Domains


4. Snapshot Management

  • Create and Manage Snapshots


5. Console and Access

  • Connect to Serial Console

    To exit: Ctrl+]


6. Storage Management

  • List, Create, and Delete Volumes

  • Pool Management


7. Network Management

  • List, Start, and Define Networks


8. Remote and Interactive Mode

  • Connect to Remote Host

  • Enter Interactive Shell


Example Use Cases

Start a Virtual Machine


Check Running VMs


Create a Snapshot Before Upgrade


Attach a CD-ROM ISO Image


Conclusion

virsh is an indispensable tool for Linux-based virtualization environments using libvirt. It provides complete lifecycle control, resource introspection, and management capabilities for virtual machines, networks, and storage — both locally and remotely. It’s highly scriptable and favored for automation and infrastructure orchestration workflows.

Last updated