kvm management information view, add, delete, pause, resume, cloning, etc.

KVM virsh management instructions

virsh view help

View command help

[root@KVM ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # help

View a specific command help

[root@KVM ~]# virsh start --help
  NAME
    start - start a (previously defined) inactive domain

  SYNOPSIS
    start <domain> [--console] [--paused] [--autodestroy] [--bypass-cache] [--force-boot]

Concentrated using sub virsh command instruction
such as: view the status of c1:

[root@KVM ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # dominfo c1
Id:             6
Name:           c1
UUID:           58f945ba-2853-c53b-5820-d52fa320f034
OS Type:        hvm
State:          running
CPU(s):         1
CPU time:       171.2s
Max memory:     1048576 KiB
Used memory:    1048576 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: unconfined_u:system_r:svirt_t:s0:c200,c417 (permissive)

You can be executed directly from the command line:

[root@KVM ~]# virsh dominfo c1

Management operations

Start a Virtual Machine

[root@KVM ~]# virsh start c1
Domain c1 started

View list of virtual machines

[root@KVM ~]# virsh list
 Id    Name                           State
----------------------------------------------------
 6     c1                             running
 
 #查看所以主机列表
 [root@KVM ~]# virsh list --all

Stop or restart a virtual machine

#关闭虚拟机c1
[root@KVM ~]# virsh shutdown c1

#强行关机
[root@KVM ~]# virsh destroy c1
Domain c1 destroyed

#重启c1
[root@KVM ~]# virsh reboot c1

Or suspend running virtual machines

[root@KVM qemu]# virsh suspend c1   #此时状态暂停于内存中
Domain c1 suspended
#查看
[root@KVM qemu]# virsh list
 Id    Name                           State
----------------------------------------------------
 9     c1                             paused   


#继续执行
[root@KVM qemu]# virsh resume c1
Domain c1 resumed

[root@KVM qemu]# virsh list
 Id    Name                           State
----------------------------------------------------
 9     c1                             running

Save the virtual machine to a local disk (snapshot)
instances in the list will be removed to save local

#保存快照到本地
[root@KVM qemu]# virsh save c1 /tmp/c1.snap

#恢复到列表
[root@KVM qemu]# virsh restore /tmp/c1.snap 
Domain restored from /tmp/c1.snap

#此刻快照还存在,可以留作备份

Add a virtual machine to the list

virsh define c2.xml

To delete a virtual machine

[root@KVM ~]# virsh undefine c1

Modify virtual machine memory size

Modify virtual machine memory size and the number of cpu
shut down the virtual machine:

[root@KVM ~]# virsh shutdown vm1

Modify the xml file vm1 virtual machine

[root@KVM ~]# vim /etc/libvirt/qemu/vm1.xml 

 <memory unit='KiB'>2536000</memory>  #最大使用内存,原来是1536000
  <currentMemory unit='KiB'>2536000</currentMemory> #设置已使用内存
  <vcpu placement='static'>2</vcpu>   #调整为两个

For direct start after modification is not in force. You need to start from the xml file identification

[root@KVM ~]# virsh define /etc/libvirt/qemu/vm1.xml   #重新识别xml文件
Domain vm1 defined from /etc/libvirt/qemu/vm1.xml

[root@KVM ~]# virsh start vm1 
Domain vm1 started

[root@KVM ~]# virsh list
 Id    Name                           State
----------------------------------------------------
 9     vm1                            running

[root@KVM ~]# virsh dominfo vm1
Id:             9
Name:           vm1
UUID:           483f35c8-e00a-4598-b738-e9aa20e0d8e6
OS Type:        hvm
State:          running
CPU(s):         2          #调整了cpu
CPU time:       33.4s
Max memory:     2536448 KiB   #调整了最大可用内存 
Used memory:    2536000 KiB   #已使用内存
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c282,c706 (enforcing)

To the fullest range of available memory, you can dynamically adjust the online virtual machine memory size, but adjusting the cpu core need to shut down the virtual machine, increase the maximum memory also need to shut down the virtual machine, modify the xml file

The vm1 adjusted to 1G memory

[root@KVM ~]# virsh setmem vm1 1G  #调整内存

[root@KVM ~]# virsh dominfo vm1
Id:             9
Name:           vm1
UUID:           483f35c8-e00a-4598-b738-e9aa20e0d8e6
OS Type:        hvm
State:          running
CPU(s):         2
CPU time:       132.3s
Max memory:     2536448 KiB
Used memory:    1048576 KiB   #已使用内存
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c282,c706 (enforcing)

Clone Virtual Machine

kvm increased by way of a virtual machine image file copying and adding xml file can be used to add instructions virt-clone VM clone

VM cloning vm1 rename vm5

[root@KVM ~]# virt-clone -o vm1 -n vm5 -f /kvm/vm5/vm5.qcow2

Xml configuration file is automatically generated after cloning, the newly generated file uuid and MAC information changes automatically transmitted. The virtual machine can be started directly. If you need to change it using vnc vnc port information, otherwise it will start error

Start the virtual machine

[root@KVM qemu]# virsh list
 Id    Name                           State
----------------------------------------------------
 13    vm3                            running
 15    vm4                            running
 16    vm5                            running  #vm5启动起来

Guess you like

Origin www.cnblogs.com/anay/p/11121696.html