Sync Hacks: Hello Pi! BitTorrent Sync for LAN

Sync Hacks is a column dedicated to exploring new applications for BitTorrent Sync, as built by users like you. BitTorrent Sync is a free, unlimited, secure file-syncing app. (And now, it’s even more mobile.) If you’ve got an epic Sync idea, use-case or how-to, shoot us an email at sync[at]

In this edition of Sync Hacks: fun with LAN. Tim Stephenson walks us through how to use BitTorrent Sync and Raspberry Pi to sync photos across devices. It’s simple. We swear. Read on for Tim’s guide to quick local backup.


From Tim:

Ok, so I’m hardly the first person to blog about Raspberry Pi, but I’m now into my second year using it. Having had to set up my second device today, I’m frustrated at having completely forgotten how to do it! So these notes will (hopefully) alleviate my frustration the next time.


The goal is a low-power machine that provides a simple way of syncing photos between machines and phones at home. I don’t plan on having a lot of external storage (either external drive or network attached storage) at this stage, so this will be a temporary way to backup photos from phones to my existing backup solution (Ubuntu One, since you ask).

I also don’t plan on having a keyboard, mouse or even monitor attached to the Pi, which makes things more flexible but also slightly harder to setup.

The basic steps should be something like this:

Create a bootable image on an SD card.

Boot the machine and tweak a few settings like assigning a static IP address and changing the machine’s name.

Install a flash drive.

Install bittorrent sync and configure to start automatically.

Basic setup

There are super instructions all over the web. I took the Raspbian download from here, and wrote to the SD Card under Linux using dd as described here.

After this, I simply connected the USB lead to the Pi from my laptop, the ethernet to my home router, and booted up. Opening the router’s LAN console initially confused me, as it did not show the Pi, but I found this was just impatience on my part. After allowing the Pi time to boot and refreshing the console, it appeared.

From a terminal on my laptop I was able confirm that the Pi was ‘up’ by:

  # note this is the IP address from my router's console
  ssh pi@


supplying the default password ‘raspberry’.

Tweaks to the install

Change hostname

To avoid confusion with other Pis on the network:

Update /etc/hostname

Update /etc/hosts, so local address(es) resolves with the new system name.

Reboot (sudo shutdown -r now)

Create new account, disable the default account:

My new account will be ‘tstephen’ and I put this in the ‘staff’ group, replace with your own as you like.

  sudo mkdir /home/tstephen
  sudo useradd -g staff tstephen
  sudo passwd tstephen
  sudo usermod -d /home/tstephen tstephen
  sudo chown -R tstephen:staff /home/tstephen/
  sudo usermod -G sudo tstephen

Once we’re sure the new user is not only working, but able to ‘sudo’, disable (lock) the default user.

sudo passwd pi -l


Install thumb drive

Plug in the drive and find its name with:

  ls /dev/s*


If, like me, you are using just the two USB ports built into the Pi (no external USB hub), and have a WiFi key in one, then it’s pretty safe to say your drive will be /dev/sda1. Test mount it and check the contents are as expected (assumes vfat formatted for Windows):

  sudo mkdir /mnt/data
  sudo mount -t vfat /dev/sda1 /mnt/data
  ls /mnt/data
  sudo umount /dev/sda1


Then make the mount happen automatically on boot by adding this to /etc/fstab:

  /dev/sda1       /mnt/data       vfat    defaults


To test without rebooting, run:

  sudo mount -a


Now since I don’t plan to pull this drive in and out much (or replace it with others), I didn’t bother to use the drive’s ID to uniquely identify which thumb drive is present in the device. (Hope I don’t come to regret that decision).

Furthermore, I decided to format the drive for ext4, since that is generally held to be faster than vfat, and I have no intention of trying to read these files from a Windows machine. (For example, read here.) Hope I don’t come to regret that decision too! You can do it like this IF YOU ARE HAPPY TO LOSE ANY FILES ON THE DRIVE:

  # Remember to replace /dev/sda1 with your device if necessary.
  sudo umount /dev/sda1               
  sudo mkfs.ext4 /dev/sda1 -L RemoteStorage


Now go back and update your fstab to specify ext4 instead of vfat.

Install Bittorrent Sync

Visit here to read about Bittorrent Sync and find the latest download link. NOTE: Remember to download the ARM build! I did this:

  tar -xfv btsync_arm.tar.gz
  mv LICENSE.txt btsync-LICENSE.txt
  sudo mv btsync* /usr/bin
  sudo btsync # start up the Bittorrent Sync daemon

Ensuring btsync starts when the Pi does

So that you don’t have to ssh into the Pi and start the btsync daemon manually every time (as above), you can create an init script as described here. Having created the file at: /etc/init.d/btsync and the configuration file at ~/.sync/config.json you need to enable it as follows:

  sudo chmod 755 /etc/init.d/btsync
  sudo /etc/init.d/btsync start       # test that the script starts
  sudo /etc/init.d/btsync stop        # test that the script stops
  sudo update-rc.d btsync defaults

Configure Bittorrent Sync

Back on my main machine I can now connect to the btsync gui by putting this into my browser’s address bar. It’s probably a good idea to setup a username and password to connect when prompted to do so. Then go ahead and connect the folders you want to sync as described in the User Guide (PDF).

And there you have it!


Got comments or questions for Tim? Hit him up on Twitter (@tstephen10).