[root@hyperStor ~]# virsh list --all
Id Name State
----------------------------------
5 node1 running
6 node2 running
12 rhcexam running
[root@hyperStor ~]# virt-viewer 12 //连接ID为12的rhcexam虚拟机,virt-viewer后接rhcexam也可以
3.virsh 命令管理虚拟机
[root@hyperStor ~]# virsh list //列出所有运行的虚拟机
[root@hyperStor ~]# virsh list --all //列出所有虚拟机,包括未运行的
[root@hyperStor ~]# virsh shutdown id|name //正常关闭虚拟机
[root@hyperStor ~]# virsh destroy id|name //强制关闭虚拟机
[root@hyperStor ~]# virsh undefine id|name //从虚拟机列表中删除虚拟机【不删除文件】
[root@hyperStor ~]# virsh start id|name //启动虚拟机
[root@hyperStor ~]# virsh suspend id|name //挂起虚拟机
[root@hyperStor ~]# virsh resume id|name //恢复虚拟机
[root@hyperStor ~]# virsh reboot id|name //重启虚拟机
[root@hyperStor images]# virsh autostart 16 //将id为16的虚拟机设置为自动启动【随着物理机启动】
Domain 16 marked as autostarted
[root@hyperStor ~]# virsh vol-clone /var/lib/libvirt/images/rhcexam.img rhcexam-clone.img //克隆镜像文件
Vol rhcexam-clone.img cloned from rhcexam.img
红色字体路径必须指定,后面的名称不用指定路径,默认跟原始镜像一个路径下
4. qemu-img 工具
给虚拟机做快照
[root@hyperStor ~]# qemu-img snapshot -c rhce-sp1 /var/lib/libvirt/images/rhcexam.img //创建镜像
[root@hyperStor ~]# qemu-img snapshot -l /var/lib/libvirt/images/rhcexam.img //列出镜像快照
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 rhce-sp1 0 2013-03-22 10:26:06 00:00:00.000
[root@hyperStor ~]# qemu-img snapshot -a rhce-sp1 /var/lib/libvirt/images/rhcexam.img //恢复快照
[root@hyperStor ~]# qemu-img snapshot -d rhce-sp1 /var/lib/libvirt/images/rhcexam.img //删除快照