I'm looking for a way to mount Samaba shares programatically.
I am aware of this question which, if it works, would allow browsing a Samba share within my app, but I want the shares to be available to other apps once mounted.
I know ES File Explorer can do this, so it must be possible to implement in code, but I'm trying to figure out how it's done. The only method I can think of is opening a Process with Runtime.getRuntime().exec(...) but then there's the issue of what commands to send. I've been playing about in a terminal emulator app and the standard mount command doesn't seem to be working. I've tried the following:
mount -t smbfs //[ipaddress] /mnt/sdcard/net/Share1
and
mount -t cifs //[ipaddress] /mnt/sdcard/net/Share1
but in both cases I'm getting the rather uninformative error message "mount: no such device"
Where could I be going wrong?
Probably smbfs/cifs are currently not supported by your kernel. As Delyan said, ensure your kernel can mount these filesystem :
$ cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev cgroup
nodev tmpfs
nodev debugfs
nodev sockfs
nodev usbfs
....
If they are not listed, you should try to do a modprobing (sometimes the module you want just have to be activated), get root access then :
# modprobe <modulename(without.ko)>
e.g. :
# modprobe cifs
If it doesn't work you will have to change or recompile your kernel (including appropriate modules).
I ran into the exact same problem. Cifs manager was working, but the command from the terminal was not. For me anyway, it turned out that I just had to modify the command slightly and it worked. Try the following command:
mount -o username=guest,password=guest -t cifs //[ipaddress]/[share] /sdcard/cifs/nas
Make sure that the local folder /sdcard/cifs/nas (or your desired equivalent) exists before running the command or you might get a "file or directory doesn't exist" error.
Related
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
I'm interesting in make some changes in init.rc file.
As I have read, I must get copy of boot.img, unpack it, add my changes to init.rc file, pack and push back new boot.img to phone, and after reboot my changes will be considered. (I can't just change init.rc file, that is at / directory, due to it will be rewritten at next reboot.)
So I try:
adb shell
su
fdisk -l /dev/block/mmcblk0
fdisk outputs list of all partition (mounted and unmounted) which are on phone.
I'm intersting in boot:
9 147456 163839 8192K 0700 BOOT
where 9 - is partition number, so my partition (device to mount) is /dev/block/mmcblk0p9.
Then I remount rootfs to read/write permissions:
mount -o rw,remount rootfs /
Create directory (mount point) /boot:
mkdir /boot
And then try to mount boot partition to /boot:
mount -t auto /dev/block/mmcblk0p9 /boot
but retrive "mount: No such device".
Are anybody faced with this ?
Thanks in advance for you help.
PS:
List of partitions can be also obtained by:
ls -l /dev/block/platform/dw_mmc.0/by-name
Edited:
I have sources, but I don't want to rebuild their, due to a large amount of time compilation. (I must make many changes in init.rc file and recompile all CyanogenMod it's very expensive).
I have tried to build only module tied, as I think, with init.rc (system/core/rootdir), just type mmp:
ila:~/cm_s4/cm_12_1/system/core/rootdir$ mmp
and obtained next line:
Install: /home/ila/cm_s4/cm_12_1/out/target/product/i9500/root/init.rc
but, no line such as (for example, when I type mmp in external/hello_world):
Pushing: /system/bin/hello_world
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'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
ioctl LOOP_SET_FD failed
I already ask about similar problem but I wrote some more detail here
to run the ubuntu in android,
I made an img file with rootstock
rootstock -f kty1104-ThinkPad-Z60t -l kty1104 -p 1 --imagesize 2047M --notarball --seed linux-image-omap,lxde,build-essential,openssh-server,tightvncserver,x11-xserver-utils
this img can chrooted on my ubuntu PC by
sudo mount -o loop,noatime -t ext2 /home/kty1104/ubuntu.img /mnt
sudo mount -t proc proc /mnt/proc
chroot /mnt /bin/bash
but when I try to this mount ~ chroot command on my android,
it says, ioctl LOOP_SET_FD failed: Bad file number on mount command
and when I just to force to chroot, it says "segment fault"
I think the problems comes from rootstock command
could somebody help me?
I tried this myself today and then did some research. It seems that the kernels of stock ROMs don't support loop devices. If you're desperate and experienced, you may try building a custom kernel. If there's another way to accomplish your goal without loop devices, you should go with that instead, since messing with kernels on embedded systems can have unexpected and/or irreversible effects(brick) if done wrong. https://android.stackexchange.com/questions/5218/can-i-mount-loopdevice-in-android