1:kvm安装虚拟机;
[html] view plain copy
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 注:可以根据具体安装修改安装参数。
2:查看所有虚拟机列表级状态:
[html] view plain copy
[root@master Desktop]# virsh list --all
Id Name State
----------------------------------------------------
2 centos7 running
- ubuntu14 shut off 3:查看运行虚拟机列表:
[html] view plain copy
[root@master Desktop]# virsh list
Id Name State
----------------------------------------------------
2 centos7 running 4:启动虚拟机系统:
[html] view plain copy
[root@master Desktop]# virsh start ubuntu14
Domain ubuntu14 started 5:关闭虚拟机系统:
[html] view plain copy
[root@master Desktop]# virsh shutdown ubuntu14
Domain ubuntu14 is being shutdown 6:重启虚拟机:
[html] view plain copy
[root@master Desktop]# virsh reboot centos7
Domain centos7 is being rebooted 7:强行关闭某虚拟机:
[html] view plain copy
[root@master Desktop]# virsh destroy ubuntu14
Domain ubuntu14 destroyed 8:标记虚拟机为自动开始:
[html] view plain copy
[root@master Desktop]# virsh autostart centos7
Domain centos7 marked as autostarted 9:关闭虚拟机为自动开始:
[html] view plain copy
[root@master Desktop]# virsh autostart --disable centos7
Domain centos7 unmarked as autostarted 10:连接终端虚拟机:
[html] view plain copy
virsh console centos7 11:挂起和恢复虚拟机:
[html] view plain copy
[root@master Desktop]# virsh suspend centos7
Domain centos7 suspended 恢复:
[html] view plain copy
[root@master Desktop]# virsh resume centos7
Domain centos7 resumed 12:删除一个虚拟机:
1:关闭该虚拟机:
[html] view plain copy
virsh shutdown ubuntu14 2:如果虚拟机关闭失败,可以强制关机:
[html] view plain copy
virsh destroy ubuntu14 3:Undefine 虚拟机配置:
[html] view plain copy
virsh undefine ubuntu14 4:删除虚拟机磁盘文件:
[html] view plain copy
rm -rf /vm-images/ubuntu14.img 13:查看虚拟机信息:
[plain] view plain copy
[root@mastercl images]# 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:虚拟机磁盘信息:
[plain] view plain copy
[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配置文件:
[plain] view plain copy
[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:编辑虚拟机配置文件:
[plain] view plain copy
[root@mastercl ~]# virsh edit centos7