virsh

virsh command is used to manage KVM vps. It is part of libvirt package.

http://libvirt.org

To list KVM virtual machines, run

virsh list

Start a VM

virsh start VM_ID

To shutdown a VM, run

virsh shutdown VM_ID

To delete a VM, run

virsh shutdown VM_ID

Connect to a Remote Server

virsh --connect qemu+ssh://[email protected]/system

You need SSH Key based authentication setup.

List All VM

boby@fwhlin:~ $ virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     vm1                            shut off

boby@fwhlin:~ $

List All Running VM

[root@server70 ~]# virsh list
 Id    Name                           State
----------------------------------------------------
 1     vm10                           running
 3     vm12                           running
 5     vm15                           running
 7     vm17                           running
 12    vm16                           running

[root@server70 ~]#

Get Info About a VM

virsh dominfo VM_NAME

example

[root@server70 ~]# virsh dominfo vm18
Id:             10
Name:           vm18
UUID:           b6c3a3d8-d96a-c3fa-1fad-04aff28e476a
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       422.9s
Max memory:     524288 KiB
Used memory:    524288 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0

[root@server70 ~]#

Change the Memory of a VM

virsh dumpxml vm18 > vm18.xml
virsh shutdown vm18
vi vm18.xml

Find

<memory unit='KiB'>524288</memor<memory unit='KiB'>524288</memory>
<currentMemory unit='KiB'>524288</currentMemory>

To change Memory to 1 GB, Replace it with

<memory unit='KiB'>1048576</memory>
<currentMemory unit='KiB'>1048576</currentMemory>

Load configuration

virsh define vm18.xml 

Example

[root@server70 ~]# virsh define vm18.xml
Domain vm18 defined from vm18.xml

[root@server70 ~]#

Start VM

virsh start vm18
[root@server70 ~]# virsh start vm18
Domain vm18 started

[root@server70 ~]#

See kvm

Comments

Leave a Reply

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