Featured Post

HOW TO: Install VPN server on Ubuntu when server is behind firewall

The whole point in this post is to run your own VPN service, and allow you to connect remote devices to your home network. To start off yo...

Apr 13, 2013

Installing Subsonic Server on NAS4Free (embedded)

Firstly, I have to say I cannot take all the credit for this... I got a lot of information from http://lameguy.wordpress.com, who in turn got it from NAS4Free wiki.

However, I did find some problems along the way, and as usual I want to keep it somewhere I can get easy access to in future - this blog.  Please also note, this will solve any m4a and flac transcoding issues, and possibly other codecs.

The whole process relies on you setting up a jail in NAS4Free so that the changes are not lost on reboot (since this is an embedded guide).

Lets start of with configuring NAS4Free to complete this task:


Configuring NAS4Free

  1. Go to this page: http://wiki.nas4free.org/doku.php?id=documentation:setup_and_user_guide:services_ssh
  2. Check so that ssh is enabled and check the port number and also check that the option “Permit root login”is enabled.(The root password is the same as the WebGUI password but the login name is always “root”)
  3. Go to the NAS4Free webgui and navigate the menu like this: System->Advanced->sysctl.conf
    Add there:
    Name: security.jail.chflags_allowed
    Value: 1
    Comment: can be whatever you want.
  4. Now navigate in the webgui like this: Advanced|File Editor
  5. In the file path textbox write “/etc/rc.conf”
  6. Click load
  7. Add to the file jail_enable=”yes”
  8. Click the save button next to the textbox where you wrote the path to the file and then restart the NAS4Free server.


Create Folders and Mount Points

SSH into your NAS4Free box using putty or similar. NOTE: Change all reference to /mnt/data to the mountpoint on your NAS where you are going to store the jail.
  • mkdir /jail
  • mkdir /mnt/data/jail
  • mkdir /mnt/data/jail/{work,proto,conf}
  • mount_nullfs /mnt/data/jail /jail


Download and Extract FreeBSD Base System

The base system has to be downloaded to make sure you get all the necessary binaries, config files and scripts. To download it you can just copy paste the following commands into the ssh shell.
  • cd /jail/work
  • fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/`uname -m`/`uname -m`/`uname -r | cut -d- -f1-2`/base.txz
  • fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/`uname -m`/`uname -m`/`uname -r | cut -d- -f1-2`/lib32.txz
The last command for fetching lib32 is not needed if you are running NAS4Free on an 32bit system.  The following two commands extract the base system into the proto folder inside the jail.
  • tar xvf /jail/work/base.txz -C /jail/proto/
  • tar xvf /jail/work/lib32.txz -C /jail/proto/


Installing the Plugins Jail Binaries

  • cd /jail
  • mkdir -p conf/root/{etc/rc.d/,usr/bin,usr/sbin}
  • cp proto/etc/rc.d/jail conf/root/etc/rc.d/
  • cp proto/usr/sbin/{jail,jexec,jls} conf/root/usr/sbin/
  • cp proto/usr/bin/mktemp conf/root/usr/bin/


Configuring the Jail

NOTE: Obviously exchange EST for your own time=zone. Next we will configure the mounts that the jail is going to be able to access.  
  • cp /etc/resolv.conf /jail/proto/etc/
  • cp /jail/proto/usr/share/zoneinfo/EST /jail/proto/etc/localtime
NOTE: Change DataDisk1 for the mounts that you have on the NAS that you want to be accessible in the jail.
  • touch /jail/conf/fstab.proto
  • mkdir /jail/proto/mnt/DataDisk1
  • nano /jail/conf/fstab.proto
Copy into the fstab file the following lines:

/mnt/data/DataDisk1 /jail/proto/mnt/DataDisk1 nullfs rw 0 0

The drive is mounted read write for playlist, comments, ratings, podcast access from Subsonic.

The next part of the configuration is to create the rc.conf file.

  • touch conf/rc.conf.local
  • nano conf/rc.conf.local
Copy into the rc.conf.local the following lines:

jail_enable="YES" # enable jails YES|NO
jail_list="proto" # name of the jails to start “proto www…”
jail_proto_rootdir="/jail/proto" # path to our jail
jail_proto_hostname="proto" # hostname
jail_proto_ip="" # ip of the jail, replace with a ip in the same subsystem as your NAS
jail_proto_interface="re0" # Network Interface to use, replace with your NAS interface name
jail_proto_devfs_enable="YES" # use devfs
jail_proto_mount_enable="YES" # mount YES|NO
jail_proto_fstab="/jail/conf/fstab.proto" # File with Filesystems to mount 

Create the Jail Start-up Script

  • nano /jail/conf/jail_start
Copy into jail_start the following lines:

#!/bin/tcsh -x
#mounting to /jail
mkdir /jail
mount_nullfs /mnt/data/jail /jail
# copy jail binaries to /usr, not needed if N4F is 454 or up
# because Daoyama include needed files, uncomment if you use low .454 version
# cp -r /jail/conf/root/ /
# link config files to /etc
ln -s /jail/conf/rc.conf.local /etc
#start all jails
/etc/rc.d/jail start

Make the start-up script executable with the following command:
  • chmod 755 /jail/conf/jail_start
And to make it run each time the NAS server is started, add the following via the webgui under System|Advanced|Command Scripts.

Command: /mnt/data/jail/conf/jail_start
Type: PostInit

Save and apply, and reboot your server. After a successful reboot check your new jail via SSH using the jls command, you should see something like this:

JID             IP Address                   Hostname                      Path
1                   proto                              /jail/proto

And that’s how you setup a FreeBSD jail on NAS4Free embedded.

Install Subsonic and Required Packages

Enter the jail with the following command (based on the output of example jls above we use 1):
  • jexec 1 csh
The pkg_add command doesn’t function properly inside the jail. To fix this you have to run the following command NOTE: I am using a 64-bit install:
  • setenv PACKAGESITE ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9.1-release/Latest/
Now start installing the packages required by Subsonic:
Now install libmp3lame so that ffmpeg can use it for transcoding:
  • pkg_add -r -v wget
  • wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Flame%2Ffiles%2Flame%2F3.98.4%2F&ts=1366036375&use_mirror=superb-dca2
  • tar -xf lame-3.98.4.tar.gz
  • cd lame-3.98.4
  • ./configure
  • make
  • make install clean
Now compile and install your own ffmpeg with libmp3lame enabled, (remember --enable-libmp3lame during make config):
  • portsnap fetch extract
  • cd /usr/ports/multimedia/ffmpeg
  • make config 
  • make install clean  


Create Folders and Unpack Subsonic 

Create the folders and download/extract subsonic standalone.
  • mkdir -p /var/subsonic/transcode
  • mkdir /var/subsonic/standalone
  • cp /usr/local/bin/lame /var/subsonic/transcode/
  • cp /usr/local/bin/flac /var/subsonic/transcode/
  • cp /usr/local/bin/ffmpeg /var/subsonic/transcode/
  • cd /tmp/
  • fetch http://heanet.dl.sourceforge.net/project/subsonic/subsonic/4.8/subsonic-4.8-standalone.tar.gz
  • tar xvzf /tmp/subsonic-4.7-standalone.tar.gz -C /var/subsonic/standalone
  • chmod 777 *.*
Enter the following command while you are still inside the jail to see if subsonic starts.
  • sh /var/subsonic/standalone/subsonic.sh
If subsonic started as it should you can connect to it via the browser at the following adress: Jail-IP:4040, default username is admin, and password admin.

Automated Start-up

To make it run each time the NAS server is started add via the webgui under: System|Advanced|Command Scripts.

Command: jexec 1 /var/subsonic/standalone/subsonic.sh
Type: PostInit

Save and apply, and reboot your server. After a successful reboot you can check your Subsonic install via http://Jail-IP:4040

If your Subsonic installation has problems with the audio (the java install couldn’t see your audio dev) install alsa-plugins via the following command:
  • pkg_add -v -r alsa-plugins

And if you want to access your new service on your android device, why not try out the official Subsonic Music Streamer

(4/17/2013 Updated for Subsonic 4.8)
(5/10/2013 Updated based on fsbruva's comments http://forums.nas4free.org/viewtopic.php?f=79&t=3166&p=19759#p19759)


btsmania said...

Thank you for this guide. I've installed MADSONIC - Mashup Mod (a fork of subsonic) 4.8 in my N40L microserver with nas4free.

BTW, jail's FreeBSD system base directory is 'proto' in this guide, right? So it needs to be changed the extraction destination from 'plugin' to 'proto' in this guide. (e.g. tar xvf /jail/work/base.txz -C /jail/plugins/ --> tar xvf /jail/work/base.txz -C /jail/proto/ )

Due to directly compiled ffmpeg(it needed very long time for me), file conversion (Flac,ogg etc. to mp3) is perfect. Thank you again for explanation in detail, and sorry for my poor english.

Best regards from Korea.

Unknown said...

Awesome post, hoping I can get it fully working.
Just hit a minor snag. For some reason the embedded USB partition reckons it's fully.
But I'm sure with this guide all the files get install via /mnt/data/###
so the embedded boot partition shouldn't have got effected at all.
Any ideas?

iainmacleod said...

Hi Michael,

Indeed you do create the Jail on a mnt, but the data is copied to the embedded system when it is run - so it is possible you don't have space.

I would recommend you back up, reinstall nas4free, giving it plenty of space on the USB for further jails, then reload your configuration.

Unknown said...

Thanks for the guide! I'm totally new to this and setting up the jail took a couple of times before i got it working. But now i'm having trouble with the "pkg_add -v -r xtrans" and all the other ones stating (Error: Unable to get ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9.1-release/Latest/xtrans.tbz: No address record
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9.1-release/Latest/xtrans.tbz' by URL
pkg_add: 1 package addition(s) failed)
Please help?

Unknown said...

Never mind just downloaded the files with IDM copied them with the help of WinSCP to the root@proto, then i did this "setenv PACKAGESITE /jail/proto/" and than continued with the guide.

iainmacleod said...

Hi Richard De Winkel,

Sorry you were having issues with this, I checked the FTP site directly and the file exists, I am not sure what happened, but I am glad you worked around the issue.

Hope the guide went well for you!

Unknown said...

I'm getting a weird responce from subsonic "No media folders found" what ever i do its telling me this i got my media files at "/mnt/Media/A2Z/" and can't figure out whats wrong i followed the guide to the letter including "DataDisk1".
Am i missing something?

Claudiu said...


Thank you very much for this tutorial. I have almost no clue about what all this means but i managed to get very far with the installation. Jail is up and running,everything seems to be ok up to "compile your own ffmpeg"..
That is where I've been stuck for the last 8hours..

Make install clean does a lot of stuff (takes about 2 hours) and then stops.. these are the last lines:
====> Compressing man pages (compress-man)
===> Building package for cmake-modules-
Creating package /usr/ports/devel/cmake-modules/work/cmake-modules-
Registering depends:.
pkg_create: find_play_pen: can't find enough temporary space to extract the files, please set your
PKG_TMPDIR environment variable to a location with at least 0 bytes
*** [do-package] Error code 1

Stop in /usr/ports/devel/cmake-modules.
*** [run-depends] Error code 1

Stop in /usr/ports/devel/cmake.
*** [build-depends] Error code 1

Stop in /usr/ports/graphics/opencv-core.
*** [lib-depends] Error code 1

Stop in /usr/ports/multimedia/ffmpeg.
*** [install] Error code 1

Stop in /usr/ports/multimedia/ffmpeg.
root@proto:/usr/ports/multimedia/ffmpeg #

Can you please tell me what to do as i'm slowly getting to the end of the rope.


Claudiu said...

Hi again,

I solved this problem.. The USB didn't have enough space. My jail is located on the same usb as the Nas4Free and the usb thumb drive was just too small.
I replaced it with a bigger one and now the jail is working and the subsonic is ok.
I can access the subsonic web page without any problem.

However when trying to set up the media folders i get the message "Folder not found".
My config is: USB drive with Nas4Free and the jail and 2 x HDD in a ZFS pool with the Music and Movies datasets. The datasets are automatically mounted in the root of the USB thumb drive, still Subsonic can not see them

I read in the subsonic forum that subsonic can not read mapped drives and that i would have to "Use UNC paths - not mapped drives and be sure that the subsonic service has logon permissions that have permission to access the shares." ...

Can someone please explain what that means in noob language ?


Claudiu said...

Just a small update.. I started from scratch. Installed TheBrig - that makes a breeze to create jails and manage them.
Then installed subsonic inside a jail on the USB and it is working great.
Happy camper now:) USB with Nas4Free and Jails on the same USB, Subsonic and UMS both working from their jails.

Cheers for the great ideas in this blog and to all those who made it possible that a complete newb managed to do all the above in less then 3 days.


iainmacleod said...

I am so sorry I missed your request for help, but pleased you managed to resolve your issues. Thanks for letting us know.