1

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?

  • 3
    The GNU cmp has a limit switch, if you wanted to you could limit the cmp to the known file size cmp --bytes=LIMIT – bsd Feb 01 '16 at 10:57
  • Another one that's usually quite quick is just to compare md5 sums. – Sam Alpher Feb 01 '16 at 17:55
  • There appears to be some none zero garbage on the USB, using dd to copy the image leaves the garbage. Trying to compute an md5sum would probably miss EOF in the same fashion as cmp was missing EOF. – bsd Feb 02 '16 at 10:02

0 Answers0