1、VMware虚拟机迁移到KVM环境中
1.1、准备好VMware中的vmdk文件
[root@Centos7 ~]# mkdir /data/vmdk
[root@Centos7 ~]# cd /data/vmdk/
[root@Centos7 vmdk]# ll
total 4005120
-rw-r--r-- 1 root root 4101242880 Jul 21 21:21 Ubuntu1804.vmdk
1.2、转换磁盘文件格式
使用到qemu-img命令,这个命令不仅可以创建磁盘,还可进行磁盘格式的转换,qemu-img加上convert指令,可以将源文件转换为指定格式的磁盘文件。
[root@Centos7 vmdk]# qemu-img -h #查看命令的帮助
qemu-img version 1.5.3, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility
Command syntax:
check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename
create [-q] [-f fmt] [-o options] filename [size]
commit [-q] [-f fmt] [-t cache] filename
compare [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1 filename2
convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename
info [-f fmt] [--output=ofmt] [--backing-chain] filename
map [-f fmt] [--output=ofmt] filename
snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename
rebase [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename
resize [-q] filename [+ | -]size
amend [-q] [-f fmt] [-t cache] -o options filename
Command parameters:
'filename' is a disk image filename
'fmt' is the disk image format. It is guessed automatically in most cases
'cache' is the cache mode used to write the output disk image, the valid
options are: 'none', 'writeback' (default, except for convert), 'writethrough',
'directsync' and 'unsafe' (default for convert)
'src_cache' is the cache mode used to read input disk images, the valid
options are the same as for the 'cache' option
'size' is the disk image size in bytes. Optional suffixes
'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M),
'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 1024P) are
supported. 'b' is ignored.
'output_filename' is the destination disk image filename
'output_fmt' is the destination format
'options' is a comma separated list of format specific options in a
name=value format. Use -o ? for an overview of the options supported by the
used format
'-c' indicates that target image must be compressed (qcow format only)
'-u' enables unsafe rebasing. It is assumed that old and new backing file
match exactly. The image doesn't need a working backing file before
rebasing in this case (useful for renaming the backing file)
'-h' with or without a command shows this help and lists the supported formats
'-p' show progress of command (only certain commands)
'-q' use Quiet mode - do not print any output (except errors)
'-S' indicates the consecutive number of bytes (defaults to 4k) that must
contain only zeros for qemu-img to create a sparse image during
conversion. If the number of bytes is 0, the source will not be scanned for
unallocated or zero sectors, and the destination image will always be
fully allocated
'--output' takes the format in which the output must be done (human or json)
'-n' skips the target volume creation (useful if the volume is created
prior to running qemu-img)
Parameters to check subcommand:
'-r' tries to repair any inconsistencies that are found during the check.
'-r leaks' repairs only cluster leaks, whereas '-r all' fixes all
kinds of errors, with a higher risk of choosing the wrong fix or
hiding corruption that has already occurred.
Parameters to snapshot subcommand:
'snapshot' is the name of the snapshot to create, apply or delete
'-a' applies a snapshot (revert disk to saved state)
'-c' creates a snapshot
'-d' deletes a snapshot
'-l' lists all snapshots in the given image
Parameters to compare subcommand:
'-f' first image format
'-F' second image format
'-s' run in Strict mode - fail on different image size or sector allocation
Supported formats: vvfat vpc vmdk vhdx vdi ssh sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsi gluster dmg tftp ftps ftp https http cloop bochs blkverify blkdebug
开始转换磁盘文件格式
[root@Centos7 vmdk]# qemu-img convert -f vmdk -O qcow2 Ubuntu1804.vmdk Ubuntu1804.qcow2
[root@Centos7 vmdk]# ll -h
total 12G
-rw-r--r-- 1 root root 3.8G Jul 21 21:23 Ubuntu1804.qcow2
-rw-r--r-- 1 root root 3.9G Jul 21 21:21 Ubuntu1804.vmdk
[root@Centos7 vmdk]# ll -h /var/lib/libvirt/images/
total 20G
-rw-r--r-- 1 root root 2.2G Jul 21 17:22 zg-test2.qcow2
-rw-r--r-- 1 root root 2.2G Jul 21 18:03 zg-test3.qcow2
-rw------- 1 root root 2.1G Jul 21 17:02 zg-test-clone.qcow2
-rw-r--r-- 1 root root 2.2G Jul 21 16:20 zg-test.qcow2
-rw-r--r-- 1 root root 10G Jul 21 10:15 zg-test.raw
-rw-r--r-- 1 root root 9.8G Jul 21 14:32 zg-window.qcow2
[root@Centos7 vmdk]# mv Ubuntu1804.qcow2 /var/lib/libvirt/images/
1.3、开始使用virt-manager工具导入文件
刚刚使用qemu-img命令已经切换了磁盘格式了,现在就使用virt-manager工具把文件导入后复原虚拟机。
[root@Centos7 vmdk]# ll -h /var/lib/libvirt/images/
total 28G
-rw-r--r-- 1 root root 3.8G Jul 21 21:23 Ubuntu1804.qcow2
-rw-r--r-- 1 root root 2.2G Jul 21 17:22 zg-test2.qcow2
-rw-r--r-- 1 root root 2.2G Jul 21 18:03 zg-test3.qcow2
-rw------- 1 root root 2.1G Jul 21 17:02 zg-test-clone.qcow2
-rw-r--r-- 1 root root 2.2G Jul 21 16:20 zg-test.qcow2
-rw-r--r-- 1 root root 10G Jul 21 10:15 zg-test.raw
-rw-r--r-- 1 root root 9.8G Jul 21 14:32 zg-window.qcow2
[root@Centos7 vmdk]# virt-manager
1.4、验证迁移的虚拟机是否可以正常使用
使用xshell连接这个虚拟机是可以正常连接的。