I'm trying to use FUSE to mount a virtual FS on a rooted android.
I've compiled a simple program that mounts a readonly virtual FS containing a single file (hello) containing the contents Hello world.
After compiling the program, I ran (as root)
mkdir /mnt/test
chmod 777 /mnt/test
a.out -d -oallow_other mnt/test
When I run ls /mnt/test as a root user, everything works as expected.
When I run ls /mnt/test as any other user, or from any other application (explorer / adb shell), I receive the contents of the underlying filesystem (in this case, the root filesystem) instead of the output from the FUSE fs.
After digging into it a little, I found out that the FUSE mounts don't show up when running cat /proc/mounts as a user, but it does show up as root. Does android (or maybe even linux ?) have special facility for hiding mountpoints to specific users ?
Solution:
I decided to run my program as daemon in initrc, and it's work well
on post-fs-data
start hello
service hello /sbin/hello
seclabel u:r:su:s0
Related
I'm trying to use the Android Adb Command Prompt to copy a folder inside the app container to a local Windows folder. The device is running Android 5.1.1 and is not rooted.
adb pull or cp aren't working. How can I copy a folder?
The following approaches aren't working:
Approach 1
adb shell
adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
error: device not found
Inside the shell you can't see to do adb pull. See here.
Approach 2
DDMS can't access the data folder.
Approach 3
adb shell
run-as DroidSample.DroidSample
cp /files/MetroLog/MetroLogs/ C:/temp/test
cp: /files/MetroLog/MetroLogs/: No such file or directory
Approach 4
adb shell
run-as DroidSample.DroidSample
cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs/ C:/temp/test
cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs is a directory (not copied).
This is also not working.
Approach 5
adb shell
run-as DroidSample.DroidSample
chmod 777 /files/MetroLog/MetroLogs
exit
exit
adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
adb shell run-as DroidSample.DroidSample
chmod 700 /files/MetroLog/Metrologs
remote object '/data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs' does not exist
So also this isn't working.
Approach 6
adb shell
mkdir /sdcard/tmp
cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs /sdcard/tmp
cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs: Permission denied
This is also not working.
Approach 7
The only thing which half work is this
adb exec-out run-as DroidSample.DroidSample cat "files/MetroLog/MetroLogs/Log - 20160509.log" > C:/temp/test/test.log
But here I don't get the original file and I also have to know the exact file name. Additionally, that I loose line breaks and I have to do this for each file. Not that what I want.
So I'm running out of ideas. How can I access the internal stored files and copy them over?
You have almost solved the problem. As the storage of this kind is secured, you need to do one additional step. You need to copy the file from secured location to sdcard of the device. And then you can copy it anywhere via usb or android pull. Here are the command sequence I executed successfully.
adb shell
run-as DroidSample.DroidSample
cd shared_prefs
cp DroidSample.DroidSample_preferences.xml /sdcard/DroidSample.DroidSample_preferences.xml
exit
exit
adb pull /sdcard/DroidSample.DroidSample_preferences.xml C:/test/
That's it.
And I really appreciate the way you posted your question. Best of luck.
You're trying to gain read access to /data partition on actual android device. Such thing is not possible without root access, even if the app folder is yours. For the reason that permissions to read /data partition are not granted and cannot be granted, unless you're using an emulator. On emulator, which by default is with admin privileges for developer, you can access the data partition to read and write. On actual device you cannot. Not with adb, not with DDMS.
So basically speaking, anything that requires access to those files under /data is not going to work. Whether you sue cp command or pull command. The moment your kernel reads the beginning of your path which starts with /data/... it says: Oops, no can do.
You are trying to access /data folder of android device which is not accessible in unrooted device.
I have written the following shell script:
alias mount='/system/xbin/busybox mount'
set -e
set -x
MNT=sda1
function mkdir_ext() {
if [ ! -d $1 ]; then
mkdir -p $1
fi
chown $2 $1
chmod $3 $1
}
mkdir_ext /storage/emulated/$MNT root:media_rw 777
mount -t ext4 /dev/block/$MNT /storage/emulated/$MNT
mkdir_ext /data/media/$MNT root:media_rw 777
sdcard -u 1023 -g 1023 /storage/emulated/$MNT /data/media/$MNT
After executing the commands above, mount reports:
root#NEO-X8:/sdcard # mount|grep sda
/dev/block/sda1 /storage/emulated/sda1 ext4 rw,seclabel,relatime,data=ordered 0 0
/dev/fuse /data/media/sda1 fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
I am working via ssh, remotely, using rooted ssh/sftp daemon, and while logged in as root, I can list the files in /storage/emulated/sda1.
From what I understand, android is case-insensitive in regards to filesystems by design, so the filesystem has to be fused.
The problem is, I see just an empty directory in /data/media/sda1. Even stranger is that, if I navigate to /storage/emulated/sda1 from the device as root with bash shell X, I also see an empty directory.
I have tried different other apps and I've tried to also use sdcard_rw instead of media_rw (with the uid / gid 1015 instead of 1023), nothing works.
How to get ext4 to work for all apps on a rooted Minix NEO X8-H? Using anything but ext4 is not an option, the 4TB drive already contains important data. As a side note, sda1 is just a small 1GB partition.
I will assume that your device is rooted from what you have done so far so will not go into that. Though I cannot be certain this is your issue I shall explain how I solved a similar problem.
Resent versions of android with the intent on improving device security are now using the (somewhat half arsed) feature of making mounts performed by most processes not visible to other processes. Working around this is frustratingly device specific, however it appears the Minix NEO X8-H is using a "vanilla" style source build of android. Therefore you have a good chance of using StickMount in order to mount the USB stick, it should enable the global mounting of USB devices running any file-system supported by your ROM (which should include ext4 given you have already mounted it before).
I have not tested this personally on your device so cannot guarantee it will work but have had success with a number of other android devices so this is certainly worth a shot.
I use mkfs -t ext4 /dev/sdf2 format SDcard and insert into samsung s4 anrdoid phone.
adb shell
su
mount /dev/block/mmcblk1p2 /root
I cant't mount this SDcard, I have googled it but no solution.
The last, I found this can succeed :)))
mk2fs -t ext4 /dev/sdf2
and ...
I am trying to add OBB file support and I have run into a bizare situation. When I call getExternalStorageDirectory(), it returns a path that does not exist on my device.
I call this at the start of my app:
Log.i( LOG_ID, "XXXXXXXXXXXXXXXX <--- "+Environment.getExternalStorageDirectory().getAbsolutePath() );
It returns:
XXXXXXXXXXXXXXXX <--- /storage/emulated/0
But when I connect via adb -d shell and run ls -al /storage/emulated I get:
lrwxrwxrwx root root 2013-12-04 15:17 legacy -> /mnt/shell/emulated/0
As you can see the path getExternalStorageDirectory() returned is not valid on my device. Any idea why this would be and how I can locate the OBB files without hard coding /mnt/sdcard/?
EDIT:
I have just run some further testing:
Works - stat( "/sdcard/Android/obb" );
Fails - stat( "/sdcard/Android/obb/uk.co.mycomp.myapp" );
shell#android:/mnt/shell $ ls -ald /sdcard/Android/obb/
drwxrwxr-x root sdcard_rw 2013-12-18 16:42
shell#android:/mnt/shell $ ls -ald /sdcard/Android/obb/uk.co.mycomp.myapp
drwxrwxr-x root sdcard_rw 2013-12-18 18:36
As you can see the two directories are identical yet I can only access the parent. This may or may not have any relevance to my issue...
In recent Android versions, the mounts are actually different for different user ID's, which invalidates the way you are trying to investigate this.
Your attempt at investigating the storage paths is frustrated by the fact that recent Android versions leverage the "Per-process namespaces" feature of the Linux kernel to provide different sets of mounts to different process ancestries. This is likely connected to the efforts towards supporting multiple (human) user accounts, with both unique and shared sub-sections of External Storage.
When you run an adb shell, you get a set of mounts inherited from adbd.
But in contrast, code run by an application (either in it's process, or a child process) gets a different set of mounts, apparently either inherited from zygote or configured soon thereafter by the process differentiation code which turns a freshly budded zygote into your app's process.
To get an idea of what mounts your app sees, install something like connectbot which you can use to get a local shell descended from an application process, and run the mount command, or any other investigation of interest. For example:
u0_a99#build:/ $ mount
/dev/fuse /storage/emulated/0 fuse rw....
/dev/fuse /storage/emulated/legacy fuse rw.....
In comparison, checking from the adb shell:
shell#build:/mnt $ mount
/dev/fuse /mnt/shell/emulated fuse rw.....
Confusingly, because the mounts are determined by the processes's ancestry rather than it's user id, using the run-as tool from adb will not get you the same view as an application process or it's child, but rather instead will give you adb's view.
However, if you have the pid of a running app's process, you can use run-as to look in it's /proc/pid##/mounts file, without having to actually get a shell descended from the app.
I've search and searched here, and no topics come close to answering the question.
Mounting and unmounting a USB stick from within a rooted APK. I've been successful in doing it from the command line via adb as follows:
prompt>> mount -t vfat -o rw /dev/block/sda1 /sdcard/usb
After this command, I can "cd /sdcard/usb" and can see the contents of the USB stick.
If I try this in code using the Process class, I can't see anything there from the command line in adb, a file explorer on the device, etc:
proc = Runtime.getRuntime().exec(new String[]{"/system/xbin/su", "-c", "mount -t vfat -o rw /dev/block/sdb1 /sdcard/usb"});
proc.waitFor();
This is a sandbox problem. It's driving me nuts. Here's what I think is going on, and I have no idea how to solve it: When the Process class invokes su, it does so in a completely new userspace -- it's own sandbox. The mount succeeds (I can see that from some debugging), then the process dies and returns to the app, which is in a different sandbox. Because of that, not only can I not see the mount, it unmounted with the su process going away.
I need to be able to mount a USB stick from my application, read/write to a file, then unmount it before it is removed (otherwise risk data corruption).
I've looked and looked for an android or java interface to the Linux mount(2) and umount(2) commands and have come up empty. There must be some way to do this!!
you must read that carefully. mounting and unmounting should be done using that
http://developer.android.com/guide/topics/connectivity/usb/host.html
I want to run hello world written on C++ and compiled with Android toolchain 9, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.
I used Android 2.3.3 - Api Level 10
Application was compiled by cross compiler for API level 9
Procedure:
Compile application:
~/toolchain_andr9/bin/ arm-linux-androideabi-g++ helloworld.cpp
Then send application to SDCARD on the emulator:
>adb push a.out /mnt/sdcard
then go to SHELL and try to run a.out:
>adb shell
>
>/mnt/sdcard/a.out
And result is:
>`/mnt/sdcard/a.out: permission denied`
command ls -l shows rights for a.out:
>`----rwxr-x system sdcard_rw 863656 2012-04-12 22:42 a.out`
I tried to change permissions:
>chmod 777 /mnt/sdcard/a.out
But rights don't change:
>`----rwxr-x system sdcard_rw 863656 2012-04-12 22:42 a.out`
I think I have left some important thing using android.
Could anybody help me and give me a way how to run application in `Android SHELL?
Thanks a lot.
P.S. sorry for my English =)
By default, the SD card is mounted with option noexec, that disallows the execution of any file on the card, no matter what it's permissions(even -rwxrwxrwx), so you need to move the file to another location and then execute it.
The easiest is to move the file to /data/local/tmp/ and execute it using the full path (usual POSIX PATH semantics).
> adb push a.out /data/local/tmp/a.out
> adb shell
> chmod 755 /data/local/tmp/a.out
> /data/local/tmp/a.out
This does not require root access and survives reboot.
If you have rooted your phone you can do a mount -o remount,rw /mnt/sdcard and it should run.
I've tried it on my Android.