3

Can I mount /data/data/com.termux/ folder on external sd card? My phone is rooted Android 10 and running low of internal storage.

As I read from How to bind mount a folder inside /sdcard with correct permissions? mounting to /sdcard requires permission to mount because /sdcard is emulated from /data/media/0 and /data/data/ is not.

And from Can the Termux environment be put on an external SD card? it can mount /data/data/com.termux/ using ln -s because ext4 support links while fat doesn't.

I don't know how /data/data/ directory works but is it possible to mount /data/data/com.termux/files/home/ directory to external sd card without formatting it as adoptable storage or making ext4 partition?

1
  • 1
    Yes. Create a loop file in SD card and mount it to /data/data/com.termux/files/home. – Irfan Latif Nov 28 '20 at 16:41
2
  • create a file in MicroSD Card. make sure the file is not too large for fat32 file size limitation

    busybox dd if=/dev/zero seek=4294967295 bs=1 count=0 of=/mnt/media_rw/6DE8-1BC6/loop.img
    
  • create a file system (confirm with y)

    /system/bin/mke2fs -t ext4 /mnt/media_rw/6DE8-1BC6/loop.img
    
  • loop mount the file to existing directory

    mkdir -p /data/data/com.termux/files/home/ubuntu20-fs
    busybox mount /mnt/media_rw/6DE8-1BC6/loop.img /data/data/com.termux/files/home/ubuntu20-fs
    

UPDATE:

that works only for busybox with largefile support. according to user Jtnqr and user Hmm you may still facing some trouble. the following is exactly the same example like above but with screenshots
* * * stop reading here * * *

only one extra step is copying files/usr into loop file before mounting


  • create a file in MicroSD Card

    ls -la /data/data/com.termux/files
    su
    mkdir /storage/26B7-11F7/com.termux
    cd /storage/26B7-11F7/com.termux
    busybox dd if=/dev/zero bs=1M count=4095 of=usr.img
    

    2020-12-27_22_39_23.png


  • create a file system (confirm with y)

    /system/bin/mke2fs -t ext4 usr.img
    

    2020-12-27_22_41_49.png


  • copy files/usr into loop file before mounting

    mkdir -p tmp/usr
    busybox mount usr.img tmp/usr
    
    df -h | grep /dev/loop
    grep termux /proc/mounts
    
    busybox cp -acv /data/data/com.termux/files/usr tmp
    df -h | grep /dev/loop
    

    2020-12-27_22_53_15.png


  • loop mount the file to existing directory

    umount tmp/usr
    busybox mount usr.img /data/data/com.termux/files/usr
    df -h | grep /dev/loop
    exit
    ls -la /data/data/com.termux/files/usr
    

    2020-12-27_22_57_21.png


the same can be repeated for other directories. you can loop mount another home.img file into files/home to extend termux storage

reason for splitting into multiple files is fat32 file size limitation < 4 GB

2
  • Busybox-1.29.2-YDS-UNIVERSAL.zip – alecxs Nov 30 '20 at 11:29
  • im trying to do the same and if i run busybox dd if=/dev/zero seek=4294967295 bs=1 count=0 of=/mnt/media_rw/26B7-11F7/com.termux/loop.img it gives me dd: /mnt/media_rw/26B7-11F7/com.termux/loop.img: Invalid argument – Hmm Dec 26 '20 at 11:49

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.