Cloud Storage On Your Raspberry Pi
OK, the Raspberry Pi is a small computer with modest storage capacity.
Mine all run on 2 GB SD cards, with plenty of space to spare.
But wouldn't it be nice to expand the storage capacity, for free?
Cloud services on the internet may be a good alternative for your storage needs.
They are completely for free as long as your storage needs are lower than the free space offered by the storage provider.
Which Cloud Service To Choose?
There are plenty cloud services out there.
Possibly the best known one is www.dropbox.com.
Dropbox is a syncing service, which means that you'll need the same space locally on all the machines the accounts syncs to.
If you have 1 GB stored on Dropbox, you'll need 1 GB of storage for your local copy on your local disk system.
Then I became aware of an extra feature offered by an unexpected service, www.box.com.
Box.com lacked a syncing client for a long time and still doesn't have a Linux syncing client today.
Let alone a client for our ARM based Raspberry Pi.
This is no problem for us because syncing is not what we are after anyway.
While searching the web I found another free 5 GB webdav service called Hidrive.
I had never heard of them.
But it works equally well as Box.com.
You can even connect to both services simultaneously, giving you a whopping 10 GB of free extra storage space for your RPi fleet.
And if even that isn't enough for you I can highly recommend Copy.com.
They are relatively new to the cloud storage market (started early 2013).
If you sign up for an account using this link you will start with a generous 20 GB of free cloud storage.
And every person you introduce to them as a new customer will earn you an extra 5 GB!
Setting Up Cloud Storage On Your Raspberry Pi
The examples below show you how to set up a webdav connection for Box.com. Setting it up for other storage providers is equally simple. You can even connect to multiple storage locations simultaneously if you need more storage space.
Setting up webdav is quite simple. First you need to install one program:
sudo apt-get install davfs2
Then create a mount point, from which you are going to access the cloud storage. I simply create a directory in user pi's home directory. You can choose the location for the mount directory wherever you want, and you can name it whatever you want.
That's all you have to do to be able to connect to your cloud disk manually. Type or copy/paste the next command to test this:
sudo mount -o uid=pi -o gid=pi -t davfs https://dav.box.com/dav /home/pi/box
After that you'll have to supply your Box.com user name and password. Then you can browse your cloud drive, which is now mounted on /home/pi/box. When you're done playing you can un-mount the drive with the following command. Please note that you should close all files which are stored on your cloud drive and leave the mount directory before you can un-mount.
sudo umount /home/pi/box
Adding Some Automation
OK, nice, now we can manually connect to our cloud drive. But we can completely automate this process. Let's start by supplying the user name and password automatically and work our way gradually to a fully automated mounting of your cloud drive.
Edit the file /etc/davfs2/secrets and add the next line at the bottom of this file:
https://dav.box.com/dav username password
Replace username and password by your own user name and password of course. Also make sure the file /etc/davfs2/secrets can only be read by root. If your RPi is used by multiple users you may consider creating the directory .davfs2 in your home directory and create a file named secrets in it containing the line above. Then ensure that only you, the owner of the file, can read it. This way each user on your RPi can have his/her own cloud drive settings.
Now you can mount your web drive with the same mount command as above.
The only difference this time is that you don't have to supply the user name and password any more.
They are taken from the secrets file.
Until now only the root user can mount and un-mount the cloud drive. This is not very desirable, especially on a multi user system. So let's change that now.
Add yourself, and all users who need to be able to mount a cloud drive, to the group davfs2.
sudo usermod -aG davfs2 pi
After that you'll have to log out and log back in to make the change effective. You can verify if you are added to the davfs2 group by typing the id command.
Now you'll have to give normal users the permission to run davfs2, without the need for root privileges. For that you'll have to enter the next command:
sudo dpkg-reconfigure davfs2
Select "Yes" in the menu which appears and press enter.
From now on you can mount the cloud drive as a normal user by typing the command:
mount -o uid=pi -o gid=pi -t davfs https://dav.box.com/dav /home/pi/box
Un-mounting the drive as normal user can be done by the command:
fusermount -u /home/pi/box
Nice, it works. But I still think the mount command looks a bit complicated. Let's change that by adding the next line to the end of the file /etc/fstab:
https://dav.box.com/dav /home/pi/box davfs rw,noexec,noauto,user,async,uid=pi,gid=pi 0 0
With this line in place mounting the cloud drive is only a matter of typing the command:
That's a lot easier to remember, isn't it.
And finally we're going make mounting fully automatic. The cloud file system will be mounted when the system boots, which makes it available at all times.
Replace the line you have added to the file /etc/fstab with the following line:
https://dav.box.com/dav /home/pi/box davfs rw,noexec,auto,user,async,_netdev,uid=pi,gid=pi 0 0
Needless to say your RPi does need an internet connection for this all to work. That's what the option _netdev in the line above is for. It will only mount the cloud drive if a network connection is available.