0

I salvaged the HDD from my old desktop, and would like to virtualize it to run under VMware Workstation.

The problem is, the HDD (with several partitions) is 1 TB in size, and when I tried to clone it to an image (using dd), the resulting image is also 1 TB, and I will have problem maintaining a VM of that size.

I know that when creating a new Workstation VM, there is an option to not allocate all the space immediately.

How can I virtualize the HDD and "deflate" the unused parts of the HDD?

Edwin Lee
  • 3,540
  • 6
  • 29
  • 36

1 Answers1

1

Managed to get a "deflated" VMDK file by doing the following.

  1. Mount each partition of the HDD

    e.g. mount -t ext4 /dev/sda1 /mnt/tmp

  2. For each partition, fill up empty space with zeros.

    e.g. dd if=/dev/zero of=/mnt/tmp/ZERO.TMP

  3. Delete the zeros file.

  4. Clone an image of the entire HDD

    e.g. dd if=/dev/sda of=/tmp/image.img

  5. Make a sparse copy of the image file.

    e.g. cp --sparse=always /tmp/image.img /tmp/image_sparse.img

  6. Use qemu-img to make a VMDK file from the sparse image file.

    e.g. qemu-img convert -O vmdk image_sparse.img image_sparse.vmdk

Edwin Lee
  • 3,540
  • 6
  • 29
  • 36
  • This is interesting. I was about to go down the same road, but I was going to use Knoppix to boot and dd the original hdd/partition into a file on an external USB drive, then use Knoppix inside the vm to restore the image file from the USB device to the vm disk image (vmdk). Assuming that worked, I was going to use windows 'disk-clean' followed by a 'clean-up unused space' in vmWare. Can you explain the purpose of filling the empty space with zeros and making the sparse image file? I'd like to know why you need those steps? – Geo... Aug 04 '18 at 12:43