FreeNAS Jail with Bittorrent Sync

Here are my instructions for creating a FreeNAS Jail with Bittorrent Sync (BTsync) running inside it. This uses no FreeNAS plugins whatsoever and takes full advantage of all the power that comes with having a FreeBSD core running at the heart of FreeNAS 9.1.  This has been done on FreeNAS-9.1.1-RELEASE-x64.

  1. Login to your FreeNAS systems web interface.
  2. Click: Jails
  3. Click: Add Jail
    0001
  4. For Jail Name use btsync and click ok.  Let FreeNAS do its thing.
    0002
  5. The jail will automatically start.  You now need to SSH into your FreeNAS box as root.  In the alternative SSH in as a regular user and then change to root with su.
  6. Run: jls
  7. Make a note of the number to the left of the btsync name used earlier.
  8. Run: jexec # csh
    [where # is the number from item 7. above]
  9. Run: mkdir /usr/local/btsync
  10. Run: cd /usr/local/btsync
  11. Run: fetch http://download-lb.utorrent.com/endpoint/btsync/os/FreeBSD-x64/track/stable
  12. Run: tar zxvf stable
  13. Run: rm stable
  14. Run: ./btsync –dump-sample-config > btsync.conf
  15. Run: pkg_add -rv nano
  16. Run: nano /usr/local/btsync/btsync.conf
  17. Change the following:
    1. Replace: “device_name”: “My Sync Device”, with a friendly name for your BTsync service, e.g. “device_name”: “Fred”,
    2. Replace: “storage_path” : “/home/user/.sync”, with “storage_path” : “/usr/local/btsync/.sync”,
    3. Replace: “password” : “password” with “password” : “XXXXXXXXXX” where XXXXXXXXXX is a password of your choosing.
  18. Close Nano and save the changes: Ctrl +X -> Y -> Enter
  19. Run: nano /etc/rc.d/btsync
  20. Insert the following:
    #!/bin/sh
    #
    # PROVIDE: btsync
    # REQUIRE: LOGIN DAEMON NETWORKING
    # KEYWORD: shutdown
    #
    # To enable BTSync, add this line to your /etc/rc.conf:
    #
    # btsync_enable="YES"
    #
    # And optionally these line:
    #
    # btsync_user="username" # Default is "root"
    # btsync_bin="/path/to/btsync" # Default is "/usr/local/sbin/btsync"
    
    . /etc/rc.subr
    
    name="btsync"
    rcvar="btsync_enable"
    
    load_rc_config $name
    
    required_files=$btsync_bin
    
    : ${btsync_enable="NO"}
    : ${btsync_user="root"}
    : ${btsync_bin="/usr/local/sbin/btsync"}
    : ${btsync_config="/usr/local/btsync/btsync.conf"}
    
    command=$btsync_bin
    command_args="--config ${btsync_config}"
    run_rc_command "$1"
  21. Close Nano and save the changes: Ctrl +X -> Y -> Enter
  22. Run:  chmod 555 /etc/rc.d/btsync
  23. Run: nano /etc/rc.conf
  24. Insert the following:
    # BitTorrent Sync
    btsync_enable="YES"
    btsync_user="nobody"
  25. Close Nano and save the changes: Ctrl +X -> Y -> Enter
  26. Run: chown -R nobody:nogroup /usr/local/btsync
  27. Run:  mv /usr/local/btsync/btsync /usr/local/sbin/
  28. Run: chown root:wheel /usr/local/sbin/btsync
  29. Login to your FreeNAS systems web interface.
  30. Click: Jails
  31. Stop the btsync jail and start it again.  Bittorrent Sync should now be running.
  32. Click: Edit Jail
  33. Make a note of IP.
  34. Login to your Bittorrent Sync web interface via: XXX.XXX.XXX.XXX:8888
    [Where XXX.XXX.XXX.XXX is the IP from Item 34]

That should about do it.

Some things to remember:

  • You can use the FreeNAS admin interface to mount storage into folders that exist outside of the jail into the jail.
  • Files and folders should all be set to nobody:nogroup as a user/group combination.  This killed off 99.9% of problems I was having.
  • Bittorrent Sync does not seem to update itself at the moment, at least it hasn’t thus far in this configuration.  This could be because it just doesn’t do it on FreeBSD or because I’ve done something stupidly wrong.  Either way you’ll have to watch the version numbers.