We have moved to a new Sailfish OS Forum. Please start new discussions there.
34

How to let Android apps to write to (real) sdcard

asked 2013-12-29 14:57:28 +0300

datakurre gravatar image

I have an ext4 formatted (class 10) sdcard, which auto-mounts correctly, thanks to

https://github.com/nemomobile/sd-utils/pull/8/files

Out of the box, Android apps can write to a special directory /data/sdcard, which is not really the sdcard, but just a special directory on phone memory.

My problem is that I'd like to use offline maps with OsmAnd+ for Android, and would prefer those maps to be saved on the real sdcard to avoid running out of memory for camera photos etc too soon.

Simply symlinking a directory from the sdcard as /data/sdcard didn't seem to work (even with chmod a+rwx).

edit retag flag offensive close delete

Comments

4 Answers

Sort by » oldest newest most voted
1

answered 2014-06-10 13:49:31 +0300

MFulz gravatar image

Ok here is a solution for the actual 1.0.7.16:

Create a file /etc/systemd/system/mnt-sdcard.mount

[Unit] Description=Mount SD Card Directory for Android Requires=local-fs.target After=local-fs.target mount-sd@mmcblk1p1.service

[Mount] What=/media/sdcard/current/android_sd Where=/mnt/sdcard Options=bind

[Install] WantedBy=mount-sd@mmcblk1p1.service>

You have to create a symlink /media/sdcard/current which points to your /media/sdcard/<uuid> and create android_sd dicrectory on the card with proper permissions (same as original /data/sdcard directory). SD card should be formatted as ext4 or btrfs.</uuid>

It's basically the same like Vuubi wrote, but with the last update ~/android_storage always points to /mnt/sdcard and this will fix it.

edit flag offensive delete publish link more

Comments

it is /data/media/ you want it to be mounted to, that is what gets fused to ~/android_storage/

chemist ( 2014-06-10 20:39:50 +0300 )edit

So can somebody tell me whether this solution from MFulz actually is sufficient? And where the thing must be called "/data/media" or otherwise?

All other solutions seem to go rather deep into the system, and the only thing I really want is be able to store osmand map files on the sd card.

(Anyway, why does such a simple thing have to be so awfully complicated?)

wcr ( 2014-06-18 17:35:46 +0300 )edit

/data/media is correct one. I've added the systemctl restart media-data.mount into one of the dalvik restart scripts, need to check which one exactly.

MFulz ( 2014-06-18 17:41:04 +0300 )edit

Thanks, and my apologies for not understanding all intricacies of this. Would it be possible to have a small how-to which explains, for example, how to just make sure one (or a few) specific directories can be created and used on the sdcard, such as the one that is needed for the big maps of osmand? This would be hugely helpful!

wcr ( 2014-06-18 18:31:59 +0300 )edit

@Jolla: what is your solution, which can be handled by just normal users? (we shouldn't expect, that they are able to hack config files!) So something is needed here, if you want to sell a reasonable amount of phones!

thomas ( 2014-07-12 20:51:12 +0300 )edit
2

answered 2014-04-24 21:01:27 +0300

chemist gravatar image

updated 2014-06-11 20:25:07 +0300

Understand what to do before you do!

What I did to share the space of my uSD between nemo and android without getting duplicates with bind-mounts or any other hickup, read carefully and use at your own risk:

  1. format the whole usdcard (mmcblk1 not mmcblk1p1) to btrfs
  2. mount that volume (=0)
  3. create two subvolumes > jolla and android
  4. set the default volume to jolla (the default is what gets mounted when something calls mount /dev/mmcblk1)
  5. stop alien-dalvik and copy everything form /data/media to the new subvolume android (don't move the files, this way you have all basics alien-dalvik needs even after pulling the uSD)
  6. add a system.service to systemd that mounts and unmounts the subvolume for android as needed and honours aliendalvik.service The problems to solve are: aliendalvik fuse-mounts its /data/media to /home/nemo/android_storage so you need to make sure everything is mounted before that happens on boot, and stop aliendalvik when the sd gets pulled or the mount needs to be lifted for any other cause.
  7. reboot and wait for the device to settle, as soon as your jolla volume is mounted in /media/, you should see /dev/mmcblk1 being mounted to both /media/sdcard/#UUID and /data/media

I did not want to write a detailed guide as I do not want to be responsible for any wrong doings all steps are pretty basic (at least the 1. -5.) for people knowing their way around the cmdline - you can find every step somewhere here @tjc [1] or in the man-pages of the required tools

UPDATE: the locations have changed again, additionally we have it fuse-mounted to ~/android_storage. The actual mount of the subvolume has to be done BEFORE alien-dalvik is running as it initiates fusing - new directory is /data/media

[1] https://together.jolla.com/question/40802/how-to-format-your-usd-card-to-btrfs-and-share-space-with-android

edit flag offensive delete publish link more

Comments

I just don't understand why you insist on copying and not moving — there's only apps data in /data/media, no aliendalvik data.

Vuubi ( 2014-06-11 19:37:32 +0300 )edit

so it does not repopulate when you have no sdcard, but has already some of the basic folders there (and I was told to not delete it, later I found out that it gets repopulated when empty)

chemist ( 2014-06-11 20:02:32 +0300 )edit

And now the latest update to 1.0.8.19 has updated the Terminal UI and wiped the mount commands I was using in buffer to allow Android apps to see the SD card. So another half hour of searching online to find this more 'permanent' fix (until perhaps another update removes these files or points the SD to another path?) to allow me to quickly pop on some music to relax, not so relaxed now! All those years working on Wintel, why oh why didn't I learn Linux? ;-)

ai ( 2014-07-18 18:09:58 +0300 )edit
2

answered 2014-03-23 13:50:19 +0300

Vuubi gravatar image

updated 2014-06-11 19:42:34 +0300

WARNING: THIS WORK-AROUND IS DEPRECATED. I suggest using chemist's solution for 1.0.7.16 Saapunki

So I made a unit called data-sdcard.mount:

[Unit]
Description=Mount SD Card Directory for Android
Requires=local-fs.target
After=local-fs.target mount-sd@mmcblk1p1.service

[Mount]
What=/media/sdcard/current/android_sd
Where=/data/sdcard
Options=bind

[Install]
WantedBy=mount-sd@mmcblk1p1.service

You have to create a symlink /media/sdcard/current which points to your /media/sdcard/<uuid> and create android_sd dicrectory on the card with proper permissions (same as original /data/sdcard directory). SD card should be formatted as ext4 or btrfs.</uuid>

edit flag offensive delete publish link more

Comments

It seems things have changed once again in 1.0.7.16 (e.g. android_storage is [also?] under home directory). I liked this approach, but where should this be in now? I think, update removed the existing data-sdcard.mount.

datakurre ( 2014-06-10 08:48:17 +0300 )edit

For me the unit continues to work after update but I'll have to investigate the purpose of ~/android_storage and which script/unit mounts it and why it is a fuse mount. Check if the file /etc/systemd/system/data-sdcard.mount and the output of "systemctl status data-sdcard.mount". Other strange thing is that "mount" output now shows that /home/nemo/android_storage is now mounted at /data/sdcard, not /media/sdcard/current/android_sd. The contents of the folder is still external flash though. I'll look at it later today.

Vuubi ( 2014-06-10 10:16:03 +0300 )edit

I can't find where the mount of ~/android_storage is done. And for me the folder is not the sdcard it's always the internal flash. I'd really like to know where this mount of ~/android_storage is done but I wasn't able to find it till now.

MFulz ( 2014-06-10 12:07:29 +0300 )edit

read my answer, fuseing gets done by alien-dalvik so if you want to bindmount anything to /data/media you have to do it before aliendalvik.service is started or after you stopped it and start it afterwards again...

chemist ( 2014-06-11 13:44:10 +0300 )edit

I prefer this solution to chemist's because this way the card can be formatted as ext4/fat32 instead of btrfs.

icebox ( 2014-12-24 13:14:23 +0300 )edit
6

answered 2013-12-29 16:05:04 +0300

penpen gravatar image

As a temporary measure you can use "bind" mount to get around the limitation.

edit flag offensive delete publish link more

Comments

What is the best way to do that? A custom systemd .mount unit?

Vuubi ( 2014-03-23 11:09:34 +0300 )edit

mount -o bind /media/sdcard/YOUR-PERSONAL-UUID /data/sdcard

Matthias ( 2014-03-23 15:04:46 +0300 )edit
Login/Signup to Answer

Question tools

Follow
16 followers

Stats

Asked: 2013-12-29 14:57:28 +0300

Seen: 6,832 times

Last updated: Jul 05 '14