代码之家  ›  专栏  ›  技术社区  ›  okutane

如何为virtualbox或vmplayer将平面原始磁盘映像转换为vmdk?

  •  58
  • okutane  · 技术社区  · 16 年前

    我有一些旧Linux文件系统的平面文件格式的旧映像。它们可供用户使用 Bochs Virtual Box

    7 回复  |  直到 6 年前
        1
  •  96
  •   ib. Evgeny Shavlyugin    4 年前

    首先,安装QEMU。在基于Debian的发行版(如Ubuntu)上,运行:

    $ apt-get install qemu
    

    然后运行以下命令:

    $ qemu-img convert -O vmdk imagefile.dd vmdkname.vmdk
    

    我假设一个平面磁盘映像是一个 dd -风格形象。convert操作还处理许多其他格式。

    有关 qemu-img 命令,请参见

    $ qemu-img -h
    
        2
  •  91
  •   Lloeki    12 年前

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

    在没有参数的情况下运行它,以获得一些有趣的细节(尤其是 --variant 旗帜):

    VBoxManage convertfromraw
    
        3
  •  9
  •   Anonymous    7 年前

    因此,为了创建一个附加的vmdk图元文件,它引用原始dd图像。

    首先,以通常的方式使用dd创建图像:

    dd bs=512 count=60000 if=/dev/zero of=usbdrv.img
    

    然后,您可以为VirtualBox创建一个引用此图像的文件:

    VBoxManage internalcommands createrawvmdk -filename "usbdrv.vmdk" -rawdisk "usbdrv.img"
    

    您可以按原样在VirtualBox中使用此映像,但根据来宾操作系统的不同,它可能不会立即可见。例如,我在一个Windows来宾操作系统上尝试使用此方法,我必须执行以下操作才能给它一个驱动器号:

    • 转到控制面板。
    • 去计算机管理。
    • 转到左侧面板中的存储\磁盘管理。
    • 您将在这里看到您的磁盘。在上面创建一个分区并格式化它。小卷使用FAT,大卷使用FAT32或NTFS。

    sfdisk -d usbdrv.img
    

    答复:

    label: dos
    label-id: 0xd367a714
    device: usbdrv.img
    unit: sectors
    
    usbdrv.img1 : start=          63, size=       48132, type=4
    

    注意分区的起始位置:63。在下面的命令中,我使用了loop4,因为它是我的案例中第一个可用的循环设备。

    sudo losetup -o $((63*512)) loop4 usbdrv.img
    mkdir usbdrv
    sudo mount /dev/loop4 usbdrv
    ls usbdrv -l
    

    total 0
    -rwxr-xr-x. 1 root root 0 Apr  5 17:13 'Test file.txt'
    

        4
  •  6
  •   xhafan    14 年前

    在windows上,使用 https://github.com/Zapotek/raw2vmdk 将dd或winhex创建的原始文件转换为vmdk。raw2vmdk v0.1.3.2有一个错误-创建vmdk文件后,编辑vmdk文件并修复原始文件的路径(在我的情况下,不是D:\Temp\flash_16gb.raw(由winhex创建),生成的路径是D:Tempflash_16gb.raw)。然后,在vmware虚拟机版本6.5-7中打开它(5.1拒绝连接vmdk硬盘)。你好!

        5
  •  1
  •   Paul Svirin Paul Svirin    15 年前

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

        6
  •  1
  •   Wolfgang Fahl    10 年前

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

    在my environment 2 x Ubuntu 12.04 LTS中,采取了以下步骤:

    • 3小时可获得60 GB分区的47 GB磁盘转储
    • 20分钟解包到一个60 GByte dd文件
    #!/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 e.g. somehost.somedomain
    #  2: disk e.g. sda
    #  3: target e.g. 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 e.g. frodo.lotr.org"  
      echo "            you need ssh and sudo privileges on that host"
      echo "
      echo "    device: the disk to dump from e.g. 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
    
        7
  •  0
  •   labgeek    6 年前

    https://sourceforge.net/projects/dd2vmdk/ 也dd2vmdk是一个基于*nix的程序,允许您通过拍摄原始映像、分析主引导记录(物理扇区0)并获取创建vmdk文件所需的特定信息来装载原始磁盘映像(由dd、dcfldd、dc3dd、ftk imager等创建)。

    就个人而言,imo Qemu和Zapotek的raw2vmdk工具是将dd转换为VMDK的最佳总体选择。

    披露:我是这个项目的作者。