I created some USB stick images in IMZ format with USB Image Tool. They are larger than they optimally should be because the tool apparently is filesystem-agnostic (images the drive block-by-block as, say, dd would) and there was old data left on it not part of the filesystem anmore. Is there a way to wipe the space within such an image that is empty from the point of view of the filesystem, and thus reduce the image size?
Bump. Any ideas how to compact an IMZ image (or even an uncompressed IMG image which can then be compressed manually much better after the deleted data is wiped)?
>inb4 "wipe empty space before imagining, or restore image to USB stick, wipe empty space, and reimage"
That's both time-consuming and putting unnecessary strain on the USB stick, wasting write its write cycles. There should be a way to wipe empty space on volumes within IMG/IMZ images?
Good question, the reason is quite simple though - they're images of bootable USB sticks, which are more or less complicated and/or time-consuming to create, such as multiboot USB sticks with various troubleshooting tools, or Linux installers created with Unetbootin (which usually take some time to create, and put strain on the USB stick as the filesystem is built). I want to archive bootable images which may be useful in the future, while optimally keeping them as compact as possible (hence the IMZ format, but old data within the raw image makes it less compressible).
Btw even if they weren't bootable images, it's easier and faster (potentially MUCH faster if there's a lot of small files) to reimage a USB stick block-wise that recreate a file system by copying loose files onto it file-by-file.
This is suggesting what >>52436999 already referred to as doable, but rather clunky and convoluted. There surely must be a way to do it with an image (rather than going through the ordeal of imaging a USB stick, wiping the free space on there and then dumping another image)?
there is no other way. i usually mount the image, create the zero.bin, remove zero.bin, umount image, then cp --sparse=always bloated.img sparse.img. then remove the bloated one.
unused blocks can be removed only in a filesystem-specific way. like trimming in an ssd. there is no trimming for images.
Wiping empty space on a physical USB stick itself is both slow as well as unnecessarily wearing out the USB stick memory. For these reasons it seems much better to do the compacting on an already dumped image.