79
50
Is is possible to convert a .vdi file into a .iso that can be burned to a cd or dvd and make it like an installer. Or Is it possible to convert virtual machines to physical environments?
79
50
Is is possible to convert a .vdi file into a .iso that can be burned to a cd or dvd and make it like an installer. Or Is it possible to convert virtual machines to physical environments?
64
Yes, and no.
You can convert a VDI into a disk image with the VBoxManage tool. This command clones a registered virtual disk image to another image file. If you want to convert your virtual disk to another format, this is the official VirtualBox tool to use[*].
VBoxManage clonehd file.vdi output.img --format RAW
VBoxManage internalcommands converttoraw file.vdi output.img
But... that output IMG file isn't an ISO image, and the OS that's installed will not be configured to run from a bootable CD/DVD. You can "burn" (write) the IMG onto a hard drive, and it might boot on bare hardware (eg not in a virtual machine). But it might not, because the OS installed on that IMG is expecting to see the virtual hardware that VirtualBox provides, and you're booting it on real hardware that it isn't expecting.
Some versions of Windows do not handle this situation well; some Linux distributions do. It is sometimes possible to configure an OS (beforehand or afterwards) to migrate it from one environment to the other like this, but specific steps depend completely on the OS being migrated.
On Windows, you may need to specify the full path to the program:
"C:\Program Files\Sun\VirtualBox\VBoxManage.exe" [...]
Add C:\Program Files\Sun\VirtualBox to your PATH to use the short version.
[*] I'm assuming the "--format RAW" option will convert to a standard disk image, as if you'd used the dd command on a physical harddrive. But frankly, I haven't found any documentation that backs this up, so be aware this may not be correct.
[+] I've just tested both commands under VirtualBox 3.1.2. Both output files are identical according to md5sum, but I haven't fully tested the output files.
See also the "All about VDIs" tutorial at the VirtualBox forums.
1Also note that if you manage to get a windows os to booting you will have to reactivate it in most cases. – Kimmax – 2015-09-07T08:55:54.160
What if you were to sysprep /generalize
the virtual install first? This would surely prepare the install to be installed on new hardware (or physical hardware in this case) – Robula – 2016-12-21T09:13:24.053
1
@Pwnna You're copying an img of a hard disk (not just a partition but an entire partition map with partitions). I've done this in the past and remember seeing what this answer describes, unused/unpartitioned space at the end: https://serverfault.com/questions/268889/is-it-possible-to-restore-disk-image-to-a-different-size-hard-disk
– sudo – 2017-07-04T07:34:40.2173What about the size of the VDI? Does that matter? Let's say the VDI size is 20GB and the actually HDD size is 200GB... What would happen? – Pwnna – 2011-12-12T17:49:57.093
That first method "clonehd" seems awefully slow. But the second worked a treat. – Matt H – 2012-09-27T23:16:15.307
21
If your vdi file contains partitions and you want to extract only one of them use the following:
First, as quack quixote said before, convert the vdi file to a raw image file:
# VBoxManage clonehd file.vdi file.raw --format RAW
Then set up a loop device for the image:
# loopdev=$(losetup --show -r -f file.raw)
Use kpartx to create devices for each partition in the raw file:
# apt-get install kpartx
# kpartx -a $loopdev
See which devices we have now. In this example, there's only one device as there's only one partition in the raw image:
# ls /dev/mapper/loop*
/dev/mapper/loop0p1
Now mount it to verify that all works properly:
# mkdir /mnt/part1
# mount /dev/mapper/loop0p1 /mnt/part1
# ls /mnt/part1
# umount /mnt/part1
Use dd to copy the partition contents to a another target partition:
# dd if=/dev/mapper/loop0p1 of=/dev/sda2 bs=1M
After you're done remove the device mappings again:
# kpartx -d file.raw
Is that possible with Windows? – Ehsan – 2016-07-24T14:46:02.920
13
The answer is a definite yes, in case your host and guest system is Linux.
It's done with the packages qemu
and TKLPatch
. You can use both VDI or VMDK files.
Read more:
3+1 "definite" with the caveat "..as long as your guest is linux". and their (your?) solution relies on some TurnKey Linux tools. but the procedure looks sound. (welcome to Super User!) – quack quixote – 2010-02-28T10:54:11.313
5
I tried the VBoxManage clonehd file.vdi output.img --format RAW
from the accepted answer but without much success.
What worked for me with a Windows 8.1 virtual machine on a Windows 7 host is this:
VBoxManage clonehd source.vdi target.vhd --format vhd
1
From @sum: You can try BootICE to replace the 6th step and be sure to install the correct MBR.
– fixer1234 – 2015-11-19T17:24:43.120Thanks. Is BootICE more reliable in some wat than the Windows 8.1 install? Will step 6 I described possibly mess up the MBR? – Jan H – 2015-11-25T12:26:22.013
1
This was posted as an answer by a new user (I believe http://superuser.com/users/523958/sum). It was going to be deleted because it didn't qualify as an answer, so I copied the post and saved it as a comment so it wouldn't be lost. I'm not personally familiar with it.
– fixer1234 – 2015-11-25T16:49:28.4373
I do this process in a very fast, with just two lines of command in Linux:
#
VBoxManage internalcommands converttoraw your_disk_virtual.vmdk your_disk_virtual.img
OR
#
VBoxManage internalcommands converttoraw your_disk_virtual.vdi your_disk_virtual.img
#
mv your_disk_virtual.img your_disk_virtual.iso
My full article: http://www.previsioni.com.br/jailsonjan/?p=389
Would the .img in this case be bootable? – Pumphouse – 2016-04-13T02:53:53.767
I think no. I've seen similar answer from 0-rep user, that seemed easy way, however, turned out useless. – T.Todua – 2017-01-14T22:45:58.090
0
Use the following command to convert:
VBoxManage clonehd CactiEZ-disk1.vmdk output.iso --format VMDK
Here is the output:
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VMDK'. UUID: 7f297ac6-95eb-4814-9237-1acfd6be976c
1
This answer on AskUbuntu.com probably applies to a lot of environments running on Linux host machines: http://askubuntu.com/a/32506/31592
– blong – 2012-10-11T02:42:14.247