Xen使用记录 - 使用xen-tools复制VM

使用Xen的笔记。


使用环境:

- ubuntu 14.04 (trusty)

- Xen 4.4

- xl / lvm2


安装xen vm (PV) 的本质是: 

1. 将文件系统拷贝到虚拟机所在的文件目录或者VG(如果使用LVM安装)

2. 配置虚拟机的参数包括:通知启动程序kernel和RAM disk的位置,分配的存储空间,网络配置等 

3. 使用xl或其他管理工具启动虚拟机


因此复制虚拟机的过程也类似。区别只是在第一步里,需要从另外一个已经装好的虚拟机的安装目录或者LV里面copy所有的文件。另外,启动前还需要额外的一步 - 修改原虚拟机中的各项配置。


以下是可能需要修改的配置:

1. /etc/fstab - This file contains the mappings between physical and network devices and filesystems. This will need to be changed to reflect the disk configuration used by the guest system.


2. /etc/passwd - Contains password information for all user and application accounts on the host system. It is important to remove the entries for any accounts which will not be required on the guest system.


3. /etc/group - This file contains information about user and application groups and, as with the passwd file, should be modified to remove any groups not required in the guest system.


4. /etc/hosts - Contains information about the local host and other hosts on the network. Be sure to change the name of the local host to match the name to be used by the guest operating system.


5. /etc/sysconfig/network or /etc/network/interfaces - Depending on which Linux distribution you are using, one of these files will contain networking information such as the host name and possibly a static IP address. Be sure to modify this file to remove any conflicts between the host and guest operating systems.


6. /etc/exports - Contains information about any filesystems local to the host operating system which are exported for NFS access to remote systems. This should be modified to reflect any exports needed for the guest OS.


xen-tools是一个简化以上步骤的小工具包,里面包含几个工具。下面步骤是用xen-tools中的xen-create-image来复制一个虚拟机的一个例子:

1. 关掉正在运行的虚拟机。也有建议使用lvcreate - s先生成一个快照。然后使用其生成新的虚拟机。两种方法都行。后一种方法需要多一个安装完删除快照的步骤。

sudo xl shutdown vm_orig

2. 将vm_orig的LV mount到一个目录:

sudo mount /dev/my_vg/vm_orig-disk /mnt/vm_template

3. 使用xen-create-image复制一个虚拟机

sudo xen-create-image --hostname=vm_copy --size=20G --memory=512M --dist=trusty --lvm=my_vg --vcpus=2 --arch=amd64 --install-method=copy --install-source=/mnt/vm_template --dhcp --kernel=/mnt/vm_template/boot/vmlinuz-3.13.0-32-generic --initrd=/mnt/vm_template/initrd.img-3.13.0-32-generic

4.启动刚生成的虚拟机

sudo xl create /etc/xen/vm_copy.cfg -c



你可能感兴趣的:(xen)