Stedl.com
Setting up a personal BitTorrent Sync server on a Raspberry Pi

Credit first, I started by following Dan's intructions on doing almost the samething. I have made a number of changes to his steps, most notably I do not have the GUI auto start anymore. It should not be needed and will only use up the Raspberry Pi limited resources.

Latest update, dropped external hard drive in favor of a USB Flash Drive. It will take up last space and should use less power and I hope be more stable.

Update 2015-05-05
  1. The needed equipment, there are many options but the provided links are what I used.
    1. Raspberry Pi [$43] Case [$13]
    2. SD card (?faster=better) [$5]
    3. USB Power 1 Amp min for the Raspberry Pi via the Micro USB port on it. (3.1amp and a second USB port to power the hard drive)
    4. For setup only not normally needed once up and running
      • USB Keyboard and Mouse
      • HDMI out to display - Remote in via Putty once running
    5. For more that just the space on the SD card

  2. Installing Linux on to your Raspberry Pi
    1. Raspbian "wheezy" image http://www.raspberrypi.org/downloads Used 2014-01-07
    2. Write the image to the SD card Used Win32DiskImager http://sourceforge.net/projects/win32diskimager/
    3. Connect
      HDMI, keyboard, Power
      System should boot up
      Default Username: "pi" Password: "raspberry"
    4. Raspbian "wheezy" Setup Screen
      Expand Filesystem - expanding the root partition to use all of SD card
      Change User Password - Set username and password (recommended)
      Advanced Options
      Host Name Change - RPi-Mil
      SSH - enable SSH
      Update (Your choice)
      If needed you can return to this setup screen using
      sudo raspi-config
    5. Finish
    6. Use the IP in Putty to remote in from another PC
      ip addr show
      Reboot
    Notes: If you need Xwindows use "startx" at prompt

  3. Installing BitTorrent Sync
    1. Find latest verion at https://www.getsync.com/platforms/desktop/ under ARM.
    2. Edit the folloing lines to match the link found on the page. Note: If you remote in from another computer you can copy and paste most of these commands. At the command line enter
      wget "https://download-cdn.getsync.com/stable/linux-arm/BitTorrent-Sync_arm.tar.gz"
      tar -zxvf BitTorrent-Sync_arm.tar.gz
    3. Start BitTorrent Sync from command line
      ./btsync
    4. Setup auto start BitTorrent Sync
      crontab -e
      Move to the end of the text and add:
      @reboot /home/pi/btsync
  4. Adding the USB Hard Drive
    1. Format drive to ext2
      In short: Download the gparted iso, burned to a CD, then use that CD to boot a computer. Then use gparted to remove old partitions (make sure you select the right drive) and put a single ext2 partition on the drive. http://gparted.sourceforge.net/
      Here is a how to http://www.wikihow.com/Use-Gparted
    2. Connect drive to RaspberryPI
      To see drive name
      sudo ls /dev/sd* 
      Normally "sd1" or "sd2", if sd2 use that in place of sd1 in the next few steps
      sudo umount /dev/sda1
      sudo mkfs.ext4 /dev/sda1 -L SYNC
      sudo mkdir /media/BTSYNC
      sudo mount /dev/sda1 /media/BTSYNC
      Now you can setup files at /media/BTSYNC
      Your new drive will now show up here, it will also show you how much space you have left.
      df -h
    3. So the system mounts the drive after a reboot
      sudo crontab -e
      near end enter
      @reboot mount /dev/sda1 /media/BTSYNC
    4. Setup drive rights for "pi"
      goto /media
      sudo chown pi BTSYNC
    5. Create Folders as needed cd = change directory
      mkdir = make directory
      Add serveral now you will add them to BitTorrent Sync later via a browser.
      mkdir Gaming1
      mkdir Gaming2
      mkdir Photos1
      mkdir Photos2
      mkdir Work
  5. Setting up folders to sync
    1. From an computer on your network go to http://ip:8888/gui
      replace ip with the IP address of your Raspberry Pi
      To learn the systems IP at the command prompt enter
      ip addr show
      If using XWindows on the Raspberry Pi its self localhost:8888/gui
    2. Use "Add Folder"
      • If new use "Generate" to create a new a secret code
      • If Adding from another source place the given secret code in the box.
      In the bottom part navigate to your folders you created in the step above in /media/BTSYNC
      So the "Path" fills in something like /media/BT-SYNC/Gaming1

  6. Sync to something!
    1. Create a folder on your desktop computer that you want to sync.
    2. Setup the Windows or Mac with Sync from https://www.getsync.com/
    3. Use the secret code you created above to sync that folder on your computer to the one on the Raspberry Pi
    4. I would recommend selecting a few meg not gig of files to sync at first. Then on the Raspberry Pi command line use
      df -h
      To see if it is saving the files on the right drive. I have messed it up and saved files to the OS drive once, it filled up fast then it hung.

From here down are extras!!
  1. Increase BitTorrent Sync security
    1. Add password to webinterface
      ./btsync --dump-sample-config > sync.conf
      nano sync.conf
      comment out:
      "storage_path" : "/home/user/.sync",
      Edit lines as wanted
      "listen" : "0.0.0.0:8888"
      "login" : "admin"
      "password" : "password"
    2. Will then need to start as
      ./btsync --config sync.conf
    3. Now change auto startup
      crontab -e
      @reboot /home/pi/btsync
      to
      @reboot /home/pi/btsync --config /home/pi/sync.conf

  2. Updating BitTorrent Sync
    1. Get latest URL from https://www.getsync.com/, under ARM. Use it in the next few steps!
    2. Stop btsync
      sudo killall btsync
    3. Download-Open/install (New 2.0)
      wget "https://download-cdn.getsync.com/stable/linux-arm/BitTorrent-Sync_arm.tar.gz"
      tar -zxvf BitTorrent-Sync_arm.tar.gz
    4. sudo reboot

  3. Keep it running!
    1. Note this hard drive case does go to sleep after 20min and would not wake up. This is my work around. I created a file on hard drive /media/BTSYNC/touch.me
      nano touch.me
      Then I added a cron entery to have the system touch the file every 15 minutes
      crontab -e
      00 * * * * touch /media/BTSYNC/touch.me
      15 * * * * touch /media/BTSYNC/touch.me
      30 * * * * touch /media/BTSYNC/touch.me
      45 * * * * touch /media/BTSYNC/touch.me
    2. After a few weeks the Raspberry Pi would seem to hang and needed a reboot, so I added this to have it reboot each night at 1:01am
      sudo crontab -e
      Add
      1 1 * * * reboot
  4. Extra Drive commands
      You may use a drive formated as NTFS
    • First install support for NTFS
      sudo apt-get install ntfs-3g
    • Partition a new drive
      sudo fdisk /dev/sdb
      Select n, p, 1, enter, enter, w
      Those - New, Primary, partition number, first cylinder, last cylinder, Write
      Format a partition
      sudo mkfs -t ext4 /dev/sdb
    • fstab
      /dev/sda        /media/BTSYNC   ext4    rw,defaults     0       0
    • To delete a directoy
      rm -r
All rights reserved, Revised: 2014-10-15 All contents ©1999-2014 James Stedl Website: http://www.stedl.com/