Home-made PC Router and NAS Server [Page 7] - Power Saving and Conclusion
- Introduction
- Install
- Router
- NAS
- VM Hypervisor and GUI
- VPN
- Power saving and Conclusion
Power saving and conclusion
Saving Power
Note: This power saving information was written about my previous hardware, and when I was running hard drives rather than SSDs.
The only way to effectively measure a desktop's power is via a meter plugged into the wall. I have an 'Eco Savers' power meter 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 trivial difference, but didn't impact the system, except the auto suspend 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, is spin down the 2.5" laptop disk when it's idle.
By executing hdparm -y for my disk, I save an additional ~2W power. I'm now at 21.8W. Including the powertop settings too, that's a 16% saving.
sudo hdparm -y /dev/sdb
I ignore /dev/sda, /dev/sdc and /dev/sdd - all three are SSDs. The /dev/sda is 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 -S180 /dev/sdb
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 spin down, and spin down (-S) occurs after 15 minutes. A full list of numbers associated with the spin down 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 -S180 /dev/sdb exit 0
To make it runnable and execute at boot, use these commands:
sudo chmod +x ~/powersave.sh
Then add the script into a cron job on reboot by inserting a new line (change the directory to your home location).
sudo crontab -e
@reboot /home/dan/powersave.sh
Now reboot and check the power usage on your wall plug monitor (if you have one). It should be lower than before.
I found in the past 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 spin down time using Ubuntu's disks utility (gnome-disks) under Drive Settings does work and keeps it after reboots. So, I just used that tool instead.
My latest Seagate drives seem to be spinning down fine with hdparm settings 127 for power management, and 180 (15 minutes) for spin down time but didn't seem to work with 241 (30 minutes).
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 reasonable 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 (I suggest specific NAS disks such as WD Red or Seagate Ironwolf which are designed to operate 24x7 and slow down when not in use).
Laptop disks (2.5") are designed to spin up 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 19.8W.
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. Low power Celerons will do even better. Something that supports DDR3L (low voltage) or DDR4 may also help a bit.
Equally, if you're re-purposing 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 than 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 will then speed up/down depending on temperatures) or do as I did on my original hardware and add a fan control with an LM2956 module to adjust the fan speed to the maximum you can whilst keeping noise within an acceptable level.
Disable sleep
If you've installed only Ubuntu server and no GUI applications, by default the system should not sleep. With a GUI though, by default you'll get automatic suspend to save power. The system system thinks it is idle, even though it might be routing internet traffic, and sleeps after a certain time, leaving all your clients without Internet.
There are two set of commands that I've applied to my system via the terminal (SSH) in order to prevent this:
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout '0' gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout '0' gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing' gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'nothing'
The gnome settings may not be necessary if gnome isn't installed, and on those the battery settings also may be unnecessary for a system that never runs off batteries. They are included for completeness though.
Conclusion
Apart from the Seagate hard disk failure and the BTRFS file system letting me down, my system has been running reliably for many months now. It's an excellent router, and now I have SSDs for the storage too, accessing the samba share from my other PCs is really quick.
It's taken a long time to build it, and write this as I go, and clearly my attempt last year to use RAID1 disks and BTRFS cost me time and data, 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.
One useful addition I did add was Plex, which allows me to cast music, pictures and videos to my TV and Chromecast/Chromecast Audio. Nextcloud might be another suggestion, giving Dropbox like synchronisation of files such as my Documents.
For my needs, it has met them well. The router happily handles Internet browsing, Gaming on the PS4, watching 4K TV streams. It never crashes and rarely needs reboots (patches being the only reason). The VPN also lets me access my files whilst away, amongst other benefits.
Some pictures:
^ Picture of server CPU, motherboard, RAM, SSD and network card before installing
^ Picture of the new hardware and old hardware side-by-side
^ Picture of server inside, outtake fan (left), CPU fan, original 180W power supply (top), disks (lower right)
^ Another picture of server inside. The top fan was upgraded to a PWM model (repurposed from
my Kolink Rocket
^ Picture of the rear. Clearly labelled WAN port so I don't forget which is which!
^ All three SSDs are mounted with an adaptor in the 3.5" drive bay
^ The 2TB hard disk was crudely mounted in the skeleton of the CD drive day
^ Picture of server operating in position
References and more reading:
How To Everything - Permanently Configure Hard Drives To Spin Down After A Given Idle Time
Ask Ubuntu - How do I disable my system from going to sleep?
- Introduction
- Install
- Router
- NAS
- VM Hypervisor and GUI
- VPN
- Power saving and Conclusion