器量大者,福泽必厚
全部博文(587)
分类: LINUX
2013-01-17 14:58:07
1:kvm克隆一个虚拟机
[root@nfs data]# virt-clone -o win2003 -n xp1 -f /home/data/xp1.img
ERROR Domain with devices to clone must be paused or shutoff. ##如果要想克隆虚拟机,原虚拟机必须处于关闭状态
[root@nfs data]# virt-clone -o win2003 -n xp1 -f /home/data/xp1.img ##克隆过程
Cloning win2003.img | 10 GB 01:552:显示所有的虚拟机
[root@nfs data]# virsh list ##只显示运行状态下的虚拟机
Id Name State
----------------------------------
[root@nfs data]# virsh list --all ##机器上有的虚拟机,无论是否在工作
Id Name State
----------------------------------
- vm01 shut off
- win2003 shut off
- win20031 shut off
- xp shut off
- xp1 shut off
关于state的详细介绍:
kvm life cycle介绍:
3:修改kvm中虚拟机的内存大小
[root@nfs ~]# virsh edit vm01 ##注意vi直接编辑不生效
修改为1.5G
[root@nfs ~]# expr 1536 \* 1024
1572864
[root@nfs ~]# virsh list
Id Name State
----------------------------------
1 win2003 running
3 vm01 running
[root@vm01 liuxiaojie]# free -m
total used free shared buffers cached
Mem: 1505 618 886 0 29 361
-/+ buffers/cache: 227 1277
Swap: 2000 0 2000
4:强制关掉宿主机导致宿主机开机后不能启动vm
解决方法:
[root@nfs ~]# virsh undefine vm01
[root@nfs ~]# virsh managedsave-remove vm01
[root@nfs ~]# virsh start vm01
5:修改域名
[root@nfs qemu]# ls
networks web01.xml win20031.xml win2003.xml xp.xml
[root@nfs qemu]# cp win20031.xml mywin2003.xml
[root@nfs qemu]# virsh undefine win20031 ##在配置文件里删除相关配置
Domain win20031 has been undefined
[root@nfs qemu]# vi mywin2003.xml
........
........
"mywin2003.xml" 72L, 2348C written
[root@nfs qemu]# virsh define mywin2003.xml
Domain mywin2003 defined from mywin2003.xml
[root@nfs qemu]# virsh list --all ##显然win20031
Id Name State
----------------------------------
1 win2003 running
3 vm01 running
- mywin2003 shut off
- xp shut off
6:删除一个虚拟机vm01
[root@nfs qemu]# virsh undefine vm01
[root@nfs qemu]# rm -f /home/data/vm01.img
7: 暂停一个虚拟机,挂起的虚拟机无法正常工作
在windows窗口中一直ping web01 的地址,地址一直是通的, 当执行完virsh suspend web01 ,网络突然就断了
When a guest is in a suspended state, it consumes system RAM but not processor resources. Disk and
network I/O does not occur while the guest is suspended. This operation is immediate and the guest can be restarted with the resume option.
8:Unpausing 一个domain ,见附件
执行virsh resume web01 后,ping 立即恢复正常!
9:执行一个guest的快照
注意web01的文件格式不能是raw,否则是不支持快照的!
10:显示快照
[root@nfs web01]# virsh snapshot-list web01
见附件:
11:删除一个快照:
[root@nfs web01]# virsh snapshot-delete web01 web01.snap4
12:删除一个域
[root@nfs web01]# virsh list --all
Id Name State
----------------------------------
1 web01 running ##处于工作状态
- myweb01 shut off
- myweb03 shut off
- mywin2003 shut off
- myxp shut off
- xp shut off
[root@nfs web01]# virsh undefine web01 ##处于工作状态也能删除!
Domain web01 has been undefined
[root@nfs web01]# virsh list
Id Name State
----------------------------------
1 web01 running
[root@nfs web01]# virsh destroy web01
Domain web01 destroyed
[root@nfs web01]# virsh list --all ##web01已经没有了!
Id Name State
----------------------------------
- myweb01 shut off
- myweb03 shut off
- mywin2003 shut off
- myxp shut off
- xp shut off
[root@nfs web01]# virsh define web01
error: Failed to open file 'web01': No such file or directory
13:启动虚拟机的两种方式:
# virsh start MyNewVM或
# virsh create /path/to/MyNewVM.xml见附件:
14:stopping or rebooting a domain
To stop running domain just run:
# virsh shutdown
To reboot a persistent domain:
# virsh reboot
Rebooting a transient domain is not possible, since right after shutdown are transient domains also undefined.
An inelegant shutdown, also known as hard-stop:
# virsh destroy
This is equivalent to unplugging the power cable.
This command does an immediate ungraceful shutdown and stops the specified guest. Using virsh
destroy can corrupt guest file systems. Use the destroy option only when the guest is unresponsive.
15:查看某个guest的信息:
[root@nfs init.d]# virsh dominfo nodeA 见附件:
16:查看物理机的相关信息:
[root@nfs init.d]# virsh nodeinfo
17:生成一个domain的xml文件(配置文件)
[root@nfs data]# virsh dumpxml nodeA >nodeAback.xml 见附件
18:Save a guest Save the current state of a guest to a file using the virsh command:
19:restore a guest