|
|
2014-03-19
, 18:03
|
|
Posts: 144 |
Thanked: 242 times |
Joined on Nov 2007
@ Finland
|
#2
|
|
|
2014-03-19
, 18:55
|
|
Guest |
Posts: n/a |
Thanked: 0 times |
Joined on
|
#3
|
|
|
2014-03-21
, 09:57
|
|
Posts: 24 |
Thanked: 7 times |
Joined on Nov 2011
|
#4
|
| The Following 3 Users Say Thank You to alci For This Useful Post: | ||
|
|
2014-03-21
, 19:04
|
|
Posts: 202 |
Thanked: 440 times |
Joined on Jul 2012
@ Germany - Potsdam
|
#5
|
#!/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}"
[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
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
[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
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
devel-su mount-sd.custom.sh "add" "mmcblk1" journalctl | grep mount-sd.custom
[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]#
|
|
2014-03-23
, 17:53
|
|
Posts: 24 |
Thanked: 7 times |
Joined on Nov 2011
|
#6
|
|
|
2014-03-23
, 19:39
|
|
Posts: 202 |
Thanked: 440 times |
Joined on Jul 2012
@ Germany - Potsdam
|
#7
|
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 ?
...
for more info, look at http://www.freedesktop.org/wiki/Software/systemd/
#MYDEBUG="" MYWORK="/mnt/sdhome" #MYDOCS="" #MYHOME="" MYNEMO=".home" #MYFOLDERS="" #MYHOMEFOLDERS="" MYANDROID=".android" JOANDROID="/data/sdcard"
| The Following User Says Thank You to meemorph For This Useful Post: | ||
|
|
2014-03-23
, 21:36
|
|
Posts: 144 |
Thanked: 242 times |
Joined on Nov 2007
@ Finland
|
#8
|
|
|
2014-03-24
, 12:23
|
|
Posts: 5 |
Thanked: 1 time |
Joined on Mar 2014
|
#9
|
|
|
2014-03-24
, 14:47
|
|
Posts: 202 |
Thanked: 440 times |
Joined on Jul 2012
@ Germany - Potsdam
|
#10
|
tracker-control -es
Why not modify mount-sd.sh?
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.