04-21-2018, 07:09 AM
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
In my case the drive was connected as /dev/sda
To get more info about the device and the current partitions I used
To use the disk I first had to reparation the disk with fdisk
Once in this “tool” I made following selections
After this I still needed to format the partition and choose a filesystem I have chosen for ext4
To confirm I used following command
2) Before I could use the disk it still needed to be mounted, first I made a folder to mount the disk on
Once the directory is made I could mount the partition to it
To confirm the partition was mounted I used following command
After this I still needed to change the permissions to my rock64 instead of my root user
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
After installing I made a user in samba
Once the user was made I needed to choose a password, after that I added following code to the /etc/samba/smb.conf file
I saved and exited the file and restarted the smbd service
Because im running UFW I also needed to allow samba in UFW with following command
After that I could access my share on my windows machine
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
Once in this “tool” I made following selections
To make the software raid in linux I used MDADM, so I installed this
Once installed I created a RAID1 with the last added disk and a “missing” disk
After this I still needed to format the partition and choose a filesystem I have chosen for ext4
Before I could use the RAID it still needed to be mounted, first I made a folder to mount the RAID on
Once the directory is made I could mount the partition to it
To confirm the partition was mounted I used following command
After this I still needed to change the permissions to my rock64 user instead of my root user
Now I needed to copy al the files from my hdd0 to my raid
Once this was don I could reparation my hdd0 again
Once in this “tool” I made following selections
Once the disk was again clean I could add it to my raid
To follow the process of the disk syncing I used
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
I saved and exited the file and restarted the smbd service
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
Because I don’t want to use my password every time I would connect to my backupserver I made a ssh-key
when asked for a passphrase I leaved it empty, now the ssh key file is made I copied it to my backup server
Before I could use the backupserver it still needed to be mounted, first I made a folder to mount the backupserver on
Once the directory is made I could mount the sshfs to it
To confirm the partition was mounted I used following command
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
To make sure I could use webdav i ranned
And answerd “YES” after that I added root and rock64 to the group
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
To make sure the file haves the right permissions I did
Before I could use the cloud it still needed to be mounted, first I made a folder to mount the cloud on
Once the directory is made I could mount the davfs to it
To confirm the partition was mounted I used following command
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
To find the UUID of md0 I used
To mount the webdav I still always have to give following code to get mounted after a reboot
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.
Since I also don’t want to backup manually I enter following command in the crontab
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.
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
To get more info about the device and the current partitions I used
Code:
$ sudo fdisk -l /dev/sda
Code:
$ sudo fdisk /dev/sda
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
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
Code:
$ sudo mount /dev/sda1 /media/hdd0
Code:
$ lsblk
Code:
$ sudo chown -R rock64:rock64 /media/hdd0/
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
Code:
$ sudo smbpasswd -a rock64
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
Code:
$ sudo service smbd restart
Code:
$ sudo ufw allow samba
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
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
Code:
$ sudo apt-get install mdadm
Code:
$ sudo mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sda1 missing
Code:
$ sudo mkfs.ext4 /dev/md0
Code:
$ sudo mkdir /media/raid
Code:
$ sudo mount /dev/md0 /media/raid
Code:
$ lsblk
Code:
$ sudo chown -R rock64:rock64 /media/raid/
Code:
$ sudo cp -a /media/hdd0/ /media/raid/
Code:
$ sudo fdisk /dev/sdb
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
Code:
$ sudo mdadm /dev/md0 --add /dev/sdb1
Code:
$ watch cat /proc/mdstat
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
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
Code:
$ sudo ssh-keygen -t rsa
Code:
$ sudo ssh-copy-id -I ~/.ssh/id_rsa.pub root@192.168.178.32
Code:
$ sudo mkdir /media/backup
Code:
$ sudo sshfs root@192.168.178.32:/data/Backup /media/backup/
Code:
$ sudo df -h
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
Code:
$ sudo dpkg-reconfigure davfs2
Code:
$ sudo usermod -a -G davfs2 root
$ sudo usermod -a -G davfs2 rock64
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
Code:
$ sudo chmod 600 /etc/davfs2/secrets
$ sudo chown root:root /etc/davfs2/secrets
Code:
$ sudo mkdir /media/stack
Code:
$ sudo mount -t davfs https://mikedhoore.stackstorage.com/remote.php/webdav/ /media/stack
Code:
$ sudo df -h
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
Code:
$ lsblk
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
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
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.