LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Linux Answers > LQ ISO
User Name
Password

Notices


By the_gripmaster at 2011-11-14 19:39
This tutorial is about how to verify the integrity of a DV/DVD burned from a ISO. Some CD/DVD burning applications add extra data when burning to the CD/DVD. So, a direct MD5 of the media may give you a misleading result. The trick is to calculate the MD5 of the CD/DVD disregarding the extra data the burning application has written.

First, calculate the MD5 sum of the ISO

Code:
[user@host Fedora16]$ md5sum Fedora-16-x86_64-DVD.iso 
bb38ea1fe4b2fc69e7a6e15cf1c69c91  Fedora-16-x86_64-DVD.iso
Next, count the number of bytes of the ISO (note down the size)

Code:
[user@host Fedora16]# wc --bytes Fedora-16-x86_64-DVD.iso
3757047808 Fedora-16-x86_64-DVD.iso
Now, put the CD/DVD in the drive and calculate the MD5 disregarding the extra data

Code:
[user@host Fedora16]$ dd if=/dev/dvd | head --bytes 3757047808 | md5sum 
bb38ea1fe4b2fc69e7a6e15cf1c69c91  -
Here's a script you can use:

Code:
#!/usr/bin/env sh
# Purpose: check integrity of a burned DVD with the ISO

if [ $# -ne 1 ]; then
  echo "Usage: $0 /path/to/isofile.iso"
  exit 1
fi

# the hash application to use, can be other like sha1sum, sha256sum, sha512sum, cksum
HASHAPP='md5sum'

# change if your device is different
DVDDRIVE='/dev/dvd'

# the ISO file
ISOFILE=$1

# check to see if file exists
if ! [ -e ${ISOFILE} ]; then
  echo "${ISOFILE} does not exist"
  exit 1
fi

hash_of_iso=$(${HASHAPP} ${ISOFILE} | cut -d' ' -f1)
echo "info: ${HASHAPP} of ${ISOFILE} - ${hash_of_iso}"
bytes_of_iso=$(wc --bytes ${ISOFILE})

hash_of_dvd=$(dd if=${DVDDRIVE} | head --bytes ${bytes_of_iso} | ${HASHAPP} | cut -d' ' -f1)
echo "info: ${HASHAPP} of ${DVDDRIVE} - ${hash_of_dvd}"

if [ ${hash_of_iso} == ${hash_of_dvd} ]; then
  echo "OK: ${HASHAPP} of ISO(${bytes_of_iso}) matches ${HASHAPP} of DVD(${hash_of_dvd})"
  exit 0
else
  echo "FAIL: ${HASHAPP} of ISO(${bytes_of_iso}) does not match ${HASHAPP} of DVD(${hash_of_dvd})"
  exit 1
fi

by metaschima on Sat, 2014-05-03 19:17
Why not just use 'cmp' instead ? One command, much simpler.

by the_gripmaster on Sun, 2014-09-14 04:46
Quote:
Originally Posted by metaschima View Post
Why not just use 'cmp' instead ? One command, much simpler.
cmp will not work because the sizes of the iso file and /dev/dvd are different. cmp will always fail

by metaschima on Sun, 2014-09-14 10:45
If it says EOF on the iso, then you know the burn is good.


  



All times are GMT -5. The time now is 01:08 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration