CentOS7使用virt-p2v将RHEL6.7的物理机转化为kvm虚拟机

来源:互联网 发布:excel横纵数据互换 编辑:程序博客网 时间:2024/05/16 13:07

CentOS7使用virt-p2v将RHEL6.7的物理机转化为kvm虚拟机


理论知识:

virt-p2v工具是RedHat公司研发的将物理机转化为虚拟机的工具,工具是通过ssh连接物理机和conversion server的。

P2V工作原理:


从2009年开始从RHEL6上有p2v和v2v后,转化过程是:先copy再convert;
到2014年从RHEL7开始转化过程与之前的相反:先convert再copy;

p2v通过ssh连接物理机和conversion server:

通过NBD协议进行数据传输:




准备环境:

待转的物理机P:RHEL6.7
安装有virt-v2v工具的conversion server:CentOS7.2+virt-v2v-1.28.1-1.55.el7.centos.x86_64
下载/制作p2v iso U盘启动:http://oirase.annexia.org/virt-p2v/virt-p2v-livecd-1.28.1-1.49.1.el7.iso

步骤:

1. 配置conversion server上的sshd:
/etc/ssh/sshd_config的AllowTcpForwarding设置为yes;
并保证允许root可登陆ssh;
2. 待转物理机插上U盘,设置U盘启动,进入p2v配置界面:

conversion server填写CentOS7.2的ip,password填写正确,勾选Use sudo;
必须先点test connection来检查ssh连通性,通过后,点击next进入配置虚拟机界面;

根据自己的情况,配置name、vCPUs等;
注意:这里所有的output选项和路径都是conversion server上的:
本人选择-o libvirt,-os p2v,其他默认
勾选enable server-side debugging以便出错时调试;
勾选物理机上的所有硬盘,注意:如果使用U盘启动,不要勾选转化U盘;
其他如网络,removable device(cdrom)等配置默认;
点击start conversion,开始转化;

你可以到conversion server上查看p2v的状态:
# tailf /tmp/virt-p2v-20160329-whskgz0u/virt-v2v-conversion-log.txt 
libguestfs: command: run: \ -rf /tmp/libguestfs709YXs
[ 158.0] Checking if the guest needs BIOS or UEFI to boot
[ 158.0] Copying disk 1/1 to /home/libing/p2v/p2v-sda (raw)
target_file = /home/libing/p2v/p2v-sda
target_format = raw
target_estimated_size = 43952962001
target_overlay = /var/tmp/v2vovl9f9083.qcow2
target_overlay.ov_source = nbd:localhost:60487
qemu-img convert -p -n -f qcow2 -O 'raw' '/var/tmp/v2vovl9f9083.qcow2' '/home/libing/p2v/p2v-sda'
    (11.00/100%)

等待virt-p2v完成,一旦转化成功,你需要关闭物理机,且不应该重新启动它;

整个过程如下:
先生成一个physical.xml:
# cat /tmp/virt-p2v-20160329-whskgz0u/physical.xml
  <devices>
    <disk type="network" device="disk">
      <driver name="qemu" type="raw"/>
      <source protocol="nbd">
        <host name="localhost" port="60487"/>
      </source>
      <target dev="sdb"/>
    </disk>
然后生成一个overlay来保护元数据不被破坏:
# cat /tmp/virt-p2v-20160329-whskgz0u/virt-v2v-conversion-log.txt | grep qemu-img 
qemu-img create -q -f qcow2 -b 'nbd:localhost:60487' -o 'compat=1.1,backing_fmt=raw' /var/tmp/v2vovl9f9083.qcow2
随后打开overlay;
之后检查虚拟机中是否有足够的磁盘空间;
然后进行转化;
最后拷贝数据:
[ 158.0] Copying disk 1/1 to /home/libing/p2v/p2v-sda (raw)
target_file = /home/libing/p2v/p2v-sda
target_format = raw
target_estimated_size = 43952962001
target_overlay = /var/tmp/v2vovl9f9083.qcow2
target_overlay.ov_source = nbd:localhost:60487
qemu-img convert -p -n -f qcow2 -O 'raw' '/var/tmp/v2vovl9f9083.qcow2' '/home/libing/p2v/p2v-sda'
    (100.00/100%)

注意:virt-p2v实际底层是virt-v2v,因此整过过程与v2v类似,其他相关配置请查看我的另一篇关于v2v的blog:
http://blog.csdn.net/lbwlh/article/details/50973023

virt-p2v server就是virt-v2v server,其中主要的工具为:
# rpm -qa | grep -i guestfs
libguestfs-1.28.1-1.55.el7.centos.x86_64
libguestfs-winsupport-7.2-1.el7.x86_64
libguestfs-tools-c-1.28.1-1.55.el7.centos.x86_64

参看文献:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html-single/V2V_Guide/index.html#chap-V2V_Guide-P2V_Migration_Converting_Physical_Machines_to_Virtual_Machines
http://libguestfs.org/virt-p2v.1.html
1 0