1:kvm安裝虛擬機;php
virt-install --name centos7.1 --boot network,cdrom,menu=on --ram 1024 --vcpus=1 --os-variant=rhel6 --accelerate --cdrom=/usr/local/iso/CentOS-7-x86_64-DVD-1511.iso --disk path=/usr/local/kvm/centos7/centos7vm.img,size=5,bus=virtio --bridge=br0,model=virtio --autostart --vnc --vncport=5900 --vnclisten=0.0.0.0
注:能夠根據具體安裝修改安裝參數。ubuntu
2:查看全部虛擬機列表級狀態:centos
virsh list --all
Id Name State ---------------------------------------------------- 2 centos7 running - ubuntu14 shut off
3:查看運行虛擬機列表:dom
virsh list
Id Name State
----------------------------------------------------
2 centos7 running ide
4:啓動虛擬機系統:centos7
virsh start ubuntu14
Domain ubuntu14 startedcode
5:關閉虛擬機系統:orm
virsh shutdown ubuntu14
Domain ubuntu14 is being shutdownxml
6:重啓虛擬機:blog
virsh reboot centos7
Domain centos7 is being rebooted
7:強行關閉某虛擬機:
virsh destroy ubuntu14
Domain ubuntu14 destroyed
8:標記虛擬機爲自動開始:
virsh autostart centos7
Domain centos7 marked as autostarted
9:關閉虛擬機爲自動開始:
virsh autostart --disable centos7
Domain centos7 unmarked as autostarted
10:鏈接終端虛擬機:
virsh console centos7
11:掛起和恢復虛擬機:
virsh suspend centos7
Domain centos7 suspended
恢復:
virsh resume centos7
Domain centos7 resumed
12:刪除一個虛擬機:
1:關閉該虛擬機:
virsh shutdown ubuntu14
2:若是虛擬機關閉失敗,能夠強制關機:
virsh destroy ubuntu14
3:Undefine 虛擬機配置:
virsh undefine ubuntu14
4:刪除虛擬機磁盤文件:
rm -rf /vm-images/ubuntu14.img
13:查看虛擬機信息:
virsh dominfo centos7
Id: -
Name: centos7
UUID: 5a62d998-01c9-4b57-995b-01b17738c316
OS Type: hvm
State: shut off
CPU(s): 1
Max memory: 1048576 KiB
Used memory: 0 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0
14:虛擬機磁盤信息:
[root@mastercl images]# pwd
/var/lib/libvirt/images
[root@mastercl images]# ls
centos7.img
[root@mastercl images]# qemu-img info /var/lib/libvirt/images/centos7.img
image: /var/lib/libvirt/images/centos7.img
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 3.6G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
15:導出(備份)虛擬機XML配置文件:
[root@mastercl images]# virsh dumpxml centos7 > /root/centos7_dump_xml
[root@mastercl images]# cd ~
[root@mastercl ~]# ls
anaconda-ks.cfg Desktop Downloads Pictures Templates
centos7_dump_xml Documents Music Public Videos
能夠看到導出的配置文件爲centos7_dump_xml。此爲虛擬機的配置文件。定義了虛擬機的參數。
16:編輯虛擬機配置文件:[root@mastercl ~]# virsh edit centos7