micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

mpd+sshfs+autofs=superjukebox!

Sun Nov 18, 2012 11:27 am

Hi,
I wanted to share with the community a set up that made me really happy. Now I can access more than 500GB of music from raspbian using my android mobile as a remote control. The music server I'm using is mpd, and my music files are stored in a remote server accessible through the internet using ssh. To automatize the operation, I configured autofs and ssh rsa key authentication and works like a charm!

Here is what I did (SERVER and USER represent your specific remote host and user):

1- Install software

Code: Select all

sudo apt-get update
sudo apt-get install mpd mpc sshfs autofs
2- Configure rsa key authentication for raspbian root user

Code: Select all

sudo ssh-keygen -t rsa
sudo ssh-copy-id USER@SERVER
3- Configure autofs to mount remote ssh filesystem on demand.
Add the following line to /etc/auto.master:

Code: Select all

/mnt /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
This will mount sshfs partitions inside /mnt directory with user permissions

Add you remote mounts to /etc/auto.sshfs

Code: Select all

SERVER -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#USER@SERVER\:
The first SERVER word indicates the directory under /mnt where autofs will mount our remote fs. After the last semicolon you can add a particular remote directory (by default, it mounts user's home). Restart autofs service to test:

Code: Select all

sudo service autofs restart
ls /mnt/SERVER
4- Configure mpd
I'm running mpd as pi user. Here is a summary of the options active in /etc/mpd.conf:

Code: Select all

music_directory     "/mnt/SERVER/musica/id3db"
playlist_directory	"/home/pi/mpd/playlists"
db_file	            "/home/pi/mpd/tag_cache"
log_file            "/home/pi/mpd/mpd.log"
pid_file            "/home/pi/mpd/pid"
state_file          "/home/pi/mpd/state"
sticker_file        "/home/pi/mpd/sticker.sql"
user                "pi"

audio_output {
	type		"alsa"
	name		"bcm2835 ALSA"
	device		"hw:0,0"	
	format		"44100:16:2"
	mixer_type	"software"
	mixer_device	"default"
	mixer_control	"PCM"
	mixer_index	"0"
}
You should comment out or edit appropriately the line bind_to_address to allow local network access to mpd server.

5-Start mpd and update your database
This may take some hours, depending on your connection and the size of your music library.

Code: Select all

sudo service mpd restart
mpc update
6-Access your music remotely and enjoy!
From linux, I'd recommend GMPC, and from andriod, MPDroid. For windows clients, I cannot recomend any, but there seems to be plenty of them: http://mpd.wikia.com/wiki/Windows_Compatibility

Cheers.

Jammo
Posts: 18
Joined: Wed Feb 06, 2013 11:28 pm
Location: London, England

Re: mpd+sshfs+autofs=superjukebox!

Wed Feb 06, 2013 11:32 pm

Hi, nice post.

I'm new the RPi, and wondering if there is much change to your setup if I want to use a Network storage device instead of a remote server?

I'm after a setup like so:
RPi connected to stereo. Eth connected (or wifi). MPD server running and remote controllable via Android app (MPDroid). However, I don't want music on the local SD card, but accessed from a storage device on the LAN.

Cheers,
J

micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

Re: mpd+sshfs+autofs=superjukebox!

Thu Feb 07, 2013 12:03 pm

Hi,
autofs allows automatic mounting of any remote filesystem, be it nfs, samba, ssh, ftp... You simply need to configure it to suit your specific environment, that is, depending on the supported access methods by your NAS. A NAS is, by definition, just a "remote" file server, so your situation is not special. Here you can have some information that may be of help to you:
https://help.ubuntu.com/community/Autofs
https://wiki.archlinux.org/index.php/Autofs
http://www.linux-consulting.com/Amd_AutoFS/autofs.html

Cheers.

miukki
Posts: 1
Joined: Wed Aug 13, 2014 6:36 pm

Re: mpd+sshfs+autofs=superjukebox!

Mon Aug 18, 2014 5:46 pm

[....] Starting Music Player Daemon: mpdFailed to load database: Database corrupted
Failed to create sticker table: unable to open database file


...

who can explan why its happend i already set :
sudo chmod +x /home/pi/mpd/sticker.sql

seem like something with permission..
or not?

bjornatic
Posts: 20
Joined: Wed May 15, 2013 4:44 pm

Re: mpd+sshfs+autofs=superjukebox!

Tue Nov 29, 2016 4:30 pm

Hello !

Sooo... I followed your tutorial and everything seems to work fine (the "ls" command properly lists the remote content) except that at the "mpc update" I get a "error: Connection reset by peer". And the second time I try I get a "error: Connection refused".

I googled my problem and tried my luck by adding "mpd: ALL" in my /etc/hosts.allow file, but that did not help...

Is there something to configure on the remote server ?

Return to “Advanced users”