yashsingh1/xdaforums huggingface dataset:
[G3 General] Magzime:
Hi,

Thanks for the scripts! Unfortunately, I can't get USM to work... :(

First things first, I'm an IT specialist and am familiar with Linux and it's file system. I'm not a developer though.

My phone is the canadian LG G3 (LG-D852) running CM 12.1.

So, when I first used the "set mass storage and mount" script and rebooted, then ran it again after reboot, the computer saw the phone in the device manager as LG-D852, with the exclamation mark stating "no drivers installed". It didn't show up in the Computer. On the phone, it said "Connected as installation" (or something like that, my phone is in french so I don't know the exact english message).

I went back to MTP, and it worked normally. Now when I try to go back to USM, the computer doesn't even detect any new peripheral (Device manager doesn't refresh and no "new device" sound). The phone doesn't show any USB connection either, but the charging LED comes on. I tried different USB cables on different computers, to no avail. The problem resides in the phone. Going back to MTP always works fine.

The "mount" command as SU gives me the /dev/block/vold/179:65 as both /mnt/media_rw/sdcard1 and /mnt/secure/asec like it should, both in vfat, meaning they are the correct numbers and partition format.

I tried disabling and re-enabling USB debugging, running the different scripts with SManager, typing the commands in terminal with su (under root user), unmounting the SD card in the phone's settings.

/sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file has the proper content (/dev/block/vold/179:65).

The other possible files don't exist:

/sys/devices/virtual/android_usb/android0/f_mass_storage/lun_ex/file

/sys/devices/virtual/android_usb/android0/f_mass_storage/lun0/file

/sys/devices/platform/msm_hsusb/gadget/lun0/file

f_cdrom_storage/lun/file is empty.

f_mass_storage/lun/cdrom_usbmode has "0" in it.

f_mass_storage/lun/cdrom also has "0" in it.

f_mass_storage/lun/file has "/dev/block/vold/179:65"

I also tried "mass_storage" alone and "mass_storage,adb" in the setprop command.

Anything else I can try before giving up? :confused:
[G3 General] agnostic-apollo:
im assuming that you have already installed the right lg g3 drivers otherwise mtp wouldnt have worked..but try reinstalling from here after uninstalling previous ones..

i dont remember where i download from...

http://www.mylgphones.com/download-and-install-the-usb-drivers-for-lg-g3-on-windows-and-mac.html

have you tried to unhide hidden drivers in device manager and uninstalled the devices that installed when u first connect the lg g3 in UMS..there are probably still there in hidden mode... that sometimes causes problem..i have to uninstall mtp drivers when i switch back to mtp..

you could try that..

thirdly you could try my new script..i wrote it to automate the whole process.

run script with su when u connect the cable or it wont work...it checks if usb cable connected, then unmounts sd card from phone then mounts it to computer then waits for cable disconnection and then mounts the sd card back to the phone..

before running the script, run the mount command and compare the sd card mount properties with the ones in the script.. also at the end.. should be same i think...make sure u have busybox..if u face a problem with remount, do it from the settings manually...

busybox mount -t vfat -o rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,utf8 /dev/block/vold/179:65 /mnt/media_rw/external_SD

busybox mount -t vfat -o rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,utf8 /dev/block/vold/179:65 /mnt/secure/asec
[G3 General] Magzime:
Neither the phone nor the computer detect any device, none at all, only the LED comes on to indicate charging, as if the phone was in "Charge only" USB setting, so the driver is not my problem, at least not anymore... Maybe it was on the first try, but I can't manage to reproduce that state anymore.

Trying the new automated script right now...........

.............................

Weird, I get an unexpected "else" on line 39, but everything seems in order, I even opened the script in Notepad++ to make sure every "if" has its "fi". I run it with SManager and SU checked.
[G3 General] agnostic-apollo:
firstly put the script in internal or system folders, because if its in the sd card you wont have access to the script after unmounting the sd card, might cause problems...

you are running the script after connecting the cable right?

go and check this using root explorer when u connect the cable and make sure its changed to 'configured'

/sys/class/android_usb/android0/state

also type getprop persist.sys.usb.config in terminal to check if it changes to mass storage,adb when you run the automated script or my previous UMS enabler script

try something connect the phone.

run the mtp enabler script attached

use the drop down menu to select mtp manually in choose usb mode or something

then run my automated script(not stored in sd card)

now it should say connected as installer

if not then im pretty sure its a driver problem or maybe aosp thing

did u reinstall drivers?

did u select "show hidden devices" in view in device manager and check if any preexisting devices are there..uninstall those...
[G3 General] Magzime:
Found the problem with the "unexpected else" in the script: wrong CRLF from Windows, had to edit with Notepad++ and save as SH script, no the script runs without error. Had to edit it to change the mount point of the SD card to fit what "mount" reports.

I have always run the scripts from the internal memory.

Busybox 1.23.2 is installed.

So, starting from scratch, before running the script.

Plugged in as MTP, can browse both internal and SD from Computer, and I see the free space for each of them. The usual stuff.

mount returns the following:

/dev/block/vold/179:65 /mnt/media_rw/sdcard1 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0

/dev/block/vold/179:65 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0

Note the /mnt/media_rw/sdcard1 instead of /external_SD in your original script, that's what I changed to fit this mount.

With cable plugged, running the script as SU with SManager, script waits at "usb mass storage connected". Looking good, but meanwhile:

Dropdown says "Connected as MTP" and "USB debugging enabled".

getprop persist.sys.usb.config now returns "mass_storage,adb"

/sys/class/android_usb/android0/state contains CONFIGURED

/sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file contains /dev/block/vold/179:65

I can't see the SD card anymore in root explorer from the phone, but in my computer, I still see the same thing: MTP connected phone, internal memory and SD card can be browsed.

The two previous lines in "mount" have been replaced by the following:

/dev/block/platform/msm_sdcc.1/by-name/userdata /dev/SM_bin ext4 rw,seclabel,nosuid,nodev,noatime,noauto_da_alloc,resuid=1000,errors=continue,data=ordered 0 0

When unplugging the cable, the scripts resumes and ends, with everything back to normal.

Now, if I reboot the phone, it goes back to the state where neither the phone nor the computer detect a connection, so I run the MTP Enabler script, now the phone shows "Connected as installer", but nothing else shows in Computer. I see the LG-D852 in the devices, yellow exclamation mark "No drivers installed" (I get this status even in regular MTP mode). I can go to the settings from the dropdown and select MTP again to get everything working normally.

Still no UMS though... :crying:
[G3 General] agnostic-apollo:
from what i can see your phones drunk! :p

its doing everything wrong!

but showing connected as installer is good,i mean if you edited the scripts with the right paths.

its the problem on your computer side, i keep telling you.. driver issue!

if we could set up a skype or teamviewer connection, i might be able to do something..

but check this out first...

http://xdaforums.com/galaxy-note-3/general/note-3-usb-mass-storage-t3020854

and try disabling usb debugging, i read that android one devices with cm12 need to disable that for ums to work...

and fyi the 'mount' command lines didnt get replaced...they are mount points for userdata partition...the last two lines didnt show when you unmounted the sd card that belonged to the sd card...

and if there is someone for whom the scripts are working, please comment....for cloudy and cm12 based...
[G3 General] binlalo:
Will this work for marshmallow? I have the same files you refer in your post.
[G3 General] agnostic-apollo:
technically it should, give it a try..

sorry for the late reply
[G3 General] ahorner:
I believe I might know how to fix the problem of "Insert disk" for some people. What's happening is that Android is disallowing access to the SD card mount.

To get this working (after running the USB mode enabler and mount commands), you can allow SELinux Permissive mode. More information here: https://source.android.com/security/selinux/validate.html

To do this via ADB, simply run the command

su -c setenforce 0

This worked for me and then I was able to read/write to my SD card from my PC!
[G3 General] agnostic-apollo:
thanks.

i have that as default,didnt think of that.

ill update my post
[G3 General] xoose:
I stumbled across this thread this morning when I was trying to work out how to back up my SDcard to my PC without losing all of its files' timestamps. I was originally going to just use my microSD card reader but I couldn't find it so looked for alternatives on the web. After reading this thread and making it work first go, I'm glad I couldn't find my card reader!

I also have some info that might be useful for Magzime with his "No drivers installed" problem if he still has it, or for anyone else so affected. I had the exact same problem with my phone about a year ago, where ADB mode worked fine and I could access the files in MyPhoneExplorer, but one day MTP mode decided to mysteriously stop working and I couldn't use Windows Explorer to access my phone's sdcard or internal storage anymore.

The problem was exactly as the "No drivers installed" error message and the script author suggests, and that is it is a problem with the PC. This can happen even if Windows thinks it has a valid and working driver, i.e, if there are no yellow exclamation marks in device manager and Windows says that it is working properly.

The way I fixed mine (without having to do a full Windows re-install) was to delete all of the old cached versions of my Android drivers one at a time until they were all gone, then rebooting and installing the latest version from Google and/or LG. (basic method to remove old versions of drivers is to repeatedly uninstall every device that appears in device manager when you plug the phone in, then tick the "delete old driver" box each time until the box stops appearing when you uninstall it).

It can be difficult to nail down all of the old versions of the drivers, because the next time you plug the phone in it still might have some drivers it didn't get rid of the first time you deleted them so it might take a few uninstalls and reboots before it starts not giving you any driver errors in device manager.

Another reason I've had this happen is when the phone wasn't getting enough USB power, due to using an under-powered USB port or a cheap or worn out USB cable. Make sure you use the motherboard-mounted USB ports where possible, otherwise you'll compound two flakey issues which will probably end up taking Windows down with a BSOD.

The quickest way to tell if it's a problem with the phone or the PC is to try connecting the phone to another PC and installing the most recent version of the phone drivers as you can find (or a known working version of them), preferably a PC that has never had any Android drivers installed on it previously. If it works on the other PC (or has different problems) then you can be fairly sure it's something to do with the PC. This is how I ended up successfully diagnosing my MTP problem, after putting up with it for several weeks thinking it was a phone ROM problem but being too lazy to reinstall my ROM.
[G3 General] agnostic-apollo:
there use to be a software i used a while back to remove drivers.. i think it was this one USBDeview

http://www.nirsoft.net/utils/usb_devices_view.html

you are right about the drivers part, they mess up a lot sometimes..a few months back i kinda corrupted my registry or something after installing and reinstalling drivers and no new phone driver would install...they all failed at installing driver...i searched a lot to fix the issue but nothing worked...good thing was i had reinstalled windows just a few days before and had to rereinstall windows...that fixed the issue...no more issue till now even after unistalling drivers mutilple times(have another bricked lg g3 :p qualcomm 9008)

you could backup your internal sd too if you want but run the commands attached only in twrp or you might corrupt some data...i did this many months ago but this should work..check the file path in the script..also you might need to run command in ums enabler script first..i think...goodluck

http://www.mediafire.com/download/9txh5gf7llw5fl4/Mount_SDcard0_as_UMS.txt
[G3 General] kingknuts:
I'm in MarshMallow stock and I cannot make it work. My model is D855.

I also tried in CM13 with no luck...

The only thing that I get is when I reboot the device is no longer recogniced by windows (8.1) until I change the USB mode to MTP.

Did you triyed in android 6?
[G3 General] PaulAngelo:
Hello all!

Just a quick question, does this MOD help you in the long run? Meaning how can this be advantageous to the user? Would this help me because when I copy/move/paste anything in ROOT EXPLORER, it tells me I have to enable SD Card to be able to perform those functions? Or is there a setting I just forgot to select or deselect?

Thanks,

Paul R
[G3 General] kingknuts:
Confirmed working on MIUI v7 (4.4 KitKat) and Stock 5.0

Confirmed not working on 6.0
[G3 General] John728:
setpermissive.txt not working

I'm using a Verizon G3 running JasmineROM 9.1 (very similar to stock).

I got the "Insert disk" error. I tried to run the setpermissive.txt script using SManager and it says:

$ sh /storage/external_SD/setpermissive.txt

Error resolving interpreter:/system/sh does not exist

Using default shell

setenforce: Could not set enforcing status: Permission denied

I typed "getenforce" in the command line and it said "Permissive" so that should be working.

When I ran Script 1 the second time it said

can't create /sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file: Permission denied

I checked with ES File Explorer and that file is there, so why is it saying it can't create the file? And why is it still saying "Insert Disk" when I connect the phone to the computer?

I get a notification saying "USB mass storage... USB connected...You've connected to your computer via USB. touch the button below if you want to copy files between your computer and your Android's SD card." I touch it and I just get a spinning ring.
[G3 General] agnostic-apollo:
ill update the main post to make it work on marshmallow , atleast stock based marshmallow(im using on fulmics rom)
[G3 General] agnostic-apollo:
this has nothing to do with root explorer, this is related to the method your mobile connects to the computer using a usb cable, there are 2 popular modes mtp and usb mass storage(ums). this just enables ums. read up on them on the internet

the root explorer issue you are having is probably to sd card permission issue, in lollipop and marshmallow you need to give apps access to sd card using a special "screen", the following website shows it.. root explorer might be asking that..if not then send a screenshot or something

https://metactrl.com/docs/sdcard-on-lollipop/
[G3 General] agnostic-apollo:
ill update the post for marshmallow
[G3 General] agnostic-apollo:
sorry the first line of setpermissive script should be /system/bin/sh, thats why the "does not exist" error..ill update the script.

but scriptmanager will still run the second line, which is the main command.

in both scripts it says permission denied, do you have root access?

if yes then u probably didnt select the skull with su written under it in script manager on the script window.

do that and then let me know
[G3 General] PaulAngelo:
OK, I gotcha. I was way off track. Sorry about that. Thanks for the heads up!

Paul R
[G3 General] agnostic-apollo:
np dude
[G3 General] Remdale:
I cannot live with MTP anymore. Sometimes it shows me empty folders. So I deleted an important folder with videos because my phone said to my PC the folder was empty.

Guys, what about Kitkat? Is there any workaround for mass storage mode?
[G3 General] agnostic-apollo:
lolz you are still on kitkat? why though!

anyways the mechanism for mass storage even on kitkat most likely would be the same, but the dev and mount paths will probably be different so you will need to modify the script as mentioned in the instructions of the OP
[G3 General] Remdale:
I prefer old OS. Just my personal preference.

I heard people say the mass storage driver was completely removed from 5.0+, so that's one of reasons of my choice. But actually I have Sharp SH-04F with 5.0 installed and it has a native mass storage driver. How can it be possible?

Do you have any idea on how the script should be modified for kitkat?
[G3 General] agnostic-apollo:
ah, completely your choice dude, even i would prefer LP/MM over nougat on my g5...

the drivers are part of the android kernel, not of Android OS on top... basically official support to acess those drivers and enable mass storage was removed from 5.0+ by removing it from the usb modes list at OS level, the drivers might still be there underneath if the manufacturer didnt remove the drivers from the source code of the kernel before building it. there is mostly no need to remove them but not sure if your smartwatch will have those or not

check the detailed info section of the OP, try to follow it, if you still need help, im here... post the output of the "mount" command too..
[G3 General] Remdale:
Thanks!

So downloaded the script from mediafire and run it with Script Manager. I permitted root access and then after "unmounting /mnt/secure/asec/" I got an error:

fuser: can't stat 'mnt/secure/asec': Permission denied

umount: can't umount /mnt/secure/asec: Permission denied

The instruction says:

1) connect the phone (and select 'cancel' whenever it asks to allow computer to access sd card, dont select 'allow' )

But my phone doesn't ask me anything. So I changed the mode to just charging beforehand.

hassan.siddiqi.14, help me please. What do I do next?
[G3 General] agnostic-apollo:
install terminal emulator from playstore, run "mount" command and copy the entire output and post here
[G3 General] agnostic-apollo:
now check if this file exists using any root file manager

"/sys/class/android_usb/android0/f_mass_storage/lun/file"
[G3 General] Remdale:
Yes, it exists
[G3 General] agnostic-apollo:
copy the script attached to /system

open terminal emulator and run following commands while connected to pc with usb

su
chmod 0755 /system/kitkat_ums_script.txt
sh /system/kitkat_ums_script.txt

grant root permission after running "su" command

i hope you have busybox installed

if it works, after unplugging, go to settings->storage and unmount and remount your sd card
[G3 General] Remdale:
After running chmod it says unable to chmod: read-only file system
[G3 General] agnostic-apollo:
didnt you change /system to rw when copying?

anyways run following command after "su"

mount -o rw,remount /system
[G3 General] Remdale:
Yeah, it was changed to RW when I copied the file. I don't know what happened.

After running the script I got a BSOD on my PC because of the modem driver. So I had to delete it first.

Anyways, I get a no disk error when trying to access the mass storage device. Following the instruction I run the 'getenforce' command and it showed me Permissive. What could be wrong?

I wanna consider that I'm using a Japanese version of LG G3 that is LGV31.
[G3 General] agnostic-apollo:
hmmm most likely some permission issue... try doing two things,

mount the sd card from storage, connect the phone to pc, enable mtp mode, allow access if it asks and then make sure you can access sd card from your pc in "my computer", then run script again...

or

mount the sd card from storage, connect phone to pc, run script, then restart and then run script again...
[G3 General] agnostic-apollo:
sorry, made an error in the previous script, forgot to remove "public" from /dev path, use this script but you still might need to follow the instructions in my previous comment if it doesn't work...
[G3 General] Remdale:
Sorry, could you please explain "mount the sd card from storage"? When not connected to PC, the sd card is usually mounted in storage. So no need to mount it again, right?
[G3 General] agnostic-apollo:
sorry, *mount the sd card from settings->storage, the script unmounts the sd card from phone and then mounts it to pc, if sd card is mounted on phone and sd card at the same time there are chances of corrupting files when files are written at the same time from both pc and phone...

when the script runs it doesn't unmount sd card using "settings", so settings does not "know" that sd card has been unmounted, and settings might show 0 bytes free space and shows sd card to still be mounted when infact it is not... so you need to unmount/eject it from settings and then mount sd card manually, for now, every time you run the script so that the phone can use the sd card
[G3 General] Remdale:
Wow man, thanks a lot! The new script has worked out.

But the only problem is this. Though the script says "unmounting sd card", I still have a full access to it from the phone and I can open files. In which way is it possible to corrupt the files in this case? If it's a big deal how do I automate the process of unmounting the sd card?

One more thing to mention is there are 3 options of connecting the phone: charging, MTP and PTP. After running the script from the very beginning none of them became checked, so the script kind of unchecked MTP.
[G3 General] agnostic-apollo:
great news, good for you!

the script just prints "unmounting sd card" before unmounting there are a few lines of code after that that does the unmounting, can you send me the complete output of the script, it might show why sd card is failing to unmount...

i have also attached another script, try this too, i changed the order of unmounting different mount points of sd card in the previous scripts i sent you, the ones in the attached scripts are the same as original...

one of the possible way to corrupt files is if you modify the same file from pc and phone at the same time, if both are writing to the same file, which write operation should actually occur, the one from phone or pc? if both happen together you will get a corrupt file...

the automatically remounting part after you unplug is disabled in the script currently, one we get unmounting fixed, ill try enabling that...you can of course unmount sd card from settings before running script, and remount after unplugging from settings to prevent corruption

the unchecking of mtp is normal, because none of those options are active...
[G3 General] Remdale:
How do I output on the screen the output of the mount command?

I wanna mention one more thing. If I run the script for the second time, the phone reboots during "unmounting /mnt/secure/asec" and then I lose root. Only if I restart the phone manually helps to get root back.
[G3 General] Remdale:
I've just found out one thing. After copying some files on the sd, I disconnected the phone but the contents of the sd card has not been updated, so I cannot see those files. So I have to remount the sd card from settings to make them visible. What do you think is the cause of it?