Wake-On-LAN with Debian on a qnap TS-119P2+

published 2014-01-28, last modified 2018-03-18

The original firmware for the qnap TS-119P2+ supports Wake-On-LAN, meaning you can power down your Network Storage (NAS) when you don’t need it and you can easily wake it up by sending it a magic ethernet packet. This is an awesome feature when you are not at home all the time (say, you have a day job) and want to conserve some power without giving up on convenience.

Martin Michlmayr published an excellent website about using Debian on the qnap TS-11x/TS-12x devices, which made it really easy to install Debian on my NAS.

Unfortunately, until very recently, with a standard Linux kernel you could not use Wake-On-LAN with the qnap devices. There were multiple reasons for that:

  1. The Linux ethernet driver for the Marvell MV643xx series chips, which those NAS use, did simply not support configuring the chip for Wake-On-LAN. I fixed this in the Linux kernel on 2013-03-11, the fix was released with Linux 3.10.
  2. On the qnap NAS, there is a microcontroller which also needs to be configured with regards to the power-saving mode it should use. The NAS has a feature called EUP, which stands for “Energy-using Products”, a EU directive for power saving. When you enable EUP, your qnap sleeps so deep, it will not react to the WOL magic packet. This saves another watt or so. To turn this off, qcontrol needed to be patched to provide access to the WOL and EUP bits.
  3. And finally, the Debian kernel just did not enable the CONFIG_MARVELL_PHY configuration option which you need to actually make use of the kernel patch I landed in Linux 3.10. The bug I filed for this was fixed with the linux package in version 3.12.8-1.

Minimum package versions

To use Wake-On-LAN, you’ll need to install linux-image-3.12-1-kirkwood ≥ 3.12.8-1. Furthermore, you’ll need qcontrol ≥ 0.5.2-2. Note that you will also perhaps need to build qcontrol from git to disable the real time clock. Once there is a new package available, I’ll update this paragraph.

Enabling Wake-On-LAN

What you’ll need once is disabling EUP and RTC (real-time clock). You need to disable the RTC because otherwise the NAS is confused about scheduled wake-up and will immediately wake up after you power it down:

qnap # qcontrol eup off
qnap # qcontrol rtc off

Before every shutdown, you need to enable Wake-On-LAN:

qnap # ethtool -s eth0 wol g
qnap # qcontrol wakeonlan on

I like to turn off WOL after booting because I think (haven’t done enough testing to definitely confirm it) that the microcontroller gets confused when it receives a WOL packet while the box is running. In that case, it will immediately power back up after you power down.

Once you enabled WOL, power off the NAS, and try turning it back on from another machine:

qnap # ip link show eth0
qnap # poweroff
x200 $ wakeonlan 00:08:9b:de:22:ff

Note that you must not disconnect the device entirely from power, as the microcontroller will lose its state. That means, when you have a power outage, you need to power on the NAS manually once.

Making the WOL setup persistent

With the following systemd unit, you’ll get WOL disabled during runtime and enabled before powering off:

Description=Enable Wake on LAN on shutdown
# Just for having the correct order when shutting down.
# Require eth0 to be present before trying to change WOL.

ExecStart=/sbin/ethtool -s eth0 wol d
ExecStart=/usr/sbin/qcontrol wakeonlan off
ExecStop=/sbin/ethtool -s eth0 wol g
ExecStop=/usr/sbin/qcontrol wakeonlan on


You can find the newest version of this service file on github.

Automatically powering off

I wrote a program called dramaqueen, which will power off the NAS once it realizes that there are no more CIFS (Samba) sessions established. In addition to the CIFS checks, you can also set custom inhibitors, for example for running a backup.

To cross-compile dramaqueen for the qnap, use:

$ go get github.com/stapelberg/zkj-nas-tools/dramaqueen
$ GOARCH=arm GOARM=5 go build github.com/stapelberg/zkj-nas-tools/dramaqueen
$ file dramaqueen 
dramaqueen: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), …

In my setup, once I suspend my workstation (and all other machines using the NAS), the NAS will notice that my session has gone and shut itself down after 10 minutes.