answered
2019-02-12 12:52:36 +0200
More elegant way to automatically mount the SD card for Alien Dalvik using SystemD mounts:
Gets mounted after SD-card is mounted and Alien Dalvik is up.
Gets unmounted if Alien Dalvik goes down.
Gets remounted when both are again up.
So survives Alien Dalvik resets etc.
How:
Put following into file:
/etc/systemd/system/home-nemo-android_storage-sd.mount
[Unit]
Description=SD card under android_storage
After=mount-sd@mmcblk1p1.service run-media-nemo-688E-0FE4.mount aliendalvik.service
BindsTo=mount-sd@mmcblk1p1.service run-media-nemo-688E-0FE4.mount aliendalvik.service
RequiresMountsFor=/run/media/nemo/688E-0FE4/ /home/nemo/android_storage/
Conflicts=rescue.target actdead.target factory-test.target
[Mount]
What=/run/media/nemo/688E-0FE4/
Where=/home/nemo/android_storage/sd/
Options=bind
[Install]
WantedBy=mount-sd@mmcblk1p1.service run-media-nemo-688E-0FE4.mount aliendalvik.service
Test with following command as root:
systemctl start home-nemo-android_storage-sd.mount
Enable the mount permanently with following command as root:
systemctl enable home-nemo-android_storage-sd.mount
For changes:
Replace all instances of "688E-0FE4" with your SD card volume name.
"Where=" is the target where to mount.
.mount file name under /etc/systemd/system needs to be the mounts target with "/":s replaced with "-":s and ending with ".mount".
"Description=" is what is shown in logs, with "Mounting [description]..."
Use the correct .mount file name with the systemctl commands.
Personally used this to move specific Android apps data to SD card.
Here WeGo example, with my SD volume named "SDCard" and files going under "Android" directory on SD card:
/etc/systemd/system/home-.android-data-media-0-Android-data-com.here.app.maps.mount
[Unit]
Description=Here WeGo data directory on SD card
After=mount-sd@mmcblk1p1.service run-media-nemo-SDCard.mount aliendalvik.service
BindsTo=mount-sd@mmcblk1p1.service run-media-nemo-SDCard.mount aliendalvik.service
RequiresMountsFor=/run/media/nemo/SDCard/ /home/nemo/android_storage/
Conflicts=rescue.target actdead.target factory-test.target
[Mount]
What=/run/media/nemo/SDCard/Android/com.here.app.maps/
Where=/home/.android/data/media/0/Android/data/com.here.app.maps/
Options=bind
[Install]
WantedBy=mount-sd@mmcblk1p1.service run-media-nemo-SDCard.mount aliendalvik.service
Enabled with:
systemctl enable home-.android-data-media-0-Android-data-com.here.app.maps.mount
For multiple mounts: Just add separate .mount file for each bind mount and enable them.
Might need more work for encrypted SD cards and to work with unmounting and remounting SD card.
Probably need to change the "mount-sd@mmcblk1p1.service":s to something like "run-media-nemo-SDCard.mount".
EDIT: Original version, without the "run-media-nemo-[volumename].mount":s, ended up trashing some of the Android App data when SD card was unmounted via Settings app Storage while bind mounts were still up, because the bind mounts stayed mounted. This also prevented remounting the card at the same place without reboot.
New version unmounts the bind mounts on SD card unmount, but doesn't remount them automatically.
They get remounted when Alien Dalvik is restarted. Haven't been able to replicate the data loss after this change.
Settings app unmount and remount don't seem to use SystemD but instructs udisksd. And the .mount dependency doesn't seem to be enough to trigger remount either. So I'm not seeing quick way to get this working with encrypted SD cards or remounting the bind mounts on SD card remount.
That's a cool idea.
santhoshmanikandan ( 2019-02-11 07:35:58 +0200 )editAlso, I was able to get a one-click solution working with Shellex app, using sudo with a modified sudoers file, (Shellex doesn't run root as-is). I can post details if anyone wants ...
Levone1 ( 2019-02-12 00:31:17 +0200 )edit