View Single Post
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: