HDD image file checksum does not match with device checksum

10,948

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

The above command (dd if=/dev/sdb bs=512 count=660297728 | md5sum) is not correct; the count parameter is not bytes, it is blocks. The OP shows a block count of 1289644 so the correct command is:

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

Solution 3

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

Edit: 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

and

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.

Share:
10,948

Related videos on Youtube

comeback4you
Author by

comeback4you

Updated on September 18, 2022

Comments

  • comeback4you
    comeback4you almost 2 years

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

    root@T42# ls -l image
    -rw-rw-r-- 1 noc noc 660297728 Sep 29 19:00 image
    root@T42# 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:

    root@T42# 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
    root@T42# md5sum /dev/sdb
    f6152942a228a21a48c731f143600999  /dev/sdb
    

    What might cause such behavior?

  • comeback4you
    comeback4you almost 9 years
    At least mount | grep sdb returns nothing.
  • comeback4you
    comeback4you almost 9 years
    blockdev --getsize64 /dev/sdb shows the size of the whole block device(same as fdisk): 1024966656 bytes. image file is 660297728 bytes and as seen from output of dd, this is also the amount of bytes copied to /dev/sdb.
  • frostschutz
    frostschutz almost 9 years
    You can't expect same checksum for different size.
  • comeback4you
    comeback4you almost 9 years
    For some reason I thought that md5sum reads only the part I copied with dd if=image of=/dev/sdb bs=512. Looks like it count in the rest of the 364668928 bytes on the disk as well.