Tuesday, June 11, 2013

Enabling blocklist in Transmission in NAS4Free


If you have tried enabling blocklist in Transmission in NAS4Free (using Transmission web interface or a client such as Transmission Remote GUI), you might have noticed that the setting goes away when you restart Transmission service and/or NAS4Free device. Pretty annoying, I know. The reason for this is the transmission startup script configures blocklist (i.e. whether it is enabled or not) based on transmission_blocklist variable in rc.conf regardless of the setting in the transmission settings file.

Knowing this, the fix is actually quite simple: go to System -> Advanced -> rc.conf and create rc.conf variable named transmission_blocklist with the value of “YES” (without quotes):


Restart the Transmission service to apply the setting and check it worked.

Monday, June 10, 2013

Setting up NAS4Free to be used as CIFS and Time Machine

Intro

Understanding of this section is not required to do the fix, but I'd like to list the reasons why I’ve created this post.

There are a couple bugs in NAS4Free code (version 0.9.1.0.1) that I have discovered while configuring my NAS system that don't allow one to configure a NAS4Free box for simultaneous use as a CIFS file server and Time Machine (AFP). The bugs are related to generation of a configuration file for mDNSresponder (aka Bonjour).

First bug relates to the fact that during generation of mdnsresponder.conf file server name for Time Machine (i.e. AFP service) is assigned to be the host name, rather than server name parameter configured in the AFP settings. Due to the way Macs (tested on my OS X 10.8) work, if the same server name is advertised for CIFS and AFP services through Bonjour, Mac will always try to connect using AFP (and not CIFS). So in order to make simultaneous access through CIFS and AFP to work, we need to (1) fix this bug, (2) assign different host names to CIFS and AFP services.

Second bug relates to the way CIFS is advertised, and my guess is this issue is unique to OS X 10.8. NAS4Free advertises CIFS to be running on port 139, whereas for OS X 10.8 to successfully connect to the share it should be advertising port 445.

Configuration

The bug I mentioned is in /etc/rc.d/mdnsresponder - script that is used to start/stop mDNSresponder service as well as generate config mDNSresponder file in /var/etc/mdnsresponder.conf (when called with mkconf argument). The plan is:
  1. Create a folder named system (you obviously can use a different name) on one of your disks.
  2. In the system folder create a patched mdnsresponder file (startup script).
  3. In the system folder create mdnsresponder.sh script that will copy patched version of mdnsresponder file into /etc/rc.d, regenerate config and restart the service.
  4. Configure NAS4Free to run mdnsresponder.sh script after reboot (PostInit).

So here we go.

1. Create persistent folder for system tweaks

NAS4Free root file system is not persistent across reboots, so if you are doing any system tweaks and need some files to be persistent, you have to store them on one of your data disks. It doesn't really matter how you name this folder, and which specific disk it resides on. In my case my data disk is called main (mounted as /mnt/main) and I've called the folder system. So either SSH to your NAS4Free box or use Advanced -> Execute Command in the web interface to run:
mkdir /mnt/main/system

2. Create patched mdnsresponder startup script

Now we need to patch mdnsresponder startup script. I'm attaching the patched script to this blog post, but I've taken it from my installation, which is version 0.9.1.0.1, so if you have a newer version you might need to patch your file by following these steps:
  1. Copy existing /etc/rc.d/mdnsresponder file to the system folder created in the previous section.
  2. Edit the file to find and replace the following lines:
    -i "count(//afp/enable) > 0" \
    -v "//system/hostname" -n \
    with:
    -i "count(//afp/enable) > 0" \
    -v "//afp/afpname" -n \
    (i.e. leave the first line intact and change //system/hostname to //afp/afpname in the second line)
  3. Then find the following lines:

    -i "count(//samba/enable) > 0" \
    -v "//system/hostname" -n \
    -o "_smb._tcp. local." -n \
    -o "139" -n \
    -n \
    and change port number from 139 to 445.

3. Create a script to update mdnsresponder on startup

Create a file named mdnsresponder.sh in /mnt/main/system with the following content:
#!/bin/sh
/bin/cp /mnt/main/system/mdnsresponder /etc/rc.d
/etc/rc.d/mdnsresponder mkconf
/etc/rc.d/mdnsresponder restart
Now make the file executable and adjust permissions on /mnt/main/system by executing:
chmod -R g=,o= /mnt/main/system
chmod u+x /mnt/main/system/mdnsresponder.sh

4. Reconfigure NAS4Free

In NAS4Free web interface create a startup script in System -> Advanced -> Command scripts. Command should be /mnt/main/system/mdnsresponder.sh and Type should be set to PostInit.

You're done. Now restart NAS4Free and see if it works. Don’t forget to specify a server name that is different from host name in AFP settings (i.e. if you called your server nas4free, you can use something like timemachine).