How to: Format your uSD-Card to share space with android
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:
- format the whole usdcard (mmcblk1 not mmcblk1p1) to btrfs
- mount that volume (=0)
- create two subvolumes > jolla and android
- set the default volume to jolla (the default is what gets mounted when something calls
mount /dev/mmcblk1
) - 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)
- 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.
- 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
umount /dev/mmcblk1p1
- unmount the card might be another /dev or even more than onemkfs.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 devicemount -o subvolid=0 /dev/mmcblk1 /media/sdcard
cd /media/sdcard
btrfs subvolume create jolla
- create folder called jollabtrfs subvolume create android
- create folder called androidbtrfs subvolume list .
- returns an ID for each subvolumebtrfs subvolume set-default *ID for jolla* /media/sdcard/
- sets jolla to be mounted as defaultchown nemo:nemo jolla/
- add-R
if neededchmod 775 jolla/
chmod 777 android/
cp -r -a -v /data/media/* /media/sdcard/android
cd ..
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
- 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).
- 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.
- 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
umount /dev/mmcblk1p1
- unmount the card might be another /dev or even more than onemkfs.ext4 /dev/mmcblk1p1
- format the cardmount /dev/mmcblk1p1 /media/sdcard
cd /media/sdcard
mkdir .android
- create folder called .android - this is hidden (starts with a dot) so it does not appear in directory listingsI 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
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
chown -R nemo:nemo .android/
chmod -R a=rwX .android/
cp -r -a -v /home/nemo/android_storage/* /media/sdcard/.android
cd ..
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.
Excellent. Many thanks:)
richardski ( 2014-04-26 02:56:05 +0200 )editworks 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@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 )editWhat'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@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