I am trying to verify a backup that I made using the following command:

dd if=/dev/sda of=/dev/sdc2

I backed up the contents of /dev/sda (internal hard drive) to /dev/sdc2 (external backup drive, connected via USB), however /dev/sdc2 (the partition where /dev/sda is being backed up into) is slightly larger than /dev/sda.

I cannot make /dev/sdc2 the size of /dev/sda because the size in bytes of /dev/sda is not divisible by 4096, which is the sector size on drive /dev/sdc.

I want to know if diff (the Unix command) will let you assume the size of /dev/sdc2 to be the size of /dev/sda (only compare the first x bytes, (x being the size of /dev/sda) of /dev/sdc2)

The reason I want to verify this is because, when I was doing running dd (and then diff /dev/sda /dev/sdc2), I got errors in the system log.

I ran diff /dev/sda /dev/sdc2 and it said that the devices differ, probably because /dev/sdc2 is larger than /dev/sda.

The errors (which repeated themselves every once in a while, with varying numbers) looked like this:

ata5.00: exception Emask 0x50 SAct 0x0 SErr 0x280900 action 0x6 frozen
ata5.00: irq_stat 0x08000000, interface fatal error
ata5: SError: { UnrecovData HostInt 10B8B BadCRC }
ata5.00: failed command: READ DMA
ata5.00: cmd c8/00:00:e0:57:f9/00:00:00:00:00/e9 tag 4 dma 131072 in
         res 50/00:00:df:57:f9/00:00:09:00:00/e9 Emask 0x50 (ATA bus error)
ata5.00: status: { DRDY }
ata5: softreset failed (device not ready)

The computer I am doing this on is running the ISO version (installer) of Arch Linux and is not connected to the internet at the moment (will be later). Should I try a different Linux distribution?

  • 1
    The error messages indicate that you have a bad SATA cable and can't access the drive correctly, not that there is a size mismatch. – psusi Dec 8 '15 at 0:02
  • @psusi Bad cable, or failing disk, or buggy controller, or buggy driver, or bad RAM... But anyway you're right, that does indicate an underlying problem. – Gilles 'SO- stop being evil' Dec 8 '15 at 22:45

Perhaps cmp is adequate in this case:

       cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]

       Compare two files byte by byte. (...)

       -n, --bytes=LIMIT
              compare at most LIMIT bytes

You will want to pass, as an argument to cmp -n, the size in bytes of the source device, which blockdev --getsize64 can compute:

cmp --bytes=$(blockdev --getsize64 /dev/sda) /dev/sda /dev/sdc2

Note, however, that the error messages you pasted seem to indicate actual read errors, so it's likely that you are facing an actual problem with your data, not just one related to how diff operates.

| improve this answer | |

A little late, but vbindiff can help here. It provides a split-screen hex view of both files, highlighting any differences. With Enter you can Move to the next difference between the files, which, in the case of a cloned partition, should be at the end of the shorter source file. So it will find any data corruption, albeit it has no progress indicator and might take hours to update the screen after triggering comparision.

Screenshots: https://www.google.com/search?q=vbindiff&tbm=isch

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.