# STEP7
# install samba server client (Windows file sharing)
# optional pkgs update
$ sudo apt-get update
$ 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
$ ls /mnt/media/
$ sudo mkdir /mnt/media
# mount music library
$ 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:
$ 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:
$ 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:
$ 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
$ ls /mnt/media
# the list contains your music files
# AUTO MOUNT THE MUSIC LIBRARY
# auto mount your music library at startup is easy
# edit fstab type
$ 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: 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.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=network-online.target,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
$ sudo systemctl daemon-reload
$ sudo mount -a
# to list all shared point type:
$ findmnt -l
# only cifs:
$ 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
# 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
$ 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
$ sudo chmod +x ~/scripts/smb_v1_fix.sh
#
# create an empty (hidden)file in your mounted library for simply touching it
sudo touch /mnt/media/.smb_v1_fix
# add a cron job to run the script every 10 mn
$ 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
$ sudo systemctl status cron
# also in system log
$ sudo grep -a "smb_v1_fix.sh" /var/log/syslog
Click the button NEXT below to continue…