Install ksmbd-tools from source:
apt install -y git gcc pkgconf autoconf automake libtool make meson ninja-build gawk libnl-3-dev libnl-genl-3-dev libglib2.0-dev # debian
dnf install -y git gcc pkgconf autoconf automake libtool make meson ninja-build gawk libnl3-devel glib2-devel # fedora
git clone https://github.com/cifsd-team/ksmbd-tools.git
cd ksmbd-tools
./autogen.sh
./configure --with-rundir=/run # --prefix=/usr/local/sbin --sysconfdir=/usr/local/etc
make -j`nproc`
make install -j`nproc`create smb user:
# We are testing in a virtual machine, so we just use the root user.
sudo ksmbd.adduser --add rootThen create config file
/usr/local/etc/ksmbd/ksmbd.conf:
[global]
writeable = yes
public = yes
[test]
comment = test dir
; Note: there should not be a space after the path.
path = /tmp/s_testStart ksmbd:
mkdir /tmp/s_test
systemctl stop smbd.service # stop samba on debian
systemctl stop smb.service # stop samba on fedora
chmod 777 /tmp/s_test # just for test
systemctl restart ksmbdInstall samba from source:
git clone https://gitlab.com/samba-team/devel/samba.git
cd samba/bootstrap/generated-dists/fedora41/ # You can replace fedora41 with your own distribution
./bootstrap.sh # It may take some time to install the dependencies
cd ../../../
./configure --with-systemd --with-libunwind
make -j`nproc`
make install -j`nproc`
export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATHWhen you only want to build and install smbd and
smbclient:
make -j`nproc` bin/smbd && rm -rf /usr/local/samba/sbin/smbd; cp bin/smbd /usr/local/samba/sbin/smbd
make -j`nproc` bin/smbclient && rm -rf /usr/local/samba/bin/smbclient; cp bin/smbclient /usr/local/samba/bin/smbclientCopy smb.service:
cp ./bin/default/packaging/systemd/smb.service /usr/lib/systemd/system/smb.serviceCreate config file /usr/local/samba/etc/smb.conf:
[test]
comment = test dir
path = /tmp/s_test
public = yes
read only = no
writeable = yesCreate smb user:
# We are testing in a virtual machine, so we just use the root user.
pdbedit -a -u rootStart samba:
# stop the ksmbd service before starting samba
systemctl stop ksmbd.service
mkdir /tmp/s_test
chmod 777 /tmp/s_test # just for test
systemctl restart smbd.service # debian
systemctl restart smb.service # fedoraPlease refer to Questions about SMB2 CHANGE_NOTIFY.
smbclientUse smbclient to connect to SMB server:
# smbclient //${server_ip}/share -U USERNAME%PASSWORD
smbclient //192.168.53.210/test -U root%1Query change notifications of root directory.
smb: \> notify /
smb: \> notify \Query change notifications of dir/:
smb: \> notify dir
smb: \> notify /dir
smb: \> notify ./dirOr you can enter dir/, and then query change
notifications:
smb: \> cd dir
smb: \dir\> notify /smbinfoIt is part of cifs-utils.
dnf install libtalloc-devel -y
git clone https://git.samba.org/cifs-utils.git
autoreconf -i
./configure
make -j`nproc`
# make installIt is unrelated to Samba or cifs.ko.
git clone https://github.com/sahlberg/libsmb2.gitPlease refer to the following two patches:
d26c2ddd3356 cifs: add SMB3 change notification support
e3e9463414f6 smb3: improve SMB3 change notification supportBuild and run new-inotify-ioctl-test.c
(LKML):
gcc -o new-inotify-ioctl-test new-inotify-ioctl-test.c
./new-inotify-ioctl-test /mnt
./new-inotify-ioctl-test /mnt/dir10.42.20.210 is the IP address of the SMB server.
Enter the following path in “File Explorer”:
# Windows is case-insensitive, so you can use either "TEST" or "test"
\\10.42.20.210\testWhen switching between samba and ksmbd, Windows may fail to mount. In that case, open PowerShell on Windows and run the following commands:
# View existing connections
net use
# Delete a specific connection
net use \\10.42.20.210\IPC$ /delete
net use \\10.42.20.210\test /delete
# Delete all connections (not recommended)
net use * /deleteThe full capture file can be found on GitHub (or on gitee).
Windows “File Explorer” enter root directory of smb server:
20:17:17.201 Notify Request No.123 [Response in: 271]20:17:17.202 Notify Response, Error: STATUS_PENDING No.124 [Response to: 123 270]Windows “File Explorer” enter dir/:
20:17:29.666 Create Request;Notify Request No.23920:17:29.668 Notify Response, Error: STATUS_PENDING No.244 [Response to: 239]20:17:29.760 Cancel Request No.270 [Response in: 271]20:17:29.760 Notify Response, Error: STATUS_CANCELLED No.271 [Response to: 123 270],
the samba server stops notifying Windows of changes to root directory of
smb serverSamba server executes touch dir/file1:
20:17:54.095 Notify Response No.285 [Response to: 239]