22

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.

Community
  • 1
  • 1
Izzy
  • 1,364
  • 3
  • 32
  • 65
  • What information are you looking for exactly (Size, location, mount) that isn't found in `/proc/mounts` – jan Dec 24 '14 at 19:14
  • @jan as described, what each partition "is for". E.g. as derived from `mount` or, as you put it, `/proc/mounts`, that `/dev/block/mmcblk1p21` is holding the `system` partition. Note however that, as the `mount` command itself, only holds partitions *currently mounted*. But I need also those ***not currently mounted*** (e.g. `recovery` when booted normally). Size is rather of secondary interest. Identification is what matters to me. – Izzy Dec 24 '14 at 19:22
  • I would just do `ls -l /dev/block/platform/omap/omap_hsmmc.0/by-name` to get a list of the partitions names pointing to the actual devices. – jan Dec 24 '14 at 19:26
  • 1
    @jan Agreed – if that were possible (see my question: *`/dev/block/platform/*/by-name`: non-existing on some devices*. – Izzy Dec 24 '14 at 19:52
  • @Andreyua You've seen the ***from the shell*** part, and the ***modifying the device (by installing an app) is not an option*** restriction? – Izzy Aug 23 '15 at 00:29

2 Answers2

15

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 :)

Izzy
  • 1,364
  • 3
  • 32
  • 65
  • Thanks a lot! I found partitions names and devices using cat /proc/mtd. – RedEyed Aug 24 '15 at 14:22
  • Glad I could help, @VadimStupakov! It's an unfortunate thing that each device seems to deal with that in a different way, so we can use no unique approach matching them all … – Izzy Aug 24 '15 at 14:24
  • Do you know if `/dev/block/platform/*/by-name` is for certain Android versions? I need to get the partition name of `recovery` and `boot`. I got it working until I tried it on older devices.. – Thomas Vos May 31 '16 at 14:12
  • @SuperThomasLab to my experience, it's rather "device specific" – but I cannot tell for sure. – Izzy May 31 '16 at 14:13
  • @Izzy Well, thanks for the quick reply. Apart from the `by-name` dir, do you know another way to get the `recovery` partition? I tried the other directories in your answer, but most don't exist, don't list the names or only show the currently mounted partitions (=not recovery). – Thomas Vos May 31 '16 at 14:17
  • @SuperThomasLab apart from guessing (e.g. by size), unfortunately no. Otherwise I had mentioned that (recovery was one of the most important partitions I was after). You could of course boot into recovery and check then, it might be mounted from there (not verified). – Izzy May 31 '16 at 14:21
  • @Izzy Just want to let you know that your Adebar doesn't work correctly on my Nexus 6P (Android N). This is the (shortened) output of your script: http://pastebin.com/7PkyyvZF. It doesn't use the `by-name` method. That's because your program uses `ls -al /dev/block/platform/*/by-name`. Apparently the Nexus 6P I tested it on has two directories at the `*` and not one. This works for me: `ls -al /dev/block/platform/*/*/by-name` – Thomas Vos May 31 '16 at 14:58
  • @SuperThomasLab I cannot test on N (No such device). But this is also not the right place for a bug report. Be welcome to file an issue at Github, and I can take a look as soon as time permits. – Izzy May 31 '16 at 15:35
1

You can get the information of mounted-partition on Linux as https://stackoverflow.com/a/15639867/629118 , but I don't think Linux kernel doesn't know about boot and recovery partition if /dev/block/platform/**/by-name doesn't have it.

So you can use the currently mounted information to guess which partition is boot or recovery or something else in /dev/block/* that is not mounted.

In fact, fastboot only sends the name of the partition which you want to flash. It means only the bootloader for fastboot knows the information, I guess.

https://github.com/android/platform_system_core/blob/8163104b3feb575a321b194a70ecb9873a70b29d/fastboot/fastboot_protocol.txt

Community
  • 1
  • 1
Kazuki Sakamoto
  • 13,929
  • 2
  • 34
  • 96
  • Thanks Kazuki – but guessing is too error-prone with 20+ partitions (26 on the device currently connected, `mmcblk1p1` to `mmcblk1p26`), of which only 3 or 4 are mounted (3 on the mentioned device) – especially "automatic guessing by a script". Even skipping all those having 2048 blocks and less, leaves 10 partitions on that device, minus the 3 mounted makes 7 to guess from. That `fastboot` can figure out itself is another proof the information must be obtainable automatically (unless it's hard-coded into its counter-part on the device). – Izzy Dec 24 '14 at 19:50
  • 1
    fastboot is a part of the bootloader and it is separated from the Linux system, so I don't think you can get the information via adb shell that communicates with adbd on the Linux kernel. – Kazuki Sakamoto Dec 24 '14 at 19:53
  • That's a valid point. I'd say fastboot is to be seen separately; when booted in fastboot-mode, the "normal system" is not "fired up" at all. So take away that "proof" from my last comment; but as apps can find the details (see the example in my question), it still must be obtainable somehow. – Izzy Dec 24 '14 at 19:57
  • DiskInfo is always correct on every device? If so, you can strace or something with root privilege to check what the app did to get the info. But I doubt it. See also http://www.all-things-android.com/content/review-android-partition-layout – Kazuki Sakamoto Dec 24 '14 at 22:07
  • I can't test it "on every device" – it's just what I've been told. And that given link I already tried yesterday. Can't get further than to a "Cloudflare DDos check", never get to the real page. Ah, just got it via Google cache: basically what I've already tried. Except for `blkid`, which is not available on the device unfortunately :( Thanks for the pointer nevertheless! – Izzy Dec 24 '14 at 22:18