Select Page

Say you have some type of home NAS or drive array which houses valuable information. And let’s say you want to go traveling for a while (as I plan to do), but leave the box in storage. What’s the best way to bring your data with you, or just a bunch of free space for projects?

For most, ditching the drive in your laptop for something which has more capacity is good enough. But what if you wanted to maintain some level of redundancy for your data?

In my case, I was coming from a 3 x 1TB drive configuration in RAID 5 with battery backed write cache (Dell PERC 5/i), running Openfiler with NFS and SMB.

The answer, of course, is Raspberry Pi.

Obviously the trade off is a drastic decrease in speed, but more than worth the effort to put this little setup together. Also, due to the CPU overhead and complexity, I didn’t want to bother with software RAID and decided instead to use lsyncd.

The kit includes:

1 x Raspberry Pi
1 x Adafruit Pi case
2 x Seagate Slim Traveler 2TB USB drive
1 x Pluggable 4 port USB hub
1 x PowerGen 2.4-Amp USB wall charger

Raspberry Pi alone doesn’t supply enough power for both drives, or even one for that matter. The powered USB hub is necessary for reliable operation of both drives.

Before we begin, we’ll need to install a few packages.

root@raspberrypi:/# apt-get install sysstat ntfs-3g lsyncd bc

Then make sure lsyncd starts on boot:

root@raspberrypi:/# update-rc.d lsyncd defaults

When working with a large directory structure as I was, upping the number of inotify watches was necessary to keep the lsyncd service from stopping unexpectedly.

root@raspberrypi:/# echo "fs.inotify.max_user_watches = 65535" >> /etc/sysctl.conf
root@raspberrypi:/# sysctl -p

Now comes the tricky part. When working with USB drives on Raspberry Pi, the first drive you plug in will always become sda, the second sdb, and so forth. We’ll need to mount each drive by ID, as opposed to sdX so that no matter the order they’re plugged in, each drive will always have the same mount point. I created a /media directory with directories usb001 & usb002. These will serve as mount points for each drive. I found the ID by plugging in one drive, then listing out /dev/disk/by-id. (It’s worth noting that I had already connected each drive to a Windows machine and formatted with NTFS.) Once you have the ID, you can assign the block device to a mount point in /etc/fstab. Then do the same for the second drive.


proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/disk/by-id/scsi-SSeagate_Backup+_BK_NA763W70-part1 /media/usb001   ntfs-3g defaults 0       0
/dev/disk/by-id/scsi-SSeagate_Backup+_BK_NA763W8P-part1 /media/usb002   ntfs-3g ro 0    0

In my case, usb002 had all of my data and I didn’t want to risk accidentally syncing it with the empty drive; note the read-only (ro) flag in the options column. Once everything finishes, I’ll remove the flag and specify ‘defaults’ like usb001.

To mount both drives:

root@raspberrypi:/# mount /media/usb001 && mount /media/usb002


settings = {
     logfile = "/var/log/lsyncd.log",
     statusfile = "/tmp/lsyncd.status"

sync {
     delay = 0,
     source = "/media/usb002",
     target = "/media/usb001",
     rsync = {
          archive = true,
          compress = false

Start lsyncd:

root@raspberrypi:/# service lsyncd start

Monitor disk utilization:

root@raspberrypi:/# watch -n 1 'iostat -d -x'

Monitor disk space:

root@raspberrypi:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.2G  2.5G  4.4G  36% /
/dev/root       7.2G  2.5G  4.4G  36% /
devtmpfs        211M     0  211M   0% /dev
tmpfs            44M  760K   44M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p1   56M   19M   38M  34% /boot
/dev/sda1       1.9T  1.2T  663G  65% /media/usb002
/dev/sdb1       1.9T  168G  1.7T  10% /media/usb001

Here’s a little bash script that spits out a percentage. You may need to modify per your own configuration.


sda=`df -h | grep sda | awk '{print $5}' | sed 's/%//g'`
sdb=`df -h | grep sdb | awk '{print $5}' | sed 's/%//g'`
pct=$(echo "scale=1; $sda * 100 / $sdb" | bc)
echo "lsyncd: $pct% complete"

Make it executable and then watch the process:

root@raspberrypi:/# chmod a+x
root@raspberrypi:/# watch -n 1 './'

Once the drives sync up and everything looks good, remove the ‘ro’ attribute in /etc/fstab if you set it previously, and use the source drive as your primary Samba share.

Lsyncd will automatically sync additional files, deletes, etc. with the second drive. If you experience any difficulty with Raspberry Pi, lsyncd, or drive complications, simply disconnect and plug directly into another machine.

About Benjamin Perove

Ben has been associated with a broad spectrum of technologies starting from an early age, and he's contributed to the success of many businesses and enterprises professionally since 2001. Most of his time is spent building cool stuff. When he's not working, he enjoys reading, playing acoustic guitar, and being with friends. He currently resides in Medellin, Colombia.