Tuesday, November 26, 2013

Installing Samba 4 on FreeBSD

Upgrading to Samba 4 on FreeBSD

Upgrading to Samba 4 is something I recently performed on my FreeBSD NAS. The main reason for upgrading was to fix some compatibility issues with Samba 3.6 and Windows 8.1. Those issues seem to be fixed in Samba 4. Unfortunately, there doesn't seem to be a lot of documentation about the procedure to upgrade from an existing Samba installation to Samba 4 on a FreeBSD system. I've created this guide to hopefully push some of you in the right direction.

Remove Old Samba

The first thing you will need to do is remove your existing installation of Samba. This is something I wasted a lot of time trying to avoid - in the end keeping the two installs caused too many issues for me to bother. You can check which version of Samba you have by issuing the command pkg_info | grep samba. This should produce an output similar to samba4-4.0.12_1. You can then remove the old version of Samba by typing the command pkg_delete samba4-4.0.12_1.

Install new Samba

Once you have removed the old version of Samba you can go ahead and install the new version by entering the following commands:

cd /usr/local/net/samba4
make install clean

It's likely that you will encounter some errors during your first attempt to install. These errors will likely relate to dependency checks. The best way I found to deal with these is to note the required package and manually upgrade it. Two packages that gave me grief were tdb (/usr/ports/databases/tdb) and talloc (/usr/ports/devel/talloc) Eventually, you will reach a point where Samba will finish installing.

Manually Create Init-scripts

In previous versions of Samba on FreeBSD you would simply enter the command "service samba start." Unfortunately, with Samba 4 you will likely be presented with the lovely error message "You should start smbd/nmbd/winbindd instead for domain member and standalone file server tasks." Unfortunately, it seems that FreeBSD doesn't have the needed scripts created to automatically start the smbd, nmbd and winbindd services at boot. Fortunately, we can create them. You will first need to login to an account that has root privileges then issue the command nano /usr/local/etc/rc.d/smbd and place the following data inside the file:

#!/bin/sh
# PROVIDE: smbd
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv ntpd
# BEFORE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name=smbd
rcvar=`set_rcvar`
command=/usr/local/sbin/smbd
start_cmd="/usr/local/sbin/smbd -D"
load_rc_config $name
run_rc_command "$1"

You will want to repeat this step for nmbd and winbindd; of course substituting the "command" and "start_command" parameters depending on the file you are editing. After you have created startup files for nmbd, smbd and winbindd you will need to make sure they are executable by entering the command chmod +x /usr/local/etc/rc.d/smbd - of course repeating this command for all three files.

Create a New Config File

Finally, you will need to copy your existing smb.conf file to /usr/local/etc/smb4.conf so that Samba 4 will run.

And that's it! You should now have a fully functional Samba4 installation