Linux – How to take sha-1, sha-256 or MD5 of CDs / DVDs

checksumdddeviceslinux

I just tried burning both a Debian CD and a Debian DVD from their .iso files and I've got a weird behavior: the checksum of the CD is correct but the one of the DVD ain't.

Here's what working:

  • downloaded the two .iso files
  • verified the checksum of the two .iso files
  • burn the CD debian-7.1.0-amd64-CD-1.iso to a CD
  • verify that the CD is correct by issuing:

    dd if=/dev/sr0 | md5sum (or sha-1 or sha-256)

And this works fine: the checksum(s) I get from the CD by using dd and piping into md5, sha-1 or sha-256 do match the official checksums.

Now what I don't get is that I did burn a DVD from the DVD .iso –and I know that the file has been correctly downloaded seen that the .iso file checksum is correct.

However if I put the DVD in the drive and issue the same:

dd if=/dev/sr0 | md5sum   (or sha-1 or sha-256)

then I get a bogus checksum.

The DVD still looks correct in that the files all seem to be there.

So here's my question: can I verify that a DVD has been correctly burned by using dd and piping its output into md5sum (or sha-1 or sha-256) or is there something "special" that would make dd work for verifying burned CDs but not burned DVDs?

*(note that I used Disk Utility on OS X to burn both the CD and the DVD)*

Best Answer

In addition to Gilles answer,

If you still have the ISO image, you could use cmp instead of checksums. It would tell you at which byte the difference happens. It would also make the check faster as if there is an error early on, it would tell you right away, whereas the checksum always has to read the entire media.

$ cmp /dev/cdrom /path/to/cdrom.iso

In case of error it should print something like this

/dev/cdrom /path/to/cdrom.iso differ, byte 123456789, line 42

In case it's correct it should print nothing, or this:

cmp: EOF on /path/to/cdrom.iso

Which means there is more data on /dev/cdrom than in the ISO, most likely zero-padding.

Even before starting any comparisons, you could check the size.

$ blockdev --getsize64 /dev/cdrom
123456999
$ stat -c %s /path/to/cdrom.iso
123456789

If it's identical, the checksum should match also. If /dev/cdrom is larger, it should be zero padded at the end. You could check that with hexdump. Use the ISO size for the -s parameter.

$ hexdump -s 15931539256 -C /dev/cdrom
3b597ff38  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
3b597fff8  00 00 00 00 00 00 00 00                           |........|

hexdump is also useful for having a look at difference at any other position in a file, in case a damage was caused deliberately by something.