Using Samba for sharing files with the desktop PCs

Preface

Now that we’ve successfully installed ALARM to our Pogoplug E02, we naturally want to use it as a handy NAS (Network Attached Storage)1 server from our clients, be it desktop or mobile. Since Windows is the most widely used desktop operating system and uses the SMB2 protocol for accessing files, it’s wise to support that.


What is Samba ?

Here comes Samba3, which is a free software implementation of the SMB/CIFS protocol and runs on most Unix, OpenVMS and Unix-like systems. The name comes from SMB (Server Message Block) mentioned above.

Installation

Since Samba is such widely used software, it’s definitely in package repositories of various distributions. Installing on Arch Linux is simplified with pacman package manager.

$ sudo pacman -Sy samba

This is all (no, really!).

Preparing the external drive

If the external drive is already partitioned, skip this section. But if we don’t have our external drive ready to put files on, we have to connect it to Pogoplug E02 and re-partition it. Using lsblk we get the device name, this example assumes it’s called /dev/sdb. We’ll use fdisk for the operation.

$ sudo fdisk /dev/sdb

At the fdisk prompt, delete old partitions and create a new one:

  1. Type o. This will clear out any partitions on the drive.
  2. Type p to list partitions. There should be no partitions left.
  3. Now type n, then p for primary, 1 for the first partition on the drive, and then press ENTER, accepting default values.
  4. Exit by typing w.

Now we can create a new partition of type ext3using mkfs.ext3 tool and name it hdd1. This is important since we’ll reference to this label later when putting the entry in /etc/fstab configuration file to mount the external drive at boot.

$ sudo mkfs.ext3 -L hdd1 /dev/sdb1

Now we’ll create a directory for the external drive and mount the drive to it. In my example it’s called hdd1.

$ sudo mkdir /media/hdd1
$ sudo mount /dev/sdb1 /media/hdd1

At the end, we only need to add the external drive to the /etc/fstab file, so it gets automatically mounted at boot. We reference it by the previously set label.

$ sudo echo "LABEL=hdd1 /media/hdd1 ext3 rw,noatime,nofail 0 0" >> /etc/fstab

Reboot the Pogoplug E02 to make sure mounting at boot works properly.

Configuration

Configuration is pretty much simple as well. But first we need to users who will be authorized to access Samba shares. We can create a new separate user with useradd, which will be used just for that case.

In my example, I use a previously configured user tadej and add it to Samba with smbpasswd tool.

$ sudo smbpasswd -a tadej

Now user tadej can access defined Samba shares with the same password he uses on the Pogoplug E02 system. We’ll define shares and the rest in the /etc/samba/smb.conf configuration file. Here’s a good starting point example :

[global]
   workgroup = WORKGROUP
   server string = POGO
   netbios name = POGO
   printcap name = /dev/null
   load printers = no
   disable spoolss = yes
   printing = bsd
   log file = /var/log/samba/log.%m
   max log size = 50
   security = user
   dns proxy = no
   name resolve order = bcast host lmhosts
   # For public share without login
   map to guest = Bad User
 
   # Android bugfix for reading files (samba4 bug see: https://bugzilla.samba.org/show_bug.cgi?id=9706)
   unix extensions = false
 
   # Fix for file batch copy issues (see: http://archlinuxarm.org/forum/viewtopic.php?f=18&t=4864)
   oplocks = no
 
   # Some Tuning
   socket options = TCP_NODELAY IPTOS_LOWDELAY 
   
   # Global security
   public = yes
 
#============================ Share Definitions ==============================
 
# whole HDD, only for tadej
[hdd1]
        comment = tadejs share
        public = no
        valid users = tadej
        read only = no
        writeable = yes
	create mask = 0775
        path = /media/hdd1

More about the specifics can be read on the excellent Arch Linux Wiki site for Samba. But in general this sets the server string and netbios name to pogo, which means it’s going to be addressable under this name in the Windows network. Security is set to user meaning all shares will authenticate using username/password credentials. After that follow some tuneup settings for performance and issues, see URLs for specific descriptions.

Note: there are some other tuneup settings available online in other how-to guides that apparently make the transfer better, but I had issues with those like screen tearing when streaming video. An example are lines:

socket options = SO_RCVBUF=131072 SO_SNDBUF=131072
write cache size = 65536
use sendfile = true
getwd cache = yes
min receivefile size = 4096

So use them with caution.

At the end we have the gist of the configuration file, share definitions. In example above this sets the path /media/hdd1 to the user tadej and makes it possible that he can write files to it. This is the most basic configuration and it will probably be good enough for a simple NAS solution.

After saving the /etc/samba/smb.conf file, we can now run our service using systemctl and enable it to be run at boot. It’s also handy to start the nmbd4 which is a NetBIOS name server to provide NetBIOS over IP name services. This makes it possible to enter a netbios name set above then using the server IP address.

$ sudo systemctl start smbd nmbd
$ sudo systemctl enable smbd nmbd

Now we can use the address \\pogo\hdd1 in Windows or other clients using SMB to reach the Samba share.