3

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

1 Answer 1

6

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.

2
  • 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

You must log in to answer this question.

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