Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I identify partitions of an Android device from the shell?

Tags:

I'm trying to find which partition is used for what, e.g. /boot, /recovery, /system, from adb shell. While this is trivial for partitions currently mounted (using the mount or df commands, see e.g. how to identify names of the partitions), this appears to be tricky when it comes to partitions not currently mounted (like /recovery when booted in "user mode").

There's a tutorial at XDA, but it didn't work out for any of the devices I've tried:

  • cat /proc/mtd: this is empty or non-existing
  • cat /proc/emmc: this is empty or non-existing
  • cat /proc/dumchar_info: non existing (MTK/MediaTek)
  • ls -al /dev/block/platform/*/by-name: either non-existing, or not having the wanted details
  • parted just yielded an Error: Can't have a partition outside the disk! on /dev/block/mmcblk1 (while simply missing the "name" column for /dev/block/mmcblk0).

So I'm at a loss. I know there are apps like DiskInfo which can show those details, so there must be stored somewhere on the device. However, modifying the device (by installing an app) is not an option in my case.

So basically my question burns down to:

Where on the Android device is this information stored?

If possible, a generic approach is preferred. If not, a "try-and-err" of several approaches (if..elseif..fi) would do as well.

For background: an example use would be "I want to retrieve the /boot partition only" (get an image of it via dd). It wouldn't do to first grab all partitions, and evaluate later – too time consuming, and too much data produced ;) – This already describes the intention: writing a little tool to retrieve a particular disk image.

like image 532
Izzy Avatar asked Dec 24 '14 18:12

Izzy


People also ask

How many partitions are there in Android?

android has 5 partitions .. The partition is actually real partition like what we did to a hardisk ?

What is the product partition Android?

The product partition in Android 9 is an extension of the system partition. There's a weak ABI between product and system partitions, so both must be upgraded at the same time, and the ABI should be system SDK-based.


1 Answers

As there seems to be no "unique way" to achieve that, I started combining ideas from allover, joining them into a script (or rather a "script library") to have them checked sequentially (until a good hit was made), and integrated that into my "Device Documentation Tool" named Adebar. Those interested can find it in the lib/partitions.lib file. As Adebar is open-source (GPLv2), feel free to copy and use it – or fork the project and improve it.

The full solution is a bit long to post here (as said, you can grab it at Github), but as SE policy is to include at least the general part in the post, here's what it does:

Different sources provide different sets of details, so it tries the "best ones" first – and then recurses down until at least something was found.

  • /proc/dumchar_info gives the most details, so this is tried first. Happy MTK users will get this.
  • /proc/mtd is the second best source.
  • /proc/emmc should have almost as much as the previous candidates, but is a bit tricky to use
  • /dev/block/platform/*/by-name, cross-checked with …
  • /proc/partitions cross-checked with /proc/mounts gives us at least the partitions mounted

So the script I've built basically walks the sources in this order, stopping as soon as it was able to collect details (e.g. if /proc/dumchar_info was found, no need to parse all the others). All of them put into separate functions, returning data using the very same structure, one could even merge results from all of them.

If someone can come up with a better solution, I'm of course always open for the idea :)

like image 179
Izzy Avatar answered Oct 15 '22 01:10

Izzy