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?My preferred way to expand storage capacity on my RPi is to use sshfs to connect a local or remote hard disk. All you need for that is an always-on computer which can be reached over ssh. This way storage capacity is virtually limitless, but not quite for free If your RPi is running 24/7, your host computer which provides the storage has to run 24/7 too.
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.
You can even share the same space among multiple Raspberry Pies and your desktop computer. That way data gathered by all of your equipment out there is always instantly available on your desktop computer.
Yet another possibility is to send commands to your remote Raspberry Pi through this cloud disk and let the Raspberry Pi send the results of these commands back the same way.
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.Dropbox is a good concept for desktop and laptop use, but it is not what we are after on our RPi. We want extra space. On top of that there is no ARM based client software for Dropbox, at least not that I am aware of.
So let's drop Dropbox from our selection list.
Similar problems exist for Google Drive and Microsoft's Skydrive and probably a dozen other cloud services out there.
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.
What makes Box.com stand out above the others is the ability to connect to your cloud drive over the webdav protocol, which is well supported by Linux.
You can sign up for a Box.com account for free and you'll get 5 GB of free cloud storage, which can all be available to your Raspberry Pi, or to your entire fleet of Raspberry Pies. Your desktop computer can also connect to that cloud space using webdav, which simplifies sharing files with your RPi fleet.
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!
Copy.com is very similar to Dropbox. It also has syncing clients for Linux and mobile devices. And it can coexist with Dropbox on the same computer peacefully. The main difference is that Copy.com is far more generous with free storage space.
There is one small drawback though. At present they don't offer webdav connections yet. But when I asked them about it I was told they plan to do so in the near future. So this one is well worth keeping an eye on. And in the mean time you can already start gathering huge amounts of free storage space.
So if you want large quantities of cloud space, which is not limited to be used by your Raspberry Pi, I would suggest you sign up for your first 20 GB using the link above. After signing up you will have to install one of the syncing clients on at least one device for you (and me) to earn the extra 5 GB space.
Let's hope Copy.com will come with webdav functionality soon to allow your RPi to benefit from the huge space they offer.
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 davfs2Then 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.
mkdir /home/pi/boxThat'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/boxAfter 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 passwordReplace 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.
You can add multiple secrets into this file, all belonging to a different storage provider. You can't have two different secrets for one and the same storage provider though, otherwise webdav won't know which one to choose from.
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 piAfter 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 davfs2Select "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/boxUn-mounting the drive as normal user can be done by the command:
fusermount -u /home/pi/boxNice, 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 0With this line in place mounting the cloud drive is only a matter of typing the command:
mount /home/pi/boxThat'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 0Needless to say your RPi does need an internet connection for this all to work. That's what the option _netdev in the line above i
All credits to
http://www.sbprojects.com/projects/raspberrypi/tipstricks.php
No comments:
Post a Comment