Run musicpd (mpd) inside FreeBSD jail

Posted on April 08, 2018 in software

These are rough notes that I made while going about installing mpd inside a jail.

  • Install and activate iocage if not already present. Follow the instructions for vnet jails.

  • Create /etc/devfs.rules if it does not already exist by copying over defaults.
    $ sudo cp /etc/defaults/devfs.rules /etc/devfs.rules
  • Append the text below to /etc/devfs.rules
    add include $devfsrules_hide_all
    add include $devfsrules_unhide_basic
    add include $devfsrules_unhide_login
    add path zfs unhide
    add path 'mixer*' unhide
    add path 'dsp*' unhide
  • Create a jail for mpd using iocage
    $ sudo iocage create -r 11.1-RELEASE --name=jukebox \
    ip4_addr="vnet0|" \
    defaultrouter="" \
    vnet=on \


    • => ip-address of default router (private ip of your FreeBSD host)
    • => ip/subnet as you have configured for jails.
  • Add pf rule for NAT (/etc/pf.conf)
    ext_if = "em0"
    nat on $ext_if inet from to any -> $ext_if
  • Reload pf
    $ sudo service pf reload
  • Add primary interface to bridge0 (default bridge for iocage-created jails)
    $ sudo ifconfig bridge0 addm em0
    $ sudo sysrc ifconfig_bridge0="addm em0 up"
  • Start the jail and login
    $ sudo iocage start jukebox
    $ sudo iocage console jukebox
  • Set appropriate output device inside jail
    $ cat /dev/sndstat
        Installed devices:
        pcm0: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
        pcm1: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
        pcm2: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
        pcm3: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
        pcm4: <Realtek ALC899 (Analog 2.0+HP/2.0)> (play/rec)
        pcm5: <Realtek ALC899 (Rear Analog Line-out)> (play) default
        pcm6: <Intel Skylake (HDMI/DP 8ch)> (play)
        No devices installed from userspace.
    $ sysctl hw.snd.default_unit=5
  • Test audio inside jail (keep master volume on speakers low, raise slowly)
    $ cat /dev/random > /dev/dsp
  • Install musicpd (server) and musicpc (client)
    $ pkg install musicpd musicpc
  • Enable the service
    In file /usr/local/etc/musicpd.conf, uncomment:
        bind_to_address         "any"
    $ sysrc musicpd_enable=YES
    $ mkdir -p /var/mpd/.mpd/playlists
    $ mkdir -p /var/mpd/music
    $ service musicpd start
  • Add some music to your library
    $ cd /var/mpd/music
    $ fetch
    $ fetch
    $ fetch
  • Use mpc from same machine to test mpd
    In FreeBSD default shell (sh):
    $ setenv MPD_HOST
    In bash:
    $ export MPD_HOST=""
    $ mpc update
    $ mpc listall | mpc add
    $ mpc volume 30
    $ mpc play
  • Test on MacOS
    $ brew install mpc
    $ export MPD_HOST=""
    $ mpc update
    $ mpc listall | mpc add
    $ mpc volume 30
    $ mpc play
  • Or if you prefer, a text-ui client that's easier to use. Once running, press 1 for help.
    $ brew install ncmpc
    $ export MPD_HOST=""
    $ ncmpc