0

I'm trying to save disk space with drive images, but all of the examples that I could find involve filling empty space with zeros and compressing the resulting image. Not all programs will work with compressed images, so I'm wondering if I can use the following method to save space with drives that aren't completely used up (due to copying from ISOs or cloning from smaller drives or something).

I have the following drive:

Disk test: 5 MiB, 5242880 bytes, 10240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x397f74b3

Device Boot Start   End Sectors Size ID Type
test1        2048  4095    2048   1M 83 Linux
test2        4096  8191    4096   2M 83 Linux

Can I just dd the first 8191 * 512 = 4193792 bytes to a file and have a raw image that works the same as the drive? In general can I just copy the highest ("end sector" * logical sector size) and end up with an equivalent raw image (assuming no hidden data is stored past the partitions)?

0

Yes — if there is no data there, you can just omit it. Accessing the partitions (e.g., via loopback) should work... other things may need you to expand the file to the correct size (e.g., with truncate -s) which effectively fills it with 0s.

If you're storing the images on Unix-like filesystems, you can use sparse files — not only for the free space after your partitions but for free space inside them. Then you don't have to do any resizing ever; e.g., e2image -a -r should be able to do this.

(Warning: You're using DOS MBR partitions which stores its partition information at the start; other partition table formats may store a backup or primary partition table at the end of the disk)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.