3

I want to create 4 partitions on external MicroSDcard through ADB shell commands, not on Windows or Linux. Also want to show all partitions in Android GUI (SETTINGS > STORAGE > SDCARD) and make them usable for all apps and file explorers.

  1. Dedicated first partition exFAT or NTFS or FAT32 (whichever Android permits and gives optimum performance) to store apps, photos and media.

  2. Second partition ext4, dedicated to applications linked through Link2SD. Or I want some applications or auto scripts or tools or commands to set the apps mainfest to always install on SD card.

  3. Third partition ext4 or NTFS or exFAT, dedicated for auto recording random backups or shadow images of partitions for different time, if possible through commands, scripts or apps like Titanium backup or others.

  4. Fourth partition ext4 or NTFS or exFAT, dedicating for Virtual memory (as we do for pagefile.sys in Windows or Linux swap partition).

If I format 1st partition with ext4, exFAT or NTFS, Android OS doesn't show it in SETTINGS > STORAGE> SDCARD > PARTITIONS and asks to mount or erase the partitions.

Now to limit and specify the questions:

  1. Can SD card have 4 partitions and will Android and SD card support it?

  2. Examples of commands to partition in Android; fdisk or parted or the best one.

  3. Is it necessary in Android that 1st partition should be FAT32? Or can we make it exFAT or NTFS to which Android Apps2SD and others apps can download?

  4. Can we force mount command in some startup boot init file to mount all four partitions?

  5. Will this mounting show the partitions in Settings and device file manager?

  6. Or can we view these partitions through ES File Manager or Solid Explorer or Root Manager and take their backups too?

Please guide me through the safe, secure, best and feasible method and procedure which does not damage the device hardware or SD card.

  • formatting or partitioning? interactive commands like fdisk or one-liners? – alecxs Jan 3 at 9:05
  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question.” Also see One post with multiple questions or multiple posts? – Irfan Latif Jan 3 at 14:21
  • @irfanlatif ok i will take care to its thanx for suggestions and guidance – Androidquery Jan 3 at 16:12
  • @IrfanLatif i have edited and tried to limit the questions towards single queries later queries i will ask in different post – Androidquery Jan 3 at 17:10
3

A few points on four partitions:

  1. Dedicated first partition exFAT or NTFS or FAT32 (whichever Android permits and gives optimum performance) to store apps, photos and media.

    For apps consider Application Class but that's expensive. Others will exert performance penalty more or less. On filesystem selection, the biggest downside with FAT32 is its 4GB maximum file size limit. Also it doesn't have some built-in phenomenon to deal with growing fragmentation which may reduce performance over time. You can find many online resources on pros and cons of FAT32 and exFAT. Also see the MS's official Filesystem Functionality Comparison.

    Is it necessary in Android that 1st partition should be FAT32?

    Not necessary if your device supports other filesystems. FAT32 is Android's default for secondary external storage (SD cards and USB drives) since the start days. Since SDXC cards (32GB+) come pre-formatted with exFAT (though not a technical limit), many OEMs add exFAT support to their devices. However exFAT was closed-source until recently, so it's not part of stock Android (except some limited addition in Android 9). But now it's very likely to be added to Android's kernel source. See some relevant details in this answer.

    So check if your kernel supports exFAT: grep exfat /proc/filesystems. NTFS is still closed-source and doesn't have a stable in-kernel open-source driver. However it's possible to mount exFAT and NTFS using FUSE drivers. In each case vold must support the filesystem.

    Or can we make it exFAT or NTFS to which Android Apps2SD and others apps can download?

    Irrespective of filesystem, all apps don't have write access to external SD card unless you make some changes to ROM. See details in How to save files to external SD card? and Android's Storage Journey.

  2. There are apps available to move unsupported apps to SD card. Or you can manually (bind) mount a SD card partition (or directory) inside /data. Surely you need ext4 (or f2fs on new devices) for this purpose (to enforce UNIX permissions). But it doesn't necessarily needs to be a partition, you can place a loop file on first partition.

    Trying to modify app's manifest (or asking how to do so) can be considered unethical or illegal.

  3. You don't need a dedicated partition to store backups. Instead first partition can be used.

  4. If you want to use whole partition for swap, that doesn't need a filesystem (but mkswap). If you want to create swap file instead (which isn't a bad idea), again you can use first partition for that. However using external SD card for swap is not always a good idea. From zram commit to mainstream kernel:

    embedded systems normally are reluctant to use eMMC or SDCard as swap because there is wear-leveling.
    ...
    Although we have real storage as swap, it was a problem, too. Because it sometime ends up making system very unresponsive caused by slow swap storage performance.

    Android supports swap with zram back-end (which creates a compressed block device within RAM) since Android 4.4. Android's OOM killers (old in-kernel lowmemorykiller and new userspace lmkd) do take swap into account. If your kernel supports ZRAM, using external SD card for SWAP is not recommended. It can worsen the performance and will kill the SD card very soon due to increased I/O operations.

If I format 1st partition with ext4, exFAT or NTFS, Android OS doesn't show it in SETTINGS > STORAGE> SDCARD > PARTITIONS and asks to mount or erase the partitions.

It can be due to unsupported filesystem (see explanation above) or multiple partitions (see explanation below). However if a partition is manually mounted with proper permissions, apps are able to read/write files there. You may use sdcardfs or FUSE to emulate the filesystem for fixed permissions. But this way Android framework is unaware of mounted filesystem and Android apps won't be notified of new storage. Neither you can manage the mounted storage from device Settings.

Can SD card have 4 partitions and will Android and SD card support it?

Android kernel by-default supports GPT which can have up to 128 partitions. MBR also supports 4 primary (or more logical) partitions (inside extended partition). Generally there is no technical limit but Android's userspace may mount only first partition, or may not recognize multi-partitioned SD card at all e.g. due to unknown partition type including Linux (0x83). Though vold supports multiple partitions before Android 6 too, you need to define FUSE (sdcard) init services, add entries to fstab, configure storage in framework-res.apk etc. If mounting multiple partitions doesn't work without these changes, you need to mount (additional or all) partitions manually (or rebuild your ROM with modified code).

Will this mounting show the partitions in Settings and device file manager?

No. See explanation above. Not sure what you mean by "device file manager".

Or can we view these partitions through ES File Manager or Solid Explorer or Root Manager and take their backups too?

Yes and no; depends on how, where and with what filesystem permissions you mounted the filesystem. See explanation above. Not sure what you mean by "take their backups too".

Examples of commands to partition in Android; fdisk or parted or the best one.

Partitioning works alike on all OSes. There's a long list of CLI and GUI tools and you'll find hundreds of tutorials online. Assuming that your SD card is enumerated as mmcblk1 and you want to create first partition of 32GB while leaving the rest for second, a one liner on Android can be:

~# sgdisk -Z -n 0:0:+32G -n 0:0:0 -p /dev/block/mmcblk1

See sgdisk manpage for explanation and more options. If needed use partx -uv /dev/block/mmcblk1 to update kernel of partition table changes, or simply reinsert SD card.

After partitioning use mkfs.fat/mkfs.exfat/mkfs.ntfs/mkfs.ext4 to create filesystem. All tools are available for Linux and work on Android as well.

Can we force mount command in some startup boot init file to mount all four partitions?

Yes. Create an init service or init.d script. See details in How to run an executable on boot?

| improve this answer | |
  • 1
    thx for pointing out the swap nonsense! – alecxs Jan 4 at 19:08
  • 1
    @IrfanLatif thanks a lot for elaborated and explained answer to each part of question highly obliged with efforts and greatness thanks a lot – Androidquery Jan 5 at 3:18
2

just partitioning and formatting from adb shell (needs to be umount)
(for doing this in recovery, delete all strings /data/local and su -c from command list)

adb push parted /data/local/tmp
adb shell chmod 0755 /data/local/tmp/parted
adb shell su -c "export PATH=$PATH:/data/local/tmp"
adb shell su -c "parted /dev/block/mmcblk1 mktable msdos"
adb shell su -c "parted /dev/block/mmcblk1 mkpart primary 1048576B 31914983423B"
adb shell su -c "mke2fs /dev/block/mmcblk1p1 -t ext4"
adb shell su -c "parted /dev/block/mmcblk1 unit B print"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.