Dear all,
I would like to share with you my solved issue with ksmbd and automount procedure.
in /etc/hotplug.d/block/
I have two files 10-mount and 60-ksmbd
10-mount content
#!/bin/sh
blkdev=`dirname $DEVPATH`
device=`basename $DEVPATH`
hdorsd=`echo "$device" | grep -E '[sh]d*|mmcblk0*' `
logger "+++++++blkdev: $blkdev -device: $device -hdorsd: $hdorsd"
sleep 3
[ -n "$hdorsd" ] && {
case "$ACTION" in
add)
s=`/usr/sbin/blkid /dev/$device|sed -n 's/.* TYPE="\([^"]*\)".*/\1/p'`
label=`/usr/sbin/blkid -d /dev/$device|sed -n 's/.*LABEL="\([^"]*\)".*/\1/p'`
#logger "+++Label: $label -Filesystem: $s"
[ -z "$label" -o "$s" = "vfat" ] && label=$device
if [ "$s" != 'f2fs' -a "$s" != 'vfat' -a "$s" != 'ntfs' -a "$s" != 'ext2' -a "$s" != "ext3" -a "$s" != "ext4" -a "$s" != "exfat" ];then
return;
fi
mkdir -p "/mnt/$label"
#logger -t hotplug "+++ New folder in /mnt/ $label"
if [ "$s" = 'vfat' -o "$s" = 'exfat' ];then
mount -t $s -o utf8,rw,async,noatime,fmask=0000,dmask=0000 /dev/$device "/mnt/$label"
fi
if [ "$s" = 'ntfs' ];then
mount -t ntfs-3g -o utf8 /dev/$device "/mnt/$label"
fi
if [ "$s" = 'ext2' -o "$s" = 'ext3' -o "$s" = 'ext4' ];then
mount -t ext4 -o rw,async,noatime /dev/$device "/mnt/$label"
chmod 777 -R "/mnt/$label"
chown root:root "/mnt/$label"
fi
if [ "$s" = 'f2fs' ];then
mount -t f2fs -o rw,async,noatime /dev/$device "/mnt/$label"
chmod -R 777 "/mnt/$label"
chown root:root "/mnt/$label"
#logger -t hotplug "Should be an f2fs filesystem"
fi
logger -t hotplug "+++ mounted filesystem: $s -label: $label"
;;
remove)
folder="$(grep /dev/$device /etc/mtab |awk '{print $2}')"
umount "$folder"
rmdir "$folder"
logger -t hotplug "+++ Removed: ${folder}"
;;
esac
}
This file with blkid automount the device.
and this is 60-ksmbd
#!/bin/sh
blkdev=`dirname $DEVPATH`
device=`basename $DEVPATH`
hdorsd=`echo "$device" | grep -E '[sh]d*|mmcblk0*' `
label=`/usr/sbin/blkid -d /dev/$device|sed -n 's/.*LABEL="\([^"]*\)".*/\1/p'`
filesys=`/usr/sbin/blkid /dev/$device|sed -n 's/.* TYPE="\([^"]*\)".*/\1/p'`
mmc_share_exist=0
mylabel="volume(sda1)"
#logger "+++1-$blkdev 2-$device 3-$hdorsd 4-$label 5-$filesys"
#vfat use ANSI label name
[ -z "$label" -o "$filesys" = "vfat" ] && label=$device
[ -n "$hdorsd" ] && {
case "$ACTION" in
add)
[ -z "$filesys" -o "$filesys" = "swap" ] && exit 0 #must have file system and not swap
[ "$label" = "rootfs" -o "$label" = "rootfs_data" ] && exit 0 #s1300 emmc rootfs and rootfs_data not setup as samba share
#first loop the shares. If there is any duplicated entry, delte it first.
i=$(uci show ksmbd|awk 'NF{p=$0}END{print p}'|sed -e "s/^.*\[\\(.*\)\].*$/\1/")
while [ "$i" -ge 0 ]
do
sharepath=$(uci get ksmbd.@share[$i].path)
[ "$sharepath" = "/mnt/$label" ] && {
uci delete ksmbd.@share[$i]
}
[ "$sharepath" = "/data" ] && mmc_share_exist=1
i=$(( i-1 ))
done
mmcblk0=`echo "$device" |grep 'mmcblk0'`
[ -n "$mmcblk0" -a "$mmc_share_exist" = "1" ] && exit 0
uci add ksmbd share
if [ -n "$mmcblk0" ]; then
uci set ksmbd.@share[-1].name="data"
uci set ksmbd.@share[-1].path="/data"
else
uci set ksmbd.@share[-1].path="/mnt/$label"
uci set ksmbd.@share[-1].name="$mylabel"
fi
uci set ksmbd.@share[-1].read_only=no
uci set ksmbd.@share[-1].guest_ok=yes
uci set ksmbd.@share[-1].create_mask=0777
uci set ksmbd.@share[-1].dir_mask=0777
uci set ksmbd.@share[-1].inherit_owner=yes
uci set ksmbd.@share[-1].force_root=1
uci commit ksmbd
/etc/init.d/ksmbd restart
logger -t hotplug "+++New share available: ${label}"
;;
remove)
i=$(uci show ksmbd|awk 'NF{p=$0}END{print p}'|sed -e "s/^.*\[\\(.*\)\].*$/\1/")
while [ "$i" -ge 0 ]
do
sharepath=$(uci get ksmbd.@share[$i].path)
d=$(uci get ksmbd.@share[$i].name)
if [ ! -e "$sharepath" -o "$d" = "$label" ]
then
uci delete ksmbd.@share[$i]
logger -t hotplug "+++Removed share: ${label}"
fi
i=$((i-1))
done
uci commit ksmbd
/etc/init.d/ksmbd restart
;;
esac
}
This file create a share...
This procedure works perfectly if it is an hotplug, but on boot or restart with flashdisk connected ksmd won't start.
So, if I run
netstat -an | grep 445
I don't see the service active.
To solve the issue on startup I run this script to restart the ksmbd service in case I need it...
#!/bin/sh
sleep 7 #just to be sure....
var=`netstat -an | grep 445 | grep tcp`
if [ -z "$var" ]
then
/etc/init.d/ksmbd restart
logger "+++++++ restarted service not active ++++++"
else
logger "+++++ ksmb is running ++++++"
fi
exit 0
I hope that this can help someone else... or if I do something wrong, suggestion are welcome...
THANKS!!!
EDIT: Solved by add an user on ksmbd