termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.4k stars 3.09k forks source link

How to access the usb storage (OTG) using the Termux? #7037

Closed iChitti closed 3 years ago

iChitti commented 3 years ago

Hello, I am kind of Novice in this field but. I am really curious about termux and the way it works. So I am trying to access the usb storage just like we access the internal storage like cd /storage/emulated/0/... Or cd /sdcard/.... I've tried some of the fix but didn't worked for me. And I also tried the following fix: https://wiki.termux.com/wiki/Termux-usb

Everything seems to work fine but after executing: termux-usb -e ./usbtest /dev/bus/usb/001/002 It's giving me this error:

usbtest.c:12: int main(int, char **): assertion "!libusb_init(NULL)" failed
/data/data/com.termux/files/usr/libexec/termux-callback: line 3: 29227 Aborted                 $TERMUX_CALLBACK "$@"

So any help from the experts is appreciated.

Thank you!

ghost commented 3 years ago

termux-usb is not right thing to access USB storage. Also Termux doesn't provide utilities or any capabilities to have a write access to such kind of storage.

At max you can get R/W access to Termux private directory on USB drive. It is usually located at

/storage/XXXX-XXXX/Android/data/com.termux

Where XXXX-XXXX is unique filesystem id. You may need to execute termux-setup-storage to create this directory.

You need to be root in order to write files to other directories of USB drives.

Overview about supported storage types and their capabilities: https://wiki.termux.com/wiki/Internal_and_external_storage

Grimler91 commented 3 years ago

See also https://github.com/termux/termux-app/issues/71, https://github.com/termux/termux-app/issues/303, https://github.com/termux/termux-app/issues/1376

iChitti commented 3 years ago

Seems like there is No Way to access USB storage currently. But thanks for yours Respnoses. Your responses make me feel the questions can be answered.

oneindelijk commented 1 year ago

I tried this too. Using the explorer on Android, through the details of a file on the USB OTG, I found the path which was something like /mnt/media_rw// I then granted termux extra permissions in the settings "allow apps to access all storage device internal and external". That didn't grant termux access to read from this path though. Perhaps I need to run the 'termux-setup-storage' again with the USB OTG connected and mounted

oneindelijk commented 1 year ago

Ooh, that actually worked. Great! Now I can use a script to transfer the video files from the DJI Avata over the USB OTG to my linux computer. On Linux, the Avata is seen as a USB device, but there seems to be no way to access the files (because I think I read somewhere that it is an ethernet device)

jorexdeveloper commented 1 year ago

I tried this too. Using the explorer on Android, through the details of a file on the USB OTG, I found the path which was something like /mnt/media_rw// I then granted termux extra permissions in the settings "allow apps to access all storage device internal and external". That didn't grant termux access to read from this path though. Perhaps I need to run the 'termux-setup-storage' again with the USB OTG connected and mounted

I have tried these steps but no luck

AlainKnaff commented 5 months ago

As described on the udroid link above, the trick is to get the storage device mounted under /storage via fuse (in addition to /mnt/media_rw). In this spot, it can be accessed by Termux.

The following command, executed as user shell (via adb shell over USB cable) sets up the device up so that both secondary SD card and USB sticks are mounted under /storage with fuse:

sm set-force-adoptable on

After this, these devices can be accessed from Termux. /storage directory is unreadable, but names are displayed just fine with df.

Setting only applies to devices inserted after command has been issued. Setting is remembered across reboots

Tested with stock Android 14 on a Pixel 7a, and with LineageOS 20 on a Galaxy Tab S3.

freebrowser1 commented 4 months ago

Same here.

It does require a root shell, as a standard shell is access denied.

Nothing 2a:~$ ls -al /mnt/media_rw/*
ls: cannot access '/mnt/media_rw/*': Permission denied
Nothing 2a:~$ sudo bash
.../files/home # ls -al /mnt/media_rw/
total 0
drwxr-x---  3 root     external_storage  60 Jul 15 21:09 .
drwxr-xr-x 16 root     system           340 Jul  9 22:38 ..
drwx------  2 media_rw media_rw          40 Jul  9 22:38 usbotg
.../files/home # ls -al /mnt/media_rw/usbotg/
total 0
drwx------ 2 media_rw media_rw         40 Jul  9 22:38 .
drwxr-x--- 3 root     external_storage 60 Jul 15 21:09 ..
.../files/home #

Nothing 2a, Android 14 stock. The usbotg subfolder was still empty, despite a memory card was plugged in the USB of the phone and its contents shown in the file manager app.