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

发布于 2024-07-12 05:13:52 字数 261 浏览 5 评论 0原文

我有一些旧 Linux 文件系统的平面文件格式的旧映像。 它们可以被 Bochs 使用,但我需要使用 虚拟盒子。 Virtual Box 无法使用这种格式的图像,因此我需要将这些图像从平面文件转换为 .vmdk 文件格式。 有什么办法可以做到这一点吗?

I have some old images of old Linux filesystems in flat file format. they can be used by Bochs, but I need to run them with Virtual Box. Virtual Box cannot use images in this format, so I need to convert these images from flat file to .vmdk file format. Is there any way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

溺渁∝ 2024-07-19 05:13:52

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

$ apt-get install qemu

然后运行以下命令:

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

我假设平面磁盘映像是 dd 样式的映像。 转换操作还可以处理许多其他格式。

有关 qemu-img 命令的更多信息,请参阅以下命令的输出

$ qemu-img -h

First, install QEMU. On Debian-based distributions like Ubuntu, run:

$ apt-get install qemu

Then run the following command:

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

I’m assuming a flat disk image is a dd-style image. The convert operation also handles numerous other formats.

For more information about the qemu-img command, see the output of

$ qemu-img -h
写给空气的情书 2024-07-19 05:13:52

由于问题提到了 VirtualBox,所以这个目前有效:

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

在不带参数的情况下运行它以获得一些有趣的细节(特别是 --variant 标志):

VBoxManage convertfromraw

Since the question mentions VirtualBox, this one works currently:

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

Run it without arguments for a few interesting details (notably the --variant flag):

VBoxManage convertfromraw
深居我梦 2024-07-19 05:13:52

回答 TJJ:但是是否也可以在不复制整个文件的情况下执行此操作?因此,只是为了以某种方式创建一个额外的 vmdk-metafile,它引用原始 dd-image。

是的,这是可能的。 以下是如何在 VirtualBox 中使用平面磁盘映像:

首先,以通常的方式使用 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。

您可能想访问 Linux 上的文件。 首先将其从来宾操作系统中卸载,然后将其从虚拟机中删除。 现在我们需要创建一个引用该分区的虚拟设备。

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'

耶!

To answer TJJ: But is it also possible to do this without copying the whole file? So, just to somehow create an additional vmdk-metafile, that references the raw dd-image.

Yes, it's possible. Here's how to use a flat disk image in VirtualBox:

First you create an image with dd in the usual way:

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

Then you can create a file for VirtualBox that references this image:

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

You can use this image in VirtualBox as is, but depending on the guest OS it might not be visible immediately. For example, I experimented on using this method with a Windows guest OS and I had to do the following to give it a drive letter:

  • Go to the Control Panel.
  • Go to Administrative Tools.
  • Go to Computer Management.
  • Go to Storage\Disk Management in the left side panel.
  • You'll see your disk here. Create a partition on it and format it. Use FAT for small volumes, FAT32 or NTFS for large volumes.

You might want to access your files on Linux. First dismount it from the guest OS to be sure and remove it from the virtual machine. Now we need to create a virtual device that references the partition.

sfdisk -d usbdrv.img

Response:

label: dos
label-id: 0xd367a714
device: usbdrv.img
unit: sectors

usbdrv.img1 : start=          63, size=       48132, type=4

Take note of the start position of the partition: 63. In the command below I used loop4 because it was the first available loop device in my case.

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

Response:

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

Yay!

年少掌心 2024-07-19 05:13:52

在 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 硬盘驱动器)。 哎哟!

On windows, use https://github.com/Zapotek/raw2vmdk to convert raw files created by dd or winhex to vmdk. raw2vmdk v0.1.3.2 has a bug - once the vmdk file is created, edit the vmdk file and fix the path to the raw file (in my case instead of D:\Temp\flash_16gb.raw (created by winhex) the generated path was D:Tempflash_16gb.raw). Then, open it in a vmware virtual machine version 6.5-7 (5.1 was refusing to attach the vmdk harddrive). howgh!

今天小雨转甜 2024-07-19 05:13:52

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

Maybe you should try using Starwind V2V Converter, you can get it from here - http://www.starwindsoftware.com/converter. It also supports IMG disk format and performs sector-by sector conversion between IMG, VMDK or VHD into and from any of them without making any changes to source image. This tool is free :)

鸢与 2024-07-19 05:13:52

krosenvold的答案启发了以下脚本,该脚本执行以下操作:

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

脚本可重新启动并检查中间文件是否存在。 它还使用 pv 和 qemu-img -p 显示每个步骤的进度。

在我的环境 2 x Ubuntu 12.04 LTS 中,步骤如下:

  • 3 小时获取 60 GB 分区的 47 GB 磁盘转储
  • 20 分钟解压到 60 GB dd 文件
  • 45 分钟创建 vmware 文件
#!/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

krosenvold's answer inspired the following script which does the following:

  • get the dd dump via ssh from a remote server (as gz file)
  • unzip the dump
  • convert it to vmware

the script is restartable and checks the existence of the intermediate files. It also uses pv and qemu-img -p to show the progress of each step.

In my environment 2 x Ubuntu 12.04 LTS the steps took:

  • 3 hours to get a 47 GByte disk dump of a 60 GByte partition
  • 20 minutes to unpack to a 60 GByte dd file
  • 45 minutes to create the vmware file
#!/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
请叫√我孤独 2024-07-19 05:13:52

Just to give you an another option, you could use https://sourceforge.net/projects/dd2vmdk/ as well. dd2vmdk is a *nix-based program that allows you to mount raw disk images (created by dd, dcfldd, dc3dd, ftk imager, etc) by taking the raw image, analyzing the master boot record (physical sector 0), and getting specific information that is need to create a vmdk file.

Personally, imo Qemu and the Zapotek's raw2vmdk tools are the best overall options to convert dd to vmdks.

Disclosure: I am the author of this project.

余罪 2024-07-19 05:13:52

我一直在使用:

dd2vmdk
https://sourceforge.net/projects/dd2vmdk/
https://github.com/labgeek/dd2vmdk

raw2vmdk
https://sourceforge.net/projects/raw2vmdk/
https://github.com/Zapotek/raw2vmdk

raw2vmdk 在我看来效果更好,但它的 java..这样,Raw、IMG、ISO 和任何未压缩的 DD 映像都可以使用。

事实证明,vmdk 文件可以引用其他文件和数据。 这些类型的 vmdk 文件是使用 raw2vmdk 创建的。 我已经轻松安装了 oVirt Raw 磁盘、DD Raw 磁盘、ISO 文件等。

这是用于通过 raw2vmdk 制作文本 vmdk 文件的 tpl 文件:

# Disk DescriptorFile
version=1
encoding="UTF-8"
CID=fffffffe
parentCID=ffffffff
isNativeSnapshot="no"
createType="monolithicFlat"

# Extent description
RW [numOfSectors] FLAT "[imgLocation]" 0

# The Disk Data Base
#DDB

ddb.virtualHWVersion = "7"
ddb.longContentID = "29075898903f9855853610dffffffffe"
ddb.uuid = "60 00 C2 91 8e 73 27 62-43 58 3b f8 05 ae 2e a0"
ddb.geometry.cylinders = "[numOfCylinders]"
ddb.geometry.heads = "[headsPerTrack]"
ddb.geometry.sectors = "[sectorsPerTrack]"
ddb.adapterType = "[diskType]"

I've been using:

dd2vmdk
https://sourceforge.net/projects/dd2vmdk/
https://github.com/labgeek/dd2vmdk

and

raw2vmdk
https://sourceforge.net/projects/raw2vmdk/
https://github.com/Zapotek/raw2vmdk

raw2vmdk works better imo, but its java.. Either way, Raw, IMG, ISO, and any uncompressed DD image will work.

it turns out vmdk files can reference other files, with the data. these type of vmdk files are created with raw2vmdk. I've easily mounted oVirt Raw disks, DD Raw Disks, ISO files like this.

This is the tpl file that is used to make the text vmdk files via raw2vmdk:

# Disk DescriptorFile
version=1
encoding="UTF-8"
CID=fffffffe
parentCID=ffffffff
isNativeSnapshot="no"
createType="monolithicFlat"

# Extent description
RW [numOfSectors] FLAT "[imgLocation]" 0

# The Disk Data Base
#DDB

ddb.virtualHWVersion = "7"
ddb.longContentID = "29075898903f9855853610dffffffffe"
ddb.uuid = "60 00 C2 91 8e 73 27 62-43 58 3b f8 05 ae 2e a0"
ddb.geometry.cylinders = "[numOfCylinders]"
ddb.geometry.heads = "[headsPerTrack]"
ddb.geometry.sectors = "[sectorsPerTrack]"
ddb.adapterType = "[diskType]"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文