You are not logged in.

#1 2014-11-03 04:05:23

Alethos
Member
Registered: 2006-01-05
Posts: 84

Greyhole Locally Mounted Shares

Could I get some help mounting the greyhole shares locally please?
Guillaume has a script for Deb & Fedora, but I've no clue how to translate that for Arch.

Here's Deb/Ubuntu

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          mount_shares_locally
# Required-Start:    $network $local_fs $remote_fs samba
# Required-Stop:     $network $local_fs $remote_fs samba
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mount Samba shares locally
### END INIT INFO

username="your username"

if [ -f /lib/lsb/init-functions ]; then
        . /lib/lsb/init-functions
fi

LOCKFILE=/var/lock/mount_shares_locally

lock_mount_shares_locally() {
        if [ -x /usr/bin/lockfile-create ]; then
                lockfile-create $LOCKFILE
                lockfile-touch $LOCKFILE &
        fi
}

unlock_mount_shares_locally() {        if [ -x /usr/bin/lockfile-create ] ; then
                lockfile-remove $LOCKFILE
        fi
}

start () {
        uid=`id -u $username`
        gid=`id -g $username`

        log_daemon_msg "Mounting Samba shares locally..."
        if [ ! -x /mnt/samba/ ]; then
                mkdir -p /mnt/samba/
        fi
        cd /mnt/samba/
        lock_mount_shares_locally
        testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p
        sleep 5
	opt="credentials=/home/${username}/.smb_credentials,uid=${uid},gid=${gid},file_mode=0660,dir_mode=0770,nobrl,hard,_netdev,iocharset=utf8,noserverino,mfsymlinks"
	supports_vers_opt=`/usr/bin/man mount.cifs | grep vers= | wc -l`
	if [ "$supports_vers_opt" != "0" ]; then
		opt="$opt,vers=3.0"
	fi
        ls -1 | while read d; do
                if [ "`mount | grep "//127.0.0.1/$d/* on " | wc -l`" = "0" ]; then
                        /sbin/mount.cifs "//127.0.0.1/$d" "$d" -o $opt
                else
                        echo "  Share [$d] is already mounted."
                fi
        done
        unlock_mount_shares_locally
        log_end_msg
        return 0
}

stop () {
        log_daemon_msg "Unmounting locally mounted Samba shares..."
        /bin/umount -l /mnt/samba/*
        log_end_msg
        return 0
}

case "$1" in
        start) 
                start
                ;;
        stop)  
                stop
                ;;
        restart)
                $0 stop && sleep 2 && $0 start
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                exit 2
                ;;
esac

..and here's Fedora/CentOS

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          mount_shares_locally
# Required-Start:    $network $local_fs $remote_fs smb mysqld
# Required-Stop:     $network $local_fs $remote_fs smb
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mount Samba shares locally
### END INIT INFO

username="your username"

if [ -f /etc/rc.d/init.d/functions ]; then
	. /etc/rc.d/init.d/functions
fi

start () {
	uid=`id -u $username`
	gid=`id -g $username`

	echo -n $"Mounting Samba shares locally: "
	mkdir -p /mnt/samba/
	cd /mnt/samba/
	testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p
	sleep 5
	opt="credentials=/home/${username}/.smb_credentials,uid=${uid},gid=${gid},file_mode=0660,dir_mode=0770,nobrl,hard,_netdev,iocharset=utf8,noserverino,mfsymlinks"
	supports_vers_opt=`/usr/bin/man mount.cifs | grep vers= | wc -l`
	if [ "$supports_vers_opt" != "0" ]; then
		opt="$opt,vers=3.0"
	fi
	ls -1 | while read d; do
                if [ "`mount | grep "//127.0.0.1/$d/* on " | wc -l`" = "0" ]; then
                        /sbin/mount.cifs "//127.0.0.1/$d" "$d" -o $opt
                else
                        echo "  Share [$d] is already mounted."
                fi
	done
	touch /var/lock/subsys/mount_shares_locally
	success $"$base startup"
	echo
	return 0
}

stop () {
	echo -n $"Unmounting locally mounted Samba shares: "
	/bin/umount -l /mnt/samba/*
	rm -f /var/lock/subsys/mount_shares_locally
	success $"$base shutdown"
	echo
	return 0
}

restart () {
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	*)
		echo $"Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac

exit $?

I tried simply using /etc/fstab to mount the shares (run of the mill cifs mount line for fstab), and while in the environment a "mount -a" does indeed work fine, but as I suspected, upon startup and or shutdown things get messed up (due to the order of operations, I'm pretty certain).

Anyone up for figuring this out? A group of media shares does me no good if Plex can't see them. smile

Last edited by Alethos (2014-11-03 04:12:04)

Offline

#2 2020-06-13 13:59:16

cerberusec
Member
Registered: 2020-01-16
Posts: 2

Re: Greyhole Locally Mounted Shares

Super old necro-post, I know. Just wanted to shed some light on this as I just encountered this issue myself.

The mount_shares_locally script parses smb.conf for samba shares and then mounts them via mount.cifs. This can easily be done in fstab using x-systemd.requires=greyhole.service, which in turn requires smb.service. For example:

# mount the greyhole drives
/dev/hdd0 /mnt/hdd0 ntfs-3g defaults 0 0
/dev/hdd1 /mnt/hdd1 ntfs-3g defaults 0 0
# note TestShare is the landing zone on /mnt/hdd0/shares/TestShare in this case, as defined in smb.conf

# mount locally
//127.0.0.1/TestShare /mnt/samba/TestShare cifs x-systemd.automount,x-systemd.requires=greyhole.service,credentials=/home/<user>/.smb_credentials,file_mode=0777,dir_mode=0777 0 0

Last edited by cerberusec (2020-06-13 14:01:04)

Offline

Board footer

Powered by FluxBB