Solution to checksum error and md5 sum error in Brasero, K3B and other burning software

| | 4 min read

If you happen to be one of those people who burn lot of iso's like we do through our RequestCD program then you would most probably have come across the dreaded checksum errors or md5sum errors. We used to get a lot of these and interestingly we found that we get consistent md5 checksum errors with certain iso images. We were almost sure that this had nothing to do with actual burning errors since they happened only for certain iso images. After hours of scouring the internet we found out the real culprit behind these errors and a way to really work around these phony error messages and actually verify if the iso was written correctly. We burn using either Brasero or K3B but this information can be applied to other cd/dvd burning software as well.

Of course we used to get checksum errors once in a while due to actual burning errors but the ones that were occurring for specific iso's did not really result in toasters. We were able to boot off these cds/dvds and perform full installations of the GNU Linux distros in them. Yes, this does not really prove that there were no errors in the actual writing process, but this got us suspicious. From our research online we got the following information

1) The burners burn in blocks of 32kB each.
2) When iso's are not exact multiples of 32kB they pad the iso's with 0's when they write them.
3) The burning software calculates the MD5 checksum on the original, unpadded iso image
4) The MD5 sum calculated after burning includes the padded zeros and will not match the original MD5 sum calculated on the iso if the size of the original iso was not a multiple of 32kB.

So we found our culprit. It is a limitation in the hardware device that causes these phony errors. Now we had to work around these errors. We found that by using the isoinfo command on the written media we could find the actual length of the data written on to the cd/dvd. Using this actual length and by raw reading using dd and piping to md5sum we were able to see that checksums calculated in this manner on cds and dvds written from the problematic iso's match those taken of the original isos.

Once we figured out this solution we scripted the whole process and created two scripts 'isomd5' and 'isosha1' to calculate the md5 and sha1 sums of the actual data written onto cds and dvds. We now use these to double check cds and dvds that are reported to have errors by K3B or Brasero. We have tested this script on Ubuntu 8.04 but this should work on any other GNU/Linux distro as well.

#!/bin/bash
filename=$1;
blocksize=`isoinfo -d -i $filename|grep "Logical block size is:"|sed 's/Logical block size is: //'`;
blockcount=`isoinfo -d -i $filename|grep "Volume size is:"|sed 's/Volume size is: //'`;
sha1checksum=`dd if=$filename bs=$blocksize count=$blockcount 2>/dev/null|sha1sum`;
echo -n -e $sha1checksum$filename\n|sed "s/\ *-/\ \ /"

Copy and save the above to /usr/local/bin/isosha1. Put your CD/DVD into your drive, say /dev/sdb. Calculate the checksum by running
isosha1 /dev/sdb

#!/bin/bash
filename=$1;
blocksize=`isoinfo -d -i $filename|grep "Logical block size is:"|sed 's/Logical block size is: //'`;
blockcount=`isoinfo -d -i $filename|grep "Volume size is:"|sed 's/Volume size is: //'`;
md5checksum=`dd if=$filename bs=$blocksize count=$blockcount 2>/dev/null|md5sum`;
echo -n -e "$md5checksum$filename\n"|sed "s/\ *-/\ \ /"

Copy and save the above to /usr/local/bin/isomd5. Put your CD/DVD into your drive, say /dev/sdb. Calculate the checksum by running
isomd5 /dev/sdb

Now the checksums generated using these scripts will match the checksums calculated on the original iso's.

Well not quite. Sometimes when the original creators of such isos come across this phony error situation they pad the iso with zeros before releasing the isos. Now the md5sum(or sha1sum) on the iso will match the md5 (or sha1) on the CD or DVD. The problem here is that, sometimes the creators of the isos forget to update the published md5sum (or sha1sum) with the new checksum calculated after padding the iso with the zeros. This would result in a situation where a checksum on the iso file will never match the published checksum. However in such cases if we run the iso through the isomd5 or the isosha1 scripts we will be able to generate the same checksum as was published at the creators site.

So the complete procedure to ensure that your cd's and dvd's are correct are as follows

1) Download iso and checksum from publishers website.
2) Calculate checksum on the downloaded iso and verify against the downloaded checksum.
3) If there is a mismatch in the checksum re-calucate the checksum using the isomd5 or isosha1 scripts.
4) If the re-calculated checksum also does not match the published checksum you have a corrupt download. Re-download or fix your corrupt iso using torrent.
5) Once the iso has been verified burn the iso using your favortite burning software.
6) If the software reports checksum errors after burning, re-calculate the checksum using the isomd5 or isosha1 scripts and verify against first the published checksums and if they don't match, then against the isomd5 or isosha1 checksums on the iso.
7) If one of the above matches the media was indeed burned successfully, if none matches you have run out of luck, you have a toaster :-).