Create you own fast NAS with advanced functionality using ROCK64

I’m going to show you how to setup a cheap, fast NAS  (Network Attached Software) with lots of functionality such as:

  • SFTP server (download/upload files – local and Internet)
  • Network drive sharing (access your files from your Windows, Linux or Mac PC)
  • Browse your images and videos over the WEB (local and Internet)
  • DLNA server to access your media from for example your TV
  • Backup and synchronize your files with a remote NAS

Contents

What you need?

Total price: $166 for 1 GB hard drive or more if you need a larger drive

Why ROCK64?

I started out creating a NAS several years ago using a Raspberry Pi with a USB 2.0 connected hard drive. It was terribly slow, since it used the same USB 2.0 controller for both the Ethernet and external USB devices. The throughput was around 3-4 MB/s.

Later I switched to a Banana Pi since Ethernet was separated from the USB 2.0 controller. The throughput was around 8-10 MB/s.

The biggest problem with Raspberry Pi and Banana Pi is that they only support up to USB 2.0 which has a theoretical max throughput of 60 MB/s (but in reality much slower).

ROCK64 is using USB 3.0 which has a theoretical max throughput of 5 GB/s. A ROCK64 NAS should give you around 70 – 100 MB/s which is almost 10 times Banana Pi and 20 times Raspberry Pi, but with only a few bucks price difference. In my case I’m always connected to a 802.11n Wifi network so I get around 20 MB/s which is limited by the Wifi network and not ROCK64.

Many of the instructions given here are also applicable for other single board computers (such as Raspberry Pi and Banana Pi).

Assembly

When you have all the parts, just put you ROCK64 in the aluminum casing, connect your USB hard drive to the USB 3.0 port (blue port), connect the power supply and the Ethernet port to your router.

You can put the ROCK64 and USB hard drive on a flat area or do as I did; mount them on a small plywood board and mount the board on the wall.

Install Linux

Many different Linux distributions exists for ROCK64. I recommend Armbian that is based on Ubuntu. It is trivial to setup and does not require you to connect ROCK64 to a monitor, keyboard or mouse, i.e. you can do all configurations remote over SSH. Download the ROCK64 image from the Armbian site. Use balenaEtcher to flash the image to your SD card.

Insert the SD card in the ROCK64 Micro-SD card slot and turn on power.

You have to look in your router configuration / status page (usually http://192.168.1.0 or http://192.168.1.1) which IP address ROCK64 got (over DHCP). If you are not able to access the router configuration / status page there are other alternatives to figure out the IP address:

  • Use nmap network scanner. Available for Windows, Linux and Mac.
  • Or, connect your ROCK64 to a monitor, keyboard and mouse.

Use SSH to connect to that IP (for Windows I recommend PuTTY SSH client). Default credentials for Armbian is:

  • User: root
  • Password: 1234

I recommend that you change your password by writing:

sudo passwd root

Set a fixed local IP address

Many of the remaining configurations requires that you know the ROCK64 IP address. By default Armbian will fetch and configure a new IP address over DHCP on every reboot.  The best way to configure a fixed IP address is to configure your router to give a specific IP address to ROCK64.

To configure a fixed IP address you need to figure out the MAC address of the ROCK64 ethernet controller.

pi@rock64:~$ ifconfig eth0 | grep ether
ether de:e5:4b:f7:2b:1d txqueuelen 1000 (Ethernet)

My ROCK64 MAC address is de:e5:4b:f7:2b:1d, your ROCK64 will have a different MAC address. 

The configuration is done through the routers configuration page under the LAN/DHCP settings. The image illustrates how it is done on an ASUS router. Check your router configuration manual on how this is done in your case.

Setup your USB hard drive

Figure out your hard drive device name by writing:

pi@rock64:~$ sudo fdisk -l /dev/sd?
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0xe0d2996c

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 64 3907024064 3907024001 1.8T 7 HPFS/NTFS/exFAT

In my case I have device id /dev/sda1 which is a 1.8 TB Samsung USB 3.0 hard drive.

I strongly recommend to format your drive using EXT4 file system. It is much faster than NTFS or FAT on Linux. EXT4 has the drawback that you cannot connect your drive to a Windows PC without external software. 

Warning!
All your files on the USB hard drive will be lost in the below step. Also, be sure to replace sda1 with the name or YOUR drive 

sudo mkfs.ext4 /dev/sda1

Now your drive is formatted with EXT4 file system.

Create a directory where you want your drive to be mounted. I like to have it on /media/usb but you could pick any folder you like. 

sudo mkdir -m 1777 /media/usb

Currently the directory is owned by root. Make yourself owner by writing.

sudo chown -R $USER:$USER /media/usb

When configuring your drive it is always better to reefer to its UUID which is globally unique instead of its device name since the device name could be changed if you connect other devices to ROCK64.

Figure out the UUID for /dev/sda1:

pi@rock64:~$ sudo blkid /dev/sda1
/dev/sda1: UUID="ab8e7dc4-e1ec-4f83-9387-4556dfe797c6" TYPE="ext4" PARTUUID="e0d2996c-01"

In my case the UUID is ab8e7dc4-e1ec-4f83-9387-4556dfe797c6. 

Now you need to update the /etc/fstab file which is the file that tells Linux which drives to mount at startup.

sudo pico /etc/fstab

Add following line in the end of the file:

UUID=ab8e7dc4-e1ec-4f83-9387-4556dfe797c6 /media/usb ext4 nofail,defaults 0 0

UUID must match your device UUID and replace /media/usb with your mount directory.

Reboot ROCK64:

reboot

When ROCK64 has been rebooted, connect to it again with SSH and check that the drive has been mounted successfully:

pi@rock64:~$ df -h | grep sda1
/dev/sda1 1.8T 1002G 739G 58% /media/usb

If your drive is not listed, something went wrong in the configuration. 

Configure SFTP server

Armbian already has a SSH server running, thus you have an SFTP server out of the box. You can try to upload some files to your NAS to check that it is working.

For Windows I recommend WinSCP as SFTP client.  For Android devices I recommend AndFTP.

Configure network drive sharing

Network drive sharing can be made using different network file system protocols, but if you are planning to connect to your NAS with a Windows PC it is recommended that you use the SMB protocol since it is supported on Windows without any additional software. The SMB protocol is enabled on ROCK64 by installing the Samba server.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba samba-common-bin

Edit the samba configuration.

sudo pico /etc/samba/smb.conf

First secure that you have following properties set in smb.conf:

workgroup = WORKGROUP
wins support = yes

Then add following in your smb.conf file:

[USB]
comment=USB
path=/media/usb
browseable=yes
writeable=yes
only guest=no
create mask=0777
directory mask=0777
public=yes

You can replace USB with the name you want for your share. Also if you have a different mount directory than /media/usb, update path configuration accordingly.

Restart the samba service:

sudo service smbd restart

Now you shall be able to access the drive from Windows, by entering following address in Windows File Explorer:

\\192.168.1.104\USB

Replace 192.168.1.104 with the IP of your ROCK64.

You can make Windows map a network drive so that it is always configured by selecting ”Map network drive” in Windows File Explorer, enter the above address and select a drive letter of your choice. 

Configure MediaWEB server

MediaWEB is a small WEB server that enables you to view your images and videos in a WEB browser. By using MediaWEB you will have a quick access to your photos and videos on any device (including mobile devices) and will also be able to access them through Internet (if you configure remote access as described later).

To install MediaWEB copy paste following commands:

export MW_ARCH=arm
mkdir ~/mediaweb
cd ~/mediaweb
curl -s https://api.github.com/repos/midstar/mediaweb/releases/latest \
| grep browser_download_url \
| grep "mediaweb_linux_${MW_ARCH}.tar.gz" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -
tar xvzf mediaweb_linux_${MW_ARCH}.tar.gz
sudo sh service.sh install

You will be prompted for the media path during the installation. Enter:

/media/usb

Or set a different location if you mounted your hard drive in another directory.

Now you can view your images and videos by navigating following location on your PC or mobile WEB browser:

http://192.168.1.104:9834

Replace 192.168.1.104 with the IP of your ROCK64.

Upload some media files to your media directory using SFTP and view them with MediaWEB.

Configure DLNA server

Digital Living Network Alliance (DLNA) is a standard protocol for viewing your media on DLNA enabled devices such as most smart-TVs. In general I recommend MediaWEB to browse and view the images and videos on your NAS from your PC or mobile devices. However on TV sets it is usually simpler to use DLNA.

MiniDLNA is a small DLNA server that works perfectly on ROCK64. To install it:

sudo apt-get install minidlna

Edit the configuration:

sudo pico /etc/minidlna.conf

Edit following configuration:

media_dir=APV,/media/usb/

Or set a different location if you mounted your hard drive in another directory.

Restart MiniDLNA with:

sudo service minidlna restart

Now you should be able to view your media from your DLNA enabled devices (such as your smart-TV). The name of the DLNA server is by default ”rock64: minidlna”.

Internet access to you NAS

To be able to access your NAS over Internet you need to have a fixed WAN IP address or a domain name. For most home users a fixed WAN IP is not offered by your Internet provider. Then you can use fixed domain name from a Dynamic DNS (DDNS) provider. Several DDNS providers exists and some of them are free. For example:

The provider gives you a domain name and the IP address connected to that domain name is updated either by your router or by an application in your network (possibly running on your ROCK64). My ASUS router has a DDNS configuration where you select the DDNS provider, enter domain name, your user name and password. The router will secure that the DDNS provider always has the valid IP address to your network.

You probably want to be able to access your NAS SFTP server and MediaWEB from Internet. 

To do this you need to configure ”port forwarding” in your router. Following port forwarding needs to be configured:

SSH (also used in SFTP):

  • Local / remote port: 22
  • Local IP: IP address of your NAS

MediaWEB

  • Local / remote port: 9834
  • Local IP: IP address of your NAS

Now you will be able to access your NAS with the domain name name. For example (MediaWEB):

http://mydomainname.dyndns.org:9834

Backup and synchronize your files with a remote NAS

What if you have stored all your photos and videos on your NAS and the hard drive crashes? Or even worse, your house burns down to the ground? Many use this as an argument to put all their media in the cloud instead of a local NAS. Don’t worry, you can synchronize all your media with a remote NAS by using the rsync application that is installed out of the box in most Linux installations (including Armbian).

The minimum requirement of the other NAS is that it has SSH that is remotely accessible. 

Lets say you have a friend that also have a Linux based NAS (ROCK64 or something else). Then you should have following directories on your hard drive:

  • friends (i.e. /media/usb/friends)
  • mine (i.e. /media/usb/mine)

All your files are put in mine. The friends folder is just for backup of your friends files.

Your friend has a similar structure, but the friends folder on his/hers NAS is where your backed up files are located.

Before starting to synchronize your file you need to create a public / private key pair on your NAS:

ssh-keygen -t rsa

Keep the default configurations, and don’t enter any pass phrase.

Enter following to view your public key:

pi@rock64:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdFErRTaFWW3K22O3uDfKRokmtv+kgMVQ5itlMFUeCfAcZ6mU8yBIeSqW9nj4GU9mFjf1KonHoGbFkAxmjOE9vX0Sh/2nelqcC5hlM/cdO4EUtlO2HUyM2wrjfME5J2+zl+2N8ltVcGrHju9k9rvUjHGmjjWikca1q9B59v+VnD/jlQuMEyWCA9B0HHWt/TJq5WpY0oAgtJiwjUjQw2c3kJsw93rwF/yXUhyvSiQTJW9urHToDqEXvbrJa4MU2hE1UVGrRnOJ8UkJKvEvX5FUh/vxbRGY9UzyUCIgrjZW9WCbLTZoqtW6xzoEcjLImYVvV69xOA80Xe4qjlHhNxJ7h pi@rock64

The public key above need to be added to the file .ssh/authorized_keys on your friends NAS. When you have added it you should be able to run ssh to your friends NAS without any user name or password:

ssh yourfriendsdomainname.com

Create a script that does to synchronization.

touch /media/usb/sync.sh
pico /media/usb/sync.sh

Put following contents in synch.sh

# Sync my files to my friend
rsync -vraO /media/usb/mine/ myfriendsdomainname.com:/media/usb/friends/

# Sync my friends files to me
rsync -vraO myfriendsdomainname.com:/media/usb/mine/ /media/usb/friends/

Test the script:

sh /media/usb/sync.sh

To automatically run the script at 2 every morning, edit the crontab by entering:

crontab -e

Add following line:

0 2 * * * /media/usb/sync.sh > /media/usb/sync.log 2>&1

Now your files will be synchronized every night. You can see the last synchronization status by viewing the /media/usb/sync.log that is created.

Note that the synchronization is performed only from your NAS. Your friend does not need to use rsync.