Reply
Thread Tools
Posts: 594 | Thanked: 1,094 times | Joined on Aug 2012 @ Rhine
#1
As the title says: i want to make an own script that's called on every boot (and shutdown), just like mount-sd.sh.

Why not modify mount-sd.sh?
  • it's called too late during boot
  • it will be overwritten by system updates

i was using it, see here: http://talk.maemo.org/showthread.php?t=92449, but since the update to 1.0.4 this does not work very well anymore, since there were a lot of changes: https://github.com/nemomobile/sd-utils/commits/master

How do i make my own script, called before the "ambiance-stuff" is executed?

edit: must be executed as root

Last edited by Leinad; 2014-03-19 at 10:11.
 
Posts: 144 | Thanked: 242 times | Joined on Nov 2007 @ Finland
#2
what is this ambiance stuff exactly?

Check /etc/systemd/system/mount-sd@.service
You can create own systemd configuration for your script and you can also bind the execution order of your service.
 

The Following 2 Users Say Thank You to Penguin For This Useful Post:
Guest | Posts: n/a | Thanked: 0 times | Joined on
#3
 

The Following 2 Users Say Thank You to For This Useful Post:
Posts: 24 | Thanked: 7 times | Joined on Nov 2011
#4
Discovering systemd... I made a graph of the systemd settings, but I don't know how to interpret it yet...

Commands are :

systemctl --order dot > sysgraph.dot

then (after transfering the file on my Ubuntu pc):

cat sysgraph.dot | dot -Tsvg > sysgraph.svg

Result can be found here: http://ubuntuone.com/7jnlRCzUhnMtOgYqjSc72m
 

The Following 3 Users Say Thank You to alci For This Useful 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:
Posts: 24 | Thanked: 7 times | Joined on Nov 2011
#6
I big thank you for this, works like a charm.

I made it even simplier as I just want my home be mounted on my sdcard, and I know it is here.

[nemo@localhost ~]$ cat /usr/sbin/mount-sd-home.sh
#!/bin/bash
ACTION=$1
if [ "$ACTION" = "add" ]; then
if [ $(mount | grep -c /mnt/sdhome) != 1 ]; then
mount -o noatime,rw,autodefrag /dev/mmcblk1p1 /mnt/sdhome
mount -o bind /mnt/sdhome/.home /home/nemo
mount -o bind /mnt/sdhome/.android /data/sdcard
fi
else
umount /data/sdcard
umount /home/nemo
umount /mnt/sdhome
fi

[nemo@localhost ~]$ cat /lib/systemd/system/mount-sd-home.service
[Unit]
Description=Handle home on sdcard
After=local-fs.target
RequiresMountsFor=/home

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

[Install]
WantedBy=multi-user.target

Everything seems to work:
- ambiences
- new pictures and videos that I take are here and browsable
- settings are persited between reboots


A question, how did you pick the dependecies ?
(After=local-fs.target
RequiresMountsFor=/home)

Is there a doc somewhere I could look at to understand the boot process ?

Regards,
Franck
 

The Following 2 Users Say Thank You to alci For This Useful Post:
Posts: 204 | Thanked: 443 times | Joined on Jul 2012 @ Germany - Potsdam
#7
Originally Posted by alci View Post
I big thank you for this, works like a charm.

I made it even simplier as I just want my home be mounted on my sdcard, and I know it is here.
...
Is there a doc somewhere I could look at to understand the boot process ?
...
I am happy it helps you.

Look #3 from nieldk -- I read a lot first.
Originally Posted by nieldk View Post
for more info, look at http://www.freedesktop.org/wiki/Software/systemd/
Systemd handels a parallel boot process with the directives.
http://www.freedesktop.org/software/...irectives.html
https://fedoraproject.org/wiki/Systemd

Yours is much easier for your needs. Mine is programmed to be flexible and for debugging. With this setting of variables it does, what yours do if you are using btrfs filesystem with subvolums ;-) :
Code:
#MYDEBUG=""
MYWORK="/mnt/sdhome"
#MYDOCS=""
#MYHOME=""
MYNEMO=".home"
#MYFOLDERS=""
#MYHOMEFOLDERS=""
MYANDROID=".android"
JOANDROID="/data/sdcard"
But its a system startup script. I think it will be deleted at next release update. The question is, how to make from this point a script (may be user script) that is release persistent.
 

The Following User Says Thank You to meemorph For This Useful Post:
Posts: 144 | Thanked: 242 times | Joined on Nov 2007 @ Finland
#8
It won't be deleted when you don't modify system files and you do not put your files into any application or account specific directory. By modifying existing system files you can guarantee it will be wiped sooner or later in system update.
__________________
Copy offers 20 GB free cloud storage
Register via this link -> confirm your email address -> install Copy client (Linux, OS X, Windows, iOS or Android) and you'll get 20 GB storage space in cloud.
 

The Following 2 Users Say Thank You to Penguin For This Useful Post:
Posts: 5 | Thanked: 1 time | Joined on Mar 2014
#9
I have tried to get similar system that alci has to work. I have checked that the script is working, but when I boot the device I get this:

[root@localhost nemo]# journalctl | grep mount-sd-home.sh
Mar 24 14:13:36 localhost mount-sd-home.sh[789]: mount: wrong fs type, bad option, bad superblock on /dev/mmcblk1p1,
Mar 24 14:13:36 localhost mount-sd-home.sh[789]: missing codepage or helper program, or other error
Mar 24 14:13:36 localhost mount-sd-home.sh[789]: In some cases useful info is found in syslog - try
Mar 24 14:13:36 localhost mount-sd-home.sh[789]: dmesg | tail or so
Mar 24 14:13:36 localhost mount-sd-home.sh[789]: mount: special device /mnt/sdhome/.home does not exist
Mar 24 14:13:36 localhost mount-sd-home.sh[789]: mount: special device /mnt/sdhome/.android does not exist

However if I use the script

/usr/sbin/mount-sd-home.sh add

It mounts nicely:

/dev/mmcblk1p1 60G 9,3G 48G 17% /media/sdcard/2f36d7c2-46bf-4c14-b8cc-2defaad1b529
/dev/mmcblk1p1 60G 9,3G 48G 17% /mnt/sdhome
/dev/mmcblk1p1 60G 9,3G 48G 17% /home/nemo
/dev/mmcblk1p1 60G 9,3G 48G 17% /data/sdcard


If I mount the sd card with the script, I am also still not able to see the pictures in my gallery after I take them. I can see them with file browser however and even open them in gallery from file browser.
 
Posts: 204 | Thanked: 443 times | Joined on Jul 2012 @ Germany - Potsdam
#10
@hopey
What filesystem are you using? May be a driver module is missing, it should be added to the dependencies of the service. I am using btrfs like SailfishOS.

If you mount it manually with the script, its to late for the tracker. You can do a
Code:
tracker-control -es
and wait a few minutes. But its only a workaround for pictures and music, not for ambiences.
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:17.