Virsh, quick for Digital Shell, is a command line consumer interface for managing digital visitor machines. Virsh means that you can create, listing, edit, begin, restart, cease, droop, resume, shutdown and delete VMs. It at present helps KVM, LXC, Xen, QEMU, OpenVZ, VirtualBox and VMware ESX. On this information, we will probably be discussing tips on how to handle KVM digital machines with Virsh administration consumer interface in Linux.

Be sure to have put in KVM and Virsh utility in your Linux machine. The next guides explains tips on how to set up KVM on DEB and RPM-based techniques.

Handle KVM Digital Machines With Virsh Instructions

Getting assist

In case you are new to or do not know tips on how to work with Virsh interactive terminal, enter the next command to view the listing of accessible instructions together with transient description.

$ virsh assist

You will notice an intensive listing of accessible virsh instructions to handle KVM digital machines from command line.

Manage Virtual KVM Machines with Virsh Program

Show virsh instructions assist part

You do not have to memorize the whole lot. Simply learn the outline of a command that you just wish to run and use it.

The instructions are grouped into the next sections:

  • Area Administration,
  • Area Monitoring,
  • Host and Hypervisor,
  • Checkpoint,
  • Interface,
  • Community Filter,
  • Networking,
  • Node Machine,
  • Secret,
  • Snapshot,
  • Backup,
  • Storage Pool,
  • Storage Quantity,
  • Virsh itself.

Every part accommodates the instructions associated to do specific set of duties. You may view assist part of a gaggle, for instance Networking, like under:

$ virsh assist Networking

You will notice instructions associated to do networking duties:

Networking (assist key phrase ‘community’):
net-autostart autostart a community
net-create create a community from an XML file
net-define outline an inactive persistent digital community or modify an present persistent one from an XML file
net-destroy destroy (cease) a community
net-dhcp-leases print lease data for a given community
net-dumpxml community data in XML
net-edit edit XML configuration for a community
net-event Community Occasions
net-info community data
net-list listing networks
net-name convert a community UUID to community identify
net-start begin a (beforehand outlined) inactive community
net-undefine undefine a persistent community
net-update replace elements of an present community’s configuration
net-uuid convert a community identify to community UUID
net-port-list listing community ports
net-port-create create a community port from an XML file
net-port-dumpxml community port data in XML
net-port-delete delete the desired community port

You may additional show assist part of a particular command as nicely. For instance, I’m going to show the assistance part of “net-name” command:

$ virsh assist net-name
net-name – convert a community UUID to community identify


[–network] community uuid

Checklist digital machines

To view listing of visitor digital machines in run or droop mode, execute the next command:

$ virsh listing
Id Identify State

As you may see, there aren’t any friends in run or droop mode.

You need to use the –inactive choice to listing inactive friends.

To view all visitor machines, run:

$ virsh listing –all
Id Identify State
– centos8-uefi shut off
– nginx_centos8 shut off

As you see within the above output, I’ve two digital machines specifically “centos8-uefi” and “nginx_centos8”. Each are powered off.

Begin Digital machines

To start out a digital machine, for instance “centos8-uefi”, run:

$ virsh begin centos8-uefi

You will notice an output like under:

Area centos8-uefi began

To confirm if the VM is working, use “listing” command:

$ virsh listing
Id Identify State
1 centos8-uefi working

Save Digital machines

To avoid wasting the present state of a working VM, run:

$ virsh save centos8-uefi centos8-save

Area centos8-uefi saved to centos8-save

This command stops the visitor named “centos8-uefi” and saves the info to a file referred to as “centos8-save”. This may take just a few moments relying upon the quantity of reminiscence in use by your visitor machine.

Restore Digital machines

To revive the beforehand saved state of a VM, simply specify the file identify like under:

$ virsh restore centos8-save
Area restored from centos8-save

Confirm if the VM is restored utilizing “listing” command:

$ virsh listing
Id Identify State
Four centos8-uefi working

Restart Digital machines

To restart a working VM, run:

$ virsh reboot centos8-uefi
Area centos8-uefi is being rebooted

Droop/Pause Digital machines

To droop a working VM, do:

$ virsh droop centos8-uefi
Area centos8-uefi suspended

Confirm it with “listing” command:

$ virsh listing
Id Identify State
1 centos8-uefi paused

Resume Digital machines

To renew the paused VM, run:

$ virsh resume centos8-uefi
Area centos8-uefi resumed

Cease lively Digital machines

To forcibly cease an lively VM, and go away it within the inactive state, run:

$ virsh destroy centos8-uefi
Area centos8-uefi destroyed

It’s also possible to gracefully cease the VM as an alternative of forcing it like under:

$ virsh destroy centos8-uefi –graceful
Area centos8-uefi destroyed

Shutdown Digital machines

To energy off a working VM, do:

$ virsh shutdown centos8-uefi
Area centos8-uefi is being shutdown

Retrieve Digital machines XML dump

To show the XML configuration file of a VM in the usual output, run:

$ virsh dumpxml centos8-uefi

This command will show the whole configuration particulars (software program and {hardware}) of the digital machine:

Manage Virtual KVM Machines with Virsh Program

Show Digital machines XML configuration file

It’s also possible to export the XML dump to a file as an alternative of simply displaying it in the usual output like under:

$ virsh dumpxml centos8-uefi > centos8.xml

This command will dump the “centos8-uefi” XML file in a file named “centos8.xml” and put it aside within the present working listing.

Create Digital machines with XML dump

You may create a brand new digital visitor machine utilizing the present XML from beforehand created friends. First, create a XML dump as proven above after which create a brand new VM utilizing the XML file like under:

$ virsh create centos8.xml
Area centos8-uefi created from centos8.xml

This command will create a brand new VM and begin it instantly. You may confirm it utilizing command:

Manage Virtual KVM Machines with Virsh Program

Create Digital machines with XML dump

Edit Digital machines XML configuration file

In case you wished to make any modifications in a visitor machines, you may merely edit its configuration file and do the modifications as you want. The friends might be edited both whereas they run or whereas they’re offline.

$ virsh edit centos8-uefi

This command will open the file in your default editor that you just set with $EDITOR variable.

Allow console entry for Digital machines

After creating KVM visitor machines, you may entry them through SSH, VNC shopper, Virt-viewer, Virt-manager and Cockpit net console and many others. Nevertheless, you may’t entry them utilizing “virsh console” command. The console command is used to attach the digital serial console for the visitor. To entry KVM friends utilizing “virsh console” command, it’s good to allow serial console entry within the visitor machine. Refer the next information to allow virsh console entry:

Rename Digital machines

In case you ever wished to rename a digital machine, refer the next information.

Show Area ID of Digital machines

To seek out the area id of a working visitor digital machine, run:

$ virsh domid centos8-uefi

Please observe that the visitor must be working to get its area id.

Show Area identify of Digital machines

To get the area identify of a working VM, run:

$ virsh domname


$ virsh domname 2

Right here, 2 is the area id.

Show UUID of Digital machines

To seek out the visitor machine UUID, run:

$ virsh domuuid


$ virsh domuuid centos8-uefi


$ virsh domuuid 2

Pattern output:


Show Digital machines particulars

To show a visitor machine’s data, use area identify, area id or area uuid like under:

$ virsh dominfo centos8-uefi


$ virsh dominfo 2


$ virsh dominfo de4100c4-632e-4c09-8dcf-bbde29170268

Pattern output:

Id: –
Identify: centos8-uefi
UUID: de4100c4-632e-4c09-8dcf-bbde29170268
OS Sort: hvm
State: shut off
CPU(s): 2
Max reminiscence: 2097152 KiB
Used reminiscence: 2097152 KiB
Persistent: sure
Autostart: disable
Managed save: no
Safety mannequin: apparmor
Safety DOI: 0

Manage Virtual KVM Machines with Virsh ProgramShow Digital machines particulars

Show host data

To get the knowledge of your host system, run:

$ virsh nodeinfo

Pattern output:

CPU mannequin: x86_64
CPU(s): 4
CPU frequency: 1167 MHz
CPU socket(s): 1
Core(s) per socket: 2
Thread(s) per core: 2
NUMA cell(s): 1
Reminiscence dimension: 8058840 KiB

Show Digital CPU data

To show the digital CPU data, run:

$ virsh vcpuinfo


$ virsh vcpuinfo centos8-uefi
CPU: 3
State: working
CPU time: 5.6s
CPU Affinity: yyyy

CPU: 1
State: working
CPU time: 0.0s
CPU Affinity: yyyy

Discover IP handle of Digital machines

Discovering the IP handle of a digital machine just isn’t an enormous deal. When you’ve got console entry to the digital machine, you may simply discover its IP handle utilizing “ip” command. Nevertheless, it’s also doable to establish a KVM VM’s IP handle with out having to entry its console. The next information explains tips on how to discover the IP handle of a KVM digital machine.

Delete Digital machines

If you do not need a VM anymore, merely delete it like under:

$ virsh destroy centos8-uefi$ virsh undefine centos8-uefi

The primary command will forcibly cease the VM whether it is already working. And the second command will undefine and delete it fully.

You may additional use following choices to delete the storage volumes and snapshots as nicely.

–managed-save take away area managed state file
–storage take away related storage volumes (comma separated listing of targets or supply paths) (see domblklist)
–remove-all-storage take away all related storage volumes (use with warning)
–delete-storage-volume-snapshots delete snapshots related to quantity(s)
–wipe-storage wipe knowledge on the eliminated volumes
–snapshots-metadata take away all area snapshot metadata (vm have to be inactive)

Handle Digital networks

Checklist digital networks

To listing of accessible digital networks, run:

$ virsh net-list
Identify State Autostart Persistent
default lively sure sure

As you may see, I’ve just one digital community which is the default one.

Show digital community particulars

To view the small print of a digital community, run:

$ virsh net-dumpxml default

Exchange “default” together with your community identify within the above command.

Pattern output:


Begin digital networks

To start out an inactive community, run:

$ virsh net-start

To auto-start a community:

$ virsh net-autostart

Create digital networks XML dump

To create the XML configuration file of an present digital community, run:

$ virsh net-dumpxml default > default.xml

The above command will create XML config of the “default” community and put it aside in a file named “default.xml” within the present listing.

You may view the XML file utilizing cat command:

$ cat default.xml


Create new digital networks from XML file

To create a brand new digital community utilizing an present XML file and begin it instantly, run:

$ virsh net-create

If you wish to create a community from XML file however do not wish to begin it automtacially, run:

$ virsh net-define

Deactivate digital networks

To deactivate an lively community, run:

$ virsh net-destroy

Delete digital networks

To delete a digital community, deactivate it frist as proven above after which run:

$ virsh net-undefine

Virsh has a whole lot of instructions and choices. Studying to make use of Virsh command line throughly is simply sufficient to setup an entire Digital atmosphere in Linux. You do not actualy want GUI functions.

For extra particulars, refer virsh man pages.

$ man virsh

Handle KVM friends graphically

Remembering all virsh instructions is sort of unimaginable and in addition pointless. In case you discover it arduous to carry out all Kvm administration duties from command line, you may strive graphical KVM administration instruments corresponding to Virt-manager and Cockpit.

Hope this helps.

Featured picture by Elias Sch. from Pixabay.

virsh start vm,virsh tutorial,virsh connect to vm ssh,virsh console not working,virsh hypervisor,virsh commands,kvm gui,virsh connect to system