VMware {code} Community
sebjames14
Contributor
Contributor

how to convert raw disk image to scsi vmdk image

I'm investigating how to deliver our network print appliance as a vmware appliance.

We build the linux based os from a script whichn generates boot, root and configuration partitons as raw images.

These can be pulled together in a disk image created using standard unix tools like dd and fdisk.

I found that you can use qemu-img to convert that raw disk image into a vmware 3 or 4 compatible image.

My problem is that this presents as an ide disk which would require us to rewrite our software

Is there a tool i can use offline to create a scsi vmdk image from a raw disk image?

thanks, seb james

Reply
0 Kudos
13 Replies
oreeh
Immortal
Immortal

You can convert the disk using vmkfstools or vmware-vdiskmanager (depending on the VMware product you use).

sebjames14
Contributor
Contributor

Hi there,

Thanks for the quick reply. I was writing my initial post on a small mobile device, and omitted to mention that I'd looked at vmware-vdiskmanager - I'm using VMWare Server 1.0.6 to run my virtual machines. I haven't managed to find the vmkfstools download; perhaps this is part of a different vmware product, as your message suggests.

I did investigate vmware-vdiskmanager - it seems to allow me to create a vmdk, but doesn't seem to have the ability to either create the vmdk from a raw disk image (such that the vmdk would contain the data in the raw disk image) or to manipulate the new vmdk after creation - that is to create partitions, copy data, get a bootloader installed.

Having had a look at the documentation for the disk development kit, it seems I can use the C++ api to create a vmdk, then copy data across, so I will try to:

1) Create vmdk

2) Copy data, bit for bit, from my raw disk image into the vmdk, using the C++ api

I'd prefer not to have to write this (admittedly small) program, so any suggestions to alternative methods would be gratefully received!

Thanks again,

Seb James

Reply
0 Kudos
oreeh
Immortal
Immortal

vmkfstools is part of ESX.

You need the convert function of vmware-vdiskmanager.

sebjames14
Contributor
Contributor

Hi, thanks again from the prompt reply.

The -r <source-disk> feature in vmware-vdiskmanager won't convert from my raw disk image file:

$ vmware-vdiskmanager -r rootfs.raw -t0 test2.vmdk

Using log file /tmp/vmware-seb/vdiskmanager.log

Failed to open the disk 'rootfs.raw' : The file specified is not a virtual disk (15).

The example given in the usage instructions for vmware-vdiskmanager imply that the source disk must itself be a vmdk disk image:

ex 3: vmware-vdiskmanager -r sourceDisk.vmdk -t 0 destinationDisk.vmdk

I have successfully modified the vix-disklib-sample to copy a raw image into a new vmdk file, so I'm in business now. It's a simple job to rewrite the DoFill() function in vixDiskLibSample.cpp to copy data from the raw image file into the vmdk.

Cheers,

Seb James

Reply
0 Kudos
oreeh
Immortal
Immortal

So you are using a complete raw disk instead of a raw partition...

Reply
0 Kudos
sebjames14
Contributor
Contributor

That's correct. We already build our network appliance with an embedded Linux OS, which lives on 4 partitions of a disk. To create a vmdk of the appliance, I've modified our existing build scripts to create a disk image (dd if=/dev/zero of=.....etc) then partition it (using sfdisk) then make and populate filesystems on the partitions (mkfs.* and tar -xf to populate or copy in a squashfs image using dd) then install a bootloader into the image.

Apart from installing the bootloader, which I still have to do within the vmware image using a Linux LiveCD, this is all working now, and I just booted our first vmware appliance! The bootloader issue is not a vmware problem.

Thanks,

Seb James

Reply
0 Kudos
sebjames14
Contributor
Contributor

Established that there is no tool to convert a raw disk image into a vmware vmdk image, but that it is simple to modify vixDiskLibSample.cpp from vmware-vix-disklib-distrib to copy a raw disk image into a newly created vmdk.

Reply
0 Kudos
oreeh
Immortal
Immortal

It is probably easier to add a VMDK of the desired size to the VM and image the disk (using Ghost, dd, ...).

Reply
0 Kudos
sebjames14
Contributor
Contributor

It is probably easier to add a VMDK of the desired size to the VM and image the disk (using Ghost, dd, ...).

I want my "build a vmware appliance" script to run entirely outside the vmware environment.

Reply
0 Kudos
dholth
Contributor
Contributor

qemu-img --help

'-s' indicates that the target image must use of type SCSI (vmdk format only)

$ qemu-img convert -s -f raw diskimage.img -O vmdk scscidisk.vmdk

Reply
0 Kudos
sebjames14
Contributor
Contributor

That's useful information, thanks for posting. The version of qemu-img I

was using didn't have that feature (it was 0.8.2 from Debian Etch).

Reply
0 Kudos
rakslice1
Contributor
Contributor

That's not in the official source... Do you have a patch for that?

Reply
0 Kudos
dholth
Contributor
Contributor

Reply
0 Kudos