2

Updated question (2018/2/20)

Thanks to grawity's answer and comment, my question can be updated.

My final goal is to acquire detailed partitioning information (including the start and end address of each partition on my android phone), either using fdisk or parted.

  1. How to "install" the parted command into my android smartphone?

  2. Can I use fdisk on a Linux system or on Cygwin on a windows system? Knowing that fdisk brought by BusyBox can't handle GPT. (If so, maybe I could post another question.)


The original question (2018/2/19)

I have installed Busybox on my smartphone, and I want to acquire detailed partitioning information, including the start and end address of each partition on my android phone.

I can use fdisk command, but maybe because my phone's disk is GPT instead of MBR, command "fdisk -l" shows no output.

So I want to use the command "parted". But I don't have it on my smartphone. How can I get it?

I've traveled to GNU website of "parted". But what I can download is only source code. Do I need to compile that? If so, how do I compile that? Can I compile the source code with MinGW on a PC with Windows system?

If I get the "parted" file, where should I put it to make it work? Is it under /system/bin?

I haven't found a usable "parted" file yet. Is it because of my bad google skill or the file has to be compiled differently for different devices?

I hope to find an official version of the "parted" file.


EDIT (2018/2/19)

I do know my storage is GPT because fdisk -l /dev/block/mmcblk0 tells me. And I've read on the net that fdisk can't handle GPT, while parted can. I'm just not sure why fdisk -l is showing nothing.

fdisk -l /dev/block/mmcblk0

Disk /dev/block/mmcblk0: 15 GB, 15634268160 bytes, 30535680 sectors
1908480 cylinders, 1 heads, 16 sectors/track
Units: cylinders of 16 * 512 = 8192 bytes

Device             Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/block/mmcblk0p1    0,0,0       0,0,0                1   30535679   30535679 14.5G ee EFI GPT
Partition 1 does not end on cylinder boundary
3
  • Your output actually shows that your fdisk version is too old and doesn't support GPT. (Is it util-linux fdisk or busybox fdisk?) It's showing the "protective MBR" partition.
    – user1686
    Commented Feb 19, 2018 at 9:26
  • I run this command on Terminal Emulator on my android phone. And I have installed busybox. I don't know about the version of fdisk. Also, when I connect with adb and run adb shell on computer, the result is the same. Do you mean the newest version of fdisk on android supports GPT? Or fdisk on a linux system can handle GPT?
    – huhiha
    Commented Feb 19, 2018 at 9:44
  • "fdisk on android" is irrelevant. The important part is where fdisk comes from – Busybox has its own version fdisk, just like it has e.g. its own version of ls and its own version of sh, completely separate from the traditional Linux fdisk/ls/sh/etc.
    – user1686
    Commented Feb 19, 2018 at 9:49

3 Answers 3

5

Note: This is applicable to Qualcomm SoC with eMMC (block device accessible through FTL). Not tested on MTK or other chipsets (paths may differ) or the devices with raw NAND/MTD memory.

PARTED

How to "install" the parted command into my android smartphone?

There is no official way, so parted isn't part of AOSP. Android doesn't want you play with its partition table. Using a static binary is the best option to avoid complications of dynamic linker/loader, libc etc.

You may get parted static binary for aarch64 (ARM-v8) and armel (ARM-v5) architecture from this link. I have compiled these on ArchLinuxARM (running on my Redmi Note 4) and on Ubuntu (PC) using gcc (cross-)compiler with glibc and they work great. Building with Bionic libc on NDK (to make it fully Android-ish) needs a lot of changes in source code because function calls (libc) and also some syscalls (kernel) differ on Android and Linux. devmapper and NLS are disabled since former isn't directly used, latter isn't supported on Android.

FDISK / GDISK

Can I use fdisk on a linux system or on Cynwin on a windows system? Knowing that fdisk brought by BusyBox can't handle GPT. (If so, maybe I could post another question.)

You may use fdisk on Android too, but fdisk is traditional tool to manipulate MBR partition tables, though newer versions also support GPT. fdisk shows somewhat info about GPT as well because GPT contains protective MBR (first sector of disk or eMMC) which contains information about partitions. Also, first partition (modem) on most of the Android devices which contains firmware for baseband processor (BP) is FAT16, more compatible with fdisk. For other partitions fdisk may behave weird or may crash.

Busybox fdisk is very minimal like other applets, and I think it hasn't been updated for a while now. Instead, GPT fdisk (gdisk) is a great tool for GUID Partition Tables and from certain aspects is better than parted.

gdisk , fdisk and mkfs.ext4 (mke2fs) static binaries are also available on above mentioned link. You may put these anywhere in your PATH; /system/bin, /system/xbin, /vendor/bin,/sbin (volatile) or even somewhere on /data or sdcard.

Now just execute:

~# parted /dev/block/mmcblk0
(parted) p free

~# gdisk -l /dev/block/mmcblk0

Please note that fdisk -l and parted -l won't show complete information (or not at all) about Android GPT because Linux kernel populates block devices directly under /dev while Android uses /dev/block path. We need to change code before compiling to make them work perfectly. fdisk -l shows loop devices because they share same nomenclature. blkid also shows partition info because it reads from /proc/partitions and /sys/dev/block/.

Finally!!!

With power comes responsibility and Linux tools are powerful. Really. A displacement of even a single byte in partition boundaries may put you in serious trouble, the worst being inability to use Factory Firmware Flashers. So, be careful!

Further reading:

7
  • Thank you very much for looking into this question! You're awesome! I haven't try out yet, but I still give you the acception! So here's why I haven't tried out. (1)parted. I don't have time yet to read the whole post. (2)gdisk. In the link you provided, I think there is only binary for windows system as you can see here. So maybe I still have to compile in order to use gdisk.
    – huhiha
    Commented May 4, 2018 at 8:42
  • And would you spend a couple of minutes to take a look at this question because I can't setup a cross-compiling environment in Cygwin. Or would you suggest me to install Linux instead of using Cygwin?
    – huhiha
    Commented May 4, 2018 at 8:44
  • Both binaries are ELF executables i.e. for Linux/Android, not for Windows. And for cross compiler, I have dual boot system; Windows and Ubuntu. Plus I have Arch chroot on my phone. I don't like Cygwin personally. There are bash for Windows and WSL etc. But those are limited in one way or other. If you want to enjoy the real freedom, use full Linux boot system. Commented May 4, 2018 at 11:13
  • I'm confused now. Following the link you provided, I reached here to look for gdisk binary. But here are 7 binaries. Which of gdisk_1.0.3-1_amd64.deb; gdisk-efi-1.0.3.zip; gdisk-windows-1.0.3.zip; gdisk-1.0.3-1.x86_64.rpm; gdisk-1.0.3-1.i386.rpm; gdisk-1.0.3.pkg; gdisk_1.0.3-1_i386.deb; is ELF executable?
    – huhiha
    Commented May 5, 2018 at 4:05
  • .deb is for Debian class distros, .rpm is for RedHat class, amd64/x86_64 is 64 bit PC, i386 is 32 bit, .pkg is for MacOS. These are all installable packages. efi.zip contains binary for UEFI i.e. to use before OS boots. Windows.zip contains 32 bit and 64 bit .exe files Commented May 5, 2018 at 10:12
2

I can use fdisk command, but maybe because my phone's disk is GPT instead of MBR, command "fdisk -l" shows no output.

It's neither MBR nor GPT. Smartphones typically use MTD partitions. These partitions are configured in the device tree, so changing them is significantly more complicated than just running a partition editor.

You can get information on the partitions by running cat /proc/mtd.

2
  • From the output it's obviously GPT. And note Android.
    – iBug
    Commented Feb 19, 2018 at 8:23
  • Sorry I didn't make it clear. I am sure that my storage is GPT. I'm just not sure why "fdisk -l" is showing nothing. The output of "fdisk -l /dev/block/mmcblk0" is added.
    – huhiha
    Commented Feb 19, 2018 at 8:25
2

maybe because my phone's disk is GPT instead of MBR, command "fdisk -l" shows no output.

Or maybe it does not have the privileges to read the partition table.

Though, as far as I know, many Android phones do not use software partitions, but something more complex than that: they partition the flash storage in hardware. So not even parted would help you in this case.

This answer on Android.SE might be relevant: https://android.stackexchange.com/questions/5232/how-can-i-view-the-android-internal-partition-table

Regarding your fdisk output example. It's not showing nothing – it's showing one partition!

But it's the wrong kind; the actual problem is that your fdisk version does not support GPT and is showing you the contents of the "protective MBR" partition table.

All GPT disks have a fake MBR containing one massive partition which covers the entire disk; its purpose is to prevent old MBR-only tools from accidentally destroying data. If you see it in fdisk's output, it means your version of fdisk is MBR-only.

The fdisk which comes with util-linux has added GPT support in v2.23. However, the Busybox fdisk has not.


That said, the rest is fairly generic and applies to all programs, not just parted.

I've traveled to GNU website of "parted". But what I can download is only source code. Do I need to compile that?

Yes.

If so, how do I compile that? Can I compile the source code with MinGW on a PC with Windows system?

Probably not. MinGW is oriented towards creating x86/x64 Windows builds – you need a cross-compiler which would provide Linux binaries and which would compile for a different CPU architecture (your smartphone uses some ARM variant).

Cygwin might have a compatible version of gcc, but doing the compilation on Linux might be much easier.

I hope to find an official version of the "parted" file.

It is rare for Linux developers to provide official compiled versions – that's usually left to the distributions.

You can download the official packages of various distributions such as Debian (Raspbian) or Arch Linux ARM, and extract the needed files manually.

Be careful to pick the correct CPU architecture of your phone.

Second, note that you'll need more than just the "parted" file: most of the core functionality is actually in a library (DLL file) called libparted.so.

5
  • Thank you for the reply. I'm gonna try official packages first because that's easier for me. But I don't know which architechture to choose. CPU-Z on my phone shows "8x ARM Cortex-A53". Should I download the "arm64" one?
    – huhiha
    Commented Feb 19, 2018 at 8:53
  • My phone's system kernel architechture is "armv8l", shown in CPU-Z. So I downloaded armv7h on archlinuxarm.org. But I have no idea how to install that. Could you give me a key word to search with if it is not simple?
    – huhiha
    Commented Feb 19, 2018 at 9:33
  • No, I meant, fdisk -l literally shows nothing, while the help text says -l will show a list of my partitions. fdisk -l /dev/block/mmcblk0 shows something which you can see. I really appreciate your reply, but my problem is still unsloved. I want to choose an easy way to use parted on my android phone. I've downloaded from the last link you provide, and I suppose armv7h is compatible on a armv8l architecture. But how do I "install" it? I don't know even know what key word I should google with.
    – huhiha
    Commented Feb 19, 2018 at 16:10
  • OK, let me guess, I think I need to put the 66KB file named "parted" under /system/bin and find the 203KB file named "libparted.so.2.0.1" (after renaming it to "libparted.so"), and put it somewhere(maybe I need to search for *.so). Is that all? Is there any document that proves? I really have no clue right now.
    – huhiha
    Commented Feb 19, 2018 at 16:23
  • Honestly, neither do I – I know regular Linux, but Android's filesystem layout is a mystery. Actually I even suspect "regular" Debian/Arch builds might not even be compatible with Android's libc...
    – user1686
    Commented Feb 19, 2018 at 17:45

You must log in to answer this question.

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