0

First off, some background:

I was tasked with creating a way to boot, configure, and save a virtual machine in a format that can be used on a physical hard drive. I accomplished this with Vagrant, Packer, and VirtualBox.

The problem is that in order to use it on a real hard drive, the output .vmdk needs to be converted to a raw format and written to the hard drive with the dd utility. The raw format is quite large because there's no shortening of empty space in this format; it's exactly as large as the file system is when it gets generated.

Is it possible to convert the .vmdk image to raw and pipe it to dd without expanding it on the writer's file system?

I've tried looking around for any existing solutions, but haven't come up with much. My guess is it's not possible.

  • 1
    guessing `qemu-img convert file.vmdk - > /dev/disc0p1` ? `qemu-img convert file.vmdk /dev/stdout`? Or really just `qemu-img convert file.vmdk /dev/disc0p1`? – KamilCuk Jul 03 '23 at 10:02
  • Hey thanks! I can give that a try. Can you elaborate on the use of `/dev/disc0p1`? I'm not familiar. – Mike Staffa Jul 03 '23 at 10:16
  • It's the real device hard drive you are copying to. /dev/sda0 or similar. – KamilCuk Jul 03 '23 at 10:18
  • Oh ok that makes sense, I thought for a moment it might be an intermediate device or something `dd` uses I didn't know about. – Mike Staffa Jul 03 '23 at 10:24

1 Answers1

1

For anyone else that might come across this, the solution was (as usual) to RTFM

The qemu-img utility has this functionality built into it, with a dd option.

The command is pretty much the syntax of dd tacked onto the end of the qemu-img utility parameters.

E.g. qemu-img dd -f vmdk -O raw if=your-image.vmdk of=/dev/sda bs=16M status=progress