Ksmbd (Samba3/4 alternative, ex cifsd/smbd) package support thread

Hello! Can I somehow get the logging level - debugging in ksmbd? My device is tp-link tl-wr1043nd v2. A USB docking station with a 1 TB disk is connected to it. One partition and file system - ext4. When I start copying a 300 MB file from Windows 10, the copy speed is 5 MBps. At the same time, the TP-link has a CPU load of 100%, the LuCi falls off, it stops responding to ping. Further, copying is interrupted, since the USB device is lost. I have to reboot my router. Can this device work with ksmbd? Is it possible to limit the CPU utilization by the samba service?

Should work, but how the physical USB port is implemented varies by device/vendor. So we always need actual speedtests to verify the possible speed of a specific device.

If you use ksmbd than you cant lower the process priority, since its a in-kernel module. If you use samba4 than the "smbd" server process can be lowered via this config setting in /etc/config/samba4:

config procd 'extra'
	option samba_nice '3'

PS: If your device has >64 MB ram you could also setup a test share on /tmp, which is in ram and use a appropriate sized, compressed testfile to check max. speeds. If its slow on /tmp than it wont go any faster on a actual disk/ssd. Lastly you can try samba4 instead of ksmbd if it fits on your device flash, just to exhaust all options. If samba4 and ksmbd is similarly slow on a ext4 share or /tmp than your device might have a bad usb port implementation or the CPU is just too slow.

1 Like

I have 64 MB RAM. I did some experiments:

  1. Copied the 1.5 GB file from USB to USB. Speed 15 MBps, CPU load 40%, copied without problems.
  2. Copied via scp over the network to USB - the speed is 2 MBps, the CPU load is 100%, but the router does not hang. The file was not copied. At the end of copying, the error is read-only file system.
    I conclude that the bottleneck is between the network and the USB. Hardly anything will help. samba4 did not fit into my flash :slight_smile: Thank you all for your help ...

decryption needs much cpu

scp encrypts the traffic. Can't do anything about it.

Hello, I have two questions.

Q1. Which config files are modified by a ksmbd installation in LuCI per this answer you gave me:

A tutorial on a ksmbd setup? - #2 by Andy2244

Knowing which configs would let me study what a LuCI install does to them so that, for my next ksmbd install, I could use the configs directly. Therefore, a source on "how to configure for ksmbd" would answer just as well.

Q2. You say that one of the advantages of ksmbd is the tiny size:

How much space saved does that represent? I guess this amounts to asking what a typical Samba install costs in space?

Please let me know if any of this should be a separate post. Sorry if it repeats anything on this page. Thanks.

The openwrt config is in /etc/config/ksmbd and a example file is in /etc/ksmbd. This config is used to generate the final /etc/ksmbd/smb.conf, which is done by combining the openwrt ksmbd config file, with the default smb.conf.template.

Samba4 is around 7 MB, so devices with 8MB nvram can't fit samba4 so ksmbd is the only alternative, outside of using a extroot to increase the space.

hi, i don't think if my problem is KSMBD or wireguard

if me use lan interface, i have no problem for access to usb key plugged on my router by windows or android

but if me use wireguard interface ( vpn ) i don't accès to the storage.

i don't think is my problem is ksmbd conf or adguard.

i attach config :

[global]
	netbios name = |NAME|
	server string = |DESCRIPTION|
	workgroup = |WORKGROUP|
	interfaces = |INTERFACES|
	bind interfaces only = yes
	ipc timeout = 20
	deadtime = 15
	map to guest = Bad User
#	smb2 max read = 64K
#	smb2 max write = 64K
#	smb2 max trans = 64K
#	cache read buffers = no
#	cache trans buffers = no

after i have many other question for ksmbd but ask later.

Hello, I have installed packages ksmbd-server, ksmbd-utils, and luci-app-ksmbd to my router TP-Link C7 v5 running on the latest sysupgrade bin (release 19.07.8).

On LuCI's Services, Network Shares, I set up a shared directory called 'dump', checked off guest, put 'root' for allowed user.

When I try to access the share from Windows, I am prompted for credentials. I use 'root' for user name and root's password for password, but am denied access.

If I check guest login (in LuCI), then when I try from Windows I am allowed in, but without write access even if I set the masks at 0000 (or 0777, for that matter, which I also tried just in case I misunderstood how a mask works in this context).

What I would like ultimately is to be able to log in as a named and allowed user (not guest) having all permissions. How can I do this?

The picture shows the exact setup. The /mnt/dump directory has nothing mounted in it (no USB storage). So far it is just an empty directory. Thanks.

By the way if I repeat the experiment with a directory to which something is mounted (for me, that would be /mnt/usb, where I have a USB storage mounted), the result is the same as above. I used /mnt/dump to eliminate any complication that may arise from the node's having something mounted in it.

is it not just a routing issue ?

i have try to bridge br-lan and wg0 but not working

i not tested reboot interface lan after ( juste reboot wg0 )
i'm test later because my darling use netflix :confused:

try this post :

not sur because i'm noob user but :

[skittlesshare]
	path = /mnt/usb1/shareroot
	force user = root
	force group = root
	create mask = 0666
	directory mask = 0777
	read only = no
	guest ok = yes
	hide dot files = no

this user use "force user and groupe" maybe .... but not sur

Thanks. I tried what you quoted (except as conformed to my config file's format, which looks like option path '/mnt/dump') but did not work. Adding the force user and force group lines also had the curious effect of wiping out LuCI's ksmbd page. Deleting those lines restored the page contents.

i have try

and allow ip 10.0.0.1 on peer, after reboot, don't work again

oh sorry ( i'm new user :confused: )

look the video : https://youtu.be/u_ReoGE4Jb8?t=1670

maybe other members more pro of me have solution for you

whoo... adding a bridge between WG and LAN may be very risky !
You'll have IP crash because they have both IP in different subnets !!!
Do not do that...

hi, I am migrated from samba4 to ksmbd on release version 21.02(Ksmbd: 3.3.9 Kmod: 3.3.9).
and got the spam in kernel log, when open any file

[32338.689393] ksmbd: ndr_decode_dos_attr:181: v107 version is not supported
.
.
.
[32891.243266] ksmbd: ndr_decode_dos_attr:181: v114 version is not supported

code tests for version 3 or 4. Sounds like some bug.

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

@danitool sleep doesn't work for me, stop_service however works and seems like a good solution, since internally it calls kill_server if needed, then performs cleanup. I'll try to make a PR.

# net/ksmbd-tools/files/ksmbd.init
-- kill_server
++ [ -e /sys/module/ksmbd ] && stop_service