13

I have a VMDK disk image that exists as multiple files:

2.0G guest-s001.vmdk  1.8G guest-s003.vmdk  128K guest-s005.vmdk
2.0G guest-s002.vmdk  1.7G guest-s004.vmdk  4.0K guest.vmdk

When running qemu-img to convert it to the qcow2 format, which input filename(s) should I specify? Just guest.vmdk, all of them, or something like guest-*.vmdk?

9 Answers 9

16

In the past, I've had to convert them first to raw images, concatenate them together, and then convert the resulting raw image to qcow2:

qemu-img convert guest-s001.vmdk guest-s0001.raw
qemu-img convert guest-s002.vmdk guest-s0002.raw
qemu-img convert guest-s003.vmdk guest-s0003.raw
qemu-img convert guest-s004.vmdk guest-s0004.raw
qemu-img convert guest-s005.vmdk guest-s0005.raw
cat guest-s0001.raw guest-s0002.raw guest-s0003.raw guest-s0004.raw guest-s0005.raw > guest.raw
qemu-img convert guest.raw guest.qcow2

Don't panic if more than just the last file is smaller than 2146762752 bytes. Some VMware products create vmdk spans with different sizes. The size should match 512 times the number of sectors listed in the extent description in the main vmdk file (readable with any text editor or "cat").

It may be possible to do this all at once too, but I haven't tried this:

qemu-img convert guest-s001.vmdk guest-s002.vmdk guest-s003.vmdk guest-s004.vmdk guest-s005.vmdk guest.qcow2

Or, if they're not actually contiguous disk images, then I'm not sure what to suggest. :)

Good luck!


A quick terminal script to convert all of the images at once would be:

for i in *.vmdk; do qemu-img convert -f vmdk $i -O raw $i.raw; done
cat *.raw > tmpImage.raw
qemu-img convert tmpImage.raw finalImage.qcow2
rm *.raw
3
  • 1
    qemu-img convert guest-s001.vmdk guest-s002.vmdk guest-s003.vmdk guest-s004.vmdk guest-s005.vmdk guest.qcow2 this method is possible, quick, comfortable !!!! Thank you :)
    – Ubuntu Master
    Jan 16, 2011 at 13:17
  • Love it. consider prepending "IFS=\n ;" to your for loop just in case the vmdk files have spaces in the names. IFS=\n ; for i in *.vmdk; do qemu-img convert -f vmdk $i -O raw $i.raw; done && cat *.raw > tmpImage.raw && qemu-img convert tmpImage.raw finalImage.qcow2 && rm *.raw
    – Lon Kaut
    Nov 26, 2018 at 18:10
  • Plain qemu-img convert guest.vmdk works, no need to convert/concatenate the individual files. Check the answer below
    – guigouz
    Jan 24, 2021 at 13:19
10

It looks like the qemu-img command has been enhanced now. I just converted a bunch of VMware multi-part images to qcow2 with the command:

$ qemu-img convert <base of the image without the S0001,2etc>.vmdk new-image.qcow2
1
  • This oddly produced a "raw" image. For a qcow2 one, I had to write qemu-img convert -O qcow2 … Jan 28, 2022 at 0:23
2

None of these answers actually worked as of QEMU 7.1.0. It became as trivial as working on the single small .vmdk file that references the other larger vmdk image files. Supposing you have the following collections of files:

'your-vm-s001.vmdk'        
'your-vm-s002.vmdk'
'your-vm-s003.vmdk'
[...]
'your-vm-s011.vmdk'
'your-vm-s012.vmdk'
'your-vm.vmdk'

Then you should simply invoke qemu-img like:

qemu-img convert -fvmdk -Oqcow2 your-vm.vmdk your-vm.qcow2
1

I'm trying this to convert to raw:

find . -type f -iname <guest-name>\*-f0\*vmdk -exec qemu-img convert {} {}.raw \;

Then to catenate:

cat <guest-name>*-f0[0-1][1-9]*raw >> <guest-name>.raw

Then to convert:

qemu-img convert <guest-name>.raw -O qcow2 <guest-name>.qcow2
0
1

I could have used parallel to do this but here is one that will do the directory:

ls *s0??.vdmk | xargs -n 2 -I % qemu-img convert % %.img

And then:

cat *.img >> imagename.raw

The ls part before the pipe will print all vdmk that have at the end an s0 and two wildcards the xargs command allows it to substitute % twice as a variable to the end of the qemu-img command.

1

Here's a simple way to do it in one line, making use of arrays:

files=(*s0??.vmdk); qemu-img convert -f vmdk -O qcow2 ${files[@]} ${files%-s001.vmdk}.qcow2;
1
  • Nice idea, though it'd be best to quote the expansion of the array in case the input file names have spaces.
    – Apteryx
    Nov 15, 2022 at 18:01
0

An option is to use wildcard in the name of images:

qemu-img convert my-multipart-image*.vmdk my-image.qcow2
0

None of the above examples did the job for me and neither did other solutions I found on the web so here you go with an updated version that works.

Filenames: Windows.10-s00{1,16}.vmdk is stored in the vmware path but also notice the single .vmdk file that is: ~4.0kb in your folder: This is how it looks for my setup: Windows.10.vmdk choose this minimal file as 'target' and then qemu-img will do the job fo us:

 4.0G       Windows.10-s001.vmdk
 4.0G       Windows.10-s002.vmdk
 4.0G       Windows.10-s003.vmdk
 4.0G       Windows.10-s004.vmdk
 4.0G       Windows.10-s005.vmdk
 4.0G       Windows.10-s006.vmdk
 4.0G       Windows.10-s007.vmdk
 3.8G       Windows.10-s008.vmdk
 12K        Windows.10-s009.vmdk
 12K        Windows.10-s010.vmdk
 12K        Windows.10-s011.vmdk
 12K        Windows.10-s012.vmdk
 12K        Windows.10-s013.vmdk
 12K        Windows.10-s014.vmdk
 12K        Windows.10-s015.vmdk
 144K       Windows.10-s016.vmdk
 4.0K       Windows.10.vmdk
  • Convert vmdk > qcow2 with below command:

    qemu-img convert Windows.10.vmdk Windows.10.qcow
    
0
0

I just resurrected a 10 year old offline root certificate authority that had run on VmWare Workstation and so have had opportunity to verify @Stuart's answer as correct as of QEMU version 6.2.0 (probably earlier). qemu-img convert will indeed recombine all the files into a single .qcow2 file. But ...

It is critical that you identify and use the "top" file in the backing chain as the source file in qemu-img convert - you cannot reliably identify the top file by VmWare's naming conventions - they vary apparently.

Use qemu-img info --backing-chain to reveal the "top" file.

Here is a script to list the backing chains for all your .vmdk files:

for i in `ls *.vmdk`
do 
echo $i
qemu-img info --backing-chain $i|grep "backing file:"
done

The file that has ALL the other .vmdk files in the backing chain is the one you want to submit to qemu-img convert as the top file. It will then take care of combining them all into the output file. Syntax:

qemu-img convert -p[c] [-f vmdk] -O qcow2 \
[-o nocow=on] <top_file>.vmdk output.qcow2

optional arguments:

-c Compresses the output file. Slower but produces a smaller file. Desirable if the output will be copied elsewhere.

-f vmdk Specifies the type of input file but if you were successful at listing the backing chain, qemu-img is certain to figure this out on it's own.

-o nocow=on Turns off Copy on Write for the file. This is desirable for performance reasons if the target file system is already COW (like btrfs).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .