HOW-TO:Set up Wake-on-LAN for Ubuntu

From Official Kodi Wiki
Revision as of 20:49, 28 May 2010 by >MacUsers
Jump to navigation Jump to search

Template:XBMC wiki toc Inline

Before you start

First off, the motherboard should support the WOL (Wake On LAN) and it should be enabled in the BIOS. Different BIOS/motherboard do it differently; on ASUS (P5N7A-VM), it's under Power > APM Configuration and in there "Resume On PCIE Wake" and "Resume On LAN(MAC)" should be enabled.

Enabling WOL in the OS

Even though WOL works in network layer 2, OS support is still one of the important things to make it work. Even if you see the light on the Ethernet port is on after the halt/shutdown, the OS shuts off the Ethernet internally. One must tell Ethernet controller to WOL when boots up and tell "halt" script not to bring down controller during shut-down.

Install ethtool

I found "ethtool" is one of the easiest to use to enable WOL; install it first if it's not there yet.

sudo apt-get ethtool

Set Wake-on-LAN options

Run the following command to enable it:

sudo ethtool -s eth0 wol g
  • Note: Not all devices support this.

This can be verified running ethtool on ethX (where X is the name/number of the Ethernet device).

xbmc@htpc:~$ sudo ethtool eth0
[sudo] password for xbmc: 
Settings for eth0:
	Supported ports: [ MII ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	.....
        .....
	Auto-negotiation: on
	Supports Wake-on: g
	Wake-on: g
	Link detected: yes
  • Note: There was a bug in the "halt" script for the previous version of kernel(s), which was stopping WOL to be kicking in but that seems to be fixed now.

Make it permanent

Next, create a file, say "walk-on-lan" in the "/etc/init.d" to automatically start WOL at the boot time.

sudo cat << EOF >> /tmp/walk-on-lan
#!/bin/bash
#
### BEGIN INIT INFO
# Provides:             walk-on-lan
# Required-Start:       \$local_fs
# Required-Stop:        \$local_fs
# Default-Start:        2 3 4 5
# Default-Stop:         0 6
# Short-Description:    Enable Wake-On-Lan 
### END INIT INFO

#
. /lib/lsb/init-functions

do_start() {
    ethtool -s eth0 wol g
    exit
} 

do_stop() {
    ethtool -s eth0 wol d
    exit
}

case "$1" in
  start)
        do_start
        ;;
  restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
  stop)
        do_stop
        ;;
  *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac
EOF
sudo chmod 755 /etc/init.d/walk-on-lan

Configure WOL service to start upon boot

"sysv-rc-conf" is Run-level configuration for Sys-V like init script links. sysv-rc-conf is not installed by default

sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf --level 2345 walk-on-lan on