cat file.gz file.gz.sig > transfer_me.signed
Then, on the remote host, you split out the appended checksum using
tail -c length_of_the_checksum_info transfer_me.signed > file.gz.sig
head -c -length_of_the_checksum_info transfer_me.signed > file.gz
Note the minus in the second command. The length depends on the type of checksum you use. You can have just
md5sum file.gz | cut -d ' ' -f 1 > file.gz.sig
Notice also, that in this way you can also unpack the transfer_me.signed
file straight away without splitting, because tar
will ignore the trailing "garbage".
A similar solution, with additional encryption or scrambling mechanisms, is used for signing updates for many mobile devices - for example the Amazon Kindles. But in their case, archive file identification is undesired, so they put all the fingerprinting information at the beginning of an update file.
Btrfs uses crc32c checksums to check the integrity of blocks.
If the checksum doesn't match the block when it's read then an alternative block is read. This is assuming there is an alternative (RAID1). If that block also fails or if there is no alternative an EIO (error input/output) is returned.
I do not know of any way to automatically detecting errors, but all errors are logged to syslog. Try dmesg | grep btrfs
. You should be looking for something like this:
[ 2993.114213] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
[ 2993.114527] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
[ 2993.114795] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
[ 2993.115097] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
You could probably make a script or a that looks through the logs and notifies you of errors at regular intervals. Or you could filter these log entries and trigger an rsyslog action.
Best Answer
This is not correct. Both of the open-source checksumming file-systems (ZFS and BTRFS) calculate a checksum for each logical block (the unnamed source Awe used is correct). This is a checksum of the on-disk data.
If the file-system has compression enabled (an increasingly common setting), this checksum is of the data after compression. This means that, even if the file fits in one logical block, it's possible (and increasingly likely) that the file-system's checksum data will be useless to you.
If you need a file checksum, the best way to get it would be to calculate it.