My Home-made PC Router and NAS Server

Note: This project has been rebuilt and full information is available here.
I suggest reading about the rebuild first. Information below is for reference purposes and no longer recommended.

Server power saving and conclusion

Saving Power

The only way to effectively measure a desktop's power is via a meter plugged into the wall. I have an 'Eco Savers' one and this reads ~24W (watts) when the server is idle. It's actually not a bad starting point considering, but there are a few tricks to get it a little lower.

The first is to use a utility called powertop

sudo apt-get install powertop
sudo powertop

With the monitor connected and powertop running, it's around 26W.

Hit tab until we reach the Tunables area.

Then hit enter for each one, watching the power usage.

For me the effective ones seemed to be:

  • Enable SATA link power management for host0 (through to host5)
  • Runtime PM for PCI Device Intel Corporation 6 Series/C200 Series Chipset Family MEI Controller #1

Others made little difference, but didn't impact the system, except the Autosuspend for my mouse, which stopped it working.

The end result was about 2W of power saved, now using 24W (or averaging slightly less). This is small, but is 8% less for a machine that will be on 24/7. Once I unplugged the keyboard, mouse and monitor too, it will also reduce further.

The other thing I can do, since all my disks are 2.5" laptop disks, is spin them down when idle.

By executing hdparm -y for all my disks, I save an additional ~4W power. I'm now at 19.8W. Including the powertop settings too, that's a 23% saving.

sudo hdparm -y /dev/sdb
sudo hdparm -y /dev/sdc
sudo hdparm -y /dev/sdd

I ignore /dev/sda - that's an SSD, and also where the O/S is installed so it shouldn't really spin down.

To make things more permanent, and less immediate, we can make a script to set the Runtime Power Management, SATA link power management and set the HDD idle times after boot.

I've used hdparm -B127 -S241 /dev/sdd

Hdparm uses a strange set of parameters, more info is in the link referenced below. This however first sets the power management flag (-B) to allow spindown, and spindown (-S) occurs after 30 minutes (full list of numbers associated with the spindown times here - http://www.howtoeverything.net/linux/hardware/list-timeout-values-hdparm-s )

nano ~/powersave.sh
#!/bin/sh
 
# Disables the lockup watchdog
echo 0 > /proc/sys/kernel/nmi_watchdog
 
# 1.5 sec intervals to check if cache writes need writing to disk (default 0.3s)
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
 
# Medium power for SATA ALPM
echo min_power | tee /sys/class/scsi_host/host*/link_power_management_policy
 
# Auto power control for PCI devices (default on)
echo auto | tee /sys/bus/pci/devices/*/power/control
 
# Stop Wake on LAN
ethtool -s enp2s0 wol d
ethtool -s enp4s0 wol d
 
# Set hard disks APM and spin down time
hdparm -B127 -S241 /dev/sdb
hdparm -B127 -S241 /dev/sdc
hdparm -B127 -S241 /dev/sdd
 
exit 0

To make it runnable and execute at boot, use these commands:

sudo chmod +x ~/powersave.sh
sudo nano /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
 
sh /home/dan/powersave.sh
exit 0

Now reboot and check the power usage on your wall plug monitor (if you have one). It should be lower than before.

For me however, I found that using hdparm did not spin my disks down after the expected time. This looks like a common problem with Western Digital disks. I spent a while looking for a solution using hdparm, but actually found that setting the spindown time using Ubuntu's disks utility (gnome-disks) under Drive Settings does work, and keeps it after reboots. So I just used that instead.

image007.jpg

Beware though - spinning up/down reduces the life of a hard disk so if you expect to be regularly accessing your files, give the drives a long timeout before spinning down. Also, be more cautious with 3.5" desktop hard drives - these have larger platters and spin faster so have more stress on them during spin-up. Laptop disks (2.5") are designed to do this more often so unless you need the best performance and/or high capacity, I'd choose those instead.

With the monitor unplugged and USB keyboard/mouse unplugged (there are now just three cables connected to my PC - Power cord, LAN Network cable and WAN Network cable), the idle power use comes down to 17.8W.

I also tried running the powertop recommendations on the gateway VM guest too, but it had no measurable difference.

Your power savings may vary. If your building new, hopefully you can do really well with an Skylake or Kaby Lake CPU (or maybe AMD Ryzen?) and a more modern motherboard. Something that supports DDR3L (low voltage) may also help a bit.

Equally, if you're repurposing an old desktop, this will not do as well as the 20W idle that I'm getting - but although it will cost more electric, for some years it will save money compared to purchasing new hardware, and you could argue more environmentally friendly then trying to dispose of old hardware!

Also, have a think about CPU and case fans. The CPU fan unless it is old hardware should definitely be a PWM type (4 pin). Case fans ideally PWM too if your motherboard supports it. These fans speed up/down depending on temperatures.

For normal fans (3 pin) or directly connected to PSU, if your PC is in a large room, you may not need many fans and could slow them down with a 7V (volt) mod, or manual speed controller (an LM2596 or similar buck step down converted is a cheap way to do this) - to save noise and power. If like me though you are putting the PC in a tiny room, where the immersion boiler is also located (which is where my WAN cable comes in), keep the fans running as the lack of airflow in the room makes the PC quite hot.

Conclusion

My system has been running reliably for many months now. It's taken a long time to build it and write this as I go, but it has been a worthwhile learning experience and hopefully other's reading can build and even improve on it.

Remember that it is flexible. If you want to add services, like HTTP server, SFTP, game servers, torrent software, you can. If you have the hardware, it could also be used to build additional VMs for say software development.

For my needs, it has met them well. The router happily handles Internet browsing, Gaming on the PS4, watching 4K TV streams and reliably working without reboots. The VPN also lets me access my files whilst away.

References:

http://askubuntu.com/questions/343268/how-to-use-manual-partitioning-during-installation

http://askubuntu.com/questions/766533/problem-on-installing-teamviewer-on-16-04-lts

https://ubuntuforums.org/showthread.php?t=2326419

http://unix.stackexchange.com/questions/210984/centos-7-using-systemctl-to-start-headless-virtual-machine-hangs

http://askubuntu.com/questions/101294/safely-close-virtualbox-machine-on-host-reboot

http://lastoctet.com/2009/04/12/bring-up-interface-in-debian-ubuntu-with/

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04

https://btrfs.wiki.kernel.org

https://www.howtoforge.com/a-beginners-guide-to-btrfs

https://seravo.fi/2015/using-raid-btrfs-recovering-broken-disks

https://ramsdenj.com/2016/04/05/using-btrfs-for-easy-backup-and-rollback.html

https://www.howtoforge.com/samba-server-ubuntu-14.04-lts

http://askubuntu.com/questions/9853/how-can-i-make-rc-local-run-on-startup

http://www.howtoeverything.net/linux/hardware/permanently-configure-hard-drives-spin-down-after-given-idle-time

 

Back to page 1