• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

virsh Command Examples in Linux

by admin

Many virtualization host servers will run Linux without a graphical user interface. Such a configuration enables more hardware resources to be available to the virtual machines. Management of the virtual machines must then occur at the command-line. The virsh command is an interactive shell to KVM virtual machines. The following are some subcommands you can use within virsh.

Option Used To
help Get help with the virsh command.
list Get a list of recognized VMs.
shutdown {VM} Gracefully shut down a VM.
start {VM} Start a VM.
reboot {VM} Reboot a VM.
create {XML file name} Create a VM from an XML file.
save {VM} {file name} Save the state of a VM with the given file name.
console {VM} Open a console to a VM.

Linux virtualization solutions are built on top of libvirt, an application programming interface (API) that provides the software building blocks for developers to write their own virtualization solutions. Solutions can also be composed of a daemon and a management interface. Several hypervisors, including VMware ESXi, KVM, QEMU, etc., are all built using libvirt. It provides a solid foundation for Linux-based virtualization. For example, the virsh tool is a part of the libvirt API.

virsh Command Examples

1. Connect to a hypervisor session:

# virsh connect qemu:///system

2. List all domains:

# virsh list --all

3. Dump guest configuration file:

# virsh dumpxml guest_id > path/to/guest.xml

4. Create a guest from a configuration file:

# virsh create path/to/config_file.xml

5. Edit a guest’s configuration file (editor can be changed with $EDITOR):

# virsh edit guest_id

6. Start/reboot/shutdown/suspend/resume a guest:

# virsh command guest_id

7. Save the current state of a guest to a file:

# virsh save guest_id filename

8. Delete a running guest:

# virsh destroy guest_id && virsh undefine guest_id

Filed Under: Linux

Some more articles you might also be interested in …

  1. Understanding the /proc/mounts, /etc/mtab and /proc/partitions files
  2. “git merge-into” Command Examples
  3. handbrakecli Command Examples
  4. “aws ses” Command Examples
  5. crontab error : “You (user) are not allowed to access to (crontab) because of pam configuration.”
  6. How to uninstall chromium-browser from Ubuntu
  7. airpaste – Share messages and files on the same network using mDNS (Command Examples)
  8. How to merge 2 volume groups (VGs) into one using vgmerge in LVM
  9. chgrp: command not found
  10. Examples of creating command alias in different shells

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright