Skip to content

Instantly share code, notes, and snippets.

@daks
Last active November 21, 2023 08:58
Show Gist options
  • Save daks/8030543 to your computer and use it in GitHub Desktop.
Save daks/8030543 to your computer and use it in GitHub Desktop.
mpd configuration with music collection on removable usb disk, using autofs to automount when needed. Used on a RaspberryPi
# /etc/udev/rules.d/10-udev-disks.rules
# udev custom rule
# using # udevadm info -a -p $(udevadm info -q path -n /dev/sda1)
# I found the necessary information about my USB device
# and take the necessary ones to make it unique (idVendor, idProduct, serial here)
# when plugging the disk, nevermind the device name it gets (sda1, sdb1,...) udev creates /dev/mpd-disk and runs the script indicated
KERNEL=="sd?1",ATTRS{idVendor}=="xxxx",ATTRS{idProduct}=="yyyy",ATTRS{serial}=="zzzzzzzzzzzz",SYMLINK+="mpd-disk",RUN+="/root/bin/hdparm-mpd-disk.sh"
# /etc/auto.master
# master configuration file for autofs
# add a line like this to handle mounting on /media/auto
# the timeout option unmounts the disk if not needed anymore
/media/auto /etc/auto.media --timeout=60
# /etc/auto.media
# specific autofs configuration file to handle /media/auto automouting
# mounts /dev/mpd-disk on /media/auto/mpd-disk
mpd-disk -fstype=auto :/dev/mpd-disk
#!/bin/sh
# if you want to use idle features of your usb disk, check hdparm documentation with man hdparm
# in my case this checks the power status
hdparm -C /dev/sda
# and this sets idle timeout as 2 minutes
/sbin/hdparm -S 24 /dev/mpd-disk
# /etc/mpd.conf
# mpd configuration file
# only relevant directives noted here
# the music directory stays as default, this way when mpd starts but no music plays the usb disk is not mounted
music_directory "/var/lib/mpd/music"
follow_outside_symlinks "yes"
follow_inside_symlinks "yes"
# commands to use
# create a link to the real music collection
cd /var/lib/mpd/music
ln -s /media/auto/mpd-disk/Music Music
# make the script executable
chmod u+x /root/bin/hdparm-mpd-disk.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment