View Single Post
Posts: 204 | Thanked: 443 times | Joined on Jul 2012 @ Germany - Potsdam
#5
I also like to use a custom mount script. Ambiences from pictures on the sdcard get lost with the new mount-sd.sh script.

I like to help you. I have build a system.service to make the custom mount. I took my old allround debug-script to do it. You can use it, should be useful for all use cases.

1. the script
Name: mount-sd.custom.sh
Code:
#!/bin/bash
# some parts from original mount-sd.sh SailfishOS vers. 1.0.4.20

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/:.*//')
MOUNT_OPTS="dirsync,noatime,users"
ACTION=$1
DEVNAME=$2

if [ -z "${ACTION}" ] || [ -z "${DEVNAME}" ]; then
    exit 1
fi

# custom part for btrfs starts here
# ----------------------------------
# (testing)  -- root mounts with noatime,autodefrag
# btrfs on ssd: rw,noatime,compress=lzo,ssd,discard,space_cache,autodefrag,inode_cache
# btrfs on hdd: rw,relatime,compress-force=zlib,autodefrag
#
# custom variables - you may change or comment
# --------------------------------------------
# debug: talk to jounal, as root do this: journalctl | grep mount
MYDEBUG="on"

# mount btrfs sd root to /media/work
MYWORK="/media/work"

# make a symlink to mountpoint with sd root
#MYDOCS="/home/${DEVICEUSER}/MyDocs"

# replace /home and/or /home/nemo
#MYHOME=".home"
#MYNEMO=".myfolder"

# replace only some folders in /home/nemo with btrfs subvolumes found in $MYHOMEFOLDERS
#MYFOLDERS="Data Desktop Documents Downloads Music Pictures Playlists Public Templates Videos"
MYFOLDERS="Pictures"
MYHOMEFOLDERS=".myfolder"

#replace android /data/sdcard with subvolume $MYANDROID
MYANDROID=".android"
JOANDROID="/data/sdcard"

# custom code begins here - do not change
#--------------------------------------------------------------------------
# no android support installed: empty(MYANDROID)
[ -d ${JOANDROID} ] || MYANDROID=""

systemd-cat -t mount-sd.custom /bin/echo "Called to ${ACTION} ${DEVNAME}"

if [ "${ACTION}" = "add" ]; then
  # set TYPE and other things and exit if nothing found
  eval "$(/sbin/blkid -c /dev/null -o export /dev/$2)"
  [ "${MYDEBUG}" ] && systemd-cat -t mount-sd.custom /bin/echo "PID=$$, ACTION=${ACTION}, DEVNAME=${DEVNAME}"
  if [ -z "${TYPE}" ]; then
    exit 1
  fi
  # do the mount if needed
  case "${TYPE}" in
    vfat|exfat)
      systemd-cat -t mount-sd.custom /bin/echo "case vfat, exfat, TYPE=${TYPE}, nothing to do."
    ;;
    ntfs)
      systemd-cat -t mount-sd.custom /bin/echo "case ntfs, TYPE=${TYPE}, nothing to do."
    ;;
    btrfs)
      systemd-cat -t mount-sd.custom /bin/echo "case btrfs, TYPE=${TYPE}, implemented - start working."
      if [ "${MYWORK}" ] 
      then
        [ -d "${MYWORK}" ] || mkdir -p "${MYWORK}"
        mount -o subvol=/,$MOUNT_OPTS ${DEVNAME} ${MYWORK}
        [ "${MYDEBUG}" ] && systemd-cat -t mount-sd.custom /bin/echo "mount -o subvol=/,$MOUNT_OPTS ${DEVNAME} ${MYWORK}, rc=$?"
      fi
      # my home mountpoint -- replaces original /home
      if [ "${MYHOME}" ]
      then
        if ! grep "${DEVNAME} /home" /proc/mounts > /dev/null
        then
          mount -o subvol=${MYHOME},$MOUNT_OPTS ${DEVNAME} /home/
          [ "${MYDEBUG}" ] && systemd-cat -t mount-sd.custom /bin/echo "mount -o subvol=${MYHOME},$MOUNT_OPTS ${DEVNAME} /home/, rc=$?"
        fi
      fi
      if [ "${MYNEMO}" ]
      then
        if ! grep "${DEVNAME} /home/${DEVICEUSER}" /proc/mounts > /dev/null
        then
          mount -o subvol=${MYNEMO},$MOUNT_OPTS ${DEVNAME} /home/${DEVICEUSER}/
          [ "${MYDEBUG}" ] && systemd-cat -t mount-sd.custom /bin/echo "mount -o subvol=${MYNEMO},$MOUNT_OPTS ${DEVNAME} /home/${DEVICEUSER}/, rc=$?"
        fi
      fi
      if [ "${MYFOLDERS}" ]
      then
        # mount the defined btrfs subvolumes
        for DD in ${MYFOLDERS}
        do
          if ! grep "/home/${DEVICEUSER}/$DD" /proc/mounts > /dev/null
          then
            mount -o subvol=${MYHOMEFOLDERS}/$DD,$MOUNT_OPTS ${DEVNAME} /home/${DEVICEUSER}/$DD/
            MYRET=$?
            [ "${MYDEBUG}" ] && systemd-cat -t mount-sd.custom /bin/echo "mount -o subvol=${MYHOMEFOLDERS}/$DD,$MOUNT_OPTS ${DEVNAME} /home/${DEVICEUSER}/$DD/, rc=$?"
          fi
        done
      fi
      # my android mountpoint
      if [ "${MYANDROID}" ] 
      then
        if ! grep "${DEVNAME} ${JOANDROID}" /proc/mounts > /dev/null
        then
          mount -o subvol=${MYANDROID},$MOUNT_OPTS ${DEVNAME} ${JOANDROID}/
          [ "${MYDEBUG}" ] && systemd-cat -t mount-sd.custom /bin/echo "mount -o subvol=${MYANDROID},$MOUNT_OPTS ${DEVNAME} ${JOANDROID}/, rc=$?"
        fi
      fi
    ;;
    *)
      systemd-cat -t mount-sd.custom /bin/echo "case '*', TYPE=${TYPE}, nothing to do."
    ;;
  esac
  if [ "${MYDOCS}" ]
  then 
    [ "${MYDEBUG}" ] && [ ! -d "${MYDOCS}" ] && systemd-cat -t mount-sd.custom /bin/echo "su ${DEVICEUSER} -c \"ln -sf ${MYWORK} ${MYDOCS}\""
    [ ! -d ${MYDOCS} ] && su ${DEVICEUSER} -c "ln -sf ${MYWORK} ${MYDOCS}"
  fi
else
  # unmount all
  btrfs fi sync /
  [ "${MYWORK}" ] && btrfs fi sync ${MYWORK}
  count=1
  while umount ${DEVNAME} 2> /dev/null
  do
    test $count -ge 40 && break
  done
fi
systemd-cat -t mount-sd.custom /bin/echo "Finished custom script to ${ACTION} ${DEVNAME} of type ${TYPE}"
The script is for a btrfs sdcard with subvolumes. You have to change the Variables in the script to your requirements. Ask if you can not read the script.

My subvolume structure for understanding the script better, At the moment I am only using ".android" and ".myfolder/Pictures".
Code:
[root@jolla nemo]# btrfs sub list /media/work
ID 256 gen 8582 top level 5 path .android
ID 258 gen 5976 top level 5 path .myfolder
ID 259 gen 6157 top level 5 path .myfolder/Data
ID 260 gen 5544 top level 5 path .myfolder/Desktop
ID 261 gen 5544 top level 5 path .myfolder/Documents
ID 262 gen 5544 top level 5 path .myfolder/Downloads
ID 263 gen 5868 top level 5 path .myfolder/Music
ID 264 gen 8582 top level 5 path .myfolder/Pictures
ID 265 gen 5545 top level 5 path .myfolder/Playlists
ID 266 gen 5545 top level 5 path .myfolder/Public
ID 267 gen 5545 top level 5 path .myfolder/Templates
ID 268 gen 5545 top level 5 path .myfolder/Videos
ID 269 gen 8582 top level 5 path .sdcard
ID 277 gen 1709 top level 5 path .home
copy the script to /usr/sbin/mount-sd.custom.sh as root
Code:
devel-su
cp mount-sd.custom.sh /usr/sbin/mount-sd.custom.sh
chown root:root /usr/sbin/mount-sd.custom.sh
chmod +x /usr/sbin/mount-sd.custom.sh
2. the systemd service
Name: mount-custom.service
Code:
[Unit]
Description=Handle custom sdcard
After=local-fs.target
RequiresMountsFor=/home

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/mount-sd.custom.sh add mmcblk1
ExecStop=/usr/sbin/mount-sd.custom.sh remove mmcblk1

[Install]
WantedBy=multi-user.target
You have to change 'mmcblk1' to 'mmcblk1p1' if you have a partiontable on your sdcard at the lines 'ExecStart' and 'ExecStop'.

copy it to /lib/systemd/system/mount-custom.service as root and activate it.
Code:
devel-su
cp mount-custom.service /lib/systemd/system/mount-custom.service
chown root:root /lib/systemd/system/mount-custom.service
systemctl enable mount-custom.service
Before you restart your phone, you should test your script
Code:
devel-su
mount-sd.custom.sh "add" "mmcblk1"
journalctl | grep mount-sd.custom
You should see something like this
Code:
[root@jolla nemo]# journalctl | grep mount-sd.custom
Mar 21 19:42:52 localhost mount-sd.custom[833]: Called to add mmcblk1
Mar 21 19:42:52 localhost mount-sd.custom[846]: PID=791, ACTION=add, DEVNAME=/dev/mmcblk1
Mar 21 19:42:53 localhost mount-sd.custom[847]: case btrfs, TYPE=btrfs, implemented - start working.
Mar 21 19:42:53 localhost mount-sd.custom[867]: mount -o subvol=/,dirsync,noatime,users /dev/mmcblk1 /media/work, rc=0
Mar 21 19:42:53 localhost mount-sd.custom[878]: mount -o subvol=.myfolder/Pictures,dirsync,noatime,users /dev/mmcblk1 /home/nemo/Pictures/, rc=0
Mar 21 19:42:53 localhost mount-sd.custom[897]: mount -o subvol=.android,dirsync,noatime,users /dev/mmcblk1 /data/sdcard/, rc=0
Mar 21 19:42:53 localhost mount-sd.custom[901]: Finished custom script to add /dev/mmcblk1 of type btrfs
[root@jolla nemo]#

Be careful and sucessful


PS: my ambiences of pictures from the Picture folder are persistent, since I use that service. Thats all I have tested until now.

Last edited by meemorph; 2014-03-21 at 19:09.
 

The Following 2 Users Say Thank You to meemorph For This Useful Post: