How to verify a CD against an ISO image?

13,604

Solution 1

If you still have the ISO, you can compare them byte by byte using cmp. It's a simple enough command and it exits on the first difference it finds, so it's considerably faster than making a checksum if there actually is an error early on.

cmp /dev/cdrom /path/cdrom.iso

Possible outcomes on success:

  • no output: it's identical and all OK. You may append && echo OK to the command if the lack of output confuses you.
  • cmp: EOF on cdrom.iso: it's identical but the cdrom has more bytes than your iso file. This is usually due to zero padding at the end of the cdrom. Since that does not matter in practice, it's still a success.

Possible outcomes on failure:

  • cmp: EOF on /dev/cdrom: for some reason the data on your CDROM is incomplete. Maybe your ISO was too large to fit a real CD.
  • /dev/cdrom cdrom.iso differ: byte 18296321, line 71780: there is some unexpected difference between your CDROM and your ISO image.

Solution 2

First, you rip your CD to a temporary file:

dd if=/dev/sr0 of=copy.iso

Then you check if copy.iso and orig.iso have the same size, for example with:

stat -c '%s %n' orig.iso copy.iso

If the size is identical, it's easy:

sha1sum orig.iso copy.iso

But I noticed that in certain cases the size can be slightly different because there are trailing zeroes in either the copy or the original image. For example, if copy.iso is smaller than orig.iso:

sha1sum copy.iso
head -c $(stat -c %s copy.iso) orig.iso | sha1sum

Of course you should also check that the trailing bytes are just zeroes:

od -j $(stat -c %s copy.iso) orig.iso

The first line, except for the offset, should be zeroes only. The second line should be an asterisk. The asterisk is to avoid showing consecutive identical lines.

Solution 3

If the ISO file is the same one used to burn the CD, then here are my two favourites:

diff /dev/sr0 /tmp/file.iso

Compares the recorded image against the image file. If you feel a bit more masochistic, you could try something like this:

sha1sum /dev/sr0 /tmp/file.iso

and compare the signatures. This one's more useful if you already have the SHA1 sum somewhere. Both commands will read the medium to the end.

If you want to do it the way @Marki555 suggests, you'll want to mount both optical drive and image first. Here's a complete script: (you can, of course, dispense with the sudo if you're root — a bad idea, in general)

sudo mkdir /tmp/{a,b}
sudo mount /dev/sr0 /tmp/a -o ro # or whatever
sudo mount /tmp/file.iso /tmp/b -o loop,ro
diff -dur /tmp/{a,b}
sudo umount /tmp/a
sudo umount /tmp/b
sudo rmdir /tmp/{a,b}

Solution 4

You can check that CD is fully readable by using dd (for example dd if=/dev/cdrom of=/dev/null). But you can't compare it directly with an ISO image. Each software will create slightly different ISO file (maybe some different headers, or padding), although these different ISO images will all provide the same CD contents (directory structure, file attributes and file contents).

So you can only mount the CD, mount the ISO image and compare it at filesystem level by using some kind of directory comparison tool (sorry, I didn't use any yet on linux).

Share:
13,604

Related videos on Youtube

Ivan
Author by

Ivan

Currently I live in Prague, CZ, use Arch Linux on my Toshiba L10 (Centrino "Dothan" 1.6 Mhz) laptop and code (am beginning, actually) Scala 2.8 with NetBeans 6.9. I like Scala very much (finally, the language I really like) and wouldn't mind to get a jr. Scala developer position.

Updated on September 18, 2022

Comments

  • Ivan
    Ivan almost 2 years

    I've got a physical burnt CD and the original ISO image of it. No reference checksum files were provided for the CD contents. How do I check the actual CD is correct (corresponds to the original image) and fully readable?

    • Silviu
      Silviu about 12 years
      Do you mean to check the data on the CD right after it was burned ? Because most burning software tools have an option to check written data (ex Nero).
    • Ivan
      Ivan about 12 years
      I know but I need to to do the check not right after the burning procedure but after some time (after the burning program was already closed), maybe even on a different PC. As far as I know Nero doesn't offer to initiate a verification procedure independently of a burning procedure - it's verification facility is only an add-on for burning and can happen only right after the burning. What I want is to insert a CD, choose an ISO file and click to verify... Another constraint is that I wan't to do this under Linux as I suspect my Windows CD/IDE driver is not ok.
    • daisy
      daisy about 12 years
      That's really difficult , are you burning a bootable CD or pure data ?
    • Ivan
      Ivan about 12 years
      A bootable CD..
    • Tim
      Tim about 5 years
      FYI, some Linux ISOs have a built-in boot option to verify their contents. You can use that option and it'll check all the disc's files against a file containing checksums. You could also run md5sum yourself and compare, if you don't want to boot the CD/DVD.
    • Admin
      Admin about 2 years
  • Kevin
    Kevin about 12 years
    diff -r will compare the directory contents recursively.
  • psusi
    psusi about 12 years
    Since the cd was burned from an already prepared iso image, there's nothing to be built differently when burning, so you can directly compare the cd with the iso image.
  • nikitautiu
    nikitautiu almost 12 years
    +1 for checksums. This is usually the de facto standard for comparing files(or directories) and not caring about knowing the differences(as is the case with diff): more minimal.
  • derobert
    derobert almost 12 years
    cmp [-l] is better suited for binary files. Diff works best on text.
  • Hitechcomputergeek
    Hitechcomputergeek over 7 years
    or you can do head -c $(stat -c %s /path/to/master.iso) /dev/sr0 | sha1sum to avoid needing to make an image of the burnt CD.
  • randomobject123
    randomobject123 about 4 years
    Brasero is a (Gnome) graphical application available in any Linux distribution. Install it and then go Edit -> Plugins and check File checksum (is checked by default). See here