Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access USB stick or the Android file system? #95

Closed
mhofert opened this issue Jan 11, 2014 · 9 comments
Closed

How to access USB stick or the Android file system? #95

mhofert opened this issue Jan 11, 2014 · 9 comments

Comments

@mhofert
Copy link

mhofert commented Jan 11, 2014

Hi,

I started working with Linux Deploy (Ubuntu 13.10 on Android 4.4.2 [Nexus 5]) and I like it a lot so far. I am wondering how one can transfer files from Ubuntu to the Android file system and the other way round? This would be very important for using Ubuntu under Android for real work. I also connected the phone to a USB stick but /media/... does not show any media. It's somehow clear, since Ubuntu runs inside an image, but is there really no way to access the Android file system? the only possibility which remains in this case, would be to upload all your data to a server and download it from within Ubuntu... but that's very tedious.

Cheers,
Marius

PS: Although it also runs Ubuntu inside an image, with the 'Complete Linux Installer' app one can access the Android file system. From within Ubuntu, go to /root/Desktop/sdcard (which accesses /sdcard on Android). With 'sudo su' I can change to /root, but it only shows some dot-files :-(

@sunaku
Copy link
Contributor

sunaku commented Jan 11, 2014

Yes, this is possible. ✨ You just need to enable "Custom mounts" and set up the proper "Mount points" in the properties (the download arrow button in LinuxDeploy) of your LinuxDeploy image.

For example, I added /data/media/0 in the "Mount points" list to make LinuxDeploy mount my SD card from Android into my chroot'ed Linux as /mnt/0. Then, I can access /mnt/0 from my chroot'ed Linux. Any changes made there will be immediately available to Android and vice versa.

This is how you can efficiently share data between Android and your chroot'ed Linux. :neckbeard:

@mhofert
Copy link
Author

mhofert commented Jan 11, 2014

Thanks a ton, works like a charm!
[this time, I indeed can close this issue :-)]

@yuezy3
Copy link

yuezy3 commented Jan 28, 2018

@sunaku Well,what I DO IS :
Enable "Custom mounts" and set up the "Mount points" to "/storage/sdcard0"
Then In my chroot'ed Linux, When I access the /storage/sdcard0, I got permission denied error.
How can i fix this?

------------------------- below are something that i run in ssh------------------------

android@localhost:~$ df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/loop1              4.0G  782M  3.1G  21% /
tmpfs                   488M  496K  488M   1% /dev
tmpfs                   488M     0  488M   0% /dev/shm
/dev/block/vold/179:97   15G  4.1G   11G  28% /storage/sdcard0
android@localhost:~$ mount
/storage/sdcard0/linux.img on / type ext4 (rw,relatime,data=ordered)
proc on /proc type proc (rw,relatime)
sys on /sys type sysfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,mode=755)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,relatime)
/dev/block/vold/179:97 on /storage/sdcard0 type vfat (rw,nosuid,nodev,noexec,relatime,dirsync,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
android@localhost:~$ ls -l /storage
total 8
d---rwxr-x 15 android aid_sdcard_rw 8192 1月  28 10:57 sdcard0
android@localhost:~$

BY THE WAY, I am in aid_sdcard_rw group:

android@localhost:~$ id
uid=1000(android) gid=1000(android) groups=1000(android),1001(aid_radio),1002(aid_bluetooth),1003(aid_graphics),1004(aid_input),1005(aid_audio),1006(aid_camera),1007(aid_log),1008(aid_compass),1009(aid_mount),1010(aid_wifi),1011(aid_adb),1012(aid_install),1013(aid_media),1014(aid_dhcp),1015(aid_sdcard_rw),1016(aid_vpn),1017(aid_keystore),1018(aid_usb),1019(aid_drm),1020(aid_available),1021(aid_gps),1023(aid_media_rw),1024(aid_mtp),1026(aid_drmrpc),1027(aid_nfc),1028(aid_sdcard_r),1029(aid_clat),1030(aid_loop_radio),1031(aid_media_drm),1032(aid_package_info),1033(aid_sdcard_pics),1034(aid_sdcard_av),1035(aid_sdcard_all),1036(aid_logd),1037(aid_shared_relro),2000(aid_shell),2001(aid_cache),2002(aid_diag),3001(aid_net_bt_admin),3002(aid_net_bt),3003(aid_inet),3004(aid_net_raw),3005(aid_net_admin),3006(aid_net_bw_stats),3007(aid_net_bw_acct),3008(aid_net_bt_stack)

Any hope will be thanks.

@musical-chairs
Copy link

musical-chairs commented Mar 18, 2018

I know this is an old issue, but permissions for accessing sdcard storage are still problematic on a default installation. This worked for me on Android 7.1. Use "Custom mounts" as posted above, then in a terminal in your linux chroot do the following:

  1. Create the group "everybody" with id 9997:
    sudo groupadd -g 9997 everybody
  2. Add your user to group "everybody":
    sudo adduser {username} everybody
  3. Log out and back in. Now you can read and write your mounted folder without needing root permissions.

@kennylouie
Copy link

I noticed a lot of differing answers to mounting external sdcard or usb in the chrooted linux. I guess I'll share what I've been using.

  1. Typically you can find your mount points for your usb sticks or sdcards in /dev/block/. To find the exact ones I usually use a terminal app like Termux in Android and use blkid as root. This prints out all the mount points e.g. /dev/block/sda1 is usually the 1 usb port on your phone.
  2. Now inside your chrooted linux you can find that /dev is usually mounted already. This means that its as easy creating a folder e.g. mnt in your home and executing sudo mount /dev/block/sda1 ~/mnt. I usually make this an alias in my bashrc. This can also be done for your sdcard e.g. sudo mount /dev/block/mmcblk1p1 ~/mnt.

@pellet
Copy link

pellet commented Sep 21, 2018

Permissions are playing up for me sometimes too and the only way I seem to be able to get around it for instance when I'm using git is to use sudo...

@leoncoolmoon
Copy link

I noticed a lot of differing answers to mounting external sdcard or usb in the chrooted linux. I guess I'll share what I've been using.

  1. Typically you can find your mount points for your usb sticks or sdcards in /dev/block/. To find the exact ones I usually use a terminal app like Termux in Android and use blkid as root. This prints out all the mount points e.g. /dev/block/sda1 is usually the 1 usb port on your phone.
  2. Now inside your chrooted linux you can find that /dev is usually mounted already. This means that its as easy creating a folder e.g. mnt in your home and executing sudo mount /dev/block/sda1 ~/mnt. I usually make this an alias in my bashrc. This can also be done for your sdcard e.g. sudo mount /dev/block/mmcblk1p1 ~/mnt.

this not working for me as it shows
"Mount is denied because the NTFS volume is already exclusively opened.
The volume may be already mounted, or another software may use it which
could be identified for example by the help of the 'fuser' command"

@istomyang
Copy link

If you want to wr sdcard without root, you can try to add your user to gruop aid_sdcard_r, and restart!

prefer:
usermod -aG group user

@ScottRFrost
Copy link

As of Android 12 / Linux Deploy 2.6.0.259, the group is now called aid_media_rw but the same process works
image

sudo usermod -aG aid_media_rw YourUsernameHere
Log out as that user
Stop Linux Deploy container
Start Linux Deploy container
Log back on as that user, you should now be able to cd /mnt/android or whatever you called your mount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants