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.

Vatish Sharma
  • 1,001
  • 4
  • 21
  • 36
  • 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. – Vatish Sharma Feb 27 '20 at 09:37
  • @IrfanLatif The image is not mounted on any android system but it is available under file explorer of Ubuntu. – Vatish Sharma Feb 27 '20 at 09:40
  • 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. – Irfan Latif Feb 27 '20 at 10:27
  • I have other sparse.imgs and they are working fine with simg2img and mount command but the one mentioned in the question and two more are not working. Any suggestions on how can I determine the problem? – Vatish Sharma Feb 27 '20 at 10:39
  • 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. – Irfan Latif Feb 27 '20 at 10:45
  • try this older build from fguy https://forum.xda-developers.com/showthread.php?t=1054836&page=5 – alecxs Feb 27 '20 at 12:21
  • 1
    sgs2toext4.jar this worked instead of simg2img. Thank you guys for your help :) – Vatish Sharma Feb 27 '20 at 12:43

2 Answers2

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/
ge0rg
  • 168
  • 1
  • 6
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
Firelord
  • 25,084
  • 20
  • 124
  • 286
关中客
  • 11
  • 1