Essential Virsh Commands for Managing Virtual Machines on Debian 12

The essential virsh commands help you manage virtual machines from the command line. If you use libvirt on Debian, you must know these commands.

In this guide, we will use Debian GNU/Linux 12 (Bookworm). All future examples in this series also use this version.

Because virsh works directly with libvirt, it gives you full control over your VMs.

What Is Virsh?

virsh is a command-line tool used to manage virtual machines through libvirt.

It allows you to:

  • Start and stop VMs
  • View VM details
  • Edit configuration
  • Control VM lifecycle

Therefore, learning the essential virsh commands is critical.

Essential Virsh Commands Explained

Below are the most important commands every administrator should know.

1. virsh list

The virsh list command shows running virtual machines.

virsh list

To show all VMs, including stopped ones:

virsh list --all

Because of this command, you can quickly check VM status.

2. virsh start

The virsh start command starts a virtual machine.

virsh start vm-name

Use this when a VM is in a shut-off state.

However, make sure the VM configuration is correct before starting.

3. virsh shutdown

The virsh shutdown command gracefully powers off a VM.

virsh shutdown vm-name

This works like pressing the power button inside the OS.

Therefore, it is safer than forcing a stop.

4. virsh destroy

The virsh destroy command forcefully stops a VM.

virsh destroy vm-name

This is similar to unplugging power.

Use it only when the VM does not respond.

5. virsh reboot

The virsh reboot command restarts a virtual machine.

virsh reboot vm-name

Because it performs a clean reboot, it is safer than destroy + start.

6. virsh autostart

The virsh autostart command enables automatic startup.

virsh autostart vm-name

Now the VM starts automatically when the host boots.

To disable autostart:

virsh autostart --disable vm-name

This is useful for production environments.

7. virsh dominfo

The virsh dominfo command shows VM details.

virsh dominfo vm-name

It displays:

  • CPU count
  • Memory allocation
  • State
  • Autostart status
  • UUID

Because of this, you can quickly check VM configuration.

8. virsh dumpxml

The virsh dumpxml command displays the VM XML configuration.

virsh dumpxml vm-name

You can also save it:

virsh dumpxml vm-name > vm-backup.xml

This helps you back up or review settings.

9. virsh edit

The virsh edit command allows live XML editing.

virsh edit vm-name

Always shut down the VM before major changes.

Because XML is strict, one mistake can prevent the VM from starting.

Quick Command Summary Table

CommandPurposeSafe to Use Anytime?
virsh listShow VM statusYes
virsh startStart VMYes
virsh shutdownGraceful stopYes
virsh destroyForce stopUse carefully
virsh rebootRestart VMYes
virsh autostartEnable auto bootYes
virsh dominfoShow VM detailsYes
virsh dumpxmlView XML configYes
virsh editModify XMLStop VM first

Why These Essential Virsh Commands Matter

The essential virsh commands allow you to manage the full VM lifecycle.

For example, you can:

  • Control power states
  • Configure startup behavior
  • Inspect VM details
  • Modify hardware settings

Because virsh works directly with libvirt, it provides precise control.

As a result, many administrators prefer it over GUI tools.

FAQ Section

Do I need root access to use virsh?

No. Add your user to the libvirt group.

Is virsh safe for production?

Yes. Many enterprise systems use it daily.

What is the difference between shutdown and destroy?

Shutdown is graceful. Destroy is forceful.

Can I automate virsh commands?

Yes. You can use shell scripts.

Does virsh work without KVM?

Yes, but performance may be lower.

Conclusion

Learning the essential virsh commands is critical for managing virtual machines on Debian GNU/Linux 12 (Bookworm). These commands help you start, stop, inspect, and configure VMs safely.

If you master these tools, you gain full control over your virtualization environment.

In the next tutorial, we will create a virtual machine using virt-install and manage it with virsh.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *