Nmbd Service Won't Start (Samba Not Working)

When running diagnostics in Plinth, these items fail:

Service nmbd is running
Listening on udp4 port 137
Listening on udp4 port 138

I don’t have samba enabled in Plinth but set it up via SSH. It was working fine. I didn’t access the share for a few months and, during that time, my FreedomBox upgraded from Bullseye to Bookworm. I recently did a clean install of the client machine (a PC runnung Debian) too and couldn’t get the share to mount anymore. I don’t know at what point the problem occurred.

If I restart the nmbd service, systemctl status nmbd says:

○ nmbd.service - Samba NMB Daemon
Loaded: loaded (/lib/systemd/system/nmbd.service; enabled; preset: enabled)
Drop-In: /usr/lib/systemd/system/nmbd.service.d
└─freedombox.conf
Active: inactive (dead) (Result: exec-condition) since Tue 2023-10-03 11:20:16 BST; 6s ago
Condition: start condition failed at Tue 2023-10-03 11:20:14 BST; 8s ago
Docs: man:nmbd(8)
man:samba(7)
man:smb.conf(5)
Process: 12104 ExecCondition=/usr/share/samba/is-configured nmb (code=exited, status=1/FAILURE)
CPU: 1.358s

testparm doesn’t show any errors. The IP address, username and password are correct. The firewall page of Plinth shows Samba Disabled and samba: 139/tcp 445/tcp Permitted (internal only). Samba is listed in firewall-cmd --list-services --zone=internal though.

After spending ages trying to figure this out I thought I’d ask here if anyone has any idea how I can get samba running again?

I have FreedomBox version 23.18 running on an Olimex Lime2 server.

Hi bella-north.

nmbd is only the Netbios name service. Could you check smbd and see if there are any errors showing up?

sudo systemctl status smbd

For me (where it’s running successfully on bookworm) it looks like this:

$ sudo systemctl status smbd
● smbd.service - Samba SMB Daemon
     Loaded: loaded (/lib/systemd/system/smbd.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/smbd.service.d
             └─freedombox.conf
     Active: active (running) since Wed 2023-09-20 16:29:49 CEST; 1 week 5 days ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
   Main PID: 1241 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 3 (limit: 1997)
     Memory: 10.6M
        CPU: 2min 5.829s
     CGroup: /system.slice/smbd.service
             ├─1241 /usr/sbin/smbd --foreground --no-process-group --configfile=/etc/samba/smb-freedombox.conf
             ├─1255 /usr/sbin/smbd --foreground --no-process-group --configfile=/etc/samba/smb-freedombox.conf
             └─1256 /usr/sbin/smbd --foreground --no-process-group --configfile=/etc/samba/smb-freedombox.conf

Notice: journal has been rotated since unit was started, output may be incomplete.

And what does the system journal show when you’re trying to start it?

sudo systemctl start smbd
sudo journalctl -xe

I hope this helps finding the root cause. I could imagine that the bookworm update made a backup copy of your config files and replaced them with the package defaults. Then, it should be easy to bring back the previous configuration.

Cheers & HTH,
Axel

Thanks for the reply Axel.

Here’s the output from these commands:

sudo systemctl stop smbd
sudo systemctl start smbd
sudo journalctl -xe

░░ Subject: A start job for unit smbd.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit smbd.service has begun execution.
░░ 
░░ The job identifier is 35215.
Oct 03 13:42:04 freedombox update-apparmor-samba-profile[16252]: grep: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 03 13:42:04 freedombox update-apparmor-samba-profile[16249]: /usr/share/samba/update-apparmor-samba-profile: line 59: /etc/apparmor.d/samba/smbd-shares.new: Read-only file system
Oct 03 13:42:05 freedombox update-apparmor-samba-profile[16253]: diff: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 03 13:42:05 freedombox update-apparmor-samba-profile[16253]: diff: /etc/apparmor.d/samba/smbd-shares.new: No such file or directory
Oct 03 13:42:05 freedombox update-apparmor-samba-profile[16254]: mv: cannot stat '/etc/apparmor.d/samba/smbd-shares.new': No such file or directory
Oct 03 13:42:07 freedombox systemd[1]: Started smbd.service - Samba SMB Daemon.
░░ Subject: A start job for unit smbd.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit smbd.service has finished successfully.
░░ 
░░ The job identifier is 35215.

sudo systemctl status smbd

● smbd.service - Samba SMB Daemon
     Loaded: loaded (/lib/systemd/system/smbd.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/smbd.service.d
             └─freedombox.conf
     Active: active (running) since Tue 2023-10-03 13:42:07 BST; 1min 17s ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
    Process: 16247 ExecCondition=/usr/share/samba/is-configured smb (code=exited, status=0/SUCCESS)
    Process: 16249 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (code=exited, status=0/SUCCESS)
   Main PID: 16256 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 3 (limit: 2099)
     Memory: 20.4M
        CPU: 3.341s
     CGroup: /system.slice/smbd.service
             ├─16256 /usr/sbin/smbd --foreground --no-process-group
             ├─16258 /usr/sbin/smbd --foreground --no-process-group
             └─16259 /usr/sbin/smbd --foreground --no-process-group

sudo systemctl stop samba
sudo systemctl start samba
sudo journalctl -xe

░░ Subject: A start job for unit samba-ad-dc.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit samba-ad-dc.service has begun execution.
░░ 
░░ The job identifier is 35310.
Oct 03 13:44:40 freedombox systemd[1]: samba-ad-dc.service: Skipped due to 'exec-condition'.
░░ Subject: Unit skipped
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit samba-ad-dc.service was skipped due to an ExecCondition= command failure, and has
░░ entered the 'dead' state with result 'exec-condition'.
Oct 03 13:44:40 freedombox systemd[1]: Condition check resulted in samba-ad-dc.service - Samba AD Daemon being skipped.
░░ Subject: A start job for unit samba-ad-dc.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit samba-ad-dc.service has finished successfully.
░░ 
░░ The job identifier is 35310.

sudo systemctl status samba

○ samba-ad-dc.service - Samba AD Daemon
     Loaded: loaded (/lib/systemd/system/samba-ad-dc.service; enabled; preset: enabled)
     Active: inactive (dead) (Result: exec-condition) since Tue 2023-10-03 13:44:40 BST; 11min ago
  Condition: start condition failed at Tue 2023-10-03 13:44:40 BST; 11min ago
       Docs: man:samba(8)
             man:samba(7)
             man:smb.conf(5)
    Process: 16278 ExecCondition=/usr/share/samba/is-configured samba (code=exited, status=1/FAILURE)
        CPU: 308ms

As far as I can tell, I have the server and client set up just the same as they were when it was working. The error when trying to mount the share on the client is:

mount error(113): could not connect to 192.168.1.xxxUnable to find suitable address.

Both dmesg and journalctl on the client say:

CIFS: Attempting to mount \\192.168.1.xxx\data
CIFS: VFS: Error connecting to socket. Aborting operation.
CIFS: VFS: cifs_mount failed w/return code = -113

These lines from your first output…

Oct 03 13:42:04 freedombox update-apparmor-samba-profile[16252]: grep: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 03 13:42:04 freedombox update-apparmor-samba-profile[16249]: /usr/share/samba/update-apparmor-samba-profile: line 59: /etc/apparmor.d/samba/smbd-shares.new: Read-only file system
Oct 03 13:42:05 freedombox update-apparmor-samba-profile[16253]: diff: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 03 13:42:05 freedombox update-apparmor-samba-profile[16253]: diff: /etc/apparmor.d/samba/smbd-shares.new: No such file or directory
Oct 03 13:42:05 freedombox update-apparmor-samba-profile[16254]: mv: cannot stat '/etc/apparmor.d/samba/smbd-shares.new': No such file or directory
Oct 03 13:42:07 freedombox systemd[1]: Started smbd.service - Samba SMB Daemon.

…look like an issue with apparmor. It also mentions a file called smdb-shares.new. To me, the suffix looks as if it could have been created by the upgrade. I am not very familiar with apparmor, but could you check if there are any stray files in that directory (speaking of /etc/apparmor.d/samba/)?

You could check if there are any log messages with apparmor or maybe you need to enable a specific aa profile? => AppArmor/HowToUse - Debian Wiki

Just a guess :slight_smile:

Update: I checked in my FB installation (also bookworm with samba enabled), and I do not have any aa profiles defined for it:

root@box:/etc/apparmor.d/samba# pwd
/etc/apparmor.d/samba
root@box:/etc/apparmor.d/samba# ls -la
total 0
drwxr-xr-x 1 root root   0 Nov  4  2021 .
drwxr-xr-x 1 root root 326 Jun 11 09:37 ..
root@box:/etc/apparmor.d/samba# 

So maybe removing these apparmor settings may help, unless they are there for a reason?

Thanks, for the guess :grin:
I don’t recall having made any changes to apparmor myself. The /etc/apparmor.d/samba dir is there but it’s empty. I tried stopping apparmor and restarting smbd but I got the same messages about missing files/directories.

I’ve installed apparmor-profiles and apparmor-utils but now after stopping the smbd service it won’t start again with the error:

Job for smbd.service failed because the control process exited with error code.
See "systemctl status smbd.service" and "journalctl -xeu smbd.service" for details.

journalctl -xeu smbd.service says:

Subject: A start job for unit smbd.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit smbd.service has begun execution.
░░ 
░░ The job identifier is 43830.
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27034]: grep: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27030]: /usr/share/samba/update-apparmor-samba-profile: line 59: /etc/apparmor.d/samba/smbd-shares.new: Read-only file system
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27035]: diff: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27035]: diff: /etc/apparmor.d/samba/smbd-shares.new: No such file or directory
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27036]: mv: cannot stat '/etc/apparmor.d/samba/smbd-shares.new': No such file or directory
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27030]: Reloading updated AppArmor profile for Samba...
Oct 03 20:22:54 freedombox update-apparmor-samba-profile[27038]: File /etc/apparmor.d/usr.sbin.smbd not found, skipping...
Oct 03 20:22:54 freedombox systemd[1]: smbd.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ An ExecStartPre= process belonging to unit smbd.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 2.
Oct 03 20:22:54 freedombox systemd[1]: smbd.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit smbd.service has entered the 'failed' state with result 'exit-code'.
Oct 03 20:22:54 freedombox systemd[1]: Failed to start smbd.service - Samba SMB Daemon.
░░ Subject: A start job for unit smbd.service has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit smbd.service has finished with a failure.
░░ 
░░ The job identifier is 43830 and the job result is failed.
Oct 03 20:22:54 freedombox systemd[1]: smbd.service: Consumed 1.454s CPU time.
░░ Subject: Resources consumed by unit runtime
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit smbd.service completed and consumed the indicated resources.

I don’t seem to be improving things!

/etc/apparmor.d/samba/smbd-shares.new: Read-only file system

This seems to the cause of the problem. Looks like your disk encountered I/O errors and mounted itself read-only to avoid writing further errors. You an confirm by running mount command. It will show ‘ro’ next to the entry for ‘/’ filesystem.

Most of the time it is bad news as the disk is going bad (power-offs don’t create errors on modern journaling file systems). SD cards fail more often than HDDs/SSDs. You may need to replace the disk. To replace, perform and image-copy of the disk to a new disk and insert in place of the old disk. Boot into the new disk and everything should be back to normal.

You may want to try recovering temporarily and see if the disk will cause errors like this in the future. For this, just reboot and see if the filesystem mounts itself read-write again (after recovering from journal). If that does not work, run file system check and then reboot.

  • fsck /dev/<device> if the file system is ext4.
  • btrfs check <device> if the file system is btrfs.

Thanks, I think you’re right. I already moved root to an SSD; the only mount points showing as read-only are:
ramfs on /run/credentials/systemd-sysctl.service
ramfs on /run/credentials/systemd-sysusers.service
ramfs on /run/credentials/systemd-tmpfiles-setup-dev.service
ramfs on /run/credentials/systemd-tmpfiles-setup.service

A reboot didn’t fix it so I’ll try swapping the SDcard when I get hold of a spare one!

Just focus on the physical filesystem mounted on ‘/’ holding your ‘/etc/’ file. Everything in /run is backed by RAM. Running journalctl will also show you the reason why the filesystem was mounted as read-only (likely disk errors).

“/” isn’t mounted read only. I found this error in journalctl:

Oct 04 17:32:58 freedombox kernel: BTRFS warning: duplicate device /dev/mmcblk0p2 devid 1 generation 7478 scanned by pool-udisksd (3507)
Oct 04 17:32:58 freedombox /usr/share/plinth/actions/actions[3502]: Error executing action: Command '['udisksctl', 'mount', '--block-device', '/dev/mmcblk0p2', '--no-user-interaction']' returned non-zero exit status 1.
                                                                    Traceback (most recent call last):
                                                                      File "/usr/share/plinth/actions/actions", line 93, in _call
                                                                        return_values = func(*arguments['args'], **arguments['kwargs'])
                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                                                      File "/usr/lib/python3/dist-packages/plinth/modules/storage/privileged.py", line 218, in mount
                                                                        subprocess.run([
                                                                      File "/usr/lib/python3.11/subprocess.py", line 571, in run
                                                                        raise CalledProcessError(retcode, process.args,
                                                                    subprocess.CalledProcessError: Command '['udisksctl', 'mount', '--block-device', '/dev/mmcblk0p2', '--no-user-interaction']' returned non-zero exit status 1.
Oct 04 17:32:59 freedombox /usr/bin/plinth[560]: Mount operation failed: by-uuid-8bee72a3-2aa4-4bb7-a434-4ecf89057300 /dev/mmcblk0p2: Command '['udisksctl', 'mount', '--block-device', '/dev/mmcblk0p2', '--no-user-interaction']' returned non-zero exit status 1.

I copied the contents of the SD card to a new one and most of that error no longer shows in journalctl but the bit about “duplicate device” is still there and samba still isn’t working. I’m guessing it has something to do with when I originally moved root from the SD card to the SSD.

Tomorrow I will try deleting the second partition of /dev/mmcblk0 and see what happens.

I’m still getting this error:

freedombox update-apparmor-samba-profile[5860]: /usr/share/samba/update-apparmor-samba-profile: line 59: /etc/apparmor.d/samba/smbd-shares.new: Read-only file system

I created a file in /etc/apparmor.d/samba/ so it definitely isn’t read only. I’ve deleted the extra /dev/mmcblk0p2 partition and reinstalled samba and apparmor. None of it seems to have made any difference. Anyone have any ideas?

This sounds really frustrating, and I am also running out of ideas. One more idea: How about trying to completely remove and reinstall apparmor. The error message refers to apparmor, and assuming something has gone wrong maybe purging the package may help? Unless you have customizations that you need to keep?

sudo apt remove --purge apparmor

Afterwards there should not be any /etc/apparmor* folders anymore.

If that solves the issue, you could try to bring it back with the default config afterwards by simple reinstalling.

No luck with that. I really appreciate the help anyway :slightly_smiling_face:

I might try a clean install tomorrow.

I checked the script /usr/share/samba/update-apparmor-samba-profile. It is a simple shell script that is executed just before starting smbd.service. In line 59 if this script, it tries to write to the file /etc/apparmor.d/samba/smbd-shares.new. Do you still see this error? Are you able to manually create a new file (as root) in the directory /etc/apparmor.d/samba?

Also the script successfully exists if it does not find the directory /etc/apparmor.d/samba. Try renaming that directory to /etc/apparmor.d/samba.bak.

I was able to create the file /etc/apparmor.d/samba/smbd-shares.new using root. nmbd and samba remained inactive (after a restart). smbd was active but still showed these errors:

Oct 06 09:04:24 freedombox update-apparmor-samba-profile[9718]: grep: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 06 09:04:24 freedombox update-apparmor-samba-profile[9715]: /usr/share/samba/update-apparmor-samba-profile: line 59: /etc/apparmor.d/samba/smbd-shares.new: Read-only file system
Oct 06 09:04:24 freedombox update-apparmor-samba-profile[9719]: diff: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Oct 06 09:04:24 freedombox update-apparmor-samba-profile[9720]: mv: cannot move '/etc/apparmor.d/samba/smbd-shares.new' to '/etc/apparmor.d/samba/smbd-shares': Read-only file system

After renaming the /etc/apparmor.d/samba dir those errors disappeared. But nmbd and samba services still wouldn’t run and I still couldn’t mount the share.

Looking at the script /usr/share/samba/is-configured (which I don’t think was in Bullseye), it seems that nmbd won’t start because of the setting disable netbios = yes in /etc/samba/smb.conf. Commenting that line out of the config allows nmbd to start properly but trying to mount the share still results in the error:

mount error(113): could not connect to 192.168.1.xxxUnable to find suitable address.

I don’t understand the script /usr/share/samba/is-configured well enough to see why it’s preventing the samba-ad-dc service from starting.

Well I’ve finally found a solution! I added my computer’s ip address as a source to the internal zone of firewalld:

sudo firewall-cmd --permanent --zone=internal --add-source=[ip address]

Don’t know what changed to make that necessary but I can now access the share again :grin:

1 Like