15

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?

Braiam
  • 35,991
Ivan
  • 17,708
  • 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). – Silviu May 27 '12 at 18:57
  • 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. – Ivan May 27 '12 at 19:12
  • That's really difficult , are you burning a bootable CD or pure data ? – daisy May 28 '12 at 13:42
  • A bootable CD.. – Ivan May 28 '12 at 20:01
  • 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. – Skylar Ittner Apr 28 '19 at 20:14
  • https://superuser.com/questions/220082/how-to-validate-a-dvd-against-an-iso – sancho.s ReinstateMonicaCellio May 07 '22 at 11:13

5 Answers5

11

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.
frostschutz
  • 48,978
5

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.

  • +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. – nikitautiu Sep 11 '12 at 13:22
  • 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. – Hitechcomputergeek Dec 21 '16 at 21:57
4

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}
Alexios
  • 19,157
2

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).

Marki555
  • 2,098
  • diff -r will compare the directory contents recursively. – Kevin May 27 '12 at 20:37
  • 5
    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. – psusi May 28 '12 at 02:35
0

Brasero can do that: Tools -> Check integrity...

  • 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 – Milan Kerslager Apr 21 '20 at 19:16