LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > ted_chou12
User Name
Password

Notices


Rate this Entry

how to wake on lan?

Posted 10-06-2012 at 02:16 PM by ted_chou12

Shutdown is easy but wake up is hard, well, in terms of both ppl and machines. Shutdown goes from system to bios, which makes life so much easier, but to initiate the machine, it just needs that physical "touch" to push the system. In fact, there is a built-in capability in your motherboard bios called "wakeonlan" or wol for short. First, you need to go into your bios to turn it on, since the menu may differ from company to company, you have to sort this out on your own. Make sure that "Wake on PCI" and "Wake on RTC" are both "ENABLED" though.
Then we can get to the linux part. Since you have enabled both, lets talk about the PCI first, I don't quite actually know why wake up by lan is categorized under the pci option, since all modern boards have lan on the board itself, you don't need to add a pci card for ethernet, but anyways.
Install package named "ethtool" on the linux machine that you want it to turn on.
Make sure you are logged in as root:
Code:
root:# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x000000ff (255)
                               drv probe link timer ifdown ifup rx_err tx_err
        Link detected: yes
Highlighted lines are very important if:
Code:
Settings for eth0:
       Supports Wake-on: g
       Wake-on: d
       Link detected: yes
Then you need to enable wake-on by:
Code:
ethtool -s eth0 wol g
Then check again with ethtool eth0 again.
Next is to shutdown this machine and use another linux machine to wake it up. On the other linux machine, you need to either install etherwake or wakeonlan to send a magical packet to the machine that you want to awake.
Code:
sh-3.1# wakeonlan  08:00:20:C2:1E:F6
Sending magic packet to 255.255.255.255:9 with 08:00:20:C2:1E:F6
Whereas the mac address is the address of the machine that you want to awake. Get it by
Code:
ifconfig
(HWaddr).
You should be able to turn on the machine remotely now.
To enable a timed wake on lan. See the 2nd part starting below:
First you have to make sure that your hwclock is in UTC time, NOT localtime. See my older post if you have questions.
Check your current time by
Code:
sh-3.1# date '+%s'
1349550525
Then this would mean a time of 5 min in the future:
Code:
sh-3.1# date '+%s' -d '+ 5minutes'
1349550876
This enables you to determine how long in the future that you want to turn on your machine:
Code:
# echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
saves this future time into the file in rtc system. Now you can check if this time is succesfully recognized by the system:
Code:
# cat /proc/driver/rtc
rtc_time        : 19:12:54
rtc_date        : 2012-10-06
alrm_time       : 19:17:37
alrm_date       : 2012-10-06
alarm_IRQ       : yes
alrm_pending    : no
update IRQ enabled      : no
periodic IRQ enabled    : no
periodic IRQ frequency  : 1024
max user IRQ frequency  : 64
24hr            : yes
periodic_IRQ    : no
update_IRQ      : no
HPET_emulated   : yes
BCD             : yes
DST_enable      : no
periodic_freq   : 1024
batt_status     : okay
the upper part is the time now and the lower part is the time in the future (bootup time). Don't worry about the timezone, cause rtc time is meant to be saved in GMT time. Now you can safely shutdown your computer to wait for it to boot up 5 minutes later without getting any closer.
Ted
Posted in Uncategorized
Views 10826 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    Sources:
    http://www.debian-administration.org/articles/122
    Quote:

    Turning on computers remotely


    Posted by Steve on Wed 20 Apr 2005 at 08:42

    Tags: boot, network booting, wakeonlan

    To save power it's often useful to turn systems off, but of course when you do that you cannot use them! This is especially frustrating when you turn off a machine which is physically remote from you, but it doesn't need to be. Many modern PCs have the ability to be remotely "woken up" and turned on.

    "WakeOnLan" is the term which is used for remotely powering on machines, as this is done by sending "magic network packets" to switch on machines.

    To use wakeonlan you'll need either:
    •A network card which supports WakeOnLan, which usually has a jumper which connects to your system's motherboard.
    •An on-board network interface which supports this functionality.

    Many modern systems with on-board NICs support wakeonlan, but it must be enabled in the BIOS. (Look for the option in the "power management" section of your BIOS, it might be called "wakeonlan", "netboot", or "wake on ring events").

    If you have the requisite hardware support can see if it's enabled by your system by running the ethtool command, this shows whether the wakeonlan option is supported by your card, and whether it is enabled.

    If you don't have this installed run:
    apt-get install ethtool

    Once it's installed run it with the name of your network interface:
    root@lappy:~# ethtool eth0
    Settings for eth0:
    Supports Wake-on: g
    Wake-on: d
    Link detected: yes

    Here we can see that wakeonlan support is available because of the g, but it's disabled. (This is explained in the manpage which you can read with "man ethtool"). To enable the magic packet support run:
    root@lappy:~# ethtool -s eth0 wol g

    Now you should be able to see that it's turned on:
    root@lappy:~# ethtool eth0
    Settings for eth0:
    Supports Wake-on: g
    Wake-on: g
    Link detected: yes

    Now that you know it's turned on you need to do one more thing. Wakeonlan software requires that you know the MAC address of the machine you wish to switch on, rather than the IP address.

    To determine the MAC address you can either:
    •Discover it on the machine itself before it is switched off, by using ifconfig
    •Determine it remotely, whilst the machine is powered on and running.

    To determine the MAC address via ifconfig just run it:
    skx@mystery:~$ /sbin/ifconfig
    eth0 Link encap:Ethernet HWaddr 00:0A:E6:F6:A3:F4
    inet addr:192.168.1.80 Bcast:192.168.1.255 Mask:255.255.255.0
    inet6 addr: fe80::20a:e6ff:fef6:a3f4/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:2218390 errors:0 dropped:0 overruns:0 frame:0
    TX packets:3098440 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:1624008578 (1.5 GiB) TX bytes:1368310661 (1.2 GiB)
    Interrupt:10 Base address:0xd400

    Here the MAC address is 00:0A:E6:F6:A3:F4, it's on the first line and is described as the "HWaddr" or "hardware address".

    If you're looking for the MAC address of another machine upon your LAN you can ping the machine, then look at the arp cache.

    For example if I wished to determine the MAC address of the machine sun.my.flat from my current host I'd run the following two commands:
    kx@mystery:~$ ping -c 1 sun
    PING sun.my.flat (192.168.1.1) 56(84) bytes of data.
    64 bytes from sun (192.168.1.1): icmp_seq=1 ttl=64 time=0.202 ms

    --- sun.my.flat ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.202/0.202/0.202/0.000 ms
    skx@mystery:~$ /usr/sbin/arp sun
    Address HWtype HWaddress Flags Mask Iface
    sun ether 08:00:20:C2:1E:F6 C eth0

    The arp command shows the machine's MAC address, the ping being required first to make sure that my current machine knew the MAC address in the first place.

    Once you have the MAC address you can shutdown the system you wish to test, and then attempt to restart it remotely.

    There are several pieces of software for sending the wakeonlan packets inside the Debian archive:
    •etherwake ◦Requires root privileges and available in all Debian distributions.

    •wakeonlan ◦Can be used by all users, but only in the Sarge (testing) and unstable (Sid) repositories


    I'm going to use wakeonlan, since it's already installed and can be used by non-root users:
    skx@mystery:~$ wakeonlan 08:00:20:C2:1E:F6
    Sending magic packet to 255.255.255.255:9 with 08:00:20:C2:1E:F6

    This sends the magic wake on lan packet to the machine on the LAN with the hardware address "08:00:20:C2:1E:F6" which we previously determined belonged to the machine sun.

    If all goes well the machine will begin to boot shortly after recieving the packet.
    http://ragsagar.wordpress.com/2011/0...in-arch-linux/
    Quote:
    How to automatically wake up your computer at a particular time ( Resume by RTC alarm in Arch Linux )

    August 15, 2011 by Rag Sagar.V രാഗ് സാഗര്*.വി


    My ISP provides unlimited download from 2am to 8am. So i was not able to sleep after 2 from the time i switched to the new broadband plan. Keeping the system on and setting a cronjob to start downloading after 2 was an option. But i was more concerned about the increasing electricity charge, than my sleep. Besides it is my social responsibility to save energy as a gonna-be software engineer . After a bit of googling and hacking i was able to wake up my system at a particular time. Here i am going to explain how i made my arch linux system to boot automatically at 2 am.

    The configuration is done in Arch Linux. For automatic wakeup it needs a BIOS which supports RTC alarm. Most of them manufactured after 2000 supports this feature.

    1) Check if your BIOS supports automatic wakeup

    Execute the command below as root.











    1

    # grep rtc /var/log/messages.log





    2

    rtc_cmos 00:03: RTC can wake from S4





    3

    rtc0: alarms up to one month


    If you can find something like this in the output.It says that the system can wakeup and a wakeup time can be setup.

    2) Enable automatic wakeup in BIOS

    Go to your BIOS setup, Under Power Management search for something like “Wake by RTC Alarm” or “Resume by RTC alarm” or “RTC resume”.Then enable it.

    3) Set the hardware clock time standard as UTC

    Edit the /etc/rc.conf file as root and set the HARDWARECLOCK variable to UTC











    1

    [ragsagar@h4ckb0x ~]$ grep ^HARDWARECLOCK /etc/rc.conf





    2

    HARDWARECLOCK="UTC"



    Make sure that your timezone is set correctly in /etc/rc.conf
    More help : https://wiki.archlinux.org/index.php/Time

    4) Set the alarm time

    Execute the following commands as root











    1

    # echo 0 > /sys/class/rtc/rtc0/wakealarm





    2

    # echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm



    This will set the the alarm time as 5 minutes into the future.



    Now run











    1

    $ cat /sys/class/rtc/rtc0/wakealarm



    If the output of above command is something like “1313383930″, the alarm is set. It is epoch time. If it doesn’t yield any result make sure that the HARDWARECLOCK variable is set to UTC and reboot and try again to set the alarm time.

    Now run











    1

    $ cat /proc/driver/rtc





    Go through rtc_time, alrm_time and alrm_date and check if they are correct(will be in UTC).Turn off the system and leave the power on. Check if the system is booting automatically after five mintues.

    5) Setting the alarm to a particular time and date.

    To set the alarm to woke up the system at 16th Aug 2:05am, Run the following as root











    1

    # echo 0 > /sys/class/rtc/rtc0/wakealarm





    2

    # date --date "Aug 16 , 2011 02:05:00" +%s > /sys/class/rtc/rtc0/wakealarm



    You can convert the epoch time to readable format and check the alarm time is correct.











    1

    [root@h4ckb0x ragsagar]# cat /sys/class/rtc/rtc0/wakealarm





    2

    1313440500





    3

    [root@h4ckb0x ragsagar]# date -d @1313440500 +%F" "%T





    4

    2011-08-16 02:05:00





    Note : The mythtv wiki about acpi wakeup says that setting the hardware clock after setting alarm will disable the alarm while most of the linux distribution sets hardware clock during shutdown. They suggest to disable hardware clock adjusting during shutdown. To do that in Archlinux set the HARDWARECLOCK=”" in /etc/rc.conf . But in my arch system the alarm was not working when i set HARDWARECLOCK=”" whereas it worked when i gave HARDWARECLOCK=”UTC”. So if the wake up alarm is not working do try after changing the value of this variable.

    To start downloading when the system boots up, i added a cronjob to restart the router at 2:15 and 7:45 (to account the download in happy hours). Also added “transmission-gtk” to the gnome-session-properties. So that transmission will be launched on startup and downloading will be started.
    Posted 10-06-2012 at 02:17 PM by ted_chou12 ted_chou12 is offline
  2. Old Comment
    Please note that you have to disable the old alarm first, if you want
    to set a new alarm. Otherwise, you get an error. Example:

    echo 12345 > /sys/class/rtc/rtc0/wakealarm
    echo 0 > /sys/class/rtc/rtc0/wakealarm
    echo 23456 > /sys/class/rtc/rtc0/wakealarm
    Posted 10-13-2012 at 08:52 PM by ted_chou12 ted_chou12 is offline
 

  



All times are GMT -5. The time now is 02:22 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration