6

I would like to install my termux environment (usr folder) to an SD card. is this possible?

I have seen this post Can I install packages to external SD card on Termux in Android?. From what I understand the problems mentioned there is only if you want to install individual packaged to the SD card. I'm looking to install the whole usr folder.

1

2 Answers 2

8

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).

  1. Create an ext4 partition on the SD card. (This can be a 2nd partition).
  2. 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)
  3. 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.
  4. 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).

  1. 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.
  2. 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.

5
  • Trying this on a rooted device but on step 6 getting ln: cannot create hard link from '/data/data/com.termux/files/home/ext4-fs/usr' to '/data/data/com.termux/files/usr': cross-device link Sep 13, 2020 at 0:11
  • @MiguelMota You need to make a symlink with option -s. (See the edited step #6)
    – Sruly
    Sep 21, 2020 at 19:44
  • Thank you for your help, but when I tried: mount /dev/block/mmcblk1p2 /data/data/com.termux/files/home/ext4-fs in my termux shell, I received a "permission denied" message. I can do a mount with tsudo, but then I cannot access the ext4-fs file without being root. I am using Android 6.0 and a v0.79 Termux. If you have any suggestions or solutions I will be grateful.
    – P B
    Mar 19 at 18:27
  • @PB As root, do chown -R <your-termux-uid>:<termux-gid> <mount-point>. The mount point in your case is /data/data/com.termux/files/home/ext4-fs
    – Sruly
    Mar 20 at 0:31
  • @Sruly But in my case mount point doesn’t persists after reboot ? Aug 6 at 14:15
1

The problem was SELinux. I resolved by installing "The SELinux Switch" and then putting in the "permissive" mode. Now I can mount with root and access in Termux WITHOUT root!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .