Tune / bug fix /usr/sbin/mount-sd.sh
This thread complements https://together.jolla.com/question/96765/trim-on-all-supported-file-systems/ and https://together.jolla.com/question/73696/sd-card-mount-slow-with-11127-so-android-has-problems/
I updated the /usr/sbin/mount-sd.sh script. Changes:
- Wait for tracker after mounting the filesystem instead of before. This works as we trigger the indexing by touching the mount dir anyway, so now we do mount -> wait -> touch instead of wait -> mount -> touch.
- Trigger indexing after unmounting.
- Remove temporary mount directory after unmounting.
- Add discard mount option for ext4 and btrfs.
- Remove some duplicated code.
To the Jolle devs: Feel free to use this script (as a template) for the next SailfishOS version. Just diff it with the current to see my changes.
#!/bin/bash # The only case where this script would fail is: # mkfs.vfat /dev/mmcblk1 then repartitioning to create an empty ext2 partition DEF_UID=$(grep "^UID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) DEF_GID=$(grep "^GID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) DEVICEUSER=$(getent passwd $DEF_UID | sed 's/:.*//') MNT=/media/sdcard MOUNT_OPTS="dirsync,noatime,users" ACTION=$1 DEVNAME=$2 if [ -z "${ACTION}" ] || [ -z "${DEVNAME}" ]; then exit 1 fi systemd-cat -t mount-sd /bin/echo "Called to ${ACTION} ${DEVNAME}" if [ "$ACTION" = "add" ]; then eval "$(/sbin/blkid -c /dev/null -o export /dev/$2)" if [ -z "${UUID}" ] || [ -z "${TYPE}" ]; then exit 1 fi DIR=$(grep -w ${DEVNAME} /proc/mounts | cut -d \ -f 2) if [ -n "$DIR" ]; then systemd-cat -t mount-sd /bin/echo "${DEVNAME} already mounted on ${DIR}, ignoring" exit 0 fi test -d $MNT/${UUID} || mkdir -p $MNT/${UUID} chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID} case "${TYPE}" in vfat|exfat) MOUNT_OPTS="uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard" ;; # NTFS support has not been tested but it's being left to please the ego of an engineer! ntfs) MOUNT_OPTS="uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8" ;; # ext and btrfs are able to discard. Add more to the list if needed. ext4|btrfs) MOUNT_OPTS+=",discard" ;; esac mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID} # This hack is here to delay triggering indexing before the tracker has started. export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$DEF_UID/dbus/user_bus_socket count=1 while true; do test $count -ge 64 && break MINER_STATUS="$(dbus-send --type=method_call --print-reply --session --dest=org.freedesktop.Tracker1.Miner.Files /org/freedesktop/Tracker1/Miner/Files org.freedesktop.Tracker1.Miner.GetStatus | grep -o 'Idle')" STORE_STATUS="$(dbus-send --type=method_call --print-reply --session --dest=org.freedesktop.Tracker1 /org/freedesktop/Tracker1/Status org.freedesktop.Tracker1.Status.GetStatus | grep -o 'Idle')" test "$MINER_STATUS" = "Idle" -a "$STORE_STATUS" = "Idle" && break systemd-cat -t mount-sd /bin/echo "Waiting $count seconds for tracker" sleep $count ; count=$(( count + count )) done # Trigger indexing test -d $MNT/${UUID} && touch $MNT/${UUID} systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} of type ${TYPE} at $MNT/${UUID}" else DIR=$(grep -w ${DEVNAME} /proc/mounts | cut -d \ -f 2) if [ -n "${DIR}" ] ; then if [ "${DIR##$MNT}" = "${DIR}" ]; then systemd-cat -t mount-sd /bin/echo "${DEVNAME} mountpoint ${DIR} is not under ${MNT}, ignoring" exit 0 fi umount $DIR || umount -l $DIR # Deregister the indexed files from tracker touch ${DIR} # Remove directory rmdir ${DIR} systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} at ${DIR}" fi fi
Well, now the engineer can test it if they want: I've compiled a version of NTFS-3G for Jolla Phone.
- https://openrepos.net/content/dryak/ntfs-3g
DrYak ( 2015-06-20 07:36:58 +0200 )editUsing this mount script I experience a sudden reboot (after a while) then auto-reboot again when the lock screen appears then somehow it comes back. First time reboot came when I opened photos from Gallery app. Today it rebooted when a video was played with ytplayer with wifi and 70% battery. Maybe the issues are not tied together - experiences of others might clarify.
llg179 ( 2015-06-23 17:51:27 +0200 )editThanks for your report. It's just a shot in the blue but maybe reverting https://github.com/V10lator/sd-utils/commit/e332cbc8b0b681209b0fab932217dc763efe3382 might help.
To revert that simply open the mount script and re-add the line marked with the subtraction sign in front (but don't copy the subtraction mark itself).
Please report back if that helped. :)
//EDIT: But please also clean your battery contacts as they might be the real root of the reboots.
V10lator ( 2015-06-24 14:28:59 +0200 )editSome months ago I put paper to bottom of battery to avoid random reboots - I think the reboot was not caused by contact problem of battery. My main motivation was to move /home/nemo/.local/share to sdcard but some apps launch later than the sdcard is mounted therefore call history and sms send-receive did not work. With your updated script the call history could not load either so it did not bring the desired effect by itself. Maybe the startup script dependencies should be configured too. I will read more about dbus and systemd - but for me a workaround was to restart the voicecall-ui service after mounting the sdcard. I gave up the idea of using ~/.local/share as a link to folder of sdcard for a while because I need a reliable phone and both your elegant script and linking share to sdcard jeopardized that. Hopefully we will receive further feedbacks soon from others. :)
How could indexing or tracker cause reboots? How can a reboot be troubleshooted?
llg179 ( 2015-06-25 00:46:52 +0200 )editNeither indexing nor tracker should cause reboots. That's why I said it's just a shot in the blue. :)
Now as you already had problems with your battery contacts cleaning them won't harm, will it? Jolla itself has a how-to do it the best way somewhere around, am too lazy to search right now but IIRC it was basically "re-insert battery around 10 times".
You see, for me it works and nobody other than you confirmed your bug. So hunting it in some corners is the only thing we can do.
V10lator ( 2015-06-26 15:50:15 +0200 )edit