CM11: Insert SD card / Cannot write to Storage

I’m a big promoter of ‘community’ driven Android ROM’s and in particular Cyanogenmod. For one reason or another all of my Android devices end up running Cyanogenmod sooner or later, stock ROM’s just don’t cut it, don’t get updated in time or are even just horrible with bloatware and other nonsense. But once in a while doing a flash I encounter a bug which Cyanogenmod/CWM or at least, something goes wrong. If you know what is going on, it’s easy to fix though, let me explain!


I don’t know if this is a mostly a Samsung phone problem or a general problem but for some reason when I install Canogenmod after doing a full whipe, the Android I end up with isn’t able to write to it’s own storage anymore. Not just the external SD card, but also the internal one!

I believe it might have something to do with my wipe procedure, but in my opinion, I’m not doing anything I should not be doing. Let me walk you through it.

1. Get the phone
2. Backup data on phone
3. Root phone
4. Install CWM on phone
5. Boot into CWM to see if the external SDcard is readable
6. If so, use my PC to put the necessary files on the SD card (Model specific Cyanogenmod build and Pa_Gapps-Modula-rmini)
7. Format all the volumes except boot using the “storage” menu
8. Install Cyanogenmod + Gapps
9. Wipe cache again just to be sure 😉
10. Reboot to Android

Quite a standard procedure I would say. I believe step 7 might be causing my problems, but how else do I start with a completely clean phone? I don’t want anything except the bootload and CWM left on it before I replace everything.

It happened again:

Today I helped my Sister’s Samsung Galaxy Note 1 (N7000) to Cyanogenmod upgrading her from an antique Android 4.1.2 version (Courtesy of crappy Samsung software department) to Android 4.4.4! Quite the difference.

This phone has a dual-core 1.6Ghz processor with 1GB of ram and it works quite well with Android 4.4.4!

It booted just fine and installing apps from the play store worked fine too. No problems! Or so it would seem at first, but digging deeper they appear.

When starting the camera for instance it will instantly crash. Using a different camera app, the app will start and display the camera but complain about not having a save location available. Other apps will display the same “Insert SD card” , “Unable to write to SD card” , “No Storage available” and other similar messages.

A second way to test if you are suffering from this problem is installing “ES file explorer” and trying to copy something from one location to another on or between your SDcards. If ES file explorer asks you for root permissions to do so, your folder permissions are wrong.

At first you might think this might have something to do with the new Android 4.4 security restrictions in allowing an app to write directly to an external SD card or not, and while that is a problem by itself, that isn’t it. That problem is also easily fixed by several apps which can be downloaded from the app store.


The Problem:

The problem is something inside the Linux/Android filesystem. You can identify it by looking at the directory “/mnt/media_rw” using terminal. To accomplish this start the Android terminal emulator (included by default in CM11) and run

su
ls -l /mnt/media_rw

drwxr-xr-x root            root               2014-09-15 20:00  sdcard0
drwxr-xr-x root            root               2014-09-15 21:00  sdcard1
drwxr-xr-x media_rw        media_rw           2014-09-15 20:00  usbdisk0

The problem is the directories having root permissions and not media_rw. That means that Android’s media write process basically is not allowed inside of the directories to do anything!


The Fix:

When we then change the permissions to media_rw everything magically starts to work again! To do this we execute the following (while still being in su mode):

chown media_rw:media_rw /mnt/media_rw/sdcard0
chown media_rw:media_rw /mnt/media_rw/sdcard1

And to be sure we also execute:

chmod 755 /mnt/media_rw/sdcard0
chmod 755 /mnt/media_rw/sdcard1

After running these commands, try the camera app and others apps again. For me, this instantly fixes it and it never returns. Flashing a new version is also no problem.

Since I now understand the problem I believe/suspect it comes from formatting the volumes using CWM which seemingly sets the wrong permissions on the underlying folders. Android itself doesn’t need them to run the OS, but your apps certainly do and will give you all kinds of weird errors because they are not allowed to write to it.



Conclusion:

Everything works fine now that the permissions are not set to root anymore. It’s a bit senseless to have your internal and/or external SD card storage only accessible by root of-course. In a normal non-rooted situation nothing would be able to use it.

So this is a bug, one I have encountered a few times before, but each time I forget how it happens or why. I don’t do anything special, yet it still happens. Hopefully this post can help someone facing the same problem!

5 thoughts on “CM11: Insert SD card / Cannot write to Storage”

Leave a Reply

Your email address will not be published. Required fields are marked *