How to Start, Stop, Restart and List VMs with Virsh
Managing KVM virtual machines from the command line starts with knowing how to start, stop, restart, and list VMs using virsh. This guide covers the essential virsh commands for VM power management with real examples.
How to Start a VM with Virsh
To start a stopped or inactive virtual machine:
virsh start <vm-name>
Example:
virsh start ubuntu-server
If successful, you will see:
Domain ubuntu-server started
To start a VM and connect to its console immediately:
virsh start <vm-name> --console
How to List Running VMs
To see all currently running virtual machines:
virsh list
Output:
Id Name State
-----------------------------
1 ubuntu-server running
2 centos-web running
How to List All VMs (Running and Stopped)
To see all virtual machines including those that are shut off:
virsh list --all
Output:
Id Name State
-----------------------------
1 ubuntu-server running
- centos-web shut off
- debian-test shut off
How to Check the State of a VM
To check the current power state of a specific VM:
virsh domstate <vm-name>
Possible states: running, shut off, paused, crashed.
How to Gracefully Shutdown a VM
To send an ACPI shutdown signal (clean shutdown):
virsh shutdown <vm-name>
How to Force Stop a VM
If the VM is unresponsive or you need to stop it immediately:
virsh destroy <vm-name>
Note: Despite the name, virsh destroy does NOT delete the VM. It only forces it to stop immediately.
How to Restart a VM
To reboot a running VM gracefully:
virsh reboot <vm-name>
To force a hard reset:
virsh reset <vm-name>
How to Enable Autostart on Boot
To make a VM start automatically when the host server boots:
virsh autostart <vm-name>
To disable autostart:
virsh autostart --disable <vm-name>
Quick Reference Table
| Task | Command |
|---|---|
| Start a VM | virsh start <vm-name> |
| List running VMs | virsh list |
| List all VMs | virsh list --all |
| Check VM state | virsh domstate <vm-name> |
| Graceful shutdown | virsh shutdown <vm-name> |
| Force stop | virsh destroy <vm-name> |
| Reboot | virsh reboot <vm-name> |
| Hard reset | virsh reset <vm-name> |
| Enable autostart | virsh autostart <vm-name> |
| Disable autostart | virsh autostart --disable <vm-name> |
Conclusion
These are the core virsh commands for managing VM power states. For a full list of virsh commands including snapshots, cloning, and network management, see our 20 Essential Virsh Commands guide.
