How do I compare a file with a floppy image and the actual floppy's content?

Is there a command that compares a floppy disk image (e.g. a .iso file) to the actual contents of the floppy the image was written on (e.g. /dev/fd0)?

Asked By: zebonaut


A floppy device file is a file. Any command that reads files will work on it.

cmp /dev/fd0 image.fat

Pass the -l option if you want a list of all differing bytes; for human consumption, this is mostly useful in the form

cmp -l /dev/fd0 image.fat | wc -l

to know how many bytes differ. Run cmp -s /dev/fd0 image.fat if you don’t want any output, just a return status of 0 if the two files are identical and 1 if they’re different.

This compares the images byte by byte. If the floppy and the image contain files and you only want to compare the files and not the metadata (file dates, etc.) nor the empty space, mount the floppy and the image and compare the directory trees.

I don’t have a floppy disk any more to check, but I’d guess:

diff <( dd if=/dev/fd0 ) floppy.img

the <( dd ..... ) reads the contents of the floppy and acts as if it is a file to diff. Then diff compares it to the file.

Answered By: jippie

Because a floppy device is effectively seen as a file, you can also compare hashes (like SHA1 or MD5) of the floppy device (/dev/fd0) and of the disk image.

Answered By: Renan
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.