Active Topics

 


Reply
Thread Tools
Posts: 204 | Thanked: 443 times | Joined on Jul 2012 @ Germany - Potsdam
#71
Originally Posted by javispedro View Post
...
I don't think that mount-sd.sh is called twice (other than add/remove). If you are experiencing this I think you need to give more information.
...
I must say: It is called twice! Once in an early stage and a mount to "/run/user/${DEF_UID}/media/sdcard" is not possible at that time. Thats why I coded a little on mount-sd.sh and generate two files containing the processid of the call.

I am using btrfs filesystem and some subvolumes. If I do not distinguish between early and late call I get some mount messages (already in use - I think - or equal to that) at startup. After startup I can find the files mount-sd.early.done and mount-sd.late.done in the /tmp folder. The early file contains a low processid (ex. 230), the other a higher id (ex. 1303).

I also have a symbolic link "/home/nemo/MyDocs -> /run/user/100000/media/sdcard". If I create an ambience from a picture that is saved in "MyDocs", I lose the ambience at reboot. Thats why I think, SailfishOS checks the ambience files between the early and the late call of mount-sd.sh. Ambiences from pictures in the other folders, that are mounted as subvolumes in early stage (~/Pictures) are persistent. So this is a problem of mounting the sdcard to "/run/user/100000/media/sdcard". If you do a mount to a self defined mountpoint (ex. /mnt/microsd) everything is done early. My question is: when is the folder "/run/user/100000/media/sdcard" available at startup?

Edit: mkdir: cannot create directory `/run/user': Permission denied
This is the problem of the mount-sd.sh. The folder /run/user does not exist at the early stage. Sometimes the /home folder is also mounted later, than mount-sd.sh is executed.

On shutdown, all subvolumes should be unmounted. That's why I put a while loop at the end of mount-sd.sh. Mine looks oversized at the moment, but it should work with other filessystems too, added a filesystem check with "file -s". If you want to use it with btrfs (at your own risk - it is experimental), you have to change the "mount -o subvol=.jolla/xxxx ${SDCARD} /home/nemo/xxxx" parts for your needs. The first mount should be done with or without compress option, just as you like it.

how I created my btrfs sdcard as root after a factory reset
Code:
mkfs.btrfs -f /dev/mmcblk1
btrfs filesystem show /dev/mmcblk1 # this is a check
mkdir /mnt/microsd
mount /dev/mmcblk1 /mnt/microsd/
btrfs subvolume create /mnt/microsd/.android
btrfs subvolume create /mnt/microsd/.jolla
btrfs subvolume create /mnt/microsd/.jolla/Desktop
btrfs subvolume create /mnt/microsd/.jolla/Documents
btrfs subvolume create /mnt/microsd/.jolla/Downloads
btrfs subvolume create /mnt/microsd/.jolla/Music
btrfs subvolume create /mnt/microsd/.jolla/Pictures
btrfs subvolume create /mnt/microsd/.jolla/Public
btrfs subvolume create /mnt/microsd/.jolla/Templates
btrfs subvolume create /mnt/microsd/.jolla/Videos
btrfs subvolume list /mnt/microsd/ # this is a check
chown -R nemo:nemo /mnt/microsd/*
cp -rav /home/nemo/Pictures/* /mnt/microsd/Pictures/
cp -rav /home/nemo/Videos/* /mnt/microsd/Videos/
# transfer mount-sd.sh to /home/nemo via filezilla or scp and do
cp /usr/sbin/mount-sd.sh /usr/sbin/mount-sd.sh.orig
cp /home/nemo/mount-sd.sh /usr/sbin/mount-sd.sh
chmod +x /usr/sbin/mount-sd.sh
mount-sd.sh
Code:
#!/bin/bash

SDCARD=/dev/sdcard
EARLYDONE="/tmp/mount-sd.early.done"
LATEDONE="/tmp/mount-sd.late.done"
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/:.*//')
LATEMNT=/run/user/${DEF_UID}/media/sdcard

if [ "${ACTION}" = "add" ]; then
  if [ -f ${LATEDONE} ]; then
    echo "$0: nothing to do!"
  else
    # try only the late mount again
    if [ -f ${EARLYDONE} ]; then
      if [ -b /dev/mmcblk1p1 ]; then
        ID_FS_TYPE=$(file -s /dev/mmcblk1p1 | tr '[:upper:]' '[:lower:]' | cut  -d " " -f2)
      elif [ -b /dev/mmcblk1 ]; then
        ID_FS_TYPE=$(file -s /dev/mmcblk1 | tr '[:upper:]' '[:lower:]' | cut  -d " " -f2)
      else
        exit $?
      fi
      su ${DEVICEUSER} -c "mkdir -p ${LATEMNT}"
      case "${ID_FS_TYPE}" in
        vfat|ntfs|exfat)
          mount ${SDCARD} ${LATEMNT} -o uid=${DEF_UID},gid=${DEF_GID}
          [ $? = 0 ] && echo "$$" >> ${LATEDONE}
        ;;
        *)
          mount ${SDCARD} ${LATEMNT}
          if [ $? = 0 ]; then
            echo "$$" >> ${LATEDONE}
            chown ${DEVICEUSER}: ${LATEMNT}
          fi
        ;;
      esac
    # first call, try both: early and late mount
    else
      # create device
      if [ -b /dev/mmcblk1p1 ]; then
        ln -sf /dev/mmcblk1p1 ${SDCARD}
        ID_FS_TYPE=$(file -s /dev/mmcblk1p1 | tr '[:upper:]' '[:lower:]' | cut  -d " " -f2)
      elif [ -b /dev/mmcblk1 ]; then
        ln -sf /dev/mmcblk1 ${SDCARD}
        ID_FS_TYPE=$(file -s /dev/mmcblk1 | tr '[:upper:]' '[:lower:]' | cut  -d " " -f2)
      else
        exit $?
      fi
      su ${DEVICEUSER} -c "mkdir -p ${LATEMNT}"
      case "${ID_FS_TYPE}" in
        vfat|ntfs|exfat)
          mount ${SDCARD} ${LATEMNT} -o uid=${DEF_UID},gid=${DEF_GID}
          [ $? = 0 ] && echo "$$" >> ${LATEDONE}
        ;;
        btrfs)
          mount -o compress ${SDCARD} ${LATEMNT}
          if [ $? = 0 ]; then
            echo "$$" >> ${LATEDONE}
            chown ${DEVICEUSER}: ${LATEMNT}
          fi
          mount -o subvol=.jolla/Desktop,compress ${SDCARD} /home/nemo/Desktop/
          mount -o subvol=.jolla/Documents ${SDCARD} /home/nemo/Documents/
          mount -o subvol=.jolla/Downloads ${SDCARD} /home/nemo/Downloads/
          mount -o subvol=.jolla/Music ${SDCARD} /home/nemo/Music/
          mount -o subvol=.jolla/Pictures ${SDCARD} /home/nemo/Pictures/
          mount -o subvol=.jolla/Public ${SDCARD} /home/nemo/Public/
          mount -o subvol=.jolla/Templates ${SDCARD} /home/nemo/Templates/
          mount -o subvol=.jolla/Videos ${SDCARD} /home/nemo/Videos/
          [ -d /data/sdcard ] && mount -o subvol=.android ${SDCARD} /data/sdcard/
        ;;
        *)
          mount ${SDCARD} ${LATEMNT}
          if [ $? = 0 ]; then
            echo "$$" >> ${LATEDONE}
            chown ${DEVICEUSER}: ${LATEMNT}
          fi
        ;;
      esac
      echo "$$" >> ${EARLYDONE}
    fi
  fi
else
  # unmount all
  umount ${SDCARD}
  myret=$?
  while [ $myret = 0 ]
  do 
    echo -n "."
    umount ${SDCARD}
    myret=$?
  done

  umount -l ${LATEMNT}
  rm -f ${SDCARD}

  # clear status flags
  rm -f ${LATEDONE}
  rm -f ${EARLYDONE}
fi

Last edited by meemorph; 2014-03-01 at 13:14.
 

The Following 3 Users Say Thank You to meemorph For This Useful Post:
Posts: 1,548 | Thanked: 7,510 times | Joined on Apr 2010 @ Czech Republic
#72
Good find! BTW, voted for your corresponding question on Together.
__________________
modRana: a flexible GPS navigation system
Mieru: a flexible manga and comic book reader
Universal Components - a solution for native looking yet component set independent QML appliactions (QtQuick Controls 2 & Silica supported as backends)
 

The Following User Says Thank You to MartinK For This Useful Post:
Posts: 204 | Thanked: 443 times | Joined on Jul 2012 @ Germany - Potsdam
#73
Thanks for putting in the link. I forgot. As I can see, there are more questions on together.jolla.com, that depend on the startup problem.
 
javispedro's Avatar
Posts: 2,355 | Thanked: 5,249 times | Joined on Jan 2009 @ Barcelona
#74
Originally Posted by meemorph View Post
I must say: It is called twice! Once in an early stage and a mount to "/run/user/${DEF_UID}/media/sdcard" is not possible at that time. Thats why I coded a little on mount-sd.sh and generate two files containing the processid of the call.
Can you show the parent process for each of the calls? Though I suspect now that one is udev while the other is systemd (because it seems that there's a systemd unit that will call mount-sd.sh, probably to workaround some issue like the one you have).
 
Posts: 204 | Thanked: 443 times | Joined on Jul 2012 @ Germany - Potsdam
#75
Originally Posted by javispedro View Post
Can you show the parent process for each of the calls? Though I suspect now that one is udev while the other is systemd (because it seems that there's a systemd unit that will call mount-sd.sh, probably to workaround some issue like the one you have).
made a debug script yesterday, here are the results

Code:
PID=224, ACTION=add
ln -sf /dev/mmcblk1 /dev/sdcard
ID_FS_TYPE=btrfs
mkdir: cannot create directory `/run/user/100000': Permission denied
mkdir -p /run/user/100000/media/sdcard, rc=1
 home is mounted.
mount -o subvol=.jolla/Desktop /dev/sdcard /home/nemo/Desktop/, rc=0
mount -o subvol=.jolla/Documents /dev/sdcard /home/nemo/Documents/, rc=0
mount -o subvol=.jolla/Downloads /dev/sdcard /home/nemo/Downloads/, rc=0
mount -o subvol=.jolla/Music /dev/sdcard /home/nemo/Music/, rc=0
mount -o subvol=.jolla/Pictures /dev/sdcard /home/nemo/Pictures/, rc=0
mount -o subvol=.jolla/Playlists /dev/sdcard /home/nemo/Playlists/, rc=0
mount -o subvol=.jolla/Public /dev/sdcard /home/nemo/Public/, rc=0
mount -o subvol=.jolla/Templates /dev/sdcard /home/nemo/Templates/, rc=0
mount -o subvol=.jolla/Videos /dev/sdcard /home/nemo/Videos/, rc=0
mount -o subvol=.android /dev/sdcard /data/sdcard/, rc=0
---callstack---
UID        PID  PPID  C STIME TTY          TIME CMD
root       158     1 16 15:44 ?        00:00:00 /lib/systemd/systemd-udevd
root       163   158  4 15:44 ?        S      0:00 /lib/systemd/systemd-udevd
root       224   163  2 15:44 ?        S      0:00 /bin/bash /usr/sbin/mount-sd.sh
---end---
PID=1318, ACTION=add
ln -sf /dev/mmcblk1 /dev/sdcard
ID_FS_TYPE=btrfs
mkdir -p /run/user/100000/media/sdcard, rc=0
mount -o compress /dev/sdcard /run/user/100000/media/sdcard, rc=0
 home is mounted.
su nemo -c "ln -sf /run/user/100000/media/sdcard /home/nemo/MyDocs"
---callstack---
root         1     0  6 15:43 ?        Ss     0:01 /sbin/init --unit=default.target
root      1318     1  1 15:44 ?        Ss     0:00 /bin/bash /usr/sbin/mount-sd.sh
---end---
 

The Following User Says Thank You to meemorph For This Useful Post:
Posts: 24 | Thanked: 7 times | Joined on Nov 2011
#76
I was using my SDCard as /home mountpoint, but latest upgrade broke my setup... Does anyone know how to recover my /home mount point with 1.0.4.20 ? (I guess it is broken because og the new mount SD as MTP functionnality)
 
Posts: 738 | Thanked: 819 times | Joined on Jan 2012 @ Berlin
#77
maybe it helps you:

old path: /run/user/100000/media/sdcard
new path: /media/sdcard/xxxx-xxxx/

xxxx-xxxx = your SDcard Code my is for example 354C-1405

i think you have to replace it in the config part
__________________
www.sailfishmods.de
 
Posts: 594 | Thanked: 1,094 times | Joined on Aug 2012 @ Rhine
#78
mount-sd.sh was overwritten by the update, so obviously you need to add the lines to mount your folders again (step 6 of first post)...

but the really bad part after the update is:
at first look, it seems that mount-sd.sh is now called for the first time later than before (now after the "ambiance-stuff"), which is really totally annoying.

the only workaround, i have for now:
copy the ambiance to the "traditional home-folder" (not on sdcard), so it can be accessed at bootup.

i hope, i or someone else finds a better solution (or this will be gone with the next update).

Last edited by Leinad; 2014-03-18 at 11:03.
 
Posts: 284 | Thanked: 661 times | Joined on Aug 2013 @ Finland
#79
Just posting the new Ovijärvi mount-sd.sh here, hopefully it will be of use here:

Code:
#!/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

    # This hack is here to delay mounting the sdcard until tracker is ready
    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

    test -d $MNT/${UUID} || mkdir -p $MNT/${UUID}
    chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID}
    touch $MNT/${UUID}

    case "${TYPE}" in
	vfat|exfat)
	    mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir $MNT/${UUID}
	    ;;
	# NTFS support has not been tested but it's being left to please the ego of an engineer!
	ntfs)
	    mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8 || /bin/rmdir $MNT/${UUID}
	    ;;
	*)
	    mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID}
	    ;;
    esac
    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=$(mount | grep -w ${DEVNAME} | cut -d \  -f 3)
    if [ -n "${DIR}" ] ; then
        umount $DIR || umount -l $DIR
        systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} at ${DIR}"
    fi
fi

Last edited by Thoke; 2014-03-19 at 21:46.
 
Posts: 24 | Thanked: 7 times | Joined on Nov 2011
#80
Originally Posted by Leinad View Post
mount-sd.sh was overwritten by the update, so obviously you need to add the lines to mount your folders again (step 6 of first post)...

but the really bad part after the update is:
at first look, it seems that mount-sd.sh is now called for the first time later than before (now after the "ambiance-stuff"), which is really totally annoying.

the only workaround, i have for now:
copy the ambiance to the "traditional home-folder" (not on sdcard), so it can be accessed at bootup.

i hope, i or someone else finds a better solution (or this will be gone with the next update).

Humm... not sure, but it feels like other settings are not saved either (or are loaded from the "traditional home-folder" before the sdcard is mounted). For example, the "fast call" setting does not persit between reboots on my phone since 1.0.4.20.
 
Reply


 
Forum Jump


All times are GMT. The time now is 00:30.