I have a script that uses dd
to write a disk image containing a Linux image to an SD card. This SD card is used by an ARM controller to boot Linux from. Most of the times this works quite well, but occasionally something seems to go wrong and the ARM controller isn't able to boot.
Writing the SD card for a second time or using a different SD card altogether fixes the issue, so I think it is reasonable to assume something goes wrong when the image is written to the SD card.
Considering the above, after writing the image, I would like to verify that the data on the SD card is the same as the image. I've tried cmp
and diff
with various options, however, the SD card is 4GB and the image is 1.9GB, so they always find a difference at the EOF of the image file.
Is there a way to compare both files until the EOF of the smaller file has been reached or should I just check if the output contains EOF?
cmp
has a limit switch, if you wanted to you could limit thecmp
to the known file sizecmp --bytes=LIMIT
– bsd Feb 01 '16 at 10:57dd
to copy the image leaves the garbage. Trying to compute an md5sum would probably miss EOF in the same fashion ascmp
was missing EOF. – bsd Feb 02 '16 at 10:02