Samba (SMB) Server


# install samba server client (Windows file sharing)
# optional pkgs update

  1. $ sudo apt-get update

  1. $ sudo apt-get install samba samba-common smbclient samba-common-bin smbclient cifs-utils

# select <no> on prompt

# mount your music library (should be shared to everyone, password not required)

# in this example “Music” is your samba share that contains the music files,
# the IP address is the PC Host
# so path to \\ServerNAS\Music
# is replaced by
# //192.168.x.x/Music

# IMPORTANT to go further you need to know:
# the IP address of your server containing your music files
# the name of the shared directory
# and login/password of the share point if you cannot get access to the directory as guest

# if /mnt/media/ directory not exist create it

  1. $ ls /mnt/media/
  2. $ sudo mkdir /mnt/media

Mount Your Music Library -
# skip this part and click NEXT button if you intend to put your music library in local hard drive

# mount music library

  1. $ sudo mount -t cifs -o username=Guest,password=,vers=1.0 //192.168.x.x/Music /mnt/media

# username+password can be filled with your credentials, in this case ‘vers=1.0’ must be skipped:

  1. $ sudo mount -t cifs -o username=myname,password=mypasswd //192.168.x.x/Music /mnt/media

# SBM1 EXAMPLE if the IP of your NAS is

  1. $ sudo mount -t cifs -o username=guest,password=,vers=1.0 // /mnt/media

# check if this is correctly mounted type:

  1. $ df -h

# your share point should be in the list and music files are available from /media/music

# result in last line should be for example:
# //192.168.x.x/Music 932G 655G 277G 71% /media/music

  1. $ ls /mnt/media

# the list contains your music files

Auto Mount Your Music Library At Startup -

# auto mount your music library at startup is easy

# edit fstab type

  1. $ sudo nano /etc/fstab

# example add the following line at end and change //192.168.x.x/Music to your values

# example1: connect as guest to \\MyNAS\Music directory (change to the IP of your NAS server and the name of shared directory)

//192.168.x.x/Music /mnt/media cifs username=guest,password=,vers=2.0,x-systemd.before=mpd.service,x-systemd.device-timeout=10s 0 0

# example2: enter your IP and change myname/mypasswd to your values:

//192.168.x.x/Music /mnt/media cifs username=myname,password=mypasswd,x-systemd.before=mpd.service,x-systemd.device-timeout=10s 0 0

# example3: with _netdev to wait for network:

//192.168.x.x/Music /mnt/media cifs username=guest,password=,_netdev,x-systemd.before=mpd.service,x-systemd.device-timeout=10s 0 0

# example4: SMB v2 with pi user:group and 755 permissions:

//192.168.x.x/music /mnt/media cifs username=guest,password=,vers=2.0,uid=1000,gid=1000,dir_mode=0755,file_mode=0755,x-systemd.before=mpd.service,x-systemd.device-timeout=10s 0 0

# complete example with:

– “\\NAS\music” library Windows share point (NAS IP address:,

– login as guest force SMB v1 (vers=1.0),

– waiting for network ( _netdev param)

// /mnt/media cifs username=guest,password=,vers=1.0,_netdev,x-systemd.before=mpd.service,x-systemd.device-timeout=10s 0 0

# example using systemd to check network availability and mount before mpd:

//192.168.x.x/Music /mnt/media cifs rw,uid=1000,gid=1000,nofail,username=dummyusr,password=dummypw,iocharset=utf8,x-systemd.before=mpd.service,,x-systemd.after=systemd-resolved.service 0 0

# CTRL+O to save
# CTRL+X to exit

# x-systemd.before=mpd.service explanation:
# It is necessary to be sure the mount point is available before running the MPD service
# and also necessary to stop the MPD service before unmounting your library (/mnt/media/)
# otherwise, if you reboot or shutdown with your MPD status is in pause or playing
# the mount point will be busy and systemd unmount filesystem will fail and can take
# a while (more than 120s) to reboot.
# mount library

  1. $ sudo systemctl daemon-reload
  2. $ sudo mount -a

# to list all shared point type:

  1. $ findmnt -l

# only cifs:

  1. $ findmnt -t cifs

# at this point you may check and fix if needed your fstab entry by
# rebooting the device and checking ls /mn/media/ directory which should contains your song files

CIFS Mounts Disconnecting Issue -
# if you are using SMB v1 and after a couple of hour your /var/log/syslog is fulfilled of

CIFS VFS: Server 192.168.x.x has not responded in xxx seconds. Reconnecting...

# then you need an extra step to maintain your smb connection
# add the following script in scripts/ directory

  1. $ sudo nano ~/scripts/

while read spot; do
   touch --no-create "${spot}/.smb_v1_fix"
done <<< "$(mount | awk '/cifs/{ print $3; }')"

# CTRL+O to save
# CTRL+X to exit

# set the permission

  1. $ sudo chmod +x ~/scripts/

# create an empty (hidden)file in your mounted library for simply touching it

  1. sudo touch /mnt/media/.smb_v1_fix

# add a cron job to run the script every 10 mn

  1. $ sudo nano /etc/cron.d/smb_v1_fix
*/10 *   *   *   *   root    /home/pi/scripts/ >/dev/null 2>&1

# CTRL+O to save
# CTRL+X to exit

# the status of your cron job can be checked easily

  1. $ sudo systemctl status cron

# also in system log

  1. $ sudo grep -a "" /var/log/syslog

Click the button NEXT below to continue…