How I made my own private cloud storage using raspberry pi
To utilize my time in COVID period I decided to make something useful but selecting what to make is a serious problem for me because I don’t want to order anything for my project to avoid risk. I want to make something from which I already have, I had one raspberry pi and external hard drive with me so I decided make something out of it. After doing little research on raspberry pi projects I successfully found a useful project which was on making own private cloud server in my home network. I found this useful because taking backup of my own laptop’s storage is difficult for me as I am using linux, I have to mount my external storage every time whenever I need to make backup. This blog will be about how I made my own private cloud space in my home network.
Dietpi is a debian based OS for raspberry pi like raspbian, it is very lightweight and have size around 400MB. DietPi allows you to automatically install and perform all the configuration on behalf of you for installing applications provided by dietpi. While configuration of dietpi on raspberry pi you can select ownCloud server to install in it automatically. ownCloud is a suite of client–server software for creating and using file hosting services. Let’s see how we can install all this and get our own cloud storage.
- INSTALL DIETPI
First you have to download the dietpi OS image from https://dietpi.com/ , go to download section and select Raspberry pi to download the image file of the OS. After this you need an SD card to copy the image to it. You can use win32 disk imager for this.
2. INSTALL OWNCLOUD
Once you inserted the sd card in raspberry pi with dietpi in it, connect your raspberry pi to a screen and ethernet cable. You can also use wifi but for simplicity I used ethernet cable. When you connect the power in raspberry pi the dietpi will start and does all the required updates and configurations.
Now after this you need to follow some prompts and select options accordingly. The most important screen is where you have to select the application which you want to install automatically in your dietpi, here you need to select owncloud.
First you need to select software optimised in the menu and you are provided a new screen to select application of your choice, select owncloud using aero keys and space key then select ok.
Then go to install and press ok to install. This will install ownCloud in your dietpi, the installation might take some time so be patient.
3. FORMATTING YOUR EXTERNAL HDD
After successful installation of ownCloud and it’s configurations you need to prepare your hard disk. To format your hard disk to ext4 you can connect it to raspberry pi and use command line utility fdisk to format it but in my case I connected my hard disk to my laptop having ubuntu in it and used gparted(GUI) for formatting.
4. CREATING PARTITION MOUNT POINT, SETTING PERMISSIONS AND /etc/fstab CONFIGURATION
Now you need to create a mount point in your dietpi’s filesystem where your external HDD gets mounted. So I created a directory with name “mycloudspace” in / directory, here I will mount the external hard drive’s partition. You also need to set the owner and group for this directory which will be www-data and also need to change permissions of the directory. Commands for all these operation are given in the screenshot given below.
But whenever you start your raspberry pi you need to manually mount external HDD’s partition, to automate this mount process you can configure /etc/fstab file. Open /etc/fstab in your favourite text editor and add the line given below in the last of the file.
/dev/sda1 /mycloudspace ext4 defaults 0 0
Now whenever you start your raspberry pi with external HDD connected, it will be mounted automatically to /mycloudspace
After all this use command mount -a to mount all the partitions having entry in /etc/fstab. This will also mount your external HDD’s partition to /mycloudspace.
5. CONFIGURING DATABASE
When a user want to access the cloud storage then s/he needs to authenticate. Therefore, for this authentication we need to create a database. First you need to login into mysql server using dietpi terminal then create a database(mycloud is the name for the database in my case) and a database user(admin). Then after this grant all the privileges to that user for the database you created. The procedure for this is shown in the screenshot given below.
6. FIRST TIME CONFIGURATION FOR CLOUD STORAGE AND CREATING ADMIN USER
First you should delete the php configuration file in /var/www/owncloud/config/config.php, you can use the command given below.
Now check the IP of dietpi to get web interface on another system in your network. In any system of your network, use browser to point the address http://IP/owncloud. You are provided with a screen where you need to fill all the details for creating an admin user and database details you created in previous step. You also need to enter the mount point where your external hard drive is mounted.
After finishing the configurations, now you can access your cloud storage. You need to go to http://IP/owncloud and you are asked to enter the username and password to authenticate for cloud storage access, if your authentication is successful then you will enter into your cloud storage where you can store your files. You can also make backup from your phone using ownCloud application which is available for iOS and android.
You can also access this storage on public network but you need to get VPN subscription or you can also purchase a static IP but in this you need configure your router for port forwarding.
You should try making this awesome private mini cloud storage for your personal files. I suggest you to look at the documentation of ownCloud to know more about the features and functions provided by ownCloud.