Calculate md5sum of a CD/DVD

I have an ISO file, which I burned to a CD. Now how can I check if the CD is correctly created? I would like a command that calculate the hash sum that I can use to check with the hash sum I calculate on the ISO file. Ideally the command should:

  • Work regardless of the ISO file: that is, I don’t want to keep a list of hash sum for each file in the disc, or remember the number of blocks whatever
  • Be relatively short: a one-line command is great, a chain of commands which is two line long is OK, a script that span one page is not
  • Be fairly efficient: for example, dd the disc back to a file then run md5sum on the file is unacceptable

If there is no answer that cannot satisfy all I will appreciate the nearest match too. Even better if you can tell me why it is not so straight-forward.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The basic problem is that we want to take the md5sum of the exact same information that was on the ISO originally. When you write the ISO to a CD, there is likely blank space on the end of the disk, which inevitably changes the md5sum. Thus, the the very shortest way:

md5sum /dev/cdrom

doesn’t work. What does work (and is common in online documentation) is only reading the exact number of bytes from the device and then doing the md5sum. If you know the number of bytes you can do something like:

dd if=/dev/cdrom bs=1 count=xxxxxxxx | md5sum

where ‘xxxxx’ is the size of the iso in bytes.

If you don’t know the number of bytes off hand, but have the iso on your disk still, you can get them using ls by doing the something like the following (taken from here):

dd if=/dev/cdrom | head -c `stat --format=%s file.iso` | md5sum

There are many other one-line constructions that should work. Notice that in each case we are using dd to read the bytes from the disk, but we aren’t piping these to a file, rather, we are handing them to md5sum straight away.

Possible speed improvements can be made by doing some calculations to use a bigger block size (the bs= in the dd command).

Method 2

There is program for this task. It’s called – checkisomd5. In Ubuntu it can be installed by command:

sudo apt-get install isomd5sum

Method 3

If the size of the image on the disc is divisible by 2048, whole number, which seems to be very common, then you can get an accurate MD5sum as follows where sr0 is the name of the optical -which can be found using, lshw -C disk– and where ‘count’ is the dividend of the image size divided by 2048.

dd if=/dev/sr0 bs=2048 count=356352 |md5sum


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x