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

[XA2][HowTo] Mounting SD card in Aliendalvik (+ making internal storage accessible to write + duplicating media workaround)

asked 2019-05-14 02:55:58 +0200

meschk gravatar image

updated 2019-11-27 17:00:10 +0200

jiit gravatar image

Here is a small guide about mounting SD card in Aliendalvik, making it accessible to Android apps. It is made for Xperia XA2 series (and maybe other devices with 8.1 dalvik, if there are any), and is tested with 3.0.3.8/3.0.3.9 (might not work with older versions due to different layout).

For the reference: phone's internal storage (/home/nemo) is being mounted to /home/.nemo_bind with bindfs (its purpose is permission spoofing, so that files created by Sailfish default user are accessible by Android media UID and vice versa). Then, this folder is being passed through to Alendalvik LXC container with read-only access. We are going to do the same mount for the SD card.

  • Log in as root using devel-su either with Fingerterm or via SSH.
  • Create files /home/sdbind.sh and /home/sdunbind.sh and put these lines there.

For sdbind.sh:

#!/bin/bash
# map files from sdcard to alien
mkdir -p /home/.sd_bind
bindfs --chmod-ignore --chown-ignore --chgrp-ignore --map=100000/1023:@100000/@1023 /run/media/nemo/<UUID> /home/.sd_bind
if [ "$?" != "0" ]; then
    echo "Failed to mount sdcard for alien"
    exit 1
fi

You should replace <UUID> with UUID of your sd card. You can see it just by using ls /run/media/nemo.

For sdunbind.sh:

#!/bin/bash
umount /home/.sd_bind || :
  • Run systemctl edit aliendalvik.service and insert these lines:

    [Service]
    ExecStartPre=/bin/su -c "/bin/bash /home/sdbind.sh"
    ExecStopPost=/bin/su -c "/bin/bash /home/sdunbind.sh"
    
  • Edit /var/lib/lxc/aliendalvik/extra_config and add this line:

    lxc.mount.entry = /home/.sd_bind data/media/0/sd none bind,rw,create=dir 0 0
    
  • Reboot. SD card then should be accessible from sd folder in Android internal storage.

Replace "rw" with "ro" if you want to mount your SD card read-only.

  • BONUS: Mounting internal storage with write support

Simply open /var/lib/lxc/aliendalvik/config and replace "ro" with "rw" in this line:

lxc.mount.entry = /home/.nemo_bind data/media/0/nemo none bind,ro,create=dir 0 0

It should be this:

lxc.mount.entry = /home/.nemo_bind data/media/0/nemo none bind,rw,create=dir 0 0

After that, reboot as usual.

  • BONUS №2: Dealing with photos and stuff being shown twice in Android apps

As I mentioned before, /home/nemo is being mounted in Aliendavik as nemo folder in internal storage. But the internal storage itself is stored in /home/nemo/android_storage. This creates bug which makes files show in filesystem two times: first one in the main folder of internal storage itself and the second one in the nemo/android_storage folder.

This can be easily fixed by creating an empty folder (for example, /home/.empty) and mounting it in the /var/lib/lxc/aliendalvik/extra_config:

lxc.mount.entry = /home/.empty data/media/0/nemo/android_storage none bind,ro,create=dir 0 0

Again, reboot. Then the nemo/android_storage folder in Android apps will show up empty and files will stop duplicating.

edit retag flag offensive close delete

Comments

suggestsions :

have sdbind and sdunbind take an argument ( with approriate [ -d "$1" ] tests at the beginning) :

bindfs --chmod-ignore --chown-ignore --chgrp-ignore --map=100000/1023:@100000/@1023 "/run/media/nemo/${1}" /home/.sd_bind

Then use a separate template .service:

ExecStartPre=/home/sdbind.sh %I

Bonus point: it should be possible to wire that template service to be "WantedBy=aliendalvik.service" so there is no nee to modify aliendalvik.service itself

Then it's all a matter of

systemctl enable sdbind@<UUID>.service
DrYak ( 2019-12-04 23:08:49 +0200 )edit

May I ask you two probably "ignorant" questions: Is this method also working on a XA2 with SFOS 3.2.1.20 ? If yes: when using android apps is all data which is normally saved to /home/nemo/android_storage now saved to the sd card? (Excuse me, if I do not understand all of your code; I'm not to familiar with this...) Best regards, Uwe.

UweLabs ( 2020-01-11 18:56:33 +0200 )edit

May I ask again if somebody knows if this procedure will work in SFOS 3.2.1.20? Best regards, Uwe.

UweLabs ( 2020-02-25 18:11:52 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-04-08 14:10:24 +0200

jovirkku gravatar image

Access to the memory card from Android apps should work better (but not perfectly) on Xperia XA2 and Xperia 10 from Sailfish OS 3.3.0 onwards.

The release notes have this text:
Many Android apps can access the SD card, now. For instance, OsmAnd and HERE WeGo map apps can save the offline map tiles to the card. Likewise, Spotify can save music to the card. Apps like WhatsApp can attach pictures from the SD card to messages now. The card name must not contain spaces.

edit flag offensive delete publish link more

Comments

@jovirkku do you know if there is a ~2Gb file size limitation which Android apps can handle as I mention here ? VLC for example stops at ~2Gb filesize, like it can't read the file after that.

nas ( 2020-04-08 16:10:40 +0200 )edit

On my Jolla1 it works perfectly, but on my XA2, android apps can only read Sdcard.

In 3.3.0.14 it was working. I think it is not directly related, but is there a way to get write access back?

https://together.jolla.com/question/226517/no-sd-card-write-access-for-android-apps/

VincentB ( 2020-05-01 21:00:51 +0200 )edit
Login/Signup to Answer

Question tools

Follow
13 followers

Stats

Asked: 2019-05-14 02:55:58 +0200

Seen: 1,171 times

Last updated: Apr 08