2

I've got a 256 GB microsd card which only works with my phone if its file system is FAT32. The issue I have with this, is that FAT32 only supports files up to 4 GiB, which is a bit low by today's standards. I am able to successfully mount an exFAT partition using a FUSE driver, which I found here: https://forum.xda-developers.com/showpost.php?p=79685842&postcount=9 I did not install that zip; instead, I simply extracted the mount.exfat binary and called it from a superuser shell. The actual issue I'm having, is that if I mount anything using that method, the Android OS doesn't "register" that as a microsd card. So apps can read and write data to the mountpoint as if it was a plain directory, but it is not recognized as an actual external storage device. I'm trying to figure out what exactly does Android do when you tap the "Mount SD card" entry in Storage settings, and how can that be replicated outside of the Settings app.

If a FAT32 card is mounted automatically by Android, here's what the mount points look like:

$ mount | grep 5D03
/dev/block/vold/public:179,65 on /mnt/media_rw/5D03-6C2D type vfat (rw,dirsync,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
/mnt/media_rw/5D03-6C2D on /mnt/runtime/default/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,mask=6)
/mnt/media_rw/5D03-6C2D on /storage/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,mask=6)
/mnt/media_rw/5D03-6C2D on /mnt/runtime/read/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,mask=18)
/mnt/media_rw/5D03-6C2D on /mnt/runtime/write/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,mask=18)

Forgetting about exFAT or other file systems for a moment, I first tried to replicate that using the same FAT32 partition which was mountable natively by Android. I unmounted the SD card from settings, which resulted in the above command not outputting anything anymore, and proceeded to mount the partition in much the same way as described by the mount output seen above. From a su -mm shell, I first created the necessary mount points with mkdir, then replicated all the entries with mount, like mount -o rw -o nosuid -o nodev [...] -t vfat /dev/block/vold/public:179,65 /mnt/media_rw/5D03-6C2D. When finished, the output from mount | grep 5D03 was almost exactly the same as if it was the Android OS doing the mounting (checked with diff: the single difference was the lack of the dirsync option, as mount complained about not recognizing that option, all other lines were exactly the same). But that still did not make the Android OS acknowledge that a SD card was indeed mounted. From this, I gather that Android does some extra step when mounting an SD card. For example, if the card is mounted natively by Android, file manager apps will show the SD card's capacity and free space, and will allow to easily browse its contents. But if I mounted the very same SD card manually, as described above, the same file manager would only offer to browse internal storage. The SD card could still be accessed if I navigated to the mount point directory (/mnt/media_rw/5D03-6C2D) so it was properly mounted and working, just not recognized by Android.

So I guess this lengthy question really boils down to this simple one: How can one mount devices in Android OS and have the mount points recognized as real external storage devices?

  • Mounting/unmounting is managed by vold daemon. exFAT support was added to vold in Pie. exFAT is mounted natively (not through FUSE, provided that kernel is built with exFAT). Some custom ROMs also have NTFS support in vold through FUSE. Apps can't access the filesystem of external storage directly at least since KitKat. Instead they use some form of Storage Access Framework to read/write the contents of external storage. So if vold is not mounting the filesystem, I don't think you can let the OS (and hence apps) know you have done this manually. – Irfan Latif Jun 14 at 22:21
  • @IrfanLatif Thanks for your comment. Does that mean I just have to replace the /system/bin/vold binary with another one, compiled with exFAT support, and it should work right away? By the way, I don't really care about exFAT specifically - I'll happily take anything that works and lets me store files larger than 4 GiB. – combinedfleet Jun 15 at 8:27
  • That sounds right but you can go through source code to see if any other things need to be replaced other than vold: android.googlesource.com/platform/system/vold/+/refs/heads/…. Btw, did you try ext4? – Irfan Latif Jun 15 at 13:25
  • @IrfanLatif Yeah, I already tried ext4, NTFS, f2fs without any success. I could mount the ext4 partition manually from a shell, but otherwise it's all the same as earlier. Makes me want to just try the vold binary from here: github.com/Magisk-Modules-Repo/vold-posix In the worst case scenario, it should just fail to mount, right? If it renders the system unable to boot, I should be able to just replace the binary with the original one. – combinedfleet Jun 15 at 14:46
  • There are other things too in the module in addition to replacing vold binary. It's worth a try. – Irfan Latif Jun 15 at 15:15

Your Answer

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

Browse other questions tagged or ask your own question.