如何将硬盘直接克隆到 vdi 映像

如何将硬盘直接克隆到 vdi 映像

我想用我的硬盘制作一个 VirtualBox .vdi 映像。

我在网上找到了一些操作指南,其中描述了如何首先使用 DD 创建 .raw 图像,然后使用 VBoxManage 将 .raw 转换为 .vdi。因此,如果我的硬盘是 1 TB,则此过程(暂时)需要 2TB 的空间来存储 .raw 和 .vdi。

我的可用空间只有 1TB 多一点。有没有办法创建硬盘的 .vdi 映像,而不必先创建 .raw 映像?

答案1

您可以直接使用以下方式创建图像VBoxManage convertfromraw. 首先卸载设备,然后:

VBoxManage convertfromraw /dev/sda MyImage.vdi --format VDI

替换/dev/sda为您想要克隆的任何磁盘或分区。

您可能需要以 root 身份执行此操作才能访问该设备。如果是这样,那么您应该更改完成的映像的所有权。

答案2

我尝试了可接受的解决方案但对我来说失败了:

# VBoxManage convertfromraw /dev/sdg /path/to/file.vdi --format VDI
Converting from raw image file="/dev/sdg" to file="/path/to/file.vdi"...
Creating dynamic image with size 0 bytes (0MB)...
VBoxManage: error: Cannot create the disk image "/path/to/file.vdi": VERR_INVALID_PARAMETER

可能是因为磁盘是通过 USB 连接的,所以无法检测到大小?

因此,我使用以下命令获取磁盘大小fdisk -l

Disk /dev/sdg: 160.0 GB, 160041885696 bytes

然后我使用了 convertfromraw 的 stdin 形式

# dd if=/dev/sdg | VBoxManage convertfromraw stdin /path/to/file.vdi 160041885696 --format VDI
Converting from raw image file="stdin" to file="/path/to/file.vdi"...
Creating dynamic image with size 160041885696 bytes (152628MB)...

答案3

还有其他更安全的方法来创建 Virtualbox 可以使用的当前系统文件。Vdi 是 Virtualbox 特定的文件,通常仅由 VB 从全新虚拟硬盘安装生成。

您还有许多其他选择。

我最近使用 disk2vhd 创建了一个 .VHD(Microsoft 虚拟硬盘),Virtualbox 完美地导入了它。(虽然它是一个 XP 系统)但我认为它与其他操作系统配合得不太好。

另外,还有 Vmwares 转换工具,可以将您的系统导出为 virtualbox 以及其他平台可以使用的多种格式。这类东西有开放标准。

http://www.vmware.com/products/converter/features.html

答案4

相关内容