We currently extract a TAR archive to a SD-Card like this

tar xf ${ROOT}/rootfs.tar -C /cynox/${DRIVE}/${TARGET} 

As a side note: The rootfs.tar contains files for an embedded Linux system. Some of those systems experience some kind of data corruption on the SD-cards. This can result in missing files, corrupted file contents etc. preventing the embedded system from functioning properly or even booting. This is most likely NOT related to problems during SD-Card creation, but to be totally sure, we also have to investigate in that direction.

What is the best way to compare the contents on the SD-Card to the contents of the source TAR afterwards?

Without knowing if its practical on Linux, things that come to mind are

  1. Create a new archive from the SD-Card and compare the MD5 of both archives (or will those somehow naturally be different?)
  2. Extract the source TAR elsewhere, calculate the MD5 of every file and compare file by file (is it practical to crawl all the folders/files?)
  3. Somehow directly compare the SD-Card contents to the packed contents of the TAR file by file?
  4. Do we need some special validations regarding folder structure, file/folder permissions and so on?

I don't know what possibilities Linux provides for this task, so I would be thankful for any suggestions, pointers in the right direction and examples if possible.

  • 2
    What about extract it to a temporary location and do rsync? It would scream if it would not be possible to save it correctly on sd card.
    – jirib
    Commented Oct 8, 2013 at 11:16
  • @JiriXichtkniha: I wasn't aware of rsync and it sounds like a good suggestion. It even supports optional checksum based comparison instead of timestamp/size. I will definitely look into it.
    – Rev
    Commented Oct 8, 2013 at 11:43

2 Answers 2


To check that you obtain the same tar file, you could do (here with GNU tar):

cd /where/it/was/extracted &&
tar tf /path/to/file.tar |
  tar -T - --no-recursion -cf - |
  cmp - /path/to/file.tar

Note that it compares content and metadata including ownership and times. So for instance, if you didn't extract the files as root, ownership are likely to be different.

You also want to make sure to use the same implementation of tar as the one that created the tar file.

  • I am not sure that we can assume the same TAR implementation in our case, since we do not create the rootfs.tar ourself. But thanks, this method may become useful anyway.
    – Rev
    Commented Oct 9, 2013 at 7:08

I would compare the checksums of each file.

First is the rootfs folder issue the following command:

rootfs# find . -type f -print0 | xargs --null sha1sum --binary > ../rootfs.sum

Then in the targetfs folder, check each file:

targetfs# sha1sum --check <PATH_TO_SUM_FILE> | grep FAILED
  • 1
    Note that it will not complain about potentially missing non-regular files, or directories not containing regular files, or corrupted metadata (times, ownership, permissions, extended attributes...). Commented Oct 8, 2013 at 13:43
  • @StephaneChazelas: I am not sure what you mean. What exactly does the suggested solution do anyway? Create a rootfs.sum which contains the individual sha1sum of each file in the original directory (the extracted tar to a temporary location?) and then compares those checksums against the contents of the new filesystem?
    – Rev
    Commented Oct 9, 2013 at 7:12
  • 1
    @Rev1.0 that's exactly it. However, as mentioned by StephaneChazelas, this will only check the files content not their metadata (owner, permissions, ...). His solution might be a better option.
    – Spack
    Commented Oct 9, 2013 at 7:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .