Compiling and Configuring Samba4 from Scratch


Software • by Sven Reifschneider • 26 May 2014 • 1 comment
#linux #howto
This article may be outdated. As of October 2022, current Samba versions are generally available on all major Linux distributions. Debian 11 uses Samba 4.14, while Arch Linux has 4.17. Thus, manually compiling Samba is no longer necessary.

In early January 2014, Samba released version 4.1.4. This version introduced several advantages and fixes over older ones, proving to be more stable, especially with large data transfers. One might assume that updating Samba on Debian-like systems is as simple as running apt-get update && apt-get upgrade. However, I found myself stuck with Samba 3.x, despite wanting the features of Samba 4.

Why Samba 4?

While Samba 3 served me well, issues arose when I changed my external hard drive (proving the adage "Never touch a running system"). With larger data transfers, Samba 3 would lose connection and even deny access to the external drive. This led me to consider Samba 4 as a potential solution. Despite finding Samba 4 in the repositories, the available version was an older beta release, not the stable version I was looking for. As of January 21, 2014, Debian Packages still listed version 4.0.0 beta2. Therefore, the only option was to compile Samba 4 myself.

> "because samba 4 is a very powerful full featured needed monster." - Naaano, ubuntuforums.org

This quote encapsulates my motivation well. Let's dive into building our own Samba 4!

Who Is This Guide For?

This guide is aimed at anyone looking to compile the latest version of Samba. It should work on any system with the necessary packages for compilation (make, build-essentials, gcc, etc.). The deinstallation of the current version may vary, but in principle, this method should work on systems like the Raspberry Pi.

Downloading, Compiling, Installing

First, remove the old Samba version, in my case, Samba 3.x, which on Debian/Ubuntu systems is straightforward:

$ apt-get remove samba*

This command uninstalls all Samba packages but retains configuration files, which is my preferred approach. Next, download the latest Samba version:

$ mkdir /home/sven/samba
$ cd /home/sven/samba
$ wget http://ftp.samba.org/pub/samba/samba-latest.tar.gz
$ tar -xzvf samba-latest.tar.gz
$ cd samba-4.1.4

The typical Linux sequence follows: ./configure, make, and make install. ./configure checks all dependencies and sets up the system for a smooth run. make compiles the software, which might take a while. Finally, make install places all files where they belong:

$ make install

The installation process might take around two hours on low-powered systems, so it's a good time to take a break. The working path created is /usr/local/samba, where all necessary files are located.

Setting Up

Key files and scripts are located in /usr/local/samba. I created startsmb and stopsmb scripts for easy administration of the Samba server.

In the old source those two scripts were missing:

# Writing the start script. Open vim and press "i" to insert the following code
$ vim /usr/local/samba/startsmb

#!/bin/sh
/usr/local/samba/sbin/smbd -D
/usr/local/samba/sbin/winbindd -D
/usr/local/samba/sbin/nmbd -D

# Save and quit vim (Esc, type :wq)
# Make script executable
$ chmod +x startsmb

# Writing the stop script. Open vim and press "i" to insert the following code
$ vim /usr/local/samba/stopsmb

#!/bin/sh
killall smbd
killall winbindd
killall nmbd

# Save and quit vim (Esc, type :wq)
# Make script executable
$ chmod +x stopsmb

Additionally, I made the Samba commands globally accessible by editing the $PATH variable in the .bashrc file:

PATH=$PATH:/usr/local/samba/bin
PATH=$PATH:/usr/local/samba/sbin

Starting Samba

With testparm, we can test our Samba configuration file smb.conf. If everything checks out, start Samba with /usr/local/samba/startsmb. To verify successful connections, use smbstatus:

$ smbstatus

Samba version 4.1.4
PID Username Group Machine
-------------------------------------------------------------------
31755 smbusr smbusr workstation (ipv4:192.168.0.9:63067)

Service pid machine Connected at
-------------------------------------------------------
IPC$ 31755 workstation Sat Jan 18 20:16:06 2014
share 31755 workstation Sat Jan 18 20:16:06 2014

Conclusion

Setting up Samba is not overly complex, but attention to detail is key. This method allows you to compile and install Samba on any Linux machine, independent of distribution packages. Samba 4 runs more efficiently for me, and the effort was worthwhile.

I hope this guide assists others. In theory, this method could also be applied to set up Samba on a Raspberry Pi, making this guide broadly applicable beyond Ubuntu/Debian.

Compiling Samba required researching various forums and sources. Below are some links that might be helpful for further details or specific needs:


Share this post

If you enjoyed this article, why not share it with your friends and acquaintances? It helps me reach more people and motivates me to keep creating awesome content for you. Just use the sharing buttons below to share the post on your favorite social media platforms. Thank you!

Sharing Illustration
Donating Illustration

Support the Blog

If you appreciate my work and this blog, I would be thrilled if you'd like to support me! For example, you can buy me a coffee to keep me refreshed while working on new articles, or simply contribute to the ongoing success of the blog. Every little bit of support is greatly appreciated!

Bitcoin (Segwit):3FsdZmvcwviFwq6VdB9PZtFK827bSQgteY
Ethereum:0x287Ffa3D0D1a9f0Bca9E666a6bd6eDB5d8DB9400
Litecoin (Segwit):MD8fMGDYtdeYWoiqMeuYBr8WBPGKJxomxP
Dogecoin:DTA6gkDCp1WncpoFJghzxCX7XPUryu61Vf
Sven Reifschneider
About the author

Sven Reifschneider

Greetings! I'm Sven, a tech innovator and enthusiastic photographer from scenic Wetterau, near the vibrant Frankfurt/Rhein-Main area. This blog is where I fuse my extensive tech knowledge with artistic passion to craft stories that captivate and enlighten. Leading Neoground, I push the boundaries of AI consulting and digital innovation, advocating for change that resonates through community-driven technology.

Photography is my portal to expressing the ephemeral beauty of life, blending it seamlessly with technological insights. Here, art meets innovation, each post striving for excellence and sparking conversations that inspire.

Curious to learn more? Follow me on social media or click on "learn more" to explore the essence of my vision.


One comment

Add a comment

You can use **Markdown** in your comment. Your email won't be published. Find out more about our data protection in the privacy policy.

01 Feb 2014, 03:48
Gebenedeit

Perfekt, genau was ich gesucht habe. Dank dir.