Bananian

Guide: NAS using OpenMediaVault (like BanaNAS but based on Bananian)

14 16916
angeloD  
Edited by angeloD at Sat Nov 29, 2014 17:27

I wanted to build a NAS using my BananaPi, I tried BanaNAS but it did not boot correctly on my one, additionally the OpenMediaVault guys strongly advise NOT to run it on a flash drive (because of the multiple writes that, in the long run will destroy the medium).

So I decided to make one myself based on Bananian (BanaNAS is based on Raspian lift), addressing (or at least trying to address) at the same time the wearing of the flash drive. This is how I made it:

1. After the boot find the ip of the machine
  1. ifconfig -a
Copy the Code
or for headless installs, on a machine on the same network
  1. nmap -n -sP 192.168.0.0/24
Copy the Code
2. ssh to the ip found: root@ip, password pi

3. run bananian-config

4. To switch off the blinking green led, add the line:
  1. echo none > /sys/class/leds/green\:ph24\:led1/trigger
Copy the Code
to the /etc/rc.local file.

5. Set a fixed ip, edit the file /etc/network/interfaces
  1. # static ip configuration
  2. iface eth0 inet static
  3.         address 192.168.0.199
  4.         netmask 255.255.255.0
  5.         gateway 192.168.0.1
Copy the Code
6. install openmediavault
  1. echo "deb http://packages.openmediavault.org/public kralizec main" > /etc/apt/sources.list.d/openmediavault.list
  2. apt-get update
  3. apt-get install openmediavault-keyring postfix
  4. apt-get update
  5. apt-get install php-apc
  6. apt-get install openmediavault
  7. omv-initsystem

  8. shutdown -r now
Copy the Code
7. ssh is now disabled, access the web interface, from a browser

User: admin
PW: openmediavault

8. Add DNS server in System/Network/DNS Server to allow name resolution

9. add extras repository
  1. echo "deb http://packages.omv-extras.org/debian/ kralizec main" >> /etc/apt/sources.list.d/omv-extras-org-kralizec.list
  2. apt-get update
  3. apt-get install openmediavault-omvextrasorg
  4. apt-get update
Copy the Code
10. Generate, in OMV a certificate to enable https.

11. Switch off the usage of swap filesystem
  1. swapoff -a
Copy the Code
12. Switch off journaling in root filesystem, remove the SD from the banana, from another machine

  1. tune4fs -O ^has_journal /dev/...
Copy the Code
13. Use /var/log in tmpfs (taken from https://www.debian-administratio ... _transient_/var/log)

Create the file /etc/init.d/transientlog with the following content:
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: transientlog
  4. # Provides: transientlog
  5. # Required-Start:
  6. # Required-Stop:
  7. # X-Start-Before: $syslog
  8. # X-Stop-After: $syslog
  9. # X-Interactive: yes
  10. # Default-Start:        2 3 4 5
  11. # Default-Stop:                0 1 6
  12. # Short-Description:        Keeps /var/log in RAM
  13. # Description: Moves the contents of /var/log to RAM during boot
  14. #              and keeps it there until shutdown/reboot, when it
  15. #              copies the contents back to permanent storage.
  16. ### END INIT INFO

  17. # Version 1.0
  18. # Author: Matteo Cortese <matteo_cortese@fastwebnet.it>
  19. #
  20. # Inspired by ramlog by Jan Andrejkovic.
  21. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.

  26. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  27. NAME=transientlog
  28. DESC="Transient log directory"
  29. LOCKFILE=/var/lock/$NAME.lock
  30. VARLOG=/var/log
  31. SIZE=16M
  32. MODE=0755

  33. # Read configuration variable file if it is present
  34. [ -r /etc/default/$NAME ] && . /etc/default/$NAME

  35. # Load the VERBOSE setting and other rcS variables
  36. . /lib/init/vars.sh

  37. # Define LSB log_* functions.
  38. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  39. . /lib/lsb/init-functions

  40. if [ -z "$VARLOGPERM" ]; then
  41.         var=`dirname $VARLOG`
  42.         log=`basename $VARLOG`
  43.         VARLOGPERM="$var/permanent$log"
  44.         unset var log
  45. fi

  46. do_start()
  47. {
  48.         # Return
  49.         #   0 if transient log has been started
  50.         #   1 if transient log was already running
  51.         #   2 if transient log could not be started

  52.         [ -f $LOCKFILE ] && return 1
  53.        
  54.         # Check if I'm root
  55.         [ `id -u` -eq 0 ] || return 2

  56.         # If VARLOG does not exist?
  57.         [ -d $VARLOG ] || return 2

  58.         # VARLOGPERM either does not exist (first invocation)
  59.         # or is empty (left from previous invocation).
  60.         #
  61.         [ -d $VARLOGPERM ] || mkdir -p $VARLOGPERM || return 2

  62.         # Mount a tmpfs over VARLOG.
  63.         # The mount will shadow the current contents of VARLOG.
  64.         # So, before, make a bind mount so that looking into VARLOGPERM
  65.         # we'll see the current contents of VARLOG, which
  66.         # will not be available anymore as soon as we mount
  67.         # a tmpfs over it.
  68.         #
  69.         mount --bind $VARLOG $VARLOGPERM
  70.         # NEEDED FOR DEBIAN Jessie
  71.         mount --make-private $VARLOGPERM
  72.         mount -t tmpfs -o nosuid,noexec,nodev,mode=$MODE,size=$SIZE $NAME $VARLOG
  73.         if [ $? -eq 0 ]; then
  74.                 # Populate the tmpfs
  75.                 if cp -rfp $VARLOGPERM -T $VARLOG; then
  76.                         # Success!
  77.                         touch $LOCKFILE
  78.                         return 0
  79.                 fi

  80.                 # Something went wrong...

  81.                 # Rollback the mount
  82.                 umount -l $VARLOG
  83.         fi

  84.         # Rollback the directory mangling
  85.         umount $VARLOGPERM
  86.        
  87.         return 2
  88. }

  89. do_stop() {
  90.         # Return
  91.         #   0 if daemon has been stopped
  92.         #   1 if daemon was already stopped
  93.         #   2 if daemon could not be stopped
  94.         #   other if a failure occurred

  95.         [ -f $LOCKFILE ] || return 1

  96.         # Check if I am root
  97.         [ `id -u` -eq 0 ] || return 2

  98.         # Merge back to permanent storage
  99.         cp -rfup $VARLOG -T $VARLOGPERM

  100.         # The following cannot fail... or can it?
  101.         umount -l $VARLOG
  102.         umount -l $VARLOGPERM
  103.         rm -f $LOCKFILE
  104.         return 0
  105. }

  106. do_reload() {
  107.         # Return
  108.         #   0 if transient log has been reloaded
  109.         #   1 if transient log was not running
  110.         #   2 if transient log could not be reloaded

  111.         [ -f $LOCKFILE ] || return 1
  112.        
  113.         # Check if I am root
  114.         [ `id -u` -eq 0 ] || return 2

  115.         # Merge back to permanent storage
  116.         cp -rfup $VARLOG -T $VARLOGPERM
  117.         touch $LOCKFILE
  118.         return 0
  119. }
  120.        
  121. case "$1" in
  122.   start)
  123.         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  124.         do_start
  125.         case "$?" in
  126.                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  127.                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  128.         esac
  129.         ;;
  130.   stop)
  131.         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  132.         do_stop
  133.         case "$?" in
  134.                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  135.                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  136.         esac
  137.         ;;
  138.   status)
  139.           if [ -f $LOCKFILE ]; then
  140.                 echo "$DESC is running"
  141.         else
  142.                 echo "$DESC is stopped"
  143.                 exit 1
  144.         fi
  145.         ;;
  146.   reload)
  147.         log_daemon_msg "Reloading $DESC" "$NAME"
  148.         do_reload
  149.         log_end_msg $?
  150.         ;;
  151.   *)
  152.         echo "Usage: $0 {start|stop|status|reload}" >&2
  153.         exit 3
  154.         ;;
  155. esac


Copy the Code
Make it executable and insert as service:
  1. chmod a+x /etc/init.d/transientlog
  2. insserv transientlog
Copy the Code
As suggested (and indicated in the original page), optionally create a file "transientlogCron"
with this content:
  1. #!/bin/sh

  2. [ -x /etc/init.d/transientlog ] || exit 0
  3. [ -f /var/lock/transientlog.lock ] || exit 0
  4. /etc/init.d/transientlog reload
Copy the Code
make it executable, chmod +x and move it in the /etc/cron.daily folder.

Enjoy now your OMV NAS....
tkaiser  
Edited by tkaiser at Sun Nov 23, 2014 17:06

Shouldn't a cronjob be executed at least daily that fires up 'service transientlog reload' to let the changes be written to the SD card?

BTW: This transientlog method is a nice approach even if you moved your rootfs to a connected SATA disk since normally you would like the disk to be sleeping most of the times and prevent spin-ups due to log activity. On my ARM based backup NAS systems I put the following into /etc/hdparm.conf:
  1. /dev/sda {
  2.         spindown_time = 120
  3. }
Copy the Code

angeloD  
tkaiser replied at Tue Nov 18, 2014 03:45
Shouldn't a cronjob be executed at least daily that fires up 'service transientlog reload' to let th ...

Thanks tkaiser , I added the part you suggested.

For the spin down of the HD, in my case with a Western Digital Green (4Tb connected through a cradle ORICO 6518sus3), the default settings are pretty ok.

All comments and suggestions are more than welcome.

angeloD  
To reduce the writes to the bare minimum it is also possible to stop the collectd and rrdcached tasks (if you are not interested in what they do...)

/etc/init.d/rrdcached stop
/etc/init.d/collectd stop
monit stop rrdcached
monit stop collectd


On Ext4 partitions, to monitor the amount of data written, an interesting file is:

/sys/fs/ext4/<<<your partition here>>>/session_write_kbytes

I want to install Bananian and OMV on the harddisk. Could I use the above method to avoid frequent writes to the disk so that it can spin down when nobody accesses it over the network?

tkaiser  
karlkloss replied at Sat Jan 24, 2015 12:05
I want to install Bananian and OMV on the harddisk. Could I use the above method to avoid frequent w ...

This might work but you should be aware that there exist different locations elsewhere on the disk where processes modify data. It's not just /var/log.

Both iotop and iostat (part of the sysstat package) might help to get processes writing constantly to disk. If you really want the disk to spin down then keep the system on the SD card and use data/mountpoint of the disk only for NAS purposes.

angeloD  
You should also be aware that, by default, you cannot use the disk where OMV is installed to store your files.

Does bananian now work by default with port multipliers like the jm321? I plan to install OMV on a small SSD and run snapraid on 3 x 2 TB disks

tkaiser  
Edited by tkaiser at Sat Mar 21, 2015 03:35
blindpet replied at Fri Mar 20, 2015 16:55
Does bananian now work by default with port multipliers like the jm321?


Will be the case when Bananian starts to use mainline kernel and uses CONFIG_AHCI_SUNXI=m (then it works as outlined here). Currently (that means using any kernel prior to 3.18) it's not possible without both patching kernel sources and recompiling the kernel as outlined in the same thread.

And regarding any sort of RAID behind a cheap and unreliable JMB321: Be aware that this piece of silicone might fail in situations when you don't expect it (eg one disk becomes unavailable and the PM decides to drop all other disks too): http://forum.lemaker.org/forum.php?mod=redirect&goto=findpost&ptid=11857&pid=71617

tkaiser replied at Sat Mar 21, 2015 03:33
Will be the case when Bananian starts to use mainline kernel and uses CONFIG_AHCI_SUNXI=m (then it ...

I have read a lot of your posts tkaiser, very informative. I understand that if one drive fails then everything gets fucked up when you are running a software raid. Is this still true for something like snapraid? What if I just use each drive separately as ext4 volumes, if a drive dies then it is an issue?

My goal is to move my media downloading to the Banana Pi and have 2 separate drives connected to the port mulitplier. I will run backup onto USB drives weekly.

I am curious if one drive fails without RAID if the data set will be compromised?

Thanks for all the time you put into posting your detailed findings.

You have to log in before you can reply Login | Sign Up

Points Rules