Ask / Submit
116

How to: Format your uSD-Card to share space with android

asked 2014-04-25 14:46:10 +0200

chemist gravatar image

updated 2016-08-03 14:24:49 +0200

Update: For JollaC see at the bottom, things changed due to missing btrfs support and android mounting has changed a bit too Old stuff in question's history

If you are OK with becoming root and follow a step by step guide on your own account, go ahead reading this guide.

Version: >1.1.9.x


This is no beginners guide, you need to know your way around!

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 from /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

detailed cmds use at your own risk

preparing the sdcard, should only be needed once!

first dosystemctl stop aliendalvik.service & systemctl stop aliendalvik.path then follow this list

  1. umount /dev/mmcblk1p1 - unmount the card might be another /dev or even more than one
  2. mkfs.btrfs -f /dev/mmcblk1 mkfs.btrfs -O ^extref -f /dev/mmcblk1 - format the card (no need for partition) - for now extref (this extends num of hardlinks available) needs to be disabled, even on the device
  3. mount -o subvolid=0 /dev/mmcblk1 /media/sdcard
  4. cd /media/sdcard
  5. btrfs subvolume create jolla - create folder called jolla
  6. btrfs subvolume create android - create folder called android
  7. btrfs subvolume list . - returns an ID for each subvolume
  8. btrfs subvolume set-default *ID for jolla* /media/sdcard/ - sets jolla to be mounted as default
  9. chown nemo:nemo jolla/ - add -R if needed
  10. chmod 775 jolla/
  11. chmod 777 android/
  12. cp -r -a -v /data/media/* /media/sdcard/android
  13. cd ..
  14. umount /dev/mmcblk1

preparing the system

  • create (as in do create not a command) /etc/systemd/system/data-media.mount and fill with:

#

[Unit]
Description=SD card btrfs subvolume for Android
ConditionPathExists=/dev/mmcblk1
ConditionPathExists=!/tmp/os-update-running
ConditionPathIsDirectory=/data/media
Requires=local-fs.target systemd-user-sessions.service
Before=aliendalvik.service
After=mount-sd@mmcblk1.service
BindsTo=mount-sd@mmcblk1.service

[Mount]
What=/dev/mmcblk1
Where=/data/media
Options=subvol=android,compress,dirsync,noatime,users

[Install]
WantedBy=local-fs.target aliendalvik.service

Second, create /etc/systemd/system/aliendalvik.service.d/sdcard.conf file:

[Unit] 
PartOf=data-media.mount

Then run systemctl enable data-media.mount.

  • the mount file gets started every time aliendalvik is started and stops aliendalvik when it gets stopped, on boot it prevents aliendalvik from starting if it is not started yet but waits for the local-fs to be settled and actually having a mountpoint

for the future we only need to load the service file to its place and enable it, if something changes I will update the code, upgrade went through without anything (see first line for updates) as the updates do not touch data-media.mount as of yet


Jolla C

This has major differences with the original solution for Jolla1 https://together.jolla.com/question/40802/how-to-format-your-usd-card-to-btrfs-and-share-space-with-android/?answer=140223#post-id-140223

  1. The SDcard is formatted to ext4 instead of btrfs (as there is no btrfs support on JollaC yet). I also kept a conventional partition layout (to make it more likely other systems can easily mount the card. although they need to support ext4).
  2. The android directory that is overlaid (bind-mount) is /home/nemo/android_storage instead of /data/media. Which is actually a good thing as now Alien is having symlinks instead of mounting in circles.
  3. Bind mounts are used, instead of btrfs subvolume mounts. The Android directory is hidden in an attempt to prevent tracker indexing the files twice.

New instructions for JollaC are as follows:

preparing the sdcard should only be needed once!

Note: some ext4 formatted uSD cards did not show up or rendered unmountable on JollaC, best fit is to format on device

first dosystemctl stop aliendalvik.service then follow this list

  1. umount /dev/mmcblk1p1 - unmount the card might be another /dev or even more than one
  2. mkfs.ext4 /dev/mmcblk1p1 - format the card
  3. mount /dev/mmcblk1p1 /media/sdcard
  4. cd /media/sdcard
  5. mkdir .android - create folder called .android - this is hidden (starts with a dot) so it does not appear in directory listings
  6. I like to create a file on the card to remind me what I have done: so create a file called Android.README and fill it with:

    Android files are contained in a hidden directory called .android

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

  7. I also like to create a file with a unique name to let me easily check that Android apps are seeing the expected SD card. Something like: touch .android/GRC-128GB-SD.android

  8. chown -R nemo:nemo .android/
  9. chmod -R a=rwX .android/
  10. cp -r -a -v /home/nemo/android_storage/* /media/sdcard/.android
  11. cd ..
  12. umount /dev/mmcblk1p1

preparing the system

  • The next step requires knowing the Filesystem UUID for the SDcard filesystem. You can get it using lsblk -no UUID /dev/mmcblk1p1. The UUID is a string like 12345678-9abc-def0-1234-56789abcdef0. This string must be used instead of the string UUID-HERE in the file below (two occurrences). You can also find the UUID in the folder the uSD is mounted to as it follows that scheme (in /media/sdcard/ the folder of the currently mounted uSD).
  • create (as in do create not a command) /etc/systemd/system/home-nemo-android_storage.mount and fill with:

#

[Unit]
Description=SD card bind mount for Android
ConditionPathExists=/dev/mmcblk1p1
ConditionPathExists=!/tmp/os-update-running
ConditionPathIsDirectory=/home/nemo/android_storage/
ConditionPathIsMountPoint=/media/sdcard/UUID-HERE/
Requires=local-fs.target systemd-user-sessions.service
Before=aliendalvik.service
After=mount-sd@mmcblk1p1.service
BindsTo=mount-sd@mmcblk1p1.service

[Mount]
What=/media/sdcard/UUID-HERE/.android/
Where=/home/nemo/android_storage/
Type=none
Options=bind

[Install]
WantedBy=local-fs.target aliendalvik.service

Then run systemctl enable home-nemo-android_storage.mount.

  • the mount file gets started every time aliendalvik is started and stops aliendalvik when it gets stopped, on boot it prevents aliendalvik from starting if it is not started yet but waits for the local-fs to be settled and actually having a mountpoint

  • If you put a different SD card in, the mount file will do nothing (because the UUID does not match). The original /home/nemo/android_storage will be used. You can repeat the steps from the top, of course, for the new card.

edit retag flag offensive close delete

Comments

Excellent. Many thanks:)

richardski ( 2014-04-26 02:56:05 +0200 )edit

works as expected! Thanks a million. Do we need to remove the card for next sailfish-sysupdate or won't there be foreseeable issues?

mosen ( 2014-04-26 20:13:51 +0200 )edit
4

@mosen no need to remove the card, the only things that might happen are that Jolla decides to mount all available subvolumes to /media/sdcard/$(UUID) or replace the mount-sd.sh script in another way (knowing the line by heart or having a backup of your mount-sd.sh might come handy at some point). Both cases do no harm as long as you did not delete your /data/sdcard/ folder from your device's internal storage. If there be problems in the future I will try to update the how-to accordingly.

chemist ( 2014-04-26 20:35:52 +0200 )edit

What's the best way to edit mount-sd.sh? I've done it with copying the file and editing it on computer (wordpad), but it got my phone into a bootloop... I've fixed that now and really want to try it again (1.0.5.19), but just want to be sure that what I'm doing is the right way...

RobNas ( 2014-04-27 15:16:31 +0200 )edit
1

@RobNas I did all steps on the Jolla, for editing files I use vim. If you copy files from and to your device, you need to make sure that permissions and ownership are preserved. There was a typo, $(DEVNAME) should be ${DEVNAME} of course (updated the entries)

chemist ( 2014-04-27 15:22:13 +0200 )edit

6 Answers

Sort by » oldest newest most voted
13

answered 2016-07-31 18:04:53 +0200

gcobb gravatar image

I have created a variant of this for use on the Jolla C, with SailfishOS 2.0.2.43 (Aurajoki). This has the following main differences with the original solution @chemist created:

  1. The SDcard is formatted to ext4 instead of btrfs (as there is no btrfs support in this Sailfish version). I also kept a conventional partition layout (to make it more likely other systems can easily mount the card. although they need to support ext4).
  2. The android directory that is overlaid is /home/nemo/android_storage instead of /data/media.
  3. Bind mounts are used, instead of btrfs subvolume mounts. The Android directory is hidden in an attempt to prevent tracker indexing the files twice.

Here is my replacement for @chemist's instructions:

preparing the sdcard, should only be needed once!

first dosystemctl stop aliendalvik.service then follow this list

  1. umount /dev/mmcblk1p1 - unmount the card might be another /dev or even more than one
  2. mkfs.ext4 /dev/mmcblk1p1 - format the card
  3. mount /dev/mmcblk1p1 /media/sdcard
  4. cd /media/sdcard
  5. mkdir .android - create folder called .android - this is hidden (starts with a dot) so it does not appear in directory listings
  6. I like to create a file on the card to remind me what I have done: so create a file called Android.README and fill it with:

    Android files are contained in a hidden directory called .android

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

  7. I also like to create a file with a unique name to let me easily check that Android apps are seeing the expected SD card. Something like: touch .android/GRC-128GB-SD.android

  8. chown -R nemo:nemo .android/
  9. chmod -R a=rwX .android/
  10. cp -r -a -v /home/nemo/android_storage/* /media/sdcard/.android
  11. cd ..
  12. umount /dev/mmcblk1p1

preparing the system

  • The next step requires knowing the Filesystem UUID for the SDcard filesystem. You can get it using lsblk -no UUID /dev/mmcblk1p1. The UUID is a string like 12345678-9abc-def0-1234-56789abcdef0. This string must be used instead of the string UUID-HERE in the file below (two occurrences).
  • create (as in do create not a command) /etc/systemd/system/home-nemo-android_storage.mount and fill with:

#

[Unit]
Description=SD card bind mount for Android
ConditionPathExists=/dev/mmcblk1p1
ConditionPathExists=!/tmp/os-update-running
ConditionPathIsDirectory=/home/nemo/android_storage/
ConditionPathIsMountPoint=/media/sdcard/UUID-HERE/
Requires=local-fs.target systemd-user-sessions.service
Before=aliendalvik.service
After=mount-sd@mmcblk1p1.service
BindsTo=mount-sd@mmcblk1p1.service

[Mount]
What=/media/sdcard/UUID-HERE/.android/
Where=/home/nemo/android_storage/
Options=bind

[Install]
WantedBy=local-fs.target aliendalvik.service

Then run systemctl enable home-nemo-android_storage.mount.

  • the mount file gets started every time aliendalvik is started and stops aliendalvik when it gets stopped, on boot it prevents aliendalvik from starting if it is not started yet but waits for the local-fs to be settled and actually having a mountpoint

  • If you put a different SD card in, the mount file will do nothing (because the UUID does not match). The original /home/nemo/android_storage will be used. You can repeat the steps from the top, of course, for the new card.

edit flag offensive delete publish link more

Comments

Thanks mate, I tried that myself a couple of days ago and was already in progress of updating the main article when something went wrong, I guess it was because I used putty out of windows with a wrong lineending or something, as I was unable to start the .mount. I will copy this in the OP if that is ok with you.

chemist ( 2016-08-02 00:17:46 +0200 )edit

Feel free (particularly if you or someone else has tested the instructions!)

gcobb ( 2016-08-02 00:56:04 +0200 )edit

I wrote it myself but in general just the same but one line of yours, I will copy it upstairs then with a link to your answer ;)

chemist ( 2016-08-03 14:11:11 +0200 )edit

Hey guys,

After 2 weeks mutiple trys I still have the same problem that my jolla phone recognizes my sdcard, but it does'nt save any android data on it and android app don't show the sd card space. I worked with gcobb's solution but it still doesn't work.

I'm using Aurajoki 2.0.2.51 and first generation Jolla Phone 1.0.0.13 and I don't know which Android Version is simulated by the Jolla Android Support.

Strangley after serval times of trying gcobb's solutions I have now 2 folders on my SD card both with a different UUID!

I need some new input and help, please!

Quermitschi ( 2016-10-19 18:23:40 +0200 )edit

@Quermitschi: Android apps and data have two main locations on Sailfish OS (release 2.0.5). One is /home/nemo/android_storage and the other /home/.android.
Bind mapping proposed by chemist and gcobb here concern directory /home/nemo/android_storage. With that approach some big junks of data like map tiles (of Here WeGo, etc.) can be moved and added to the SD card and used from there. Very good. However, Android apps themselves and their data reside under /home/.android. For instance, the game of Clash of Clans has nothing under /home/nemo/android_storage (afaics). No, both the apk and the game data are under the tree of /home/.android.
I wonder if a similar bind mapping of /home/.android (or of an appropriate subdir, e.g. /home/.android/data/data) would make it possible to collect the app data to the memory card. It would be interesting to know. Making this work fluently and reliably would probably need more insight to Alien Dalvik.

jovirkku ( 2016-11-22 17:06:07 +0200 )edit
4

answered 2014-06-12 19:39:58 +0200

Vuubi gravatar image

This is how you can make chemist's version of systemd service unit (androidsdcard.service) into systemd mount unit.

First, create /etc/systemd/system/data-media.mount file:

[Unit]
Description=SD card btrfs subvolume for Android
ConditionPathExists=/dev/mmcblk1
ConditionPathIsDirectory=/data/media
Requires=local-fs.target
Before=aliendalvik.service
After=local-fs.target mount-sd@mmcblk1.service
BindsTo=mount-sd@mmcblk1.service

[Mount]
What=/dev/mmcblk1
Where=/data/media
Options=subvol=android,compress,dirsync,noatime,users

[Install]
WantedBy=local-fs.target aliendalvik.service

Second, create /etc/systemd/system/aliendalvik.service.d/sdcard.conf file:

[Unit] 
PartOf=data-media.mount

Then run systemctl enable data-media.mount (androidsdcard.service must be disabled before that).

edit flag offensive delete publish link more

Comments

there should be a button to convert to answer at your comment... that is why I asked @eric can you clean up again please (sry)

chemist ( 2014-06-12 20:18:32 +0200 )edit

No, I don't see any buttons there except vote arrow.

Vuubi ( 2014-06-12 20:27:31 +0200 )edit
2

Running a fresh install of 1.1.0.39, with Android support installed and Yandex Store working, but I don't seem to have the folder "aliendalvik.service.d/" in etc/systemd/system/. Should I create it and then create /etc/systemd/system/aliendalvik.service.d/sdcard.conf file or is there something else I need to do?

oenone ( 2014-11-26 00:30:47 +0200 )edit
2

@oenone

i just created a folder called aliendalvik.service.d and inside this folder i made the file sdcard.conf

aki ( 2014-12-14 17:09:49 +0200 )edit

I missed something crucial here. Why does Android apps complain "not enough space"? My lucky guess is that alien-dalvik cannot access android subvolume or somewhat. I only used wuubi's mount script.

DarkWhite ( 2015-01-06 16:05:31 +0200 )edit
2

answered 2014-06-11 12:47:51 +0200

alci gravatar image

If you want to use the sdcard as an extended memory and put your /home on it, you need to make sure it is mounted at the right moment and available for the ambiance setting, etc...

I tried the solution mentioned by the OP, but it implies modifying a system script, which is not upgrade-proof. Moreover, the script is not called early enough to let ambiance and some settings work...

I have found that a much solution is this one: Maemo thread to mount sdcard as /home I am using this for 2 month and a half now, 2 upgrades, and it has worked reliably for now. Of course, YMMV :-)

edit flag offensive delete publish link more

Comments

2

changed it to a systemd service, and this is not about using your sdcard as /home...

chemist ( 2014-06-11 15:09:38 +0200 )edit
1

answered 2015-02-22 18:36:23 +0200

jolladiho gravatar image

updated 2015-02-24 21:24:04 +0200

This is a workaround for 1.1.2. Someone changed it from a comment to an answer, thanks for this. I wrote it as comment, before chemist published the fix for 1.1.2 in the top thread. I recommend to use the fix from chemist.

As difference to the fix: No changes to delivered system files are necessary. You need the script and a change in the androidsdcard.service.

After reading comments from top thread, I wrote a little script, for all, who use a .service for the android-sd mount, like described in top thread. It puts some messages in the journalctl if you use it with 'mydebug=1'. Change the 'mymountoptions' var to your needs (the subvol entry at minimum!). The script waits for all alien processes, before it stops the aliendalvik.service and .path. Then it mounts the subvol to /data/media and starts the aliendalvik.path again. Use at your own risk.

If you make some mistakes, you have to know, how to start the recovery shell, mount the root subvol and remove a systemd service in that environment.

The script: /usr/local/bin/tmpfix-alien-mount-1.1.2.15.sh

#!/bin/bash
# dirty but handy
# stop android after startup, do mount and restart aliendalvik.path
# set the vars to your needs (user variables)
mymountoptions="subvol=.android,compress,dirsync,noatime,users,autodefrag,rw"
mydebug=1 # set to 1 for logging (jounalctl | grep tmpfix-alien-mount)
# no changes below needed
myservices="alien_audio_server aliensensorserver alien_bridge_server alien_gps_server alien_keyboard_server"
[ $mydebug == 1 ] && systemd-cat -t tmpfix-alien-mount /bin/echo "started with: PID=$$"
for i in $myservices
do
  mycount=$(/bin/ps -ef | /bin/grep -v grep | /bin/grep $i | wc -l)
  while [ $mycount -lt 1 ]
  do
    /bin/sleep 1
    mycount=$(/bin/ps -ef | /bin/grep -v grep | /bin/grep $i | wc -l)
  done
  [ $mydebug == 1 ] && systemd-cat -t tmpfix-alien-mount /bin/echo "$i found, counts: $mycount"
done
[ $mydebug == 1 ] && systemd-cat -t mount-sd.custom /bin/echo "all aliendalvik processes found."
/bin/sleep 1
systemctl stop aliendalvik.service
/bin/sleep 1
systemctl stop aliendalvik.path
[ $mydebug == 1 ] && systemd-cat -t tmpfix-alien-mount /bin/echo "aliendalvik stopped."
/bin/sleep 1
/bin/mount -o $mymountoptions /dev/mmcblk1 /data/media
[ $mydebug == 1 ] && systemd-cat -t tmpfix-alien-mount /bin/echo "mount with $mymountoptions done."
/bin/sleep 1
systemctl start aliendalvik.path
[ $mydebug == 1 ] && systemd-cat -t tmpfix-alien-mount /bin/echo "aliendalvik.path restarted, all done, exit."

I put it in /usr/local/bin and make it executable for user/group root.

In my androidsdcard.service I replaced the 'ExecStart' and 'ExecStop' part with.

ExecStart=/usr/local/bin/tmpfix-alien-mount-1.1.2.15.sh
ExecStop=/bin/umount /data/media

My Jolla did not shutdown correctly as I tried to add a 'systemctl stop aliendalvik.service' and .path to the ExecStop.

edit flag offensive delete publish link more

Comments

Please delete

elastic ( 2015-08-04 00:16:24 +0200 )edit
1

answered 2015-12-30 18:14:22 +0200

tyler gravatar image

I meet a wired problem: if I was downloading to card through an android app, software cannot write/read sd card after some time.

$ cd android_storage/    # another android app is downloading in background
$ while true; do
> date
> date > write_test
> sleep 3
> done
Wed Dec 30 23:46:46 CST 2015
Wed Dec 30 23:46:49 CST 2015
Wed Dec 30 23:46:52 CST 2015
Wed Dec 30 23:46:55 CST 2015
Wed Dec 30 23:46:58 CST 2015
Wed Dec 30 23:47:01 CST 2015
Wed Dec 30 23:47:04 CST 2015
Wed Dec 30 23:47:07 CST 2015
Wed Dec 30 23:47:10 CST 2015
Wed Dec 30 23:47:13 CST 2015    # frozen forever, android app downloading frozen
^C
$ ls    # frozen here forever
edit flag offensive delete publish link more

Comments

iirc that is android hooking the device and stalling any write, like stuck maps download (happened quiet often to me) - no idea if it is the btrfs driver or alien though. Stop alien and try again from scratch. Does it happen always or random? Would you mind checking if that happens without the sdcard mounted (internal storage), aka reproduce.

chemist ( 2015-12-31 13:48:05 +0200 )edit
0

answered 2014-06-11 12:32:11 +0200

RobNas gravatar image

updated 2014-06-13 14:21:14 +0200

This answer is obsolete now. I've left the part of editing with VIM, for anyone who's interested. To create a file, just type in terminal: touch /to/path/filename.extension Where "/to/path/" is the location of where the file needs to be located, and "filename.extension" is, surprisingly, the filename and extension. I've edited it with VIM. How to:
pkcon install zypper - if you haven't installed vim yet
zypper in vim - if you haven't installed vim yet
vim /usr/sbin/mount-sd.sh
To edit in vim, type "i"
Now you can type your text. After editing, get out of edit-mode, by pressing ESC twice. Then enter shift twice (capslocking it) and tap z twice ("ZZ"is the command for vim to save and exit).

edit flag offensive delete publish link more

Comments

1

I updated the top post, you need to be more patient with me please... and stop scaring people! you do not loose no data from your sdcard, it is just not mounted! my workaround answer is a bash-script, if you are unable to see that you probably should stay away from this how-to!

chemist ( 2014-06-11 15:11:39 +0200 )edit

You're right, I've screwed up. To be honest, I don't understand half of the code what is be done there and I'm just trying to use common sense (and a good bit of good luck). I've used part of the rewritten code for 1.0.7.16 now, and it's working again.

RobNas ( 2014-06-13 14:17:31 +0200 )edit

@RobNas join me on IRC if you need help or anything, if you updated to 1.0.7.16/18 the only thing you need to do is create the androidsdcard.service and enable it (or the .mount Vuubi describes in his answer), if you had the early version without the "after mount-sd@..." and update the service file, you need to stop and disable it before you do, systemd needs to be reloaded to reflect the changes then you enable it again and everything should work as expected!

chemist ( 2014-06-13 15:27:08 +0200 )edit

@chemist from step 1 ( umount /dev/mmcblk1p1 - unmount the card might be another /dev or even more than one) I am met with the message "umount: /media/sdcard/E42F-2BD2: umount failed: Operation not permitted"

please can you advise

ozzyo1212 ( 2015-01-11 12:14:18 +0200 )edit

@ozzyo1212 you probably need to be root to do that, if that did not help you need to be privileged (devel-su -p or -P iirc)

chemist ( 2015-01-11 23:36:30 +0200 )edit
Login/Signup to Answer

Question tools

Follow
94 followers

Stats

Asked: 2014-04-25 14:46:10 +0200

Seen: 22,939 times

Last updated: Aug 03 '16