I needed to replace an old desktop PC with a shared network drive. I was also looking for a solution to automatically save pictures from my mobile phone and my wife's mobile phone. My wife had a requirement that she be able to backup her pictures with minimal intervention. I decided that the NextCloud software provided a good solution for that requirement. Using a single board computer, I ended up building a cloud server that replaced the shared network drive, enabled access to my files from anywhere I had a web browser or my cell phone, the ability to share files like with Google Drive or One Drive. But unlike Google Drive or One Drive, I could host the webserver on my own hardware withou monthly fees with storage limits only set by the size of the drives I installed on the webserver.
This is a recipe for creating a self-hosted cloud NAS (Network Accessible Storage Server) with a shared hard drive for storage and automatic backup to another network drive. The NAS setup includes the setup for a file server and NextCloud to allow the upload of files from mobile devices or through a web interface. It also explains how to share the web interface to the public internet so the files are accessible from anywhere.
First, the server consists of a LibreComputer Renegade single-board computer similar to a Raspberry Pi 3. The Renegade is connected through an ethernet cable with a powered USB 3.0 hub plugged into its USB 3.0 port. An external USB 3.0 hard drive is plugged into the hub. I plugged the USB drive into the USB 3.0 port on the LibreComputer Renegade. The Renegade specs say you must use a power USB hub with an external hard drive. Indeed, I found that an external USB drive would draw enough power to cause strange operations without a powered USB Hub. The instructions below will guide you through the software installation and configuration.
1.) Follow instructions from https://hub.libre.computer/t/raspbian-11-bullseye-for-libre-computer-boards/82 summarized as follows:
a.) Download 2022-09-22-raspbian-bullseye-arm64-lite+roc-rk3328-cc.img.xz image file from https://distro.libre.computer/ci/raspbian/11/
b.) Burn the image to the SD card using Pi Imager. I used custom image settings and no advanced options.
c.) Add an ssh file to turn on ssh on the ROC-RK3328-CC (Renegade) to the boot directory with the following commands on my Linux laptop:
This is a recipe for creating a self-hosted cloud NAS (Network Accessible Storage Server) with a shared hard drive for storage and automatic backup to another network drive. The NAS setup includes the setup for a file server and NextCloud to allow the upload of files from mobile devices or through a web interface. It also explains how to share the web interface to the public internet so the files are accessible from anywhere.
First, the server consists of a LibreComputer Renegade single-board computer similar to a Raspberry Pi 3. The Renegade is connected through an ethernet cable with a powered USB 3.0 hub plugged into its USB 3.0 port. An external USB 3.0 hard drive is plugged into the hub. I plugged the USB drive into the USB 3.0 port on the LibreComputer Renegade. The Renegade specs say you must use a power USB hub with an external hard drive. Indeed, I found that an external USB drive would draw enough power to cause strange operations without a powered USB Hub. The instructions below will guide you through the software installation and configuration.
1.) Follow instructions from https://hub.libre.computer/t/raspbian-11-bullseye-for-libre-computer-boards/82 summarized as follows:
a.) Download 2022-09-22-raspbian-bullseye-arm64-lite+roc-rk3328-cc.img.xz image file from https://distro.libre.computer/ci/raspbian/11/
b.) Burn the image to the SD card using Pi Imager. I used custom image settings and no advanced options.
c.) Add an ssh file to turn on ssh on the ROC-RK3328-CC (Renegade) to the boot directory with the following commands on my Linux laptop:
d.) Add a default user and password with the following commands on my Linux laptop:
In nano added [username]: so that userconf is a single line like
For example:
2. Boot the Renegade computer. Confirm it is on the network by looking up the ip address and pinging it. You can also ping using the host name raspberrypi.local
3. Log into an ssh session. All of the remaining steps from 4 and beyond will be executed on the Renegade using an ssh session.
4. In the ssh session run the following commands to make sure the OS is up to date
5. Rename the hostname to nas (you can set the hostname to whatever you'd like, really) with the following commands:
6. When the Renegade rebooted, it terminated the ssh session. I waited for it to reboot and then logged back in via ssh using the new hostname
7. Expand the file system to take up the entire SD Card
Select Advanced Options -> Expand Filesystem
8. Prepare the USB drive
a.) Get the device name and create a partition
8. Prepare the USB drive
a.) Get the device name and create a partition
I get sda as the device
b.) Create a partition using fdisk
b.) Create a partition using fdisk
fdisk has single key commands. m is menu, d is delete partition, n is new partition, p is print or list the partitions
c.) Format the drive (sda1 means sda, partition 1)
c.) Format the drive (sda1 means sda, partition 1)
9. Configure the Renegade to mount the USB drive on boot
a.) Get the UUID of the drive:
a.) Get the UUID of the drive:
I get /dev/sda1: UUID="07076bce-1487-4fe2-8660-fb67c6b6db09" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b7f89f76-01"
b.) Add a line to the end of /etc/fstab using the UUID
b.) Add a line to the end of /etc/fstab using the UUID
Add the line
c.) Create the mount directory
d.) Mount the drive
e.) Change the permissions
10. Increase the size of the Swap file (i.e. virtual RAM. Yes, I know you don't really want to use this because it's slow and could wear out your SD Card, but if you need Swap space to manage memory requirements, you want a bigger Swap file.
Change CONF_SWAPSIZE=100 to whatever value you'd like. I used CONF_SIZE=2048 for 2GB
After the reboot, open up the ssh session again.
11. Configure the IP Address to be static
a.) Get the router Gateway IP Address:
11. Configure the IP Address to be static
a.) Get the router Gateway IP Address:
Mine is 192.168.254.254
b.) Get the router DNS Address from resolv.conf:
b.) Get the router DNS Address from resolv.conf:
Mine is 192.168.254.254 and 208.67.220.220 because I use OpenDNS for Internet filtering
c.) Setup for a Static IP by editing /etc/dhcpcd.conf
c.) Setup for a Static IP by editing /etc/dhcpcd.conf
Add a section as follows
12. Mounting the Network Backup Drive (I have another server with a Samba Drive that I want to use as a backup to the drive connected to the Renegade)
a.) Install cifs
a.) Install cifs
b.) Create a directory to mount to (I called it share)
c.) Create credentials file
Add the login credentials for the network drive and save the file
Change the permissions so that only the root user can read the file
d.) Mount the network drive
e.) Configure fstab so that the network drive will be mapped every time the Renegade reboots
Add the following line at the end of the file
13. Create a backup script and scheduling it to run daily at 2:00 AM. In my case, I wanted the network drive to be the backup for the USB drive connected to the Renegade.
a.) Create a bash script file to backup the USB drive to the network share.
a.) Create a bash script file to backup the USB drive to the network share.
The contents are:
This will create a log file with the date/time and synchronize the contents of the USB drive to the network drive using rsync. This will creating a backup of the USB drive on the network drive.
Change the permissions to allow execution of the backup script
Change the permissions to allow execution of the backup script
b.) Schedule the bash script to run on a regular basis using cron.
14. Sharing the USB Drive as a SAMBA Drive
a.) Install samba
a.) Install samba
b.) Configure the shared drive
Add the following to the bottom of the file.
This will share a Samba share network drive at location //nas/share
c.) Create a samba user and password for accessing the shared drive
c.) Create a samba user and password for accessing the shared drive
You will be prompted for a password
d.) Restart the samba service to enable the share
d.) Restart the samba service to enable the share
thre15. Install NextCloud using the guide below
https://pimylifeup.com/raspberry-pi-nextcloud-server/#setting-up-a-mysql-database-and-user-for-nextcloud
16. If desired, configure access on the Internet outside of your local network
https://pimylifeup.com/raspberry-pi-port-forwarding/?__cf_chl_tk=EE9dAfgvbS0ewGHaORLSEFZa.6L37yPRjWYBtnlB.mI-1691452991-0-gaNycGzND6U
If you want a free DNS Server so you can set up an URL for your NexCloud acces, you can use the priver below
https://www.dynu.com/DynamicDNS/IPUpdateClient/DDClient
17. You can also install a Plex Media Server to manage your movies, music, and pictures. You can also share and play these files on other devices on your network or across the Internet if your Internet connection is quick enough
https://pimylifeup.com/raspberry-pi-plex-server/
In the steps above, we went through a basic NAS server configuration including burning a server image to a single board computer, setting up the ssh access, host name, network configuration, swap file configuration, external hard drive, access to a network shared drive, sharing a network shared drive, creating a backup script, and setting up the script on a scheduler. The last three steps are links to guides for setting up NextCloud and Plex on the server and granting access for file and media sharing and playback.
Hopefully this guide is helpful. I certainly learned a lot in the process of setting up my server and wanted to document what I learned here. Thanks for reading this far.
https://pimylifeup.com/raspberry-pi-nextcloud-server/#setting-up-a-mysql-database-and-user-for-nextcloud
16. If desired, configure access on the Internet outside of your local network
https://pimylifeup.com/raspberry-pi-port-forwarding/?__cf_chl_tk=EE9dAfgvbS0ewGHaORLSEFZa.6L37yPRjWYBtnlB.mI-1691452991-0-gaNycGzND6U
If you want a free DNS Server so you can set up an URL for your NexCloud acces, you can use the priver below
https://www.dynu.com/DynamicDNS/IPUpdateClient/DDClient
17. You can also install a Plex Media Server to manage your movies, music, and pictures. You can also share and play these files on other devices on your network or across the Internet if your Internet connection is quick enough
https://pimylifeup.com/raspberry-pi-plex-server/
In the steps above, we went through a basic NAS server configuration including burning a server image to a single board computer, setting up the ssh access, host name, network configuration, swap file configuration, external hard drive, access to a network shared drive, sharing a network shared drive, creating a backup script, and setting up the script on a scheduler. The last three steps are links to guides for setting up NextCloud and Plex on the server and granting access for file and media sharing and playback.
Hopefully this guide is helpful. I certainly learned a lot in the process of setting up my server and wanted to document what I learned here. Thanks for reading this far.