Raspi Green NAS auf Deutsch
Raspi Green NAS auf Deutsch

Raspi Green-NAS (Serial and Relais HAT)

3D-Simulation - Bare Board without Raspberry PI

I needed some extensions for my homeserver consisting of a Raspberry Pi4, so I finally decided to build an extension board on my own.

I'll try to avoid the term HAT in the following instead I will be talking of an extension board because that's what it is.

I'm not a friend of people that keep on inventing new terms for old socks. – HAT, Shield, Sketch — App...

Function

Photo - Board on top of PI4B

Here the completed board, plugged on my Pi4B.

The board contains four coil drivers for connecting two bipolar relays.

Additionally, UART5 is layed out as a RS-232 interface via a 9 pin Sub-D connector (like on a PC).

In general, the coil drivers should work with any Pi having a 40 pin connector, i.e. starting from Pi1B+, the serial interface requires at least a Pi4B.

An anecdote by the way: the resistors and diodes you see in the photo are actually from my assortment that I purchased in my apprenticeship, about 45 years ago... which were still solderable without problems, without storage under inert gas or the like! At that time, metal film resistors were not yet very common, respectively expensive and 5% tolerance was the state of the art, which is still more than sufficient here.
In fact, I still remember resistors with a silver tolerance ring (±10%) or without the ring at all (±20%)

Circuit and layout has again be done using KiCad. Meanwhile I must say that KiCad proved as a really professional tool for creating schematics and PCB layouts. It surely has some disadvantages compared to competitors but it also has powerful tools and if you work with it for a while (and did not rely too much on the provided library) you know what can be done in KiCad and what you'd better import from LibreCad you can work accurately and fast. Additionally, the possibility to directly edit the human readable files proved very time saving in some cases. A simple search-and-replace can do half of an hour work in a 20 k$-suite of a competitor.

Relays

Photo - Original Adapter I used bipolar relays Hongfa HFE20. Similar relays with two coils(!) will work just the same. Bipolar relays only need current for switching. They keep their state even without power supply, i.e. a closed contact remains closed during a reboot (until actively switched to a certain position).

Photo - Modified Adapter (opened) I mounted the relays into a plug adapter (Goobay 68906). This was available from my distributor for only €1.70, what is a tenth of the money they want for an empty case. An old telephone cable serves as connection with a perfectly fitting twist-proof strain relief.

Photo - Modified Adapter (complete) I dismounted the switch and replaced it by the relay. It fitted perfectly into the space of the switch. It has nearly the same dimensions and covers the hole of the switch so there is no danger that anything could get into the case producing a short or a dangerous situation.

On the Way to a green NAS

I use the two relays to switch the (mains-) supply of my NAS and backup disk. It is not only the few watts of standby power but also for the lifetime of the wall warts. In my experience, the cheap adapters that come along with a docking station or a USB case are not designed for 24/7 operation.

Well known NAS servers consume an unnecessary amount of power, especially if you don't use them permanently. I used a Thecus N5550 for some time, consuming 26 watts of power even in standby, that is about five euros per month only to be there (active: 50 W). For €60 a year I could go out for a really good dinner on New Year's Eve. We can do it cheaper!

Indeed, using multiple disks in a raid array for most of the private users is simply overkill. A regular backup is much more important. Raid can not replace this. You can get 3.5" disks up to 26 TB now, what should be more than enough for any private application.

The majority of private and Soho administrators would probably only notice the failure of one drive when a second drive also fails and access is no longer possible. Sure, it will last longer, the system will work longer, but a failure is a failure! Who will pay attention to whether something is flashing or glowing red on the NAS? Hopefully they at least have a backup then!

If some crypto-trojan encrypts your disk, this will happen relatively fast (well, hours but you would not take notice of it immediately) and even your raid would be encrypted over night!

RAID can not replace a Backup!

Therefore, the backup disk must be regularly replaced by a second (third, fourth...) so that there is always a disk available that is not online and would therefore also have been encrypted!

A backup can only be replaced by a more frequently backup, so frequent that a ransom demand is not profitable for the attacker or you can say a restore is cheaper!

During my time as an administrator of a medium-sized company, I used the following scheme:

In addition to the purchase of twenty hard drives during the first year to set up the infrastructure, we are talking about a few hundred dollars per year. That is nothing even compared to simple mistakes like accidentally deleting an important file.

Hard drives are cheap. Cheap compared to the potential loss of data, even in private life (think about it, all the photos of your life are gone... what would they have been worth to you? Now or in 30 years?). Buying a new one every year and keeping twenty of them in rotation is nothing compared to the potential loss!

As a home user, you may not need twenty hard drives, but each additional one increases the chance that you can recover something irretrievable, even if you accidentally deleted it years ago and only now realize it.

Remember to mount the backup disk read-only in this case. This way, a virus that may still be active cannot make it unusable (unless it is intelligent enough and found a way to mount it somewhere else R⁠/⁠W!) An NFS mount from a definitely uninfected system might be the solution, or a copy on a USB stick, which could be replaced if necessary. In any case, be careful with the two or three backup disks! Use only copies of them, that you have made on a clean system, even if this costs extra time!

The complete loss of the live system must only cause relatively low costs. For me as a private user, a weekly backup is usually sufficient, for a medium-sized company perhaps daily, for larger companies rather more often (or more differentiated, current data must be backed up more oftenly, archive data rather just every now and then).

That's why I not only have backups of the software, I also have a second Pi4B in my drawer, with a slightly older but working SD card which can replace a failed system within half an hour.

During my time as an administrator, a spare server of our Dual Quadcore Intel E5430 together with a RAID array would have cost several thousand euros, and I couldn't convince management to do that. But when it costs only € 150 including the 1 TB SSD, it's worth considering even for home users.

If you really need more than one disk for NAS, this would be the time to consider a dual docking station or a Mobius case as well as software raid. I haven't done that.

Backup

Backup is very easy. A script turns on the disk, waits until it's ready and mounts it. Then, it runs a rsync backup, unmounts the disk, sync and switches it off. Done.

Sounds fast but it can take its time. From one docking station to the other my Pi4B makes a terabyte in about four hours. A full backup of 6 TB would take about a day. If the target is not new and you only have to sync the difference to the last backup, it would be much faster, of course (in my system, hosting an 8 TB disk, normally in about 15 minutes).

My backup script is additionally designed in such a way that the backup disk must of course be formatted, but must also already contain each (root) directory to be backed up, at least as an empty directory. So you can use e.g. smaller disks as a backup target to backup only certain or frequently changed directories.

NAS

It is not so simple with NAS. This should give us one or more Samba shares that Windows-clients could use via their network neighborhood. The disk should be started automatically on access and shut down when no longer needed. I solved this with a combination of Autofs and Cron.

Mounting with Autofs

Autofs makes it easy to mount a disk only while it is being accessed. Each mount point has a separate config file what can also be an executable script.

Unfortunately, this feature does not exist for unmount! Here comes my way:

The mount script turns on the disk, waits 20 seconds until it is ready and sets an appropriate sleep time via hdparm. So the disk at least goes into standby if it is no longer in use.

One problem is that Autofs seems to cache the result of the script for some time. So it is not always executed! Obviously Autofs is not made for a task like this...

Powering off with Cron

An entry in crontab checks once an hour if the disk appears in the system (in /dev/disk/by-uuid) and if it is mounted (in /proc/mounts). If it is not, we can switch it off.

This is, of course, not optimal but it comes very close to the desired behavior.

Dockingstations

Not every docking station can be used for our purpose.

A Sharkoon dual dockingstation failed because it does not have a power switch. It must be turned on by pressing a button every time you power it on 😠. Why should anyone build such a crap?

RAM

What can you gain from more RAM?

In my experience, nothing at all. My Pi4B has 1 GB of RAM. It works perfectly and fast, without any notable penalty.

More RAM only costs money and rises energy consumption. I would recommend to use the smallest Version available, it will be absolutely sufficient.

The Pi4B with 1 GB of RAM actually (end of 2024) is at about 40 Euro, the one with 8 GB at about twice the price, without any noteable advantage in our case.

Power consumption

So what is the gain? The Pi4B as a NAS controller must be always on and consumes about 3 W (without WLAN, it does not make sense to connect a server via WLAN anyway). The disk subsystem does not need additional standby power. Even when powered on, there is no additional driving power required. All it consumes is the power of the dockingstations and the disk drives themselves. This varies between different types but will be in the range of 10..15 W per 3.5" drive.

The costs are about €6.50 per year for the Raspi, even if your disk would be permanently spinning this would not be more than €40 per year.

To give a comparison: using the professional NAS with five disks mounted you'd have to pay €57 just for stand by and €110 for the permanently active system. Since especially in a home environment the disks are used only rarely, we can talk of a saving by a factor of 6..8.

Of course, the professional System has its advantages which it may play out in an environment with tens of users working day and night, it would be much faster then. In addition, the failure of a single hard disk could be repaired by an attentive (!) administrator without interrupting operations or losing data. But for most of the home and SOHO users, this has no real meaning.

And further?

I have integrated another server into my system that hosts frequently used files (several times a day, home directories, etc.), actually my main server that everyone uses every day.

I not only updated the system to more recent hardware (Pi5), but also added a 1 TB SSD for data that I use every day. An M.2 HAT mounted under my expansion board provides daily data fast and reliable. This required some experimentation with different connector strips so that the height was right, the PCIe cable was not too short and still protruded enough to contact my expansion board.

When I was young, there were hard drives with a size of 5 MB, 10 MB and in the luxury class of 20 MB (yes, megabytes, there was space for several HD floppy disks! Changing floppy disks when compiling was finally a thing of the past and the speed gain was breathtaking!), at prices of several thousand D-Marks then. Today I can get SSDs that are a hundred thousand times bigger, tens of thousands of times faster costing less than a tenth of that. And instead of taking up a shoebox of space (including an own power supply and a fan), they are now barely bigger than a postage stamp and need almost no power!
Hard disks then had access times of 65 ms, what was good for about 15 random I/Os per second. That was absolutely incredible but the modern SSD allows one million I/Os per second!

This only works if I remove the EEPROM on my board, so the initialization on my side has to work purely by the scripts, which is not a problem.

Stacking expansion boards was not originally planned, and both EEPROMs would be addressed at the same time.

The previous server for this was an Intel Atom 525D, which consumed around 30 W (this makes about 100 € of costs per year!). The Pi5 is around eight times faster and replaces it, with practically no additional power costs! The SSD hardly makes a difference, the system still requires around 3 W.

Saved another New Year's Eve meal for two 😋 (per year!), even a modest firework display 😮 and a glass of Rotkäppchen 🥂 is still possible.

So what do I have now?

For me it also has some additional tasks such as:

Overall, I must say, I am quite happy with the result.

What else can it do?

I'm convinced that a server like this can meet all the demands of a SOHO or even a medium-sized company.

It's fast, really fast. While it can't keep up with a professional NAS or a dual-quad-core XEON with a SSD RAID, no one will notice those few milliseconds, let alone that they actually cost money.

But it can't do RAID.

No, it can't. Unless you find an M.2 HAT that can accommodate two or more SSDs with hot-swap capability.

But it would be conceivable to simply run a complete second system in parallel (for a mere € 150). This would have to be operated in a (logically) separate network, to which only the server has access and which is hidden from the rest of the infrastructure, otherwise there would be two machines responding to the same name. Files could be kept synchronized in real time using lsyncd, for example, even a PostgreSQL database for the ERP system can be kept consistent with the one on the spare server.

Also note the different levels of protection: The dual-quad-core XEON with RAID controller protects against the failure of a hard drive, which can then be replaced with a new one without interrupting operation. However, if the server itself (or the RAID controller) fails, you'll have downtime until you order, receive, and install a new one, which can take up to a week easily! Your savvy administrator can get the replacement Pi up and running in a maximum of half an hour, although this would also be necessary if only the SSD failed.

Even the redundant system would only require 6 W of power (compared to the 400 W of the XEON system), corresponding to € 18 in electricity costs per year instead of € 1200.

My approach in this case would be to synchronize file directories (homes, projects, documentation, etc.) using lsyncd and implement the Postgres database with its replication features. I would prefer to perform operating system updates separately on both machines. Log directories or journal files shouldn't be synchronized anyway, as they evolve independently.

That would be your part then, since I don't have this problem.