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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

KVM Virsh Command Examples on CentOS and RHEL

by admin

virsh is the interface or command for managing the virtual machines based on the KVM hypervisor. On virsh interface virtual machines are identified by their domain names, so virsh is generally used to list current domains, to create, pause & shutdown domains. Virsh comes under GNU Lesser General Public License and supports Xen, QEmu, KVM, LXC, OpenVZ, VirtualBox, and VMware ESX.

In this tutorial, we discuss the practical examples of virsh command:

Example 1: Get KVM version installed on the host machine.

# virsh version
Compiled against library: libvir 0.9.4
Using library: libvir 0.9.4
Using API: QEMU 0.9.4
Running hypervisor: QEMU 0.12.1

Example 2: Get KVM Hypervisor(Host) Memory info.

# virsh nodememstats
total  :        65979984 kB
free   :        44783040 kB
buffers:        604388 kB
cached :        16473328 kB

Example 3: Get KVM Hypervisor CPU info.

# virsh nodecpustats
user:          122779270000000
system:        1304262720000000
idle:          470011564690000000
iowait:        110371800000000

Example 4: Get a number of Guest Virtual machines irrespective of state such as running, save, shutdown, etc.

# virsh list --all
Id Name              State
----------------------------------
3 test               running

Example 5: Get all the networks available for the KVM hypervisor.

# virsh net-list
Name                 State      Autostart
-----------------------------------------
default              active     yes

Example 6: Get Hardware information of a KVM guest machine.

Syntax:

# virsh dominfo BaseMachine

Example:

# virsh dominfo test
Id:             3
Name:           test
UUID:           9ae96029-6c3d-8bd1-6e19-926183f89074
OS Type:        hvm
State:          running
CPU(s):         4
CPU time:       26862.0s
Max memory:     4194304 kB
Used memory:    4194304 kB
Persistent:     yes
Autostart:      disable
Managed save:   no

Example 7: Shutdown the Virtual Machine.

# virsh shutdown machine_name

Example 8: Reboot the Virtual Machine.

# virsh reboot machine_name

Example 9: Force off or destory the machine.

# virsh destroy machine_name

Example 10: Start the Virtual Machine.

# virsh start machine_name

Example 11: Connect to specific virtual machine using virt-viewer.

syntax:

# virt-viewer -c qemu:///system machine_name

Example:

# virt-viewer -c qemu:///system test

Example 12: Create New virtual Machine using virt-install.

Suppose i want to install Centos 6.X on 10GB space, then first create a img file using below command:

# dd if=/dev/zero of=/var/lib/libvirt/images/centos-linux.img bs=1M count=10240

then run virt-install command:

# virt-install --virt-type kvm --name CentOS-Linux --ram 2048 --vcpus=2 --disk path=/var/lib/libvirt/images/centos-linux.img --network bridge=br0 --graphics vnc --cdrom /root/CentOS-6.2-x86_64-bin-DVD1.iso --os-variant=RHEL6

Below Screen will appear when we run the above command:

virt viewer centos

Example 13: Live Migration of Virtual Machine from One Hypervisor to Another using virsh command.

Basic Requirements of Live Migration:

  • The guest image must be located on a shared storage and it must be accessible using iSCSI, NFS, GFS2 or Fibre Channel.
  • The shared storage must be mounted on the same path on both hosts.
  • Both guests must run the same version of KVM.
  • Both guests must have the same network configuration and bridging configuration (their IPs must be different)
# virsh migrate --live machine_name qemu+ssh://destination_server/system

Filed Under: CentOS/RHEL, Linux, RHV

Some more articles you might also be interested in …

  1. RHV – How to shutdown a VM from AdminPortal
  2. pstree Command Examples in Linux
  3. dphys-swapfile: command not found
  4. How to use wget to download file via proxy
  5. cpufreq-aperf Command Examples in Linux
  6. mcookie: command not found
  7. dirb: command not found
  8. How to Configure YUM to connect to Oracle Public Repository in Oracle Enterprise Linux
  9. How to start/stop Virtual Machines in RedHat Virtualization
  10. How to analyze basic system performance using – vmstat, sar, iostat and mpstat

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright