If your device is rooted, you can do it, but it is a little tricky. (You may need to use another terminal app or work in failsafe of termux).
- Create an
ext4
partition on the SD card. (This can be a 2nd partition).
- Make a new folder where you want to mount the new partition on. (For example in your home folder add a folder called
ext4-fs
)
- In termux mount the partition (I'm assuming a 2nd partition). You need to know the path to the device. I have found it to be
/dev/block/mmcblk1p2
but this may be different on your device. mount /dev/block/mmcblk1p2 /data/data/com.termux/files/home/ext4-fs
.
- Copy the
usr
folder from termux /data/data/com.termux/files/usr
to the new mounted partition.
From here on you will need to use commands that are in /system/bin/
. (And may need to use failsafe mode or an other terminal app).
- Rename the
usr
folder to something like usr-old
. /system/bin/mv /data/data/com.termux/files/usr /data/data/com.termux/files/usr-old
.
- Make symlink to the
usr
folder that's now on the new partition. ln -s /data/data/com.termux/files/home/ext4-fs/usr /data/data/com.termux/files/usr
. This will now be your termux usr folder which is linked to the folder on the sd card. (You can force a symlink even if usr
already exists with ln -sfn
)
Now you can delete the old usr
folder (That we renamed usr-old
).
Now termux uses the symlinked folder that is on your SD card for all that needs the usr
folder which is the whole termux environment.
Every time you take out the SD card and reinsert it you will need to remount the partition.