HDD image file checksum does not match with device checksum

I have a 660297728 byte HDD image with MD5 hash f5a9d398e974617108d26c1654fe7bcb:

[email protected]# ls -l image
-rw-rw-r-- 1 noc noc 660297728 Sep 29 19:00 image
[email protected]# md5sum image
f5a9d398e974617108d26c1654fe7bcb  image

Now if I dd this image file to /dev/sdb disk and check the MD5 hash of the disk, then it is different from MD5 hash of the image file:

[email protected]# dd if=image of=/dev/sdb bs=512
1289644+0 records in
1289644+0 records out
660297728 bytes (660 MB) copied, 1006.38 s, 656 kB/s
[email protected]# md5sum /dev/sdb
f6152942a228a21a48c731f143600999  /dev/sdb

What might cause such behavior?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Is /dev/sdb exactly 660297728 bytes large? (blockdev --getsize64 /dev/sdb). If not, the checksum would naturally be different. Use cmp image /dev/sdb to find out where the differences are in detail. If it says EOF on image, it’s identical.

Solution 2

Maybe your disk on /dev/sdb has been modified by udisks or another process of your OS (automatically mounted for example).

Maybe the image is the image of a partition and not the whole hard disk.

You can compare yours disks with fdisk:

fidsk -l /dev/sdb


fdisk -l /path/to/image

See the numbers of blocks (and their sizes) maybe it will correspond to a only one partition.

Retry the md5sum on the concerned partition on /dev/sdb:
md5sum /dev/sdbx (x is the number of the partition)

and compare with the md5 of your image

Edit 2:

Your source HDD does a size of 660297728 bytes (660 MB) so when you have done the dd, it was:

dd if=/dev/sda of=/path/to/image

So the image has the same size of the entire source hdd: 660297728 bytes

If you do a md5sum of the source HDD and image it must be the same.

When you copy the image to the new HDD, you do:

dd if=image of=/dev/sdb

But sdb has a size of 1 TB, so:

  • the first 660297728 bytes has been written by dd
  • the next 440 MB has not been written, the data are the same before dd maybe some zeroes or other.

If you do a md5sum on the entire sdb, you will include the 440 MB which has not been written and the result will not be the same of the md5sum of image.

If you want to do the md5sum of the new disk, you do:

dd if=/dev/sdb bs=512 count=1289644 | md5sum

The result must be the same.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply