{"id":330,"date":"2019-05-10T22:38:17","date_gmt":"2019-05-11T06:38:17","guid":{"rendered":"http:\/\/www.skifactz.com\/wifi\/?p=330"},"modified":"2019-05-11T21:19:28","modified_gmt":"2019-05-12T05:19:28","slug":"orange-pi-nas","status":"publish","type":"post","link":"https:\/\/www.skifactz.com\/wifi\/?p=330","title":{"rendered":"Orange Pi NAS"},"content":{"rendered":"<p>You can spend upwards of $200 on a home Network Attached storage (NAS) or you can build one using spare parts like I did. Not only the DIY solution is cheaper, but it also allows you to customize the NAS to meet your needs.<\/p>\n<p>It&#8217;s also a great way to learn how all this stuff works. This tutorial covers the hardware assembly and installation of all necessary software.<\/p>\n<p>You should be familiar with Linux, but beginners can follow the steps with an occasional Google cross reference.<\/p>\n<p>Unless you&#8217;re logged in as the root user you will need to prepend many of the commands with sudo, i.e. \u201csudo nano \/etc\/network\/interfaces \u201d to temporarily grant yourself superuser privileges.<\/p>\n<h1>The Hardware Build<\/h1>\n<p>The parts list:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.orangepi.org\/orangepione\/\">Orange Pi One<\/a><\/li>\n<li>2.5&#8243; SSD<\/li>\n<li>Pressboard<\/li>\n<li>screws, PVC spacers, zip tie<\/li>\n<\/ul>\n<p>Orange Pi One does not support USB 3. <strong>Read Disk I\/O<\/strong> below for data transfer rates.<\/p>\n<figure id=\"attachment_327\" aria-describedby=\"caption-attachment-327\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_mounting_plate.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-327\" src=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_mounting_plate-300x225.jpg\" alt=\"Orange Pi Case Alternative\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_mounting_plate-300x225.jpg 300w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_mounting_plate-768x576.jpg 768w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_mounting_plate.jpg 1000w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-327\" class=\"wp-caption-text\">Mounting plate for Orange Pi and SSD<\/figcaption><\/figure>\n<p>I gave up on using a premade <a href=\"https:\/\/usa.banggood.com\/Orange-Pi-ABS-Transparent-Case-For-Orange-Pi-PC-p-1026176.html?gmcCountry=US&amp;currency=USD&amp;createTmp=1&amp;utm_source=googleshopping&amp;utm_medium=cpc_bgcs&amp;utm_content=garman&amp;utm_campaign=pla-usg-ele-pc&amp;gclid=CjwKCAjwwtTmBRBqEiwA-b6c_7GZEDeSqy5YlW-WMKR9Py9iNTIhb4ruVUV7vgTXWvncd2BMHMDjnxoCn1EQAvD_BwE&amp;cur_warehouse=CN\">Orange Pi One enclosure<\/a> because they can not accommodate a 2.5&#8243; SSD. Instead I cut a piece of pressboard to the SSD size, spray painted it chrome and mounted it on top of the SSD using #4 bolts.<\/p>\n<p>The SSD mounting holes are spaced a bit wider than the holes on the Orange Pi One board. That&#8217;s why we need a mounting plate to mount Orange Pi One.<\/p>\n<p>I used short PVC spacers to lift off the Orange Pi and screwed it into the pressboard.<\/p>\n<p>The USB to SATA cable loop was tugging on the USB connector. I pulled it tighter with a zip tie to relieve the stress on the connector. I will look for a better cable.<\/p>\n<figure id=\"attachment_328\" aria-describedby=\"caption-attachment-328\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_nas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-328 size-medium\" src=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_nas-300x225.jpg\" alt=\"Orange Pi Case Alternative\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_nas-300x225.jpg 300w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_nas-768x576.jpg 768w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/orangepi_nas.jpg 1000w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-328\" class=\"wp-caption-text\">Orange Pi + SSD = NAS<\/figcaption><\/figure>\n<h1>The Operating System<\/h1>\n<p>The OS is installed on a Micro SD card. I use Debian. I&#8217;ve had this computer for a while and don&#8217;t remember if I downloaded the OS image from the <a href=\"http:\/\/www.orangepi.org\/downloadresources\/\">Orange Pi site<\/a>\u00a0 or from the official Debian site.<\/p>\n<p>However, I upgraded to Debian 9 Stretch using just the official Debian repo. Make sure to use the armhf architecture.<\/p>\n<h3>Connecting to the Orange Pi<\/h3>\n<p>You can connect the Orange Pi One HDMI output to a display and add a USB hub to connect a mouse and a keyboard. Instead I just ssh into the machine from another Linux box like:<\/p>\n<pre>ssh &lt;myUserName&gt;@&lt;OrangeOneIP&gt;<\/pre>\n<p>You can <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-ssh-keys-on-debian-9\">create a private\/public RSA key pair<\/a> on the client machine and push the public key to the Orange Pi to avoid being prompted for the password.<\/p>\n<p>You can also connect from outside of your network if you setup port 22 forwarding in your router\/firewall to send traffic to the IP address of the Orange Pi. If you do so, make sure your passwords are very strong.<\/p>\n<p>You may experience thousands of brute force password crack attempts an hour. A good tool to reduce risk is <a href=\"https:\/\/www.fail2ban.org\/\">Fail2ban<\/a> which temporarily bans originating IPs after five failed login attempts. You can install Fail2ban with:<\/p>\n<pre>apt-get install fail2ban<\/pre>\n<h3>Static IP<\/h3>\n<p>It&#8217;s very useful for a NAS to have a static IP address. Debian 9 is usually configured to use DHCP at install time.<\/p>\n<p>To setup static IP address use a text editor like vi or nano:<\/p>\n<pre>nano \/etc\/network\/interfaces<\/pre>\n<p>And add something like:<\/p>\n<pre class=\"easycode; title: Static IP setup;lang:Bash;collapsed:1;\"> auto eth0\r\n\r\nallow-hotplug eth0\r\n\r\niface eth0 inet static\r\n\r\naddress 192.168.1.100 #This is the static IP address for Orange Pi\r\n\r\nnetmask 255.255.255.0\r\n\r\ngateway 192.168.1.1 #This is your router IP address<\/pre>\n<p>&nbsp;<\/p>\n<p>The actual IP addresses may be different in your case. Make sure to select an unused IP address for the Orange PI.<\/p>\n<p>The new configuration will not take effect until you reboot or restart networking with:<\/p>\n<pre>systemctl restart networking<\/pre>\n<h3>The Overclocking Issue<\/h3>\n<p>The original Orange Pi One shipped with some overclocking issue. Run the dmesg command to see if the log is flooded with something like this:<\/p>\n<pre>[ 16.876698] [ARISC WARING] :callback not install\r\n\r\n[ 16.886241] [cpu_freq] ERR:set cpu frequency to 480MHz failed!<\/pre>\n<p>To mitigate the problem install:<\/p>\n<pre>apt-get install cpufrequtils<\/pre>\n<p>And edit the configuration:<\/p>\n<pre>nano \/etc\/init.d\/cpufrequtils<\/pre>\n<p>to change:<\/p>\n<pre>governor=\"powersave\"<\/pre>\n<p>This is not the most elegant solution. It will make your\u00a0 CPU run slower, but it will also runs cooler and the errors will go away.<\/p>\n<h3>Mounting the USB Drive<\/h3>\n<p>Your USB connected SATA drive will not automatically mount when connected. To mount manually you first need to find out the device name.<\/p>\n<p>Connect the drive and execute dmesg. The device name will be printed towards the bottom of the log. Let&#8217;s say the drive device name is sda1 in our example.<\/p>\n<p>Create a directory that will become the mountpoint and mount the drive:<\/p>\n<pre>mkdir ~\/storage\r\n\r\nmount \/dev\/sda1\/ ~\/storage<\/pre>\n<p>If you mount the drive with sudo then you need to change the ownership so your regular user can read and write:<\/p>\n<pre>chown -R &lt;yourUserName&gt;:&lt;yourUserName&gt; \/home\/&lt;yourUserName&gt;\/storage<\/pre>\n<h3>Auto Mount the USB Drive with Systemd<\/h3>\n<p>The drive will not mount at reboot unless you configure it in fstab (the old way) or systemd (Debian 8 or higher).<\/p>\n<p>Make a little mount script in your home directory:<\/p>\n<pre>nano ~\/storagemount.sh<\/pre>\n<p>Copy, paste, customize, save:<\/p>\n<pre class=\"easycode; title:storagemount.sh;lang:Bash;collapsed:1;\"> #!\/bin\/bash\r\n\r\n# Mount USB SSD\r\n# This script is run as service at boot time by \/etc\/systemd\/system\/storagemount.service\r\n# Substitute your actual user name in place of &lt;yourUserName&gt;\r\n\r\nmountpoint=\/home\/&lt;yourUserName&gt;\/storage\r\nmount \/dev\/sda1 $mountpoint\r\nchown -R &lt;yourUserName&gt;:&lt;yourUserName&gt; $mountpoint<\/pre>\n<p>&nbsp;<\/p>\n<p>Then add a new service for systemd which will execute the above bash script at boot time:<\/p>\n<pre>nano \/etc\/systemd\/system\/storagemount.service<\/pre>\n<p>Copy, paste, customize, save:<\/p>\n<pre class=\"easycode; title: storagemount.service;lang:Systemd;collapsed:1;\">[Unit]\r\n\r\nDescription=Mount SSD and change owner to regular user\r\n\r\n[Service]\r\n\r\nType=simple\r\n\r\nExecStart=\/home\/&lt;yourUserName&gt;\/storagemount.sh\r\n\r\n[Install]\r\n\r\nWantedBy=multi-user.target<\/pre>\n<p>&nbsp;<\/p>\n<p>Reload systemd and kick off your new service:<\/p>\n<pre>systemctl daemon-reload\r\n\r\nsystemctl enable storagemount.service\r\n\r\nsystemctl start storagemount.service<\/pre>\n<h1>Customizations<\/h1>\n<p>Your system is now up and running and you can setup servers and services that will make it into a NAS.<\/p>\n<h3>Setup Samba<\/h3>\n<p>A NAS requires a Samba server so that Windows, MacOS, and Linux machines can connect to the network share. To install SMB use:<\/p>\n<pre>apt-get install samba<\/pre>\n<p>Open the Samba configuration file:<\/p>\n<pre>nano \/etc\/samba\/smb.conf<\/pre>\n<p>Copy, paste, customize, save:<\/p>\n<pre class=\"easycode; title: smb.conf;lang:;collapsed:1;\">[&lt;yourShareArbitraryName&gt;]\r\n  comment = All Users\r\n  path = \/home\/&lt;yourUserName&gt;\/storage\r\n  valid users = @users\r\n  force group = users\r\n  create mask = 0774\r\n  directory mask = 0771\r\n  writable = yes<\/pre>\n<p>&nbsp;<\/p>\n<p>The &#8220;storage&#8221; directory is the mountpoint we had created earlier.<\/p>\n<p>Add a Samba user:<\/p>\n<pre>smbpasswd -a &lt;newUserName&gt;<\/pre>\n<p>Restart the Samba server:<\/p>\n<pre>systemctl restart smbd<\/pre>\n<p>At this point the machines on your network should see the share and connect as newUserName you created.<\/p>\n<p>Connecting to the share is specific to your client OS. In Windows you can right click &#8220;Computer&#8221; and select &#8220;Map Network Drive.&#8221; In the folder field type:<\/p>\n<pre>\\\\&lt;OrangePI-IP-Address&gt;\\&lt;yourShareName&gt;<\/pre>\n<h3>Atomated Backup<\/h3>\n<p>The beauty of building your own NAS is that you can add any type of service you need. I added a daily automated backup to an off-site server I own. You can also use Google Drive, Amazon S3 Bucket, or any other cloud storage<\/p>\n<p>I have a ~\/backup.sh script containing something like:<\/p>\n<pre class=\"easycode; title: backup.sh;lang:;collapsed:1;\"> #!\/bin\/bash\r\n\r\nrunuser -l &lt;yourUserName&gt; -c 'rsync -amz --delete \/home\/&lt;yourUserName&gt;\/storage\/ &lt;yourUserName&gt;@&lt;someServer&gt;.com:backup-directory'<\/pre>\n<p>&nbsp;<\/p>\n<p>It uses the rsync command to do incremental backup of ~\/storage to a remote server called someServer.com. The &#8211;delete option ensures that any files deleted on the NAS are also removed from the backup server.<\/p>\n<p>We use systemd again to make a service out of this script and schedule it. You can also use cron to schedule.<\/p>\n<p>Create a backup service:<\/p>\n<pre>nano \/etc\/systemd\/system\/backup.service<\/pre>\n<p>Copy, paste, customize, save:<\/p>\n<pre class=\"easycode; title: backup.service;lang:;collapsed:1;\">[Unit]\r\nDescription=Rsync backup of NAS storage to a remote server\r\n\r\n[Service]\r\nType=oneshot\r\n\r\nExecStart=\/bin\/bash -c \/home\/&lt;yourUserName&gt;\/backup.sh<\/pre>\n<p>&nbsp;<\/p>\n<p>Create a daily timer for the service:<\/p>\n<pre>nano \/etc\/systemd\/system\/backup.timer<\/pre>\n<p>Copy, paste, customize, save:<\/p>\n<pre class=\"easycode; title: backup.timer;lang:;collapsed:1;\">[Unit]\r\nDescription=NAS backup timer\r\n\r\n[Timer]\r\nOnBootSec=45s\r\nOnUnitActiveSec=1d\r\nUnit=backup.service\r\n\r\n[Install]\r\nWantedBy=timers.target<\/pre>\n<p>&nbsp;<\/p>\n<p>The 1 day period is specified in \u201cOnUnitActiveSec=1d. \u201d<\/p>\n<p>Reload systemd and kick off your new backup service:<\/p>\n<pre>systemctl daemon-reload\r\n\r\nsystemctl enable backup.timer\r\n\r\nsystemctl start backup.timer<\/pre>\n<p>To check all timers:<\/p>\n<pre>systemctl list-timers --all<\/pre>\n<h1>Disk I\/O<\/h1>\n<p>Orange Pi One has USB 2 on-board. The average write rates I clocked are:<\/p>\n<p>33 MB\/s for EXT4 formatted drive<\/p>\n<p>17 MB\/s for NTFS formatted drive<\/p>\n<p>This same drive is able to hit 93 MB\/s using USB 3 on another machine.<\/p>\n<p>If you format your drive as EXT4 you will not be able to read it on MacOS\/Windows without some extra <a href=\"https:\/\/www.howtogeek.com\/112888\/3-ways-to-access-your-linux-partitions-from-windows\/\">EXT file system software.<\/a>\u00a0 I&#8217;m primarily Linux based and EXT4 works just fine for me.<\/p>\n<p>To test the\u00a0 speed, make a tmp folder on the drive and run dd:<\/p>\n<pre>mkdir ~\/tmp\r\n\r\ndd if=\/dev\/zero of=~\/tmp\/output.img bs=8k count=256k<\/pre>\n<h1>Mounting The Computer<\/h1>\n<p>The SSD has standard mounting holes on the sides. I used small L brackets to mount the finished NAS to the underside of my desk.<\/p>\n<figure id=\"attachment_347\" aria-describedby=\"caption-attachment-347\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_horizontal.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-347\" src=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_horizontal-300x225.jpg\" alt=\"Orange Pi mounted under a desk\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_horizontal-300x225.jpg 300w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_horizontal-768x576.jpg 768w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_horizontal.jpg 1000w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-347\" class=\"wp-caption-text\">Orange Pi NAS mounted with L brackets<\/figcaption><\/figure>\n<p>I used small thumbscrews to fasten the SSD to the L brackets. They allow me to easily lower the Orange Pi for a quick access to the pin headers.<\/p>\n<figure id=\"attachment_350\" aria-describedby=\"caption-attachment-350\" style=\"width: 263px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_vertical-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-350\" src=\"http:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_vertical-1-263x300.jpg\" alt=\"Orange Pi mounted with L brackets\" width=\"263\" height=\"300\" srcset=\"https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_vertical-1-263x300.jpg 263w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_vertical-1-768x878.jpg 768w, https:\/\/www.skifactz.com\/wifi\/wp-content\/uploads\/2019\/05\/OrangePi_mounted_vertical-1.jpg 875w\" sizes=\"auto, (max-width: 263px) 100vw, 263px\" \/><\/a><figcaption id=\"caption-attachment-350\" class=\"wp-caption-text\">Orange Pi hanging vertically<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>You can spend upwards of $200 on a home Network Attached storage (NAS) or you can build one using spare parts like I did. Not only the DIY solution is cheaper, but it also allows you to customize the NAS to meet your needs. It&#8217;s also a great way to learn how all this stuff &hellip; <a href=\"https:\/\/www.skifactz.com\/wifi\/?p=330\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Orange Pi NAS<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-hardware"],"_links":{"self":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330"}],"version-history":[{"count":17,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":351,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions\/351"}],"wp:attachment":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}