How to run "parted" command in terminal emulator on my android smartphone


Question

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

Answer

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:




Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes