Wake On Lan

The ability to wake a machine up over the network is really nice.  This feature is referred to as wake on lan (WOL).  Most modern hardware supports this, and many operating systems have it nicely integrated (Mac OSX for one) – under Linux it required a bit more magic.  This post is specific to Ubuntu 9.10, however it probably applies to other versions and variants.

Primarily I was looking to wake up from suspended state as I tend to let my machine sleep when I’m not using it, however WOL works with both hibernate and full shutdown. If you are having trouble, its a good idea to validate that your BIOS settings are correct – as support for WOL can be enabled/disabled in the BIOS.

Unfortunately since everyone has different hardware, the details of the solution will be different.  I learned a lot of this from a thread in the ubuntu forums.  Here is my specific solution, read on past the break if you want to understand how I arrived at this solution.

I created a file /etc/init.d/wakeonlan with the following contents

#! /bin/sh
### BEGIN INIT INFO
# Provides:          wake on lan
# Required-Start:    $network
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Configures WOL
# Description:       Configures Wake-On-Lan
### END INIT INFO
#
ethtool -s eth0 wol g
echo enabled >  /sys/class/net/eth0/device/power/wakeup
echo SLOT > /proc/acpi/wakeup
echo KBC > /proc/acpi/wakeup

Ensuring the permissions allow execute (chmod a+x wakeonlan).  And added it to the startup sequence:

sudo update-rc.d -f wakeonlan defaults

Now every reboot you’ll get WOL setup, and the keyboard will wake up the machine too.

The rest of this post covers how I figured out what magic went into the init.d script. First we need to tweak the network driver to enable WOL behaviour, in my case that’s eth0:

sudo ethtool -s eth0 wol g

In my case it seems I also need to set the wake up flag in the driver to enabled, otherwise the card loses power and the WOL flag we just set doesn’t help since the power is off.

sudo sh -c "echo enabled >  /sys/class/net/eth0/device/power/wakeup "

Now that we have the card configured to stay powered (to some level) and react to the WOL packet, we need to configure the ACPI wakeup file (/proc/acpi/wakeup) to enable the ethernet card.  This is where things will be system dependent – my file looks like:

$ cat /proc/acpi/wakeup
Device    S-state      Status   Sysfs node
USB1      S3     disabled  pci:0000:00:1d.0
USB2      S3     disabled  pci:0000:00:1d.1
USB3      S3     disabled  pci:0000:00:1d.2
USB4      S3     disabled  pci:0000:00:1d.3
USBE      S3     disabled  pci:0000:00:1d.7
SLOT      S5     disabled   pci:0000:00:1e.0
KBC      S3     disabled   pnp:00:07
COMA      S5     disabled  pnp:00:0b

Hmm, so none of these say “ethernet” or “eth0”- now what?  We turn to the lspci command

$ lspci -tv
-[0000:00]-+-00.0  Intel Corporation 82865G/PE/P DRAM Controller/Host-Hub Interface
+-02.0  Intel Corporation 82865G Integrated Graphics Controller
+-06.0  Intel Corporation 82865G/PE/P Processor to I/O Memory Interface
+-1d.0  Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #1
+-1d.1  Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #2
+-1d.2  Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #3
+-1d.3  Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #4
+-1d.7  Intel Corporation 82801EB/ER (ICH5/ICH5R) USB2 EHCI Controller
+-1e.0-[0000:03]----08.0  Intel Corporation 82562EZ 10/100 Ethernet Controller
+-1f.0  Intel Corporation 82801EB/ER (ICH5/ICH5R) LPC Interface Bridge
+-1f.1  Intel Corporation 82801EB/ER (ICH5/ICH5R) IDE Controller
+-1f.3  Intel Corporation 82801EB/ER (ICH5/ICH5R) SMBus Controller
\-1f.5  Intel Corporation 82801EB/ER (ICH5/ICH5R) AC'97 Audio Controller

So now we know the PCI address for eth0 is

+-1e.0-[0000:03]----08.0  Intel Corporation 82562EZ 10/100 Ethernet Controller

and we match that the to /proc/acpi/wakeup file line

SLOT      S5     disabled   pci:0000:00:1e.0

This tells us that we need to enable the SLOT device in the wakeup file:

sudo sh -c "echo SLOT > /proc/acpi/wakeup"

I thought it’d be nice to make my keyboard also able to wake the machine up from sleep, this simply requires enabling the KBC device:

sudo sh -c "echo KBC > /proc/acpi/wakeup"

The last step is to do these steps every time we clean boot the system.  There was another useful thread in the ubuntu forums that describes how to create an /etc/init.d script to do it.  My script was presented above in its complete form.

6 thoughts on “Wake On Lan”

  1. Thank you so much for this. I was missing the /proc/acpi/wakeup bit but now have WOL working fine on an old Dell Dimension 4600.

  2. Hi, I was using WOL under windows but since I have installed Ubuntu on my Optiplex I have a trouble to wake my machine from outside of my firewall on wifi router, never understood why (until now of course). Now it is working great again. Many thanks.

  3. Hi
    I was wondering if this will work for waking up a server while in suspend mode with a bluetooth phone. I’m having trouble with this issue for years now…
    It’s like running a script when detecting bluetooth activity (maybe)
    Email me if any news on this topic geniemediaguardATgmail.com

    Thanks
    GMG

  4. The WOL facility is using a feature of the networking hardware which monitors the traffic and will raise a signal on the bus to wake the PC. You won’t be able to do this with bluetooth activity.

    A simpler solution would be to get a router that supports wake on lan, and make use of it to trigger the PC wake-up based on some event you can trigger with your phone.

    Check out http://www.dd-wrt.com/wiki/index.php/WOL – while there are examples of doing remote (internet) wake-up, you could clearly do the same on your internal network too. I am of course assuming you have a smart phone connected to the same network via wifi.

  5. Hi Roo,

    Just wanted to say thanks for pulling together all that info and posting a complete solution here. Worked wonderfully. Really appreciate it. Now I don’t have to leave my machine on all day, wasting energy, when I go into the the office — “just in case” I might need it.

    Thanks again!

    Keith C.

Leave a Reply

Your email address will not be published.