Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I just got the Galaxy Nexus and learned that it does not support USB Mass Storage mode. It only supports MTP and PTP. I regularly use my phone as a USB flash drive at work so this is a problem. I can transfer files back and forth with MTP however I need to edit files directly on my phone.

I'd like to find a way to continue to use the phone as an external drive and be able to access the files on my phones storage directly without transferring the files back and forth however I have several constraints: The network at my work isn't connected to the internet, it doesn't have wifi, and the computers do not have Bluetooth and this is not going to change. Ideally I would not have to install anything on the computer, but if there are no other options I'd consider this.

Are there any hacks or workarounds that will allow me to use my Galaxy Nexus as an external flash drive in the way I described?

Can I create a separate mountable FAT partition on the phones storage that I can access from a Windows XP computer a well as through the Android OS in the way that's possible with other devices that have external storage cards?

The Phone: It's a rooted & unlocked Galaxy Nexus on VZW and currently running CM9.

share|improve this question
    
I am not 100% sure but I think the stock kernel isn't even able to do that. you need an aftermarket kernel or just a custom ROM to do that. G Nexus GSM: full update guide for Cyanogenmod9 (4.0.4 atm, 4.1 CM10 is in a very early stage still). Here's an apk that might help too. needs root. –  ce4 Jul 22 '12 at 22:18
    
Thanks, that thread looks promising except for this. Hopefully it's not true otherwise I'll have a GN for sale. –  Matt Jul 22 '12 at 22:50
2  
I don't think you necessarily need a separate SD card to use UMS, but I think you do need a separate partition (formatted FAT) for it to work, a la the Kindle Fire which does not have an external SD card slot. –  eldarerathis Jul 23 '12 at 13:47
1  
I think you need to expand a little on why MTP/PTP is not suitable for your usage. Despite the name, MTP can actually transfer any arbitrary file, not just media files. The only operations you can't do in MTP are those that requires block level access, e.g. defragging, reformatting, partitioning, etc. –  Lie Ryan Jul 23 '12 at 22:47
    
I don't want to transfer files, I want to edit them in their location on my phone just like it was a flash drive. I don't believe you can do that with mtp, am I mistaken? –  Matt Jul 24 '12 at 3:54
show 2 more comments

5 Answers

Short Answer:

Currently you can't make use of your device (any device that relies on MTP) to act as an MSC, due to the protocol specifications!

Elaborating

As to clarify, Galaxy Nexus uses one massive partition for the entire device, its like saying that: system, data and sdcard are all together.

MTP was selected for Galaxy Nexus because it allows the use of this large storage area, that from a system point of view, insures a better communication with files, provides a more secure file system and gives less trouble to maintain.

Why isn't capable to go your way:

There are no separated partitions in Galaxy Nexus, only one large storage area. Even emulating a fat32 file system, one would still need to be able to translate between fat32 and ext4 at a low level. This is practically impossible.

If the Galaxy Nexus had a partition, you could have block-level access and thus you could have mass storage access.


Long boring version:


Short background

The Mass Storage Class (MSC), commonly know as USB Mass Storage (UMS), that we are all used to use on or devices, is a protocol that allows a Universal Serial Bus (USB) device to become accessible to a host computing device, to enable file transfers between the two. On the golden days, one just needed to plug in the phone, hit "USB mode" and start moving files, editing files, etc...


Media Transfer Protocol (MTP)

Things have changed a lot, when we talk of the new transfer method that's being used on your device, the Media Transfer Protocol (MTP):

1 Introduction see page 15 zip bellow

Media Transfer Protocol, or MTP, is a protocol designed for content exchange with and command and control of transient storage devices. It was been developed as an extension to PTP, or Picture Transfer Protocol, and is targeted primarily at Digital Still Cameras, Portable Media Players and Cellular phones.

While the introduction still leaves margin for doubt, this protocol was developed and implemented with a very specific purpose: to facilitate the transfer of media files and associated metadata between devices:

1.1 Purpose see page 15 zip bellow

The primary purpose of this protocol is to facilitate communication between media devices that have transient connectivity and significant storage capacity. This includes the exchange of binary objects and the enumeration of the contents of that connected device.


File Types supported?

At this point we already know that this is for media files and media based devices, but one question that I've seen on the comments remains: Can we copy files other then media files (audio/video)? Yes we can:

1.3 MTP Object Model see page 15 zip bellow

The term "media" in "Media Transfer Protocol" is used to identify any binary data, and is not restricted to audio/video formats to which it is commonly applied. Some examples of non-audio/video objects include contacts, programs, scheduled events and text files.


What about "live edit" ?

Your question specially concerns the usage of your device (Galaxy Nexus) as an external USB storage drive. Why it can't be done? The MTP protocol limits data to a unidirectional operation, also latter explained that the device storage is used by the computer as a local file:

4.2 Unidirectional Data Flow see page 29 zip bellow

The data flow in MTP is always unidirectional. When initiating an operation, data flows only from the Initiator to the Responder. When responding to the requested operation, the data flows only from the Responder to the Initiator. During the binary data-exchange phase, data may flow from the Responder to the Initiator or from the Initiator to the Responder, but never both. Bi-directional, binary data exchange must be performed by multiple operations.


Advantages vs Drawbacks

Advantages

The MTP does carry some advantages with it, mainly concerning the security and integrity of the user data:

Microsoft MTP Implementation Overview

When a USB host computer has mounted an MSC partition, it assumes absolute control of the storage, allowing for example, the file system to get corrupted or reformat to an unsupported type.

Meanwhile, the MTP overcomes this by making the unit of managed storage a local file that can either be written or read.

Drawbacks

The MTP isn't treated as a traditional removable drive, so, no recovery tools can be used to save the day.

The support is still underway, some Operating systems stile require third-party software.

MTP standards (as mentioned earlier) don't allow for direct modification of objects. Instead, modified objects must be reuploaded in their entirety.


References:

I hope this clarifies as to why MTP is good (improvement), but OTOH bad (user will have to change habits).

Here's the reading material used to synthesize the answer:

The above answer is credited to the contents and authors of this reference links.

share|improve this answer
3  
I appreciate the very detailed description of mtp, however I have already accepted the fact that I can't use mtp the way I want. What I'm interested in is finding a way around the limitation. For example, repartitioning the internal storage to create a separate mountable partition. Any suggestions on how I can get around the mtp limitations? –  Matt Jul 27 '12 at 5:36
    
@Matt The comment was becoming to large, I've added a clarification under the "short answer" section. Sorry if I didn't made myself clear earlier. –  Zuul Jul 27 '12 at 10:04
    
Thanks for the added information but again I was already aware of most of this. What I'm interested in knowing is, short of other solutions, can the phone be re-partitioned with a separate FAT partition that would support UMS? If so, how? –  Matt Jul 28 '12 at 17:39
    
I ended up awarding the bounty to ce4 because his code was the closest thing to a solution but thanks for the detailed information and the help you provided. –  Matt Aug 1 '12 at 16:07
add comment

It may be possible to export a loopbacked image file via USB as UMS/MSC.

You will definitely need:

  • root
  • kernel support: loopback (/dev/block/loop0) and UMS (/sys/devices/platform/usb_mass_storage/)
  • custom app to enable/disable this or a custom init script to always export the image file
    Here's an example for an easy hackable app, a little development needed though... One needs to change the default block device (/dev/block/mmcblk0pX) to the loop0 and also losetup the loop0 beforehand, then build. Additionally it could be possible to have it mounted on the Android device if it's not exported, e.g. at /sdcard/fat

Here's a short test on my Galaxy Nexus (in recovery mode):

#create a 10mb image file and format it with FAT, name it testFat:
me@workstation:~$ dd if=/dev/zero of=/tmp/fat.img count=10 bs=1M
10+0 records in
10+0 records out
10485760 Bytes (10 MB) copied, 0,00699535 s, 1,5 GB/s
me@workstation:~$ mkfs.vfat -n fatTest /tmp/fat.img 
mkfs.vfat 3.0.9 (31 Jan 2010)
me@workstation:~$ file /tmp/fat.img
/tmp/fat.img: x86 boot sector, [...], label: "fatTest    ", FAT (16 bit)

#Push it to my phone, create loop0 from it and export it via UMS
me@workstation:~$ adb push /tmp/fat.img /sdcard/fat.img
5215 KB/s (10485760 bytes in 1.963s)
me@workstation:~$ adb shell
root@android # ls /sys/devices/platform/usb_mass_storage/lun0
file    power   ro      uevent
root@android # losetup /dev/block/loop0 /sdcard/fat.img
root@android # losetup
/dev/block/loop0: 0 /sdcard/fat.img
root@android # echo /dev/block/loop0 > /sys/devices/platform/usb_mass_storage/lun0/file 
root@android # exit

#See that it works. Yay!
me@workstation:~$ 
me@workstation:~$ mount
[...]
/dev/sdg on /media/fatTest type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks)
me@workstation:~$ dmesg
[137805.009285] sd 27:0:0:0: [sdg] 20480 512-byte logical blocks: (10.4 MB/10.0 MiB)
[137805.010024] sd 27:0:0:0: [sdg] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[137805.013446]  sdg:
me@workstation:~$
share|improve this answer
    
I have no testing device (GNexus) at hand right now, would someone be so kind and have a look if UMS is included in CM9? Just see if this is available: /sys/devices/platform/usb_mass_storage/lun0/file –  ce4 Jul 27 '12 at 12:38
1  
Early CM10 doesn't appear to, so I would guess CM9 doesn't either. –  eldarerathis Jul 27 '12 at 16:32
    
@eldarerathis: Thanks for looking! It might be compiled into a different kernel or one had to enable that himself to get it working. –  ce4 Jul 28 '12 at 9:57
    
@ce4 This looks promising but I'd love to see more details explaining how to accomplish this. Are you re-partitioning the phone's storage permanently or is this a different kind of solution? Are there any drawbacks to this method like comprising the file-system's integrity? –  Matt Jul 28 '12 at 17:47
    
I use my phone as a flash drive. I plug it into a shared computer at work, edit a document then save it and go. Transferring the file to the computer and back again doesn't really work for me. I'll get on the chat a little later. –  Matt Jul 28 '12 at 19:33
show 2 more comments

This is the TL;DR version.

Sorry, USB Mass Storage is simply impossible with the Galaxy Nexus.

The reason for this is that USB Mass Storage gives the PC block-level access to the filesystem, and to maintain the integrity of the filesystem, it must be exclusive access. This is why Android phones unmount the SD card and apps can't use data on the SD card while the phone is in USB Mass Storage mode.

The Galaxy Nexus, however, doesn't have an SD card. It's the phone's voluminous internal storage that is being accessed.

MTP (see @Zuul's excellent explanation) gets around this and lets both the phone and PC access the files without the phone having to be locked out. The down sides are that you don't get exclusive block-level access, and operating system support for MTP just isn't quite there yet.

If this is a feature you simply can't live without, then your best bet is to use a different phone. Not coincidentally, this is one of the reasons I got rid of the Galaxy Nexus and got a DROID RAZR MAXX.

share|improve this answer
1  
"This is why Android phones unmount the SD card..." What about the apps that allow for dual mounting the sd (and internal storage for that matter) to the computer and the Android os simultaneously? I had such an app on my Rezound and it worked pretty well. –  Matt Jul 27 '12 at 5:41
    
I've never heard of any app like that. Got evidence of its existence? –  Michael Hampton Jul 27 '12 at 6:20
    
That sounded really harsh! google.hu/… –  Richard Borcsik Jul 27 '12 at 7:13
1  
And you never lost any data? You're very fortunate, then. –  Michael Hampton Jul 27 '12 at 16:30
3  
Yes, that's exactly why the system doesn't permit it in the first place. –  Michael Hampton Jul 28 '12 at 17:49
show 5 more comments

It appears that AOKP JB build 4 has:

" USB mass storage emulation for certain devices (i9*)"

I have not used it myself yet.

share|improve this answer
add comment

You could give this XDA-Developers App a try:

Note: This App was developed in the early days of Ice Cream Sandwich Ports. At this time none of the Ports had native USB Mass Storage support and this App was meant as a temporary workaround to use UMS nevertheless. So this App won't be interesting for you, unless the ICS or JB Port you use still doesn't natively support UMS. If that is the case, here comes help:

The app starts automatically after booting up the device and automatically detects when the device is being connected via USB to a computer. Then a notification pops up in the notification bar and by tapping on the notification you will open a GUI to enable/disable USB Mass Storage; just/almost like the original UMS feature.

Sounds quite good so far -- only your Galaxy Nexus is not explicitly mentioned on the list of known supported devices. This doesn't necessarily mean it will not work, but just at the moment it is not known. Should be worth a try.

share|improve this answer
    
This has been already discussed, see the OP comments. Alas, it's also a dead end. :( –  ce4 Jul 30 '12 at 20:11
    
I couldn't find the comments you refer to -- but if that's already a known option, I apologize. And "dead end" means it no longer works? Oh gosh, guess I skip the next updates ;) –  Izzy Jul 30 '12 at 20:26
    
No offense! :) was more meant as "FYI". The "here's an apk" refers to the same thread as your XDA link. –  ce4 Jul 30 '12 at 20:33
    
We had a rather long conversation in the main android chat about that. Don't know if there's a long enough history but it's got some more info if you can still access it –  ce4 Jul 30 '12 at 20:41
    
Thanks for the info, ce4 -- unfortunately I currently miss the time to dig deeper into it. I just see MTP is not yet as complete as it should be for switching off UMS altogether, so I was pretty sure there must be a solution still available. And I remembered some threads on enabling UMS again on ICS and up. Hopefully there is something around pretty soon -- as MTP seems not to be the answer for everybody. –  Izzy Jul 30 '12 at 20:47
show 2 more comments

protected by Matthew Read Dec 9 '12 at 17:42

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.