I, like others, noticed that my 3006 firmware router was pegging the CPU at 100% when I enabled Samba in the GUI (version 3.6.25). I was using built-in Samba on my RT-AX86U running Merlin 3004.388.9_2 just fine. I had even figured out how to make Time Machine backups work.
The CPU issue made me decide to revisit my attempts to get Samba 4 running on my router.
I am now stable for several days and decided to write a tutorial for everyone (and myself if I have to repeat this).
Install Entware Samba 4 Packages:
Create Samba Users in Entware:
It'll prompt for the passwords after each command.
Update/create /opt/etc/samba/smb.conf:
Modify /opt/etc/init.d/S91smb so that smbd is replaced with /opt/sbin/smbd. Do the same thing for nmbd or comment it out if you want to disable NETBIOS (what I did).
Now we need to ensure that it doesn't automatically get killed whenever you reboot your router. I tried a lot of things, but this seemed to do the trick:
1. Create /jffs/scripts/custom-start-smb.sh:
2. Add this to /jffs/scripts/service-event:
3. Add this to /jffs/scripts/post-mount:
4. Create our cron job:
Now you can reboot (my preference) or just run
I'll make a separate post about avahi later. I'm still working out the kinks on that.
The CPU issue made me decide to revisit my attempts to get Samba 4 running on my router.
I am now stable for several days and decided to write a tutorial for everyone (and myself if I have to repeat this).
Install Entware Samba 4 Packages:
Bash:
# Ensure Entware is up to date
opkg update
# Install Samba 4 and its utilities
opkg install samba4-server samba4-utils
Create Samba Users in Entware:
Bash:
/opt/bin/smbpasswd -a User1
/opt/bin/smbpasswd -a User2
/opt/bin/smbpasswd -a Router_Admin_Name
Update/create /opt/etc/samba/smb.conf:
Bash:
[global]
## Identity and basic settings
netbios name = RT-AX86U_PRO-82
server string = RT-AX86U_Pro Samba4
workgroup = WORKGROUP
## Security
security = user
passdb backend = smbpasswd
smb passwd file = /opt/etc/samba/smbpasswd
map to guest = Bad User
guest ok = no
## Networking
bind interfaces only = yes
interfaces = br0
## Character sets
unix charset = UTF8
## Performance / behavior
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE
load printers = no
disable spoolss = yes
printing = bsd
deadtime = 30
## Protocol versions
min protocol = SMB2
max protocol = SMB3
smb encrypt = desired
## File and directory permissions
create mask = 0777
directory mask = 0777
# -------------------------------------------------------------------
# Turn off legacy NetBIOS altogether (no UDP/137,138 traffic)
# We only use SMB2/3 over TCP (port 445) on macOS & Win11
# -------------------------------------------------------------------
disable netbios = yes
name resolve order = host
## macOS compatibility (Time Machine, resource forks)
strict allocate = yes
vfs objects = catia fruit streams_xattr
fruit:metadata = stream
fruit:zero_file_id = yes
fruit:model = MacSamba
fruit:nfs_aces = no
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_ad_files = yes
## Logging
log level = 1
logging = syslog
###############################################################################
# Your Shares
###############################################################################
[TimeMachine]
comment = TimeMachine
path = /tmp/mnt/TimeMachine
valid users = User1, User2
read list = User1, User2
write list = User1, User2
browseable = yes
writable = yes
read only = no
create mask = 0700
directory mask = 0700
fruit:model = TimeCapsule
fruit:time machine = yes
[Shared]
comment = Shared Data
path = /tmp/mnt/Data/Shared
valid users = User1, User2
read list = User1, User2
write list = User1, User2
browseable = yes
writable = yes
[User2]
comment = User2 Data
path = /tmp/mnt/Data/User2
valid users = User2
read list = User2
write list = User2
browseable = yes
writable = yes
create mask = 0700
directory mask = 0700
[User1]
comment = User1 Data
path = /tmp/mnt/Data/User1
valid users = User1
read list = User1
write list = User1
browseable = yes
writable = yes
create mask = 0700
directory mask = 0700
Modify /opt/etc/init.d/S91smb so that smbd is replaced with /opt/sbin/smbd. Do the same thing for nmbd or comment it out if you want to disable NETBIOS (what I did).
Bash:
#!/bin/sh
[ -f /opt/etc/samba/smb.conf ] || exit 0
mkdir -p /opt/var/log/samba
mkdir -p /opt/var/lib/samba/private
mkdir -p /opt/var/cache/samba
mkdir -p /opt/var/run/samba/ncalrpc
start() {
echo "Starting SMB services: "
/opt/sbin/smbd -D
[ $? = 0 ] && echo "OK" || echo "FAIL"
# echo "Starting NMB services: "
# /opt/sbin/nmbd -D
# [ $? = 0 ] && echo "OK" || echo "FAIL"
}
stop() {
echo "Shutting down SMB services: "
kill -9 `pidof smbd`
[ $? = 0 ] && echo "OK" || echo "FAIL"
# echo "Shutting down NMB services: "
# kill -9 `pidof nmbd`
# [ $? = 0 ] && echo "OK" || echo "FAIL"
}
restart() {
stop
start
}
reload() {
echo "Reloading smb.conf file: "
kill -HUP `pidof smbd`
[ $? = 0 ] && echo "OK" || echo "FAIL"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit $?
Now we need to ensure that it doesn't automatically get killed whenever you reboot your router. I tried a lot of things, but this seemed to do the trick:
1. Create /jffs/scripts/custom-start-smb.sh:
Bash:
#!/bin/sh#
# only start my services if they’re not already running
# 1) Bail out if Core-Files/Entware isn’t mounted yet
[ -x /opt/bin/opkg ] || exit 0
MARKER=/jffs/configs/.smb_started
# 2) if we already did our “first start”, bail
[ -f "$MARKER" ] && exit 0
# 3) Samba
if ! pidof smbd >/dev/null; then
logger -t custom-start "First-time start: Samba4"
/opt/etc/init.d/S91smb start
fi
# record that we ran once
touch "$MARKER"
2. Add this to /jffs/scripts/service-event:
Bash:
if { [ "$1" = "stop" ] || [ "$1" = "restart" ]; } && [ "$2" = "samba" -o "$2" = "nasapps" ]; then
logger -t entware-smb "service-event: firmware NAS stopping, clearing .smb_started flag"
rm -f /jffs/configs/.smb_started
fi
3. Add this to /jffs/scripts/post-mount:
Bash:
[ -x "${1}/entware/bin/opkg" ] && rm -f /jffs/configs/.smb_started # clear stale flag file so our cron task will run
4. Create our cron job:
cru a entware_smb */3 * * * * /jffs/scripts/custom-start-smb.sh
Now you can reboot (my preference) or just run
/opt/etc/init.d/S91smb start
and enjoy Samba 4. In my experience, it comes up significantly faster and does not peg the CPU. Even on my old router running the 3004 firmware, one CPU was typically pegging at 100% for several minutes after a reboot before I could access the shares.I'll make a separate post about avahi later. I'm still working out the kinks on that.
Last edited: