Rock64 Webserver / NAS project
#1
Star 
First, I would like to introduce myself briefly. I am Mike, 26 years old and I’m currently studying at Erasmus University College in Brussels.
For a lesson "Trends & Talents" I must develop a project independently that is not given in another lesson. I already started another post before deciding to use this project as my school project ( https://forum.pine64.org/showthread.php?tid=5132 ).

The main idea is to build a Linux server with 2 main goals, a web server and a personal NAS(mainly for home use).

Web server
For now I own a domain name with a web hosting and no SSL.

I will install and configure Apache, MariaDB and PHP to run my HTML/PHP website, additional I will install tomcat and java to run my java projects.
I will use Let’s encrypt and Certbot to handle the SSL/TLS-certificates to make sure that all the traffic uses the safer HTTPS protocol.
 
NAS
Now I own a Netgear Readynas 102 with 2x3TB WD red disks, this to share my files in my home network. My Readynas is synced with a Cloud service through my Laptop.

The 2x3TB disk will be connected to the Rock with 2 “USB 3.0 to SATA III HARD DRIVE ADAPTER CABLE/ CONVERTER with UASP” cables connected to a USB 3.0 hub. I will install and configure SAMBA to share the drives in my home network over the Gigabit ethernet port.
The drives will be synced to the cloud directly from the Rock (Encrypted or not encrypted, not sure yet)

I will use a 4GB version with Debian Stretch Minimal Community Build Image by ayufan.

Most of the hardware is already ready and I’m now playing and testing with the software for the last 3 months, step by step I will post the made progress.

I will use this board to post my progress and hopefully to receive tips, tricks and feedback from you, the readers, I’ll try to share everything like schematics, scripts and step by step explanation how I installed or configured scripts and/or software.
  Reply
#2
First, I started building the rock64 and all its hardware in a case,
I also made a PCB to connect the GPIO pins to additional hardware like a TFT screen, a fan, RGB strips, …
(Since there are only 10 images allowed per post I replaced some images by the word Image.

I started with making a PVC plate to support the rock64 and other pcb’s.
I closed the back openings with a plexiglass plate so that I could screw the extension cord to it.
[Image: 20170927_165359.jpg] Image

After that I attached the power supply on the bottom plate of the case.
[Image: 20171029_154936.jpg] Image

With some resistors and transistors I made the RGB led strip to work,
with hot glue I made a 45° profile for the RGB strip also have I soldered a cable to the stripes to connect to the self-made PCB.
Image Image [Image: 20171101_120848.jpg]

Build in a 2.4” LCD screen for later on.
[Image: 20171103_164035.jpg] Image

Making openings in the back plate to attach the extension cords.
Image [Image: 20171108_144849.jpg]

Etching and soldering my own PCB.
Image Image [Image: 20171215_123315.jpg] Image

Making the power and signal cables myself.
[Image: 20171111_130439.jpg] Image Image

Made a plexiglass case to coverup the 220V part.
Image [Image: 20180120_190420.jpg]

Schematics of the PCB
Image [Image: Schematic.png]
Download link of the Eagle project : https://mikedhoore.stackstorage.com/s/flyba19r25RlVyX

The final result  
[Image: 20180220_203004.jpg]


The album to see more photos: https://ibb.co/album/mpWuLa

Used hardware
ThermalTake Core V1 Case (Amazon.com)
PVC and Plexi plates (laying around in my hobby room)
2x 10cm RGB led strip (laying around in my hobby room)
Rock64 4GB (Pine64.org)
64GB eMMC (Pine64.org)
Serial console (Pine64.org)
USB 2.0 male to female extension cable (laying around in my hobby room)
Micro SD to eMMC converter (ameridroid.com)
Heatsink 20x20x10mm (ebay.com)
50W dual power supply (ebay.com)
2.4” LCD screen (ebay.com)
USB 3.0 A to 20 Pin header cable (ebay.com)
HDMI extension cable (ebay.com)
2x RJ45 extension cable (ebay.com)
Dual USB 2.0 extension cable (ebay.com)
USB 3.0 hub (ebay.com)
White Nylon spacer M2.5 (ebay.com)
White Nylon screw  M2.5 (ebay.com)
Panel Mount Rocker Switch Fuse Holder Power Socket (ebay.com)
2x 3.5mm power jack for rock64 and usb3.0 hub (laying around in my hobby room)
2x 5.5mm power jack for USB to SATA cable (laying around in my hobby room)
2x USB 3.0 to SATA III CABLE with UASP (Pine64.org)
Cables, screws, Heat shrink tubing, … (laying around in my hobby room)
Custom made PCB (Made in my school)

Used GPIO pins
GPIO 1: RGB-strip Red (PWM) (P5+ / pin 10 / GPIO2_B7 / 79)
GPIO 2: RGB-strip Green (PWM) (P5+ / pin 12 / GPIO2_C4 / 84)
GPIO 3: RGB-strip Blue (PWM) (P5+ / pin 14 / GPIO2_C6 / 86)
GPIO 4: FAN (PWM) (P5+ / pin 4 / GPIO2_C2 / 82)
GPIO 5: FAN (IN RPM) (P5+ / pin 6 / GPIO2_C3 / 83)
GPIO 6: LED Case power (OUT) (P5+ / pin 3 / GPIO2_C1 / 81)
GPIO 7: LED Case HDD (OUT) (P5+ / pin 5 / GPIO2_C7 / 87)
GPIO 8: Switch Case power (IN) (P5+ / pin 9 / GPIO2_C0 / 80)
GPIO 9: Switch Case reset (IN) (P5+ / pin 11 / GPIO2_C5 / 85)
GPIO 10: LCD led background (PWM)
SPI TXD: LCD
SPI RXD: LCD
SPI CLK: LCD
SPI CSN0: LCD
SPI CSN1: LCD
UART TX: serial-usb (Pi-2 / pin 8)
UART RX: serial-usb (Pi-2 / pin 10)
Ethernet RD+ (P5+ / pin 17 )
Ethernet RD- (P5+ / pin 18 )
Ethernet TX+ (P5+ / pin 19 )
Ethernet TX- (P5+ / pin 20 )
5V (P5+ / pin 2)
GND (P5+ / pin 7)
3.3V (P5+ / pin 1)
  Reply
#3
To get started with the rock64 I first did some "Basic" configuration

1)     First of all I used etcher to burn the image on the eMMC with a µSD to eMMC converter.
        etcher : https://www.etcher.io
        Image : https://github.com/ayufan-rock64/linux-build/releases/latest (i have chosen Stretch minimal)
        µSD to eMMC : https://ameridroid.com/products/emmc-adapter
        
2)    After that I connected the board to the serial console and opened a terminal with putty
        Howto connect : https://forum.pine64.org/showthread.php?tid=5029
        PuTTY : https://www.putty.org/
        
3)    Once connected the first thing I did was change the host name
        HowTo : https://forum.pine64.org/showthread.php?...0#pid30220
        Reboot for changes to take effect
        
4)    Then I changed the password for rock64 user and root user
        For rock64 user :     
Code:
$ passwd
        For root user :        
Code:
$ sudo passwd root
        
5)    To make sure I have a fixed IP address I configured following file like this
        File : /etc/network/interfaces.d/eth0
Code:
allow-hotplug eth0
iface eth0 inet static
address 192.168.178.250
netmask 255.255.255.0
gateway 192.168.178.1
dns-nameservers 8.8.8.8 192.168.178.1
After saving the file I disabled the dhcp services with following code(to prevent IP-aliasing)    
Code:
$ sudo systemctl disable dhcpcd.service
Reboot for changes to take effect
        
6)    At last I updated the rock64 with following command to make sure that all services that are running on the system are the latest version
Code:
$ sudo apt-get update
$ sudo apt-get upgrade     
        
So far for the "Basic" configuration
  Reply
#4
PINE64 moderators and developers meet up at Brussels on first week of February annual for FOSDEM event and looking forward to meet up with you on FOSDEM 2019. Keep up on your good work and beer on me.
  Reply
#5
(04-02-2018, 09:44 PM)tllim Wrote: PINE64 moderators and developers meet up at Brussels on first week of February annual for FOSDEM event and looking forward to meet up with you on FOSDEM 2019. Keep up on your good work and beer on me.

Thanks Smile
I am already looking forward to it and i will certainly be present  Big Grin
  Reply
#6
After the “Basic” configuration I got started with my webserver part,

1)     First, I started installing Apache
Code:
$ sudo apt install apache2
You can check this is working by surfing in your web browser to the IP address of your rock.
 

2)     Once this was working I installed Maria DB to have a database if needed     
Code:
$ sudo apt install mariadb-server
        The database server needs to be secured, I have done this by following command
       
Code:
$ sudo mysql_secure_installation
        Then I got some question :
                       Set root password [Y/n]                          Answer yes and set password
                       Remove anonymous users? [Y/n]           Answer yes
                       Disallow root login remotely? [Y/n]          Answer yes
                       Remove test DB an access to it? [Y/n]    Answer yes
                       Reload privilege tables now? [Y/n]           Answer yes
        You can check this is working with following commands
Code:
$ sudo mysql – u root -p
MariaDB [(none)]> show database;
MariaDB [(none)]> exit 
 

3)     After that I installed PHP with following command
Code:
$ sudo apt install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-gd php7.0-opcache
        For this to take effect I restarted the apache server with following command
       
Code:
$ sudo systemctl restart apache2
        To check if PHP is working correctly I deleted the index.html file from the html folder and made a new index.php file with the phpinfo function
       
Code:
$ sudo rm /var/www/html/index.html
$ sudo nano /var/www/html/index.php
//Add following code in the index.php
<?php phpinfo(); ?>        
        You can check this is working by surfing in your web browser to the IP address of your rock.
 

4)     To add some extra security I installed a firewall to block all open ports on the rock 
Code:
$ sudo apt install ufw
        Of course not all our ports have to be blocked or the webserver cannot be accessed, I allowed next ports : 22 for SSH access, 80 for http access and 443 for https access.
       
       
Code:
$ sudo ufw allow 22
$ sudo ufw allow 80
$ sudo ufw allow 443       
        After entering thes ports I started up UFW
       
Code:
$ sudo ufw enable
        To check the open ports
       
Code:
$ sudo ufw status verbose
 

Used resource for 1 to 4 is https://www.cyberciti.biz/faq/how-to-ins...9-stretch/
 

5)     To make access to the database easier I installed phpMyAdmin with following command   
Code:
$ sudo apt install phpMyAdmin
        While installing I got some questions:
        Web server to reconfigure?                                                     Chose apache2
        Config DB for phpMyAdmin with dbconfig-common?               Choose Yes
        Password of the DB admin user                                               Give the root password from MariaDB install
        MySQL app password for phpMyAdmin                                   Choose a password (this doesn’t need to be same as the root but it can)
        This completes the installation, then I still had to configure phpMyAdmin to Apache
       
Code:
$ sudo nano /etc/apache2/apache2.conf
//Add following code to the bottom of apache2.conf
Include /etc/phpmyadmin/apache.conf        
        Next I granted full access to the user phpMyAdmin in MariaDB so that I could connect to the DB outside “localhost”
       
Code:
$ sudo mysql – u root -p
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit       
        Then I restarted apache for the changes to take effect
       
Code:
$ sudo /etc/init.d/apache2 restart
        You can check this is working by surfing in your web browser to the IP address of your rock and adding /phpmyadmin to the IP address (example : 192.168.178.250/phpmyadmin)

Used resource for 5 is https://pimylifeup.com/raspberry-pi-mysql-phpmyadmin/


6)     Most of my projects I write are in Java so I needed to install Java and of course a tomcat server, first of all I started installing Oracle Java on my Rock (at the moment of installing 8u162 was the latest version, u will need to check http://www.oracle.com/technetwork/java/j...33151.html to see what is now the latest version and change the command accordingly )
Code:
$ sudo wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/jdk-8u162-linux-arm64-vfp-hflt.tar.gz
$ sudo tar -zxvf jdk-8u162-linux-arm64-vfp-hflt.tar.gz
$ sudo mv jdk1.8.0_162/ /usr/
$ sudo rm jdk-8u162-linux-arm64-vfp-hflt.tar.gz
$ sudo update-alternatives --install /usr/bin/java java /usr/jdk1.8.0_162/bin/java 2
$ sudo update-alternatives --config java        
        To verify the installation I checked the Java version
       
Code:
$ java -version
        At last I have set up the Environmental Variable’s in /etc/profile
       
Code:
$ sudo nano /etc/profile
//Added following code to the bottom of /etc/profile
export JAVA_HOME=/usr/jdk1.8.0_162/
export JRE_HOME=/usr/jdk1.8.0_162/jre/
export PATH=$JAVA_HOME/bin:$PATH      


7)     After installing Java we need a server to run Java projects, I installed tomcat 8 (at the moment of installing v8.5.28 was the latest version, you will need to check http://www-us.apache.org/dist/tomcat/ to see what is now the latest version and change the command accordingly )
        I started with making a low-privilege user to run the tomcat service
Code:
$ sudo groupadd tomcat
$ sudo mkdir /opt/tomcat
$ sudo useradd -g tomcat -d /opt/tomcat -s /bin/nologin tomcat       
        Then I downloaded and installed tomcat server
       
Code:
$ sudo wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.28/bin/apache-tomcat-8.5.28.tar.gz
$ sudo tar -zxvf apache-tomcat-*.tar.gz
$ sudo mv apache-tomcat-8.5.28/* /opt/tomcat/
$ sudo rm  apache-tomcat-8.5.28.tar.gz
$ sudo chown -R tomcat:tomcat /opt/tomcat/        
        After installing I manual started tomcat with
       
Code:
$ sudo sh /opt/tomcat/bin/startup.sh
//To stop tomcat manual use
$ sudo $ sudo sh /opt/tomcat/bin/shutdown.sh        
        Because it’s not user friendly to start tomcat on each reboot cycle I added a system service
       
Code:
$ sudo nano /etc/systemd/system/tomcat.service
//I added following code to the new file tomcat.service
[Unit]
Description=Apache Tomcat 8.x Web Application Container
Wants=network.target
After=network.target
     
[Service]
Type=forking
       
Environment=JAVA_HOME=/usr/jdk1.8.0_162/
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true'
Environment='JAVA_OPTS=-Djava.awt.headless=true'
      
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
SuccessExitStatus=143
       
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
       
[Install]
WantedBy=multi-user.target    
        For this system service file to work I needed to restart system daemon and then enable the service.
       
Code:
$ sudo systemctl daemon-reload
$ sudo systemctl enable tomcat    
        Now I can start tomcat with the following commands
       
Code:
$ sudo systemctl start tomcat
//To see the status of the service I can run the command
$ sudo systemctl status tomcat    
        To have access to the web GUI I needed to make an user in tomcat-user.xml
       
Code:
$ sudo nano /opt/tomcat/conf/tomcat-users.xml
// Add following code just above </tomcat-users>
<role rolename="admin-gui,manager-gui"/>
<user username="admin" password="XXX" roles="manager-gui,admin-gui"/> 
        The Tomcat admin web GUI is standard made to only allow access from the local host, since I’m using a headless system I need add some extra code so I can access the admin web GUI, I needed to change 2 files
       
Code:
$ sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
//Change         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />     To
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.178.*" />
$ sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
//Change         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />     To
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.178.*" />      
        I added |192.168.178.* so I’m not able to enter the admin web GUI when I’m not home, to make It’s accessible from anywhere you can add only |*
        Before the changes take effected I needed to restart my tomcat server
       
Code:
$ sudo systemctl restart tomcat
        Because I’m using UFW firewall I first had to add port 8080 to UFW and reload UFW
       
Code:
$ sudo ufw allow 8080
$ sudo ufw reload       
        You can check this is working by surfing in your web browser to the IP address of your rock and adding :8080 to the IP address (example : 192.168.178.250:8080)
Used resource for 6 and 7 is https://www.itzgeek.com/how-tos/linux/de...nt-18.html


8)     Because I don’t want to let my user surf to mydomain.com:8080 I wanted to link a subdomain to the tomcat server(Java) and my main domain the apache server(html and php), this is done by adding a proxy to mine .conf file in apache      
Code:
$ sudo nano /etc/apache2/sites-available/000-default.conf
//Add following code the bottom of the file
<VirtualHost *:80>
ServerAdmin mike@mikedhoore.be
ServerName java.mikedhoore.be
ServerAlias www.java.mikedhoore.be
ProxyPreserveHost On
       
# setup the proxy
<Proxy *>
      Order allow,deny
      Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>        
        I also changed the ServerName and Alias from the original virtual host to
       
Code:
ServerName mikedhoore.be
ServerAlias www.mikedhoore.be        
        After adding this code I still needed to activate proxy in apache and restart the apache server
       
Code:
$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo service apache2 restart        
        Of course I also made the corresponding DNS records.
 
Used resource for 8 https://serverfault.com/questions/195611...ame-server
 
So now I have a working apache server that can run HTML and PHP on my main domain and a tomcat server that can run Java on a subdomain, both can access my database and I can easy access my database in a web GUI.
At last I also will implement HTTPS access, but I’m waiting for CertBot to implement wildcards in Apache.
  Reply
#7
Ones the webserver was up and running I started installing / configuring my NAS part of my Rock64 project.

1)      First, I started by installing 1 HDD to the rock64 over USB 3.0 with the USB3.0 to SATA cable from the web shop here. ( https://www.pine64.org/?product=usb-3-0-...-with-uasp )
To confirm the drive was recognized I used following command
Code:
$ lsblk
In my case the drive was connected as /dev/sda
To get more info about the device and the current partitions I used
Code:
$ sudo fdisk -l /dev/sda
To use the disk I first had to reparation the disk with fdisk
Code:
$ sudo fdisk /dev/sda
Once in this “tool” I made following selections

Code:
m --> To show the full menu
g --> To create a new and empty GPT partition table
n --> To make a new partition
1 --> To give the partition number
enter --> To choose the default first sector
enter --> To choose the default last sector
w --> To save the changes and exit

After this I still needed to format the partition and choose a filesystem I have chosen for ext4
Code:
$ sudo mkfs.ext4 /dev/sda1
To confirm I used following command
Code:
$ sudo lsblk -fs
 

2)      Before I could use the disk it still needed to be mounted, first I made a folder to mount the disk on
Code:
$ sudo mkdir /media/hdd0
Once the directory is made I could mount the partition to it
Code:
$ sudo mount /dev/sda1 /media/hdd0
To confirm the partition was mounted I used following command
Code:
$ lsblk
After this I still needed to change the permissions to my rock64 instead of my root user
Code:
$ sudo chown -R rock64:rock64 /media/hdd0/
After this I could make directory’s and files in the disk
 

Used resource for 1 and 2 https://forum.pine64.org/showthread.php?tid=4925
 

3)      Because I want to use the disk as a NAS I needed to share the folder, since I have mostely windows and android machines in my home network I used SMB
First of all I installed SAMAB on the Rock64
Code:
$ sudo apt-get install samba
After installing I made a user in samba
Code:
$ sudo smbpasswd -a rock64
Once the user was made I needed to choose a password, after that I added following code to the /etc/samba/smb.conf file
Code:
$ sudo nano /etc/samba/smb.conf
// Added following code to the bottom of the file
[hdd0]
path = /media/hdd0
available = yes
valid users = rock64
read only = no
browsable = yes
public = yes
writable = yes
I saved and exited the file and restarted the smbd service
Code:
$ sudo service smbd restart
Because im running UFW I also needed to allow samba in UFW with following command
Code:
$ sudo ufw allow samba
After that I could access my share on my windows machine Big Grin
 

Used resource for 3 https://www.howtogeek.com/176471/how-to-...and-linux/
 

4)      After a few days I decide to add my second disk to the rock and make a software raid, I shutdown the rock and unplugged the first disk, plugged in a usb3.0 hub and connected the previous disk and the second disk to the hub. Once rebooted I noticed my first disk was now under /dev/sdb and the last connected disk was under /dev/sda.
So now I wanted to make a RAID1 but I didn’t want to lose my data on the previous disk.
First of all I partitioned the newly added disk
Code:
$ sudo fdisk /dev/sda
Once in this “tool” I made following selections

Code:
m --> To show the full menu
g --> To create a new and empty GPT partition table
n --> To make a new partition
1 --> To give the partition number
enter --> To choose the default first sector
enter --> To choose the default last sector
w --> To save the changes and exit
To make the software raid in linux I used MDADM, so I installed this
Code:
$ sudo apt-get install mdadm
Once installed I created a RAID1 with the last added disk and a “missing” disk
Code:
$ sudo mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sda1 missing
After this I still needed to format the partition and choose a filesystem I have chosen for ext4
Code:
$ sudo mkfs.ext4 /dev/md0
Before I could use the RAID it still needed to be mounted, first I made a folder to mount the RAID on
Code:
$ sudo mkdir /media/raid
Once the directory is made I could mount the partition to it
Code:
$ sudo mount /dev/md0 /media/raid
To confirm the partition was mounted I used following command
Code:
$ lsblk
After this I still needed to change the permissions to my rock64 user instead of my root user
Code:
$ sudo chown -R rock64:rock64 /media/raid/
Now I needed to copy al the files from my hdd0 to my raid
Code:
$ sudo cp -a /media/hdd0/  /media/raid/
Once this was don I could reparation my hdd0 again
Code:
$ sudo fdisk /dev/sdb
Once in this “tool” I made following selections
Code:
m --> To show the full menu
g --> To create a new and empty GPT partition table
n --> To make a new partition
1 --> To give the partition number
enter --> To choose the default first sector
enter --> To choose the default last sector
w --> To save the changes and exit
Once the disk was again clean I could add it to my raid
Code:
$ sudo mdadm /dev/md0 --add /dev/sdb1
To follow the process of the disk syncing I used
Code:
$ watch  cat /proc/mdstat
And after a few hours my disk where synced and I had a software RAID1
The only thing I needed to extra was change the /etc/samba/smb.conf file
Code:
$ sudo nano /etc/samba/smb.conf
// Added following code to the bottom of the file
[raid]
path = /media/raid
available = yes
valid users = rock64
read only = no
browsable = yes
public = yes
writable = yes
I saved and exited the file and restarted the smbd service
Code:
$ sudo service smbd restart
 

Used resource for 4 https://unix.stackexchange.com/questions/281654/convert-a-non-boot-single-hdd-to-raid-1-without-deleting-it
 

5)      The disks I used in my rock64 came from an old Readynas 102, now I had the idea to use this readynas as a backup for my Rock. First I installed sshfs
Code:
$ sudo apt-get install sshfs
Because I don’t want to use my password every time I would connect to my backupserver I made a ssh-key

Code:
$ sudo ssh-keygen -t rsa
when asked for a passphrase I leaved it empty, now the ssh key file is made I copied it to my backup server
Code:
$ sudo ssh-copy-id -I ~/.ssh/id_rsa.pub root@192.168.178.32
Before I could use the backupserver it still needed to be mounted, first I made a folder to mount the backupserver on
Code:
$ sudo mkdir /media/backup
Once the directory is made I could mount the sshfs to it
Code:
$ sudo sshfs root@192.168.178.32:/data/Backup /media/backup/
To confirm the partition was mounted I used following command
Code:
$ sudo df -h
After that my backup server was mounted and I could access it from inside my rock and copy files to it under the root user
 

Used resource for 5 https://www.cyberciti.biz/faq/how-to-mou...-on-linux/
 

6)      I also wanted an off-site backup in the cloud, since my cloud service only support webdav I needed to configure it as a davfs, first of all I installed davfs2
Code:
$ sudo apt-get install davfs2
To make sure I could use webdav i ranned
Code:
$ sudo dpkg-reconfigure davfs2
And answerd “YES” after that I added root and rock64 to the group
Code:
$ sudo usermod -a -G davfs2 root
$ sudo usermod -a -G davfs2 rock64
Because I don’t want to use my password every time I would connect to my cloud I saved my credentials in the file ~/.davfs2/secrets
Code:
$ sudo nano ~/.davfs2/secrets
// Added following code to the bottom of the file
#Stack by transIP
https://mikedhoore.stackstorage.com/remote.php/webdav mikedhoore MyPass
To make sure the file haves the right permissions I did
Code:
$ sudo chmod 600 /etc/davfs2/secrets
$ sudo chown root:root /etc/davfs2/secrets
Before I could use the cloud it still needed to be mounted, first I made a folder to mount the cloud on
Code:
$ sudo mkdir /media/stack
Once the directory is made I could mount the davfs to it
Code:
$ sudo mount -t davfs https://mikedhoore.stackstorage.com/remote.php/webdav/ /media/stack
To confirm the partition was mounted I used following command
Code:
$ sudo df -h
After that my backup server was mounted and I could access it from inside my rock and copy files to it.
 

Used resource for 6 https://ajclarkson.co.uk/blog/auto-mount...pberry-pi/ and https://wiki.archlinux.org/index.php/Davfs2
 

7)      After a reboot the made mounts from raid, backup and stack disappeared so I needed to save them in /etc/fstab
Code:
$ sudo nano /etc/fstab
// Added following code to the bottom of the file
UUID=f995d3c4-c9e3-48bc-a021-e099200308f6 /media/raid ext4 defaults 0 0

root@192.168.178.32:/data/Backup /media/backup fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/rock64/.ssh/id_rsa,allow_other,default_permissions,uid=1000,gid=1000 0 0
 
https://mikedhoore.stackstorage.com/remote.php/webdav/ /media/stack davfs x-systemd.requires=network.target,auto,nouser 0 0
To find the UUID of md0 I used
Code:
$ lsblk
To mount the webdav I still always have to give following code to get mounted after a reboot
Code:
$ sudo mount -a
 

Used resource for 7 https://www.howtogeek.com/howto/38125/ht...s-it-work/
 

8)      Since I only want to back up the files that are changed I used rsync to back up from my rock to my backup server and cloud so I stared by installing rsync.

Code:
$ sudo apt-get install rsync
Since I also don’t want to backup manually I enter following command in the crontab
Code:
$ sudo crontab -e
// Added following code to the bottom of the file
#Rsync every hour from raid(sda1 + sdb1 = md0) to backup(sshfs)
10 * * * * rsync -avzh /media/raid/ /media/backup/ >> /var/log/Mike/rsyncBackup.log
#Rsync every day from raid(sda1 + sdb1 = md0) to Stack cloud
0 3 * * * rsync -avzh /media/raid/ /media/stack/BACKUP_NAS/ >> /var/log/Mike/rsyncStack.log
So now my rock backups every hour to my backup server and once a day to my cloud also the results are written in .log files
 

Used resources for 8 https://www.tecmint.com/rsync-local-remo...-commands/ and https://kvz.io/blog/2007/07/29/schedule-...g-crontab/
 

 
After all this I now have a working NAS that I can access in my home network over SMB, it also backups on premises and off premises in the cloud.
  Reply
#8
I also written some scripts for the GPIO pins first off all I wrote a script to initialize all the pins that I have connected

Code:
#!/bin/sh
#RED - RGB-strip
echo 79 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio79/direction
#BIG - Case Button
echo 80 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio80/direction
#POWER - Case Led
echo 81 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio81/direction
#FAN - Case fan
echo 82 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio82/direction
#RPM_FAN - Case fan
echo 83 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio83/direction
#GREEN - RGB-strip
echo 84 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio84/direction
#SMALL - Case Button
echo 85 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio85/direction
#BLUE - RGB-strip
echo 86 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio86/direction
#HDD - Case Button
echo 87 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio87/direction


To test all these pins I also wrote a script
Code:
#!/bin/bash
#MikeD
#Test all pins in use
LOOPS=5
ON_TIME=.5
OFF_TIME=.25
echo " "
echo " _________________________ "
echo "|                         |"
echo "|  Test script  voor I/O  |"
echo "|  ***** BY MIKE D. ****  |"
echo "|-------------------------|"
echo "|      ~~ INPUTS ~~       |"
echo "| BIG =" `cat /sys/class/gpio/gpio80/value` "                |"
echo "| SMALL =" `cat /sys/class/gpio/gpio85/value` "              |"
echo "| RPM_FAN =" `cat /sys/class/gpio/gpio83/value` "            |"
echo "| PRESS BIG button        |"
while [ `cat /sys/class/gpio/gpio80/value` -gt 0 ]; do
sleep .1
done
echo "| BIG == OK !             |"
echo "| PRESS SMALL button      |"
while [ `cat /sys/class/gpio/gpio85/value` -gt 0 ]; do
sleep .1
done
echo "| SMALL == OK !           |"
echo "| Rotate case fan         |"
while [ `cat /sys/class/gpio/gpio83/value` -gt 0 ]; do
sleep .1
done
echo "| RPM_FAN == OK           |"
echo "|-------------------------|"
echo "|   ~~ ALL INPUTS OK ~~   |"
echo "|-------------------------|"
echo "|     ~~ OUTPUTS ~~       |"
echo "| RED - RGB-strip         |"
read -p "| Press enter to toggle   |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio79/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio79/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| GREEN - RGB-strip       |"
read -p "| Press enter to toggle   |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio84/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio84/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| BLUE - RGB-strip        |"
read -p "| Press enter to toggle   |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio86/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio86/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| FAN - Case-fan          |"
read -p "| Press enter to toggle   |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio82/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio82/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| POWER - Case-led        |"
read -p "| Press enter to toggle   |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio81/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio81/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| HDD - Case-led          |"
read -p "| Press enter to toggle   |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio87/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio87/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "|-------------------------|"
echo "|  ~~ ALL OUTPUTS OK ~~   |"
echo "|-------------------------|"
echo "|  ***** BY MIKE D. ****  |"
echo "|_________________________|"
echo " "


At last I wrote a script to power my fan in function of the temperature
Code:
#!/bin/bash
#MikeD Automatic fan on cpu temp
 
CHECK_TIME=10 #IN SEC
 
function pwm(){
LOOP=0
while [ $LOOP -lt $(($CHECK_TIME*75)) ]; do
        echo 1 > /sys/class/gpio/gpio82/value
        sleep $1
        echo 0 > /sys/class/gpio/gpio82/value
        sleep $2
        LOOP=$(($LOOP+1))
done
}
 
function fanOff() {
                echo 0 > /sys/class/gpio/gpio82/value
                sleep $CHECK_TIME
}
 
function fanTweFiv() {
                pwm .025 .075
}
 
function fanFifty() {
                pwm .050 .050
}
 
function fanSevFiv() {
                pwm .075 .025
}
 
function fanFull() {
                echo 1 > /sys/class/gpio/gpio82/value
                sleep $CHECK_TIME
}
 
while [ 1 ]; do
        TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
 
if [ $TEMP -le 20000 ]
then
                fanOff
fi
 
if [ $TEMP -gt 20000 -a $TEMP -le 25000 ]
then
                fanTweFiv
fi
 
if [ $TEMP -gt 25000 -a $TEMP -le 35000 ]
then
                fanFifty
fi
 
if [ $TEMP -gt 35000 -a $TEMP -le 45000 ]
then
                fanSevFiv
fi
 
if [ $TEMP -gt 45000 ]
then
                fanFull
fi
 
done
  Reply
#9
@ mikedhoore

- How stable has this setup been for you? Especially around the x2 hdd's on your USB 3.0 hub?
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are HW design files available for ROCK64? irenek 3 6,201 12-11-2023, 09:31 PM
Last Post: tllim
  Rock64 is unreliable after 3 years of service - power problem? ReleaseTheGeese 0 611 11-23-2023, 05:05 AM
Last Post: ReleaseTheGeese
  Rock64 PoE compatbility with Pi4 Hatt recent Single Board Computer offering from PINE kharak 1 1,500 04-26-2023, 11:38 PM
Last Post: tllim
  Case for the rock64 that supports the POE hat. o1CRiMSON1o 0 865 03-21-2023, 03:48 PM
Last Post: o1CRiMSON1o
Brick Rock64 usb2.0 Power Control Floating GPIO Tutorial Files & Notes MarkHaysHarris777 6 14,552 01-15-2023, 10:36 AM
Last Post: ds00
  rock64 totally brick dakobg 2 2,312 11-07-2022, 05:45 PM
Last Post: olivercfc
  3D-Printable Button Pegs for the ROCK64 Aluminium Case CounterPillow 2 4,078 08-04-2022, 01:31 AM
Last Post: Vicky Weimann PhD
  Where can I find the ROCK64 POE HAT Zoz 2 3,331 06-08-2022, 12:44 AM
Last Post: Zoz
Smile wooden case for ROCK64 killor 13 18,419 03-04-2022, 06:56 AM
Last Post: killor
  1wire DS18b20 on Rock64? mypineme 6 8,244 09-28-2021, 03:07 PM
Last Post: TRS-80

Forum Jump:


Users browsing this thread: 6 Guest(s)