8

I was wondering about how to create / extract / verify .tar.md5 files. These files are used when flashing images to android devices, see here for example.

As far as I can tell the checksum is appended to the file like this:

cp file.tar file.tar.md5
md5sum file.tar >> file.tar.md5

Firstly I would like to know how to extract the file. Can I simply use tar -xf on the file.tar.md5?

How can I verify the integrity of the file? I would like to remove the last bytes (containing the checksum) from the file to obtain the original file back. I guess you would have to use a regexp to match the checksum file.tar? Is something like this implemented somewhere already?

4
  • That doesn't make sense. The hash files that accompany tarballs and other large files typically contain only the hash, not a copy of the original file. Aug 26, 2016 at 19:21
  • To put it another way, the file type is not .tar.md5, it's just .md5. file.tar identifies which file it's a hash of. Aug 26, 2016 at 19:22
  • I would have thought that as well, but that just isn't true: file file.tar.md5 => file.tar.md5: POSIX tar archive (GNU)
    – hfhc2
    Aug 26, 2016 at 19:44
  • Also: the series of commands is shown here: youtu.be/JBcbd-Xfkg8?t=1m47s
    – hfhc2
    Aug 26, 2016 at 19:48

2 Answers 2

10

First of all tar -xf should work since tar continues while it matches its' packing algorithm. If the file stops matching so would tar. Also most archive managers such as 7-zip or winrar will open it if you remove the ".md5". They might print error regarding mismatch with the end of the file, ignore it.

As for verifying the file:

  • print out the stored md5sum: tail -z -n 1 [File name here].tar.md5

  • calculate the md5sum of the tar part of the file: head -z -n -1 [File name here].tar.md5 | md5sum

1
  • Thanks, I was unsure regarding how to use the tail command in this case:)
    – hfhc2
    Aug 26, 2016 at 21:01
1

What works for me with Ubuntu 19.10 is:

  • download single-file 4 GiB zip from sammobile com
  • unzip to several *.tar.md5
  • run the below command-line

.

for F in *.tar.md5; do echo -n "$F " &&
  EXP=($(tail --lines=1 "$F")) &&
  ACT=($(head --lines=-1 "$F" | md5sum)) &&
  if [ ${EXP[0]} = ${ACT[0]} ]; then echo -n "md5ok " &&
  tar --extract --file "$F" && echo "done" 
  else echo "FAIL"; fi; done &&
unlz4 --multiple --verbose *.lz4
AP_G965U1UEU3ARL1_CL14745140_QB21029084_REV01_user_low_ship_MULTI_CERT_meta.tar.md5 md5ok done
BL_G965U1UEU3ARL1_CL14745140_QB21029084_REV01_user_low_ship_MULTI_CERT.tar.md5 md5ok done
CP_G965U1UEU3ARL1_CP11407818_CL14745140_QB21029084_REV01_user_low_ship_MULTI_CERT.tar.md5 md5ok done
CSC_OMC_OYM_G965U1OYM3ARL1_CL14745140_QB21029084_REV01_user_low_ship_MULTI_CERT.tar.md5 md5ok done
HOME_CSC_OMC_OYM_G965U1OYM3ARL1_CL14745140_QB21029084_REV01_user_low_ship_MULTI_CERT.tar.md5 md5ok done
…

But we should all try to get away from bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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