How to run "parted" command in terminal emulator on my android smartphone 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. 


How to "install" the parted command into my android smartphone? 
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
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:


ArchLinux Partitioning
Android Partitions