如何将flat raw磁盘映像转换为virtualbox或vmplayer的vmdk?

我有一些旧的Linux映像以平面文件格式分发,他们可以被bochs虚拟机使用,但是我需要使用Sun Virtual Box来运行它们。 Virtual Box不能使用这种格式的图像,所以我需要将这些图像从平面文件转换为.vmdk文件格式。 有没有办法做到这一点?

apt-get install qemu (在debian / ubuntu上安装QEMU)

然后运行以下命令: qemu-img convert -O vmdk imagefile.dd vmdkname.vmdk

我假设一个扁平磁盘映像是一个dd样式的映像。 转换操作也处理许多其他格式。

由于这个问题提到VirtualBox,目前这个工作:

 VBoxManage convertfromraw imagefile.dd vmdkname.vmdk --format VMDK 

运行它没有参数一些有趣的细节(值得注意的是 – – --variant标志):

 VBoxManage convertfromraw 

在Windows上,使用https://github.com/Zapotek/raw2vmdk将由dd或winhex创build的原始文件转换为vmdk。; raw2vmdk v0.1.3.2有一个bug – 一旦vmdk文件被创build,编辑vmdk文件并修复原始文件的path(在我的情况下,而不是D:\ Temp \ flash_16gb.raw(由winhex创build))生成path是D:Tempflash_16gb.raw)。 然后,在vmware虚拟机版本6.5-7(5.1拒绝附加vmdk硬盘)中打开它。 howgh!

也许你应该尝试使用Starwind V2V Converter,你可以从这里得到它 – http://www.starwindsoftware.com/converter 。 它还支持IMG磁盘格式,并在IMG,VMDK或VHD之间进行扇区间的转换,而无需对源映像进行任何更改。 这个工具是免费的:)

krosenvold的回答启发了以下脚本:

  • 通过ssh从远程服务器获取dd转储(作为gz文件)
  • 解压缩转储
  • 将其转换为vmware

该脚本可重新启动并检查中间文件的存在。 它也使用pv和qemu-img -p来显示每一步的进度。

在我的环境中2 x Ubuntu 12.04 LTS的步骤是:

  • 3小时才能获得60 GB的分区的47 GByte磁盘转储
  • 20分钟解压缩到一个60 GB的dd文件
  • 45分钟来创buildvmware文件
 #!/bin/bash # get a dd disk dump and convert it to vmware # see http://stackoverflow.com/questions/454899/how-to-convert-flat-raw-disk-image-to-vmdk-for-virtualbox-or-vmplayer # Author: wf 2014-10-1919 # # get a dd dump from the given host's given disk and create a compressed # image at the given target # # 1: host eg somehost.somedomain # 2: disk eg sda # 3: target eg image.gz # # http://unix.stackexchange.com/questions/132797/how-to-use-ssh-to-make-a-dd-copy-of-disk-a-from-host-b-and-save-on-disk-b getdump() { local l_host="$1" local l_disk="$2" local l_target="$3" echo "getting disk dump of $l_disk from $l_host" ssh $l_host sudo fdisk -l | egrep "^/dev/$l_disk" if [ $? -ne 0 ] then echo "device $l_disk does not exist on host $l_host" 1>&2 exit 1 else if [ ! -f $l_target ] then ssh $l_host "sudo dd if=/dev/$disk bs=1M | gzip -1 -" | pv | dd of=$l_target else echo "$l_target already exists" fi fi } # # optionally install command from package if it is not available yet # 1: command # 2: package # opt_install() { l_command="$1" l_package="$2" echo "checking that $l_command from package $l_package is installed ..." which $l_command if [ $? -ne 0 ] then echo "installing $l_package to make $l_command available ..." sudo apt-get install $l_package fi } # # convert the given image to vmware # 1: the dd dump image # 2: the vmware image file to convert to # vmware_convert() { local l_ddimage="$1" local l_vmwareimage="$2" echo "converting dd image $l_image to vmware $l_vmwareimage" # convert to VMware disk format showing progess # see http://manpages.ubuntu.com/manpages/precise/man1/qemu-img.1.html qemu-img convert -p -O vmdk "$l_ddimage" "$l_vmwareimage" } # # show usage # usage() { echo "usage: $0 host device" echo " host: the host to get the disk dump from eg frodo.lotr.org" echo " you need ssh and sudo privileges on that host" echo " echo " device: the disk to dump from eg sda" echo "" echo " examples: echo " $0 frodo.lotr.org sda" echo " $0 gandalf.lotr.org sdb" echo "" echo " the needed packages pv and qemu-utils will be installed if not available" echo " you need local sudo rights for this to work" exit 1 } # check arguments if [ $# -lt 2 ] then usage fi # get the command line parameters host="$1" disk="$2" # calculate the names of the image files ts=`date "+%Y-%m-%d"` # prefix of all images # .gz the zipped dd # .dd the disk dump file # .vmware - the vmware disk file image="${host}_${disk}_image_$ts" echo "$0 $host/$disk -> $image" # first check/install necessary packages opt_install qemu-img qemu-utils opt_install pv pv # check if dd files was already loaded # we don't want to start this tedious process twice if avoidable if [ ! -f $image.gz ] then getdump $host $disk $image.gz else echo "$image.gz already downloaded" fi # check if the dd file was already uncompressed # we don't want to start this tedious process twice if avoidable if [ ! -f $image.dd ] then echo "uncompressing $image.gz" zcat $image.gz | pv -cN zcat > $image.dd else echo "image $image.dd already uncompressed" fi # check if the vmdk file was already converted # we don't want to start this tedious process twice if avoidable if [ ! -f $image.vmdk ] then vmware_convert $image.dd $image.vmdk else echo "vmware image $image.vmdk already converted" fi