以映像文件方式保存的虚拟机复制非常方便.
只要拷贝xen vm的img镜像文件和配置文件,并修改相应配置文就可以了
1.关闭虚拟机
xm shutdown vm1
2.复制虚拟机映像文件和配置文件
\cp /opt/vm1/vm1.img /opt/vm1/vm2.img
\cp /etc/xen/vm1 /etc/xen/vm2
3.修改虚拟机配置文件
vi /etc/xen/vm2
- name = "vm1"
- uuid = "85386e79-9f79-e243-9b62-3c9da736ae9f"
- maxmem = 2048
- memory = 2048
- vcpus = 2
- bootloader = "/usr/bin/pygrub"
- on_poweroff = "destroy"
- on_reboot = "restart"
- on_crash = "restart"
- disk = [ "tap:aio:/opt/vm1/vm1.img,xvda,w" ]
- vif = [ "mac=00:16:36:47:a2:89,bridge=virbr0,script=vif-bridge" ]
修改name,uuid,mac保持唯一,通常将最后一位加1,修改disk路径.
修改后的配置
- name = "vm2"
- uuid = "85386e79-9f79-e243-9b62-3c9da736ae0f"
- maxmem = 2048
- memory = 2048
- vcpus = 2
- bootloader = "/usr/bin/pygrub"
- on_poweroff = "destroy"
- on_reboot = "restart"
- on_crash = "restart"
- disk = [ "tap:aio:/opt/vm1/vm2.img,xvda,w" ]
- vif = [ "mac=00:16:36:47:a2:80,bridge=virbr0,script=vif-bridge" ]
4.启动并进入虚拟机
vm create vm2 -c
5.修改主机名
5.1 hostname vm2
5.2 vi /etc/sysconfig/network
5.3 vi /etc/hosts
6.修改网卡ip和mac,和xen配置对应
vi /etc/sysconfig/network-scripts/ifcfg-eth0
- DEVICE=eth0
- BOOTPROTO=static
- BROADCAST=192.168.122.255
- HWADDR=00:16:36:47:A2:80
- IPADDR=192.168.122.12
- NETMASK=255.255.255.0
- NETWORK=192.168.122.0
- ONBOOT=yes
7.重启网络,完成修改
/etc/init.d/network restart
8.测试
8.1 ctrl+]退出虚拟机
8.2启动"vm1"虚拟机
8.3测试vm1网络
ping 192.168.122.11
8.4测试vm2网络
ping 192.168.122.12
8.5测试虚拟机之间的网络
vm console vm2
ping 192.168.122.11
阅读(1297) | 评论(0) | 转发(0) |