Is it possible to somehow make VirtualBox directly use a raw partition image for a virtual machine?
By raw partition image, I mean a file that contains a byte-by-byte copy of the partition that I would like to boot from.
I'm not looking to boot from a raw disk image, nor am I looking for a way to boot from a VHD (which isn't raw because it contains other metadata).
Answer
Both of the answers here get you most of the way there, but here's what I ended up finding helpful:
First of all, note that a fixed-size VHD file only contains 1 sector of metadata at the end of the file, which is a lot easier to deal with than a file with metadata the beginning. For booting Linux partition images, a VHD would work just fine. There used to be a tool called
VHDTool
by Microsoft which could instantly append the extra sector of metadata to turn a raw image into a VHD, but it's hard to find a copy online now. There are probably other tools that could do the same, or you could make a different image of the same size and transfer the appended sector (wasteful, but gets the job done).Otherwise, a VMDK file will do what you need, because it's just a text file (with LF line endings at least in my case, but maybe CRLF will work too) that can reference other files to use as the chunk. Here's the format one of my VMDK files had (read more here):
# Disk DescriptorFile
version=1
CID=YYYYYYYY
parentCID=ffffffff
createType="partitionedDevice"
# Extent description
RW 1234 FLAT "\\.\C:\Path\To\Image.raw" 5678
# The disk Data Base
#DDB
ddb.virtualHWVersion = "4"
ddb.adapterType="ide"
ddb.geometry.cylinders="16383"
ddb.geometry.heads="16"
ddb.geometry.sectors="63"
ddb.uuid.image="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="00000000-0000-0000-0000-000000000000"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
ddb.geometry.biosCylinders="1024"
ddb.geometry.biosHeads="255"
ddb.geometry.biosSectors="63"The important bits to fill in are the following:
YYYYYYYY
: This is the content ID. When the virtual disk is created, it's a random hexadecimal 32-bit value as far as you're concerned. For details see the VMDK specification.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
is the ID of your disk. As far as I know, it can be any random GUID, but I'm not sure.1234
is the number of sectors in theImage.raw
file that you want to map to the disk5678
is the sector offset inside theImage.raw
file where you want the mapping to begin
The other bits about the disk geometry seem irrelevant as far as I can tell.
Note that you don't need any particular commands to make a VMDK, but as others have stated, VBoxManage internalcommands createrawvmdk
can create one for you as well, which you may find easier or harder depending on what you're trying to do.
Also note that VMDKs can point to actual partitions or disks as well (\\.\PhysicalDriveN
on Windows, etc.), but the caveat is that VirtualBox doesn't lock the volumes using those disks, so you'll get write errors and/or corruption depending on your OS and whether the volume is mounted.
No comments:
Post a Comment