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?
Managed to get a "deflated" VMDK file by doing the following.
Mount each partition of the HDD
e.g. mount -t ext4 /dev/sda1 /mnt/tmp
For each partition, fill up empty space with zeros.
e.g. dd if=/dev/zero of=/mnt/tmp/ZERO.TMP
Delete the zeros file.
Clone an image of the entire HDD
e.g. dd if=/dev/sda of=/tmp/image.img
Make a sparse copy of the image file.
e.g. cp --sparse=always /tmp/image.img /tmp/image_sparse.img
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