1

If there is a Linux.img file, I can see the actual size of the image. if there is a Linux.img.xz file, how can I tell the size of it when xz = Popen(["/usr/bin/xz", "-cdk", "Linux.img.xz"], stdout=PIPE) is executed. The decompressed file is written to the standard output, there will not be an actual file on the disk that I can check with command fdisk -l <FILE>.

Why I am doing this is because the image is about to be written to a SD card. Right before that I want to check if the image is larger than the SD card. Using the stdin and stdout can avoid disk writing which can speed up the process a little bit.

10
  • 1
    Related: stackoverflow.com/questions/1815329/… Jun 1, 2018 at 21:14
  • 1
    @Morrison, I don't see any similarity with that question. The image contains partition information, the actual size is different that the file size. I want to know how to get the actual size from the decompressed file in the stdout.
    – Jason Liu
    Jun 1, 2018 at 21:17
  • If you're writing this image to the sd card, why do you care about partition information rather than image file size? Are you dealing with images with dead space that you're happy to truncate? If so, why? Jun 1, 2018 at 21:20
  • 1
    Now i'm confused as OP is using dd: serverfault.com/q/95639/299610 and could just expanded data first to /dev/null to get count Jun 1, 2018 at 21:24
  • 1
    @JasonLiu In that case fdisk -l should not have any part in the solution. You just need to know the uncompressed size. xz does store this in the header when it's known, though you can have completely valid xz files without a correct size (due to streaming compression or concatenation). Depending on how robust and general you need it to be, you could simply decode it from the header and ignore cases where it's wrong. Jun 1, 2018 at 21:37

1 Answer 1

0

Since the system image file is not compressed. Turns out the question becomes how to get the uncompressed size of the compressed image.

One way to check is to use the command xz -l. This should return the all information about the compressed file including uncompressed size. The answer is inspired by that other guy.

Your Answer

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

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