This guide will provide us a very simple way to have a personal cloud with Raspberry Pi. We’ll use a Raspberry Pi 3 model B+, with an external USB drive that will store all our data. Our USB disk will be formatted in this procedure in order to assure that it will work. So be aware to use a free USB disk in order to avoid lose of data at format time.
From software side, we’ll use Docker to have the enhancements obtained from container and NextCloud.
Step By Step Guide
Prepare OS environment
Our private cloud will be installed on Raspian Stretch Lite. Even if Raspian Buster have been released, at the time of this post the new OS is, IMHO, still not completely stable.
Enable USB Mount at boot
We’ll use an USB drive to write data. So, we need to be sure that at every boot the USB Disk will be ready, without struggling on mounting it from terminal. For this purpose, I’ll use USBmount. Type on terminal:
sudo apt-get install usbmount
To be sure it will works, we need to change the line MountFlags=slave to MountFlags=shared in “/lib/systemd/system/systemd-udevd.service”. Type
sudo nano /lib/systemd/system/systemd-udevd.service
and change the line (should be on line 27).
Reboot the RPI. Now, the simple command “mount” should list the following line within the other mounted devices:
/dev/sda on /media/usb0 type vfat (rw,nodev,noexec,noatime,nodiratime,sync,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
If we want to make USB drive writable from users (not only from root), we need to edit usbmount.conf:
sudo nano /etc/usbmount/usbmount.conf
identify “FS_MOUNTOPTIONS” and edit it as follow:
- vfat is the filesystem
- umask=0000 is the permission of the file and folder. 0000 means rwx-rwx-rwx
Prepare Your USB Device
I experienced some issues formatting my USB disk in FAT32. The only way I found to have a working installation was to format in ext4 the flash disk. Be aware: this operation will erase ALL your data in your USB disk.
According with an askUbuntu guide (https://askubuntu.com/questions/22381/how-to-format-a-usb-flash-drive), identify the USB drive among all storage partitions and volumes on your computer use:
You can also use:
Suppose it may be /dev/sda. Unmount it with:
sudo umount /dev/sda
To format drive with the ext4 file system format:
sudo mkfs.ext4 /dev/sda
Reboot to have it mounted and ready to be used for our docker volumes.
NOTE: in next section I’ll assume that your USB Disk is the only disk plugged on RPI. This should assure that at the boot it will be mounted on “/media/usb0”.
Install Nextcloud Container
It’s time to use Docker. As usual, it allows us to install and prepare the container with 1 row:
docker run -d -p 8080:80 --name nextcloud --restart unless-stopped \ -v /media/usb0/nextcloud:/var/www/html \ -v /media/usb0/apps:/var/www/html/custom_apps \ -v /media/usb0/config:/var/www/html/config \ -v /media/usb0/data:/var/www/html/data \ -v /media/usb0/theme:/var/www/html/themes \ nextcloud
this simple command will map all main volumes on your USB key and initialize Nextcloud container. Be patient, because slow USB disks will require a while to prepare the container. You will be able the initialization process by typing:
docker logs nextcloud
or simple monitoring USB disk space used from:
watch df -H
at the end of process it should have been used about 287MB of space.
Login nextcloud and last settings
Once the initialization have been completed, open with your browser the address http://<<YOUR_RPI_IP_ADDRESS>>:8080. You will see the following homepage (in your language, depending on your browser settings):
If you want to use an external database, you have to set it in database section (link below the password field). If you want to use the built-in SQLlite DB, just insert username and password which you want to use for your cloud page and click on finish configuration to access (again, after a while for database initialization) the Nextcloud presentation pages and, after a few next, to Nextcloud home page: