![]() The key information was the use of the command truncate. I re-propose the same answer here, it can be useful. I originally posted the same answer here, on StackExchange Ask Ubuntu. # qemu-img convert -f raw -O vmdk foo.img foo.vmdkīut if it's going to be written to a real disk again, you have to convert it back to a raw image. # qemu-img convert -f raw -O qcow2 foo.img foo.qcow ![]() Note that this still requires you to prepare the image by cleaning the free space using the above method. qcow2 for Qemu, VDI for VirtualBox, or VMDK for VMware. with a virtual machine – is to convert the raw image to one of the image formats used by virtualization software e.g. Note that the output device (sda) must be of sufficient size to fit the original image, otherwise data will be lost or corrupted.Īn alternative method, if you want to keep using the image – e.g. This will uncompress it 'live': # cat | gunzip | dd of=/dev/sda Note that you must uncompress the image when writing it back to disk. Even at lowest compression levels, a long series of zeros will compress well: # ls -s Then compress it with a tool like gzip or xz. # losetup -find -partscan foo.imgĭd if=/dev/zero of=/mnt/filler conv=fsync bs=1Mĭd: error writing ‘/mnt/filler’: No space left on device Otherwise, an easy way to achieve this is to create a huge file on the disk, containing only null bytes, then delete it. This works on loop devices in a similar way to TRIM on SSDs unused areas are replaced with zeros and the underyling. With recent kernels (3.2 or later), it's easiest to do so by mounting each partition of the loop image, then issuing a discard using fstrim on the mountpoint. First make sure the free space is actually empty, and doesn't contain leftovers of deleted files.
0 Comments
Leave a Reply. |