2

I want to compare the content of two disk images. (For example two disk images with gutsy n edgy) Is there a straight forward command for it in Unix?

5

To compare disk images byte-for-byte and list all the differing bytes, you can run

cmp -l /path/to/first.img /path/to/second.img

This will compare everything, including any unoccupied space. If these are filesystem images and you want to do a file-against-file comparison, you need to mount them, then use a file comparison tool such as diff or rsync.

1
rsync --delete -n -aPc /disk1/ /disk2/

This will not copy any files to disk2 nor delete and files from disk1 thanks to the -n, but it will show you any files which differ between the two filesystems.

  • 1
    The question isn't clear but you may have to mount that image before you can compare (if it is an iso) – trent Mar 3 '11 at 6:52
  • But i suppose for this to work my disk images would have to be mounted. Without mounting and simply having it as X.img files can i make a comparison? How about creating a hash value and comparing? – user73304 Mar 6 '11 at 16:13
  • Yes, you could do md5sum foo.iso bar.iso – Steven Mar 6 '11 at 16:47
  • @Steven: Hashes are vulnerable to hash collision. You could just diff img1.img img2.img if you want to be sure the images are identical. One disadvantage is that this won't report how the images are different... – Borealid Mar 6 '11 at 20:04
  • If you're going to worry about md5 collisions on iso files, you should worry about collisions with rsync (which uses md5 along with a checksum). – Steven Mar 6 '11 at 22:22
0

Here's a command that will compare /dev/sda1 to /dev/sdb1, with a GUI to show progress; partitions tend to be big inputs so it's nice to know how long you need to wait for completion. The command is for a particular 6 terabyte disk, the progress data will only be as good as your size estimate.

gprog --size-estimate 6001173463040 < /dev/sda1 | cmp - /dev/sdb1

gprog is available from http://stromberg.dnsalias.org/~strombrg/gprog/ I'm the author.

You could conceivably do something similar with pv, though I'm not sure what it'd do with any output from cmp.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy