[G3 General] agnostic-apollo:
After getting fed up with the slow and stupid MTP mode i started thinking that USB Mass Storage support should still be there underneath even if its not enabled because i dont think 'android' developers would use MTP themselves, even if its imposed on us(yes i know the benefits of MTP but we should still have the option someway)

So i did some research and found a way to mount my LG G3 D850s Ext SDcard as Usb Mass Storage!

DISCLAIMER: USE AT YOUR OWN RISK. i wont be responsible for any harm if any that comes to your device.

Read the whole post before asking questions.

Detailed Info at the end if you need to make any more changes to the script.

Troubleshooting/Requirments:

1) Root Required (select the skull with 'su' written underneath in script manager script window if you are using script manager or run 'su' before running script if you are using terminal emulator)

https://play.google.com/store/apps/details?id=os.tools.scriptmanager&hl=en

2) Busybox needed (available in playstore)

3) Selinux mode should be permissive (before running any other scripts run setpermissive script attached or run 'su' in terminal and then 'setenforce 0' in terminal emulator. Selinux in enforcing mode may give "insert disk error". There is a bit more detail at the end about this)

4) SD card should be portable storage in Marshmallow and not adoptable. (this is not for lollipop)

5) Dont store the scripts in sd card (store them in internal sd or /system or /data )

6) Select 'cancel' if it asks to allow computer to access sd card when connecting mobile to computer, dont select 'allow' (only marshmallow) (Edited)

Marshmallow Instructions:

I am using Fulmics rom (Stock based)

I updated to marshmallow( just a few weeks ago and did get the UMS working after some time(usb related stuff has changed in MM but finally got it working with a trick). The main problem i still havent solved is mounting the SD card back to the phone with the right permissions with just commands. Marshmallow has changed a lot with adoptable and portable storages in marshmallow and how it handles permissions to sd card. I have been trying to find a way but havent found anything on the internet. Maybe ill ask around in XDA to solve this to make everything automated.

Basically the automated MM script does unmount SD card card from phone and mounts it on the computer with UMS but it cant remount the sd card back on the phone. But there is a workaround for now, that is to go into settings->Usb and Storage and eject and remount sd card manually.

The script is automated and you only need to run just this after connecting usb.

make sure you have fulfilled all the requirements given at the start of the post!

The instructions for getting UMS to work on MM are

A) Download:

'[MM]USB Mass Storage Automatic' script here http://www.mediafire.com/download/x5rl47mv9m3zc2z/[MM]USB_Mass_Storage_Automatic.txt

B) Change the script if needed:

You probably wont need to change the script but still follow the next 2 steps

1) run 'mount' command in terminal emulator

2) Locate the line saying "/dev/block/vold/public:179,65 /mnt/media_rw/XXXX-XXXX" (the XXXX-XXXX are your sd card serial number, dont worry about it).

what you need is the "/dev/block/vold/public:179,65"

The line 8 of my script is

sdcarddev="/dev/block/vold/public:179,65"

If "/dev/block..." part is the same as what you got above, dont change the script.

If the path is different, change the script to whatever you got!

so if you got "/dev/block/vold/179:65" change line in script to "sdcarddev="/dev/block/vold/179:65""

Save the script!

If script doesnt work later on, look over the detailed info at the end for any changes or post a comment

C) Normal Use ( i dont think restart is needed) :

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

2) run the '[MM]USB Mass Storage Automatic' script using script manager with 'su'

3) The sd card should show up on your computer

4) Unplug usb cable

5) Go to settings->Storage & USB in your phone and under portable storage your sd card should be shown. Click the triangle at the right to eject Sd card then Click Sd card 'name part' again to mount it again.

6) You should be back to normal and should be able to use sd card again as before.

If you want to go back to mtp mode just swipe down the notification area and change usb mode to mtp after connecting usb cable.

Lollipop Instructions:

Read detailed info at end to make changes to scripts.

Either enter the commands manually in terminal emulator or run the scripts with su(root) permissions with Script Managers like

https://play.google.com/store/apps/details?id=os.tools.scriptmanager&hl=en

There are four scripts attached

1) USB mass storage enabler and mount

2) USB mass storage enabler

3) Mount Ext-Sd card

4) MTP enabler

There are mainly two parts for making UMS to work, changing usb config property to UMS and mounting sd card on computer.

When you change the property 'persist.sys.usb.config' you will have to restart the phone(restart might not be necessary). but after restarting Ext-SDcard wont mount automatically when you plug in USB cable.(There will be an drive icon in 'My Computer' but it wont open unless you run mount command.)

So you can either run Script 1 before reboot and again after reboot. No harm.

Or run Script 2 before reboot and Script 3 after reboot.

Script 4 is to revert back to MTP mode. No restart needed but you will have to choose MTP in USB options and maybe enable USB debugging if needed.

Order for enabling USB mass Storage:

1) Run Script 1 or Script 2

2) Restart (might not be necessary)

3) Run Script 1 or Script 3

Plug in usb cable at any time. It should say 'connected as Installer' instead of 'connected as MTP'

Order for enabling MTP:

1) Run Script 4

2) Choose MTP in USB connect option.

command: setprop persist.sys.usb.config mtp,adb

Restart phone if needed.

Automated script for Lollipop:

run setpermissive script before this script if you have selinux in enforcing mode

Automatic script link

http://www.mediafire.com/?gjdfef0rdajigc5

Detailed Info:

This info is old and was mainly written in relation on lollipop, marshmallow has small changes

There are two parts to mounting as USB Mass Storage:

1) Changing USB config property to USB Mass Storage

command: setprop persist.sys.usb.config mass_storage

2) Mounting ext-SDcard

command: echo /dev/block/vold/179:65 > /sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file

You are going to need root for this.

I own a LG G3 D850 and running Lollipop CloudyG3 2.2 (Stock based ROM)

The scripts attached are according to my partition names(maybe others can confirm if its the same for them)

Instructions to edit scripts if needed:

Confirming ext-SDcard path:

Basically go to /dev/block/vold/ in root explorer and confirm the name of partition. It was 179:65 for me.

There were two files here 179:64 and 179:65. i confirmed my ext-SDcard was 179:65 using 'mount' command in terminal and locating the line /storage/external_SD.

If any changes are needed make them in the script 'USB mass storage enabler and mount.txt' accordingly.

Confirming mass_storage file path:

We are going to mount ext-SDcard to /sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file

confirm you have this file using root explorer. Although i think this is going to be same for all LG G3.

Or try these

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

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

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

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

If any changes are needed make them in the script 'USB mass storage enabler and mount.txt' accordingly.

Insert Disk Error in computer:

@ahorner mentioned that if you get "insert disk" it might be due to selinux being in enforcing mode.

you can check with command "getenforce" in terminal

you can change it to permissive mode with

"setenforce 0" command in terminal or run the setpermissive script in attachment.

If you want to change back to enforcing after you are done you can run the setenforce script.

hope that helps. thanks to @ahorner

Credits:

http://xdaforums.com/showthread.php?p=29435666#post29435666 @aaki_rocker

http://xdaforums.com/showpost.php?p=51040713&postcount=275 @MetaIIica

Please share your experiences.