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:
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 is able to discard, damn Jolla team...
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
| 2 | No.2 Revision |
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:
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 is and btrfs able to discard, damn Jolla team...
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
| 3 | No.3 Revision |
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:
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