MusicLounge: Samba (SMB) Server


# STEP7

# 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 - Read More...

# 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 192.168.1.10:

  1. $ sudo mount -t cifs -o username=guest,password=,vers=1.0 //192.168.1.10/jukebox /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 - Read More...

# AUTO MOUNT THE MUSIC LIBRARY
# 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

//192.168.x.x/Music /mnt/media cifs auto,username=guest,password=,x-systemd.automount,x-systemd.device-timeout=10 0 0

# connect as guest example (enter your IP)

//192.168.x.x/Music /mnt/media cifs auto,username=guest,password=,x-systemd.automount,x-systemd.device-timeout=10 0 0

# SMB v1 (outdated SMB version) example (enter your IP)

//192.168.x.x/Music /mnt/media cifs auto,username=guest,password=,vers=1.0,x-systemd.automount,x-systemd.device-timeout=10 0 0

# add _netdev option to fstab entry to wait for network before attempting to mount music library
# ATTENTION: the param _netdev could be a problem in DHCP without an entry in /etc/network/interfaces

  1. sudo nano /etc/network/interfaces
auto eth0
iface eth0 inet dhcp

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

//192.168.x.x/Music /mnt/media cifs auto,username=myname,password=mypasswd,x-systemd.automount,x-systemd.device-timeout=10 0 0

# _netdev example (do not forget to check /etc/network/interfaces):

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

# using SMB v1 (windows NT server) is risky but if you know what you are doing do not forget to allow SMB1 in /etc/samba/smb.conf
# SMB1 is NT1 in samba configuration
# edit conf

  1. sudo nano /etc/samba/smb.conf

# add the 2 lines below

client min protocol = NT1
server min protocol = NT1

# complete example with:
– Music library share point IP 192.168.1.62,
– login as guest
– force SMB v1 (vers=1.0),
– waiting for network ( _netdev param)

//192.168.1.62/Music /mnt/media cifs username=guest,password=,vers=1.0,_netdev,x-systemd.automount,x-systemd.device-timeout=10 0 0

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

# 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 - Read More...
#
# 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/smb_v1_fix.sh
#!/bin/bash

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/smb_v1_fix.sh

#
# 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/smb_v1_fix.sh >/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 "smb_v1_fix.sh" /var/log/syslog

Click the button NEXT below to continue...