-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Instead of bmaptool copy writing every block of the (sparse/block-mapped) image onto the SD card/USB stick each time, would it not be an improvement to only flash/write the differing blocks?
My use-case is iteratively working on developing system images (embedded systems, headless servers, desktop systems) where changes often are small (bytes/kilobytes/megabytes) and entire partitions may be left untouched. Sparse images and bmaptool helps, but all image data is still repeatedly written even if there was no change. Writing only the diff would reduce writes by hundreds of megabytes each iteration.
- Could perform an "offline" binary image-to-image file diff as a preparation step before writing to the SD card, and only write mismatching blocks. This assumes that the previous image perfectly matches the SD card contents, which would require that the SD card is used in a completely immutable manor.
- Could perform an "online" block-by-block diff, by reading (batches) from the SD card before deciding what to write. This assumes that the additional reads are long-term "healthier" than writes in terms of SD card wear. The end result is that the SD card contents matches the image file, apart from the sparse holes which would be skipped anyhow. This approach also supports interchangeably using multiple SD cards.
Perhaps writing diffs could be implemented as an argument: bmaptool copy --diff=online.
I don't claim to understand the inner workings of flash memory, but it seems to me that reads are relatively cheap and that reducing writes should generally be beneficial.
- https://en.wikipedia.org/wiki/Flash_memory
- https://en.wikipedia.org/wiki/Write_amplification
- https://en.wikipedia.org/wiki/Wear_leveling
- https://en.wikipedia.org/wiki/SD_card
It would be nice to estimate how effective (in blocks, percent, bytes) a diff write could be. Any tool suggestions for counting the number of differing blocks between image files and/or block devices?
A diff between two image files using diffoscope looks quite promising, although it's on a file (system) level instead of block level.
Details
# NOTE: terminal output.
sudo diffoscope aaa.img bbb.img
# NOTE: split html file output.
sudo diffoscope --html-dir='html' aaa.img bbb.imgUnfortunately false "file rename"-looking mismatches clutter the file list diff, making it harder to spot metadata differences.