2

I have sparse.img image with the following properties:

$ file sparse.img 
sparse.img: Android sparse image, version: 1.0, Total of 2512896 4096-byte output blocks in 60 input chunks.

I want to see its contents so

  • I have converted it into raw image.
  • Created a new directory
  • Trying to mount the raw image on to the directory

using the following commands:

$ simg2img sparse.img sparse_raw.img
$ mkdir raw
$ sudo mount -t ext4 -o loop sparse_raw.img raw

First two commands run fine and I can see sparse_raw.img generated of size larger than sparse.img.

Last command failed with an error:

wrong fs type, bad option, bad superblock on /dev/loop27, missing codepage or helper program, or other error.

I think that may be the sparse_raw.img is not an ext4 image but how can I sure about it?

I have tried to mount it as

  • ext2, ext3 or without -t
  • without -o loop but nothing works.

Please suggest a way to fix it.

8
  • Does this answer your question? How do I find what type of file system is of an attached USB or SD card? Feb 27, 2020 at 8:04
  • file sparse_raw.img prints data. hexdump -C -n1040 sparse_raw.img prints 78 ba 2a 63 7a 05 50 ed ... so it doesn't match with 10.20.f5.f2 or 53.ef. Feb 27, 2020 at 9:37
  • 1
    @VatishSharma I didn't say you need to mount the filesystem to see what filesystem it is. Checking filesystem is same irrespective of if it's a block device or a loop file; on Android or on Linux distro. Output of file and hexdump shows that it's not a filesystem. So mounting will definitely fail. Problem is with your sparse.img or simg2img, not with mounting. Feb 27, 2020 at 10:27
  • 1
    @VatishSharma who created the sparse.img? Ask them what tool they used for sparseness and compression, and what filesystem it contains. It can be ext4 or rarely f2fs (on /system or /vendor). Or EROFS in case of Huawei. Some vendors also experimented with SquashFS. Also use a different simg2img binary. Better build from latest source. Feb 27, 2020 at 10:45
  • 1
    sgs2toext4.jar this worked instead of simg2img. Thank you guys for your help :) Feb 27, 2020 at 12:43

2 Answers 2

5

The file system might not be in the beginning of the raw partition image.

First you need to convert the image from sparse to raw, using either simg2img or sparse_img_to_ext4.py.

Then, you need to find the beginning of the actual partition, binwalk is my favorite tool for that:

$ binwalk super.raw.img

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
1048576       0x100000        Linux EXT filesystem, rev 3.0, ext2 filesystem data, UUID=8f83745e-c212-5aab-a776-4aeed9fad9fa, volume name "/"
[...many many irrlevant hits...]

Now you can mount the file system using the first offset from the binwalk output:

sudo mount super.raw.img -t ext4 -o ro,loop,offset=0x100000 /media/super/
1

The ext4 feature (400) is the new metadata_csum feature. If this feature is enabled and old tools are used to mount the filesystem they will only be able to mount read-only.

Try to mount it read-only:

$ sudo mount -t ext4 -o ro system.img.raw ~/mnt

You must log in to answer this question.

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