Configuring Raspberry Pi Zero W as NAS/backup server using Unison
"Free" cloud storage: overview
I built a super cheap linux box for backing up my files remotely. I used the cheapest components, mostly what I had on hand. My costs were less than $50, one time, if you factor in my friend who's willing to let this live at his house permanently ($free/pricele$$). The total power draw is about 3.4W at idle which works out to about $7/year at least in southern California where rates are sky high.
Parts:
- Raspberry pi Zero W: ~$12
- 2GB Micro SD card ($3?)
- Samsung S7 phone charger
- WD Elements 500GB HD (<$30)
- Old USB hub with power adapter ($10?)
Linux on a raspberry pi
1) wpa_supplicant.conf with unix line endings:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YourNetworkSSID"
psk="Your Network's Passphrase"
key_mgmt=WPA-PSK
}
2) ssh (file is empty).
On my first boot of the Pi didn't manage to log into my network. Checking the SD card is confusing because on boot the Pi deletes the ssh and wpa file from the fat partition. To find out what's going wrong connect your pi to HDMI and run journalctl (dmesg reported wlan0 wasn't ready but not why). I had a typo in wpa_supplicant. I wasted a lot of time trying to find solutions, which involved lots of commands and configuration files which are all no longer used in a modern raspbian-stretch image. Don't believe what you read online.
The Pi's green light flashes quite a bit during boot but once it is solid the machine was ssh'able (about 1 minute). I removed the pi user (userdel) and made one for me (adduser), adding it to /etc/sudoers with sudoedit.
The idle power usage at this point was less than 1w if you can believe my killawatt.
Plugging in a hard drive
This explains how to mount and format an USB drive (not that different from any other type of drive).
Adding /dev/sda /mnt ext4 defaults,nofail to /etc/fstab makes the drive mount automatically at boot. chown user /mnt makes it so that your user can write to the mounted drive.
- hdparm is the standard program you see everywhere, but mostly doesn't work with USB drives
- sdparm is specific to SCSI drives in theory, but apparently many USB mass storage devices emulate SCSI. Not in my case anyway.
- sg3-utils is another way of sending SCSI commands. I'm really starting to doubt this whole USB pretends to be SCSI since it didn't work either
- udisks2 is another generic disk control program & deamon (not just for SCSI!) that didn't work.
- smartmontools from the name you'd think it's only for SMART (drive health) but apparently they threw the kitchen sink in there (total install footprint is 30MB!). This worked.
Cutting to the chase:
apt-get install smartmontools
add this line to /etc/rc.local:
When spun up the total power usage reached 6W, but more importantly the idle consumption is just 3.4 W. That's around 3W for the HD for those keeping track. I suspect it could be much better but for the low-efficiency powered hub I'm using. The power adapter actually feels warm to the touch even at idle. When I was using the coolmax drive my idle consumption was just 2.4W, total using a LG phone USB charger, but the drive didn't always spin up on reboot.
Attempting to save more power (made a tiny difference)
https://www.jeffgeerling.com/blogs/jeff-geerling/raspberry-pi-zero-conserve-energy
Installing unison
apt-get install unisonBest to read the manual because there's lots of options to consider. Here's the basics of my pi.prf file on my PC. There's really too much to cover here sorry.
# Unison preferencesauto = true
fastcheck = yes
# Skip files ending in Name (mind the /)
ignore = Name *.tmp
ignore = Name Thumbs.db
ignore = Name ZbThumbnail.info
ignore = Name Release/*.pch
ignore = Name Debug/*.pch
ignore = Name Release/*.bsc
ignore = Name Debug/*.bsc
ignore = BelowPath $RECYCLE.BIN
ignore = BelowPath RECYCLER
ignore = Name System Volume Information
ignore = Name lost+found
root = h:/
root = ssh://user@DNS//mnt
times = true
xferbycopying = true
perms = 0
maxthreads = 1




