Wake on Lan for Virtual Machines for 6.1+


dmacias

Recommended Posts

Wake On Lan for Virtual Machines 6.1+

Based on simoncadman/libvirt-wakeonlan github https://github.com/simoncadman/libvirt-wakeonlan

 

This plugin is a daemon which listens for a wake on lan packet on udp port 7, port 9 and ether protocol 0x0842 then starts the corresponding KVM based virtual machine. I tested it to work with an android app called Wake On Lan, ether-wake and asus router.

 

This will work with 6.1+

 

This will only work on stopped or hibernated virtual machines. It will not wake up vm's in a sleep state.

 

1. Copy the plugin url:

https://raw.githubusercontent.com/dmacias72/unRAID-libvirtwol/master/plugin/libvirtwol.plg
 

 

2. Paste url into install plugin text input and click install

 

3. Wake On Lan will be added to Settings/VMSettings page for starting the daemon

 

As of 2018.01.13 NerdPack plugin is required to install Python 2

https://raw.githubusercontent.com/dmacias72/unRAID-NerdPack/master/plugin/NerdPack.plg

 

Change Log:

###2019.01.06
- move all python dependencies to virtual environment package
- add initial support for virtual bmc

###2018.10.28
- update libvirt-python to 4.7 for 6.6
- remove support link from readme

###2018.01.13
- require NerdPack for Python 2 install
- add notification for missing python
###2017.11.28a
- update libvirt-python to 3.8 for 6.4
- update python to 2.7.14a for 6.4
- add work around to plugin install services
###2017.11.28
- move to separate repo

###2017.04.11
- update python for 6.2, 6.3 and 6.4
###2017.01.30a

harden code for XSS and CSRF vulnerabilities

- fix form not defined and submitting

- update libvirt-python to 2.5.0 for 6.3

- update python to 2.7.13

- add support link to readme

###2016.11.05

- fix: continue script on exception e.g. error in vm xml

###2016.10.22

- fix: min and max

###2016.10.15

- add: min and max versions

###2016.10.09

- update for 6.3

###2016.09.16

- update python to 2.7.12

###2016.06.04

- add rc script

- amend dynamix plugin api

###2016.04.16

- add help button comments

- add dynamix plugin API

- add white-space: normal to fix status css formatting

###2016.03.23

- remove libpcap package

###2016.03.19

- add wake on lan to advanced view

###2016.03.14

- update package locations

###2016.03.12

- add dual package support for 6.1 and 6.2+

- add python 2.7.11 for 6.2+

- add libvirt python 1.3.1 for 6.2+

- move settings to php file and include in vm settings

- move all permissions on scripts to plugin package install

###2016.01.22

- update install and remove scripts

- check if config exists

- create a default config file

###2016.01.02

- fix not starting with array

###2015.12.21a

- fix config file and start/stop

- add unRAID version check

- add md5 package ckeck

- convert install and remove scripts

###2015.12.01

- added fix for other packet sizes

###2015.11.18

- update python to 2.7.9

###2015.11.17

- fix start and stop event permissions

###2015.11.16

- added promiscuous mode to listen for all packets

- will recieve all ether proto 0x0842 packets now

###2015.11.15

- added support for ethertype 0x0842

- tested with ether-wake but asus router still not waking

###2015.11.14c

- fix plugin page image and link

- pkg variable typo

###2015.11.14

- initial commit

 

Edited by dmacias
  • Upvote 1
Link to comment
  • 3 weeks later...

Hi dmacias,

 

many thanks for your plugin. I want to use it for my virtual gaming machine to be started automaticly if SHIELD TV wants to start a game.

But if i sent a "magic packet" the from SHIELD or from my Router to the virtual MAC, nothing happens. I can see the Broadcast with tcpdump in the network. Virtual host will not be started. Also the log (/var/log/libvirt/libvirtwakeonlan.log) is empty.

 

My Setup:

unRAID- 6.1.4

Bridged network (br0)

 

If you need more information, let me know it.

 

Thx

Link to comment

 

 

Hi dmacias,

 

many thanks for your plugin. I want to use it for my virtual gaming machine to be started automaticly if SHIELD TV wants to start a game.

But if i sent a "magic packet" the from SHIELD or from my Router to the virtual MAC, nothing happens. I can see the Broadcast with tcpdump in the network. Virtual host will not be started. Also the log (/var/log/libvirt/libvirtwakeonlan.log) is empty.

 

My Setup:

unRAID- 6.1.4

Bridged network (br0)

 

If you need more information, let me know it.

 

Thx

 

Is the daemon running? Under Settings/VM Manger/Wake On Lan does Enable Wake On Lan have a green running next to it? Check the log that after you start the daemon it says something like this.

/usr/local/emhttp/plugins/libvirtwol/scripts/start
Dec 1 06:08:50 server kernel: device br0 entered promiscuous mode

Check there's nothing else that could be blocking the packet like firewall or something else.  Can you try wol from a computer or phone app to see if that works? Also there's a log created at /var/log/libvirt/libvirtwakeonlan.log

Link to comment
Under Settings/VM Manger/Wake On Lan does Enable Wake On Lan have a green running next to it?

The daemon is running. Status under "Settings/VM Manger/Wake On Lan" is green.

 

root@Hub:~# ps -ef | grep libvirtwol
root     14180     1  0 14:20 pts/0    00:00:00 /usr/bin/python /usr/local/emhttp/plugins/libvirtwol/scripts/libvirtwol.py br0

 

dmesg

device br0 entered promiscuous mode

 

No logging

root@Hub:~# ls -l /var/log/libvirt/
total 16
-rw------- 1 root root 13795 Dec  1 07:44 libvirtd.log
-rw-rw-rw- 1 root root     0 Dec  1 14:22 libvirtwakeonlan.log

 

There is no firewall between unRAID system and the clients (same network).

I tried a 3rd app on my android phone (Wake On Lan from Mike Webb). No wakeup with SHIELD, Router and the android app.

Link to comment

That's the same android app I used. It uses upd port 9. Only thing I can think is to enable wake on lan in your bios. Maybe the network card is blocking it. I have a tcpdump package in my github. I'll get you the link and some commands to run from unRAID console in a few.

Link to comment

Under Settings/VM Manger/Wake On Lan does Enable Wake On Lan have a green running next to it?

The daemon is running. Status under "Settings/VM Manger/Wake On Lan" is green.

 

root@Hub:~# ps -ef | grep libvirtwol
root     14180     1  0 14:20 pts/0    00:00:00 /usr/bin/python /usr/local/emhttp/plugins/libvirtwol/scripts/libvirtwol.py br0

 

dmesg

device br0 entered promiscuous mode

 

No logging

root@Hub:~# ls -l /var/log/libvirt/
total 16
-rw------- 1 root root 13795 Dec  1 07:44 libvirtd.log
-rw-rw-rw- 1 root root     0 Dec  1 14:22 libvirtwakeonlan.log

 

There is no firewall between unRAID system and the clients (same network).

I tried a 3rd app on my android phone (Wake On Lan from Mike Webb). No wakeup with SHIELD, Router and the android app.

 

That's the same android app I used. It uses upd port 9. Only thing I can think is to enable wake on lan in your bios. Maybe the network card is blocking it. I have a tcpdump package in my github. I'll get you the link and some commands to run from unRAID console in a few.

Here's the package. Just wget and installpkg and some commands to test with it. See if anything shows in the console when you send a wol packet.

https://raw.githubusercontent.com/dmacias72/unRAID_6.0/master/tcpdump-4.4.0-x86_64-1.txz

tcpdump -i br0 ether proto 0x0842

tcpdump -i br0 udp port 9

Link to comment

New status. There was a typo in the mac-address on the app on my phone :).

 

I can now wakeup the virtual machine from my phone with the app but not from the SHIELD TV.

 

tcpdump -i br0 udp port 9 (Wake On Lan app)

19:20:30.361997 IP 10.10.10.152.53474 > 10.10.10.255.9: UDP, length 102
19:20:30.362026 IP 10.10.10.152.55554 > 10.10.10.255.9: UDP, length 102
19:20:30.362106 IP 10.10.10.152.58293 > 10.10.10.255.9: UDP, length 102

 

tcpdump -i br0 udp port 9 (SHIELD TV)

19:21:28.369284 IP 10.10.10.178.53735 > 10.10.10.255.9: UDP, length 192
19:21:28.369330 IP 10.10.10.178.53735 > 255.255.255.255.9: UDP, length 192
19:21:28.569890 IP 10.10.10.178.53735 > 10.10.10.255.9: UDP, length 192
19:21:28.569908 IP 10.10.10.178.53735 > 255.255.255.255.9: UDP, length 192
19:21:28.770436 IP 10.10.10.178.53735 > 10.10.10.255.9: UDP, length 192
19:21:28.770467 IP 10.10.10.178.53735 > 255.255.255.255.9: UDP, length 192
19:21:43.468351 IP 10.10.10.178.47381 > 10.10.10.255.9: UDP, length 192
19:21:43.468493 IP 10.10.10.178.47381 > 255.255.255.255.9: UDP, length 192
19:21:43.669343 IP 10.10.10.178.47381 > 10.10.10.255.9: UDP, length 192
19:21:43.669478 IP 10.10.10.178.47381 > 255.255.255.255.9: UDP, length 192
19:21:43.870465 IP 10.10.10.178.47381 > 10.10.10.255.9: UDP, length 192
19:21:43.870480 IP 10.10.10.178.47381 > 255.255.255.255.9: UDP, length 192

 

tcpdump -i br0 ether proto 0x0842

-no output-

 

Only different packet length (102 for the app and 192 for the SHIELD) for the magic packet.

Maybe the shield is sending more information in the magic packet than needed which cant be parsed from libvirtwol.

 

I increased the snaplength in tcpdump and loaded it into wireshark:

Phone APP (wakeup works):

Frame 1: 144 bytes on wire (1152 bits), 144 bytes captured (1152 bits)
Ethernet II, Src: LgElectr_16:b5:0e (8c:3a:e3:16:b5:0e), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Internet Protocol Version 4, Src: 10.10.10.152, Dst: 10.10.10.255
User Datagram Protocol, Src Port: 50467 (50467), Dst Port: 9 (9)
Wake On LAN, MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
    Sync stream: ffffffffffff
    MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)

 

SHIELD (wakeup doesn't work):

Frame 1: 234 bytes on wire (1872 bits), 234 bytes captured (1872 bits)
Ethernet II, Src: Nvidia_54:24:52 (00:04:4b:54:24:52), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Internet Protocol Version 4, Src: 10.10.10.178, Dst: 10.10.10.255
User Datagram Protocol, Src Port: 35927 (35927), Dst Port: 9 (9)
Wake On LAN, MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09), password: 00:00:00:00:00:00
    Sync stream: ffffffffffff
    MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
        MAC: RealtekU_e6:3b:09 (52:54:00:e6:3b:09)
    Password: 00:00:00:00:00:00

 

What is "Password: 00:00:00:00:00:00" in tha magic packet from the SHIELD (at the end of the wireshark output)?

Can we cut it out from libvirtwol or ignore it?

 

Thx for your time and effort.

Link to comment

Libvirtwol.py mac address section relies on packet size to parse the packet for 16 repetitions of a mac address. For you it doesn't work because of the extra packet size.

 

I was able to reproduce your problem by using etherwake -p 00:00:00:00:00:00 -i br0 macaddress.

 

I'll look at the libvirtwol.py script again and see if I can tweak it.

Link to comment

thanks for great plugin, but mostly for KVM virtu idle/sleep dont work proper, like for Openelec ;(

i was talked about this with @jonpanozzo and @@eschultz - this is last thing what about dreaming:

"wakup virtu like Openelec from Remote and autosleep after some idle time"

 

Let me know if you tested with Openelec - if this will work maybe will be possibility write script with looking on USB activity (some remote)\

and when find it, then call to script wake on lan to resume virtu ...

 

Or maybe somebody will have better idea how this resolve ....

 

Link to comment

thanks for great plugin, but mostly for KVM virtu idle/sleep dont work proper, like for Openelec ;(

i was talked about this with @jonpanozzo and @@eschultz - this is last thing what about dreaming:

"wakup virtu like Openelec from Remote and autosleep after some idle time"

 

Let me know if you tested with Openelec - if this will work maybe will be possibility write script with looking on USB activity (some remote)\

and when find it, then call to script wake on lan to resume virtu ...

 

Or maybe somebody will have better idea how this resolve ....

I wish I could test with Openelec but my system only supports vt-x. Probably a script involving udev might work.  I personally use Nevo Q50 zwave remotes to wake Openelec boxes through a Micasaverde Vera. I send a zwave scene command to Vera which then sends the wake on lan packet to my Openelec boxes.

Link to comment
  • 2 weeks later...
  • 3 weeks later...

This is indeed very awesome!

 

Could you perchance implement resumption of paused VMs via magic packet as well?

 

Sometimes my VM gets paused and I have to use the webui to resume it..

I'll see what I can do but when I was writing the VM Manager that unRAID uses now which is based on libvirt php it was hard to determined the a pm suspend paused state and resume which is different than a regular paused state. Now this is based on libvirt python and there are some more options available but some quick tests I tried didn't work.

 

I would suggest you either turn off power management in the vm or change it to hibernate instead which would power off the vm and allow it to be woken.

Link to comment
  • 2 months later...
  • 5 weeks later...

I updated the plugin about a month ago to work with 6.2. I just tried and was able to wake a ubuntu and windows vm from my asus router and my wakeonlan plugin. 6.2 needs python 2.7.11. Do you have any other python plugins or nerd pack that may install python 2.7.9?

Link to comment

I updated the plugin about a month ago to work with 6.2. I just tried and was able to wake a ubuntu and windows vm from my asus router and my wakeonlan plugin. 6.2 needs python 2.7.11. Do you have any other python plugins or nerd pack that may install python 2.7.9?

 

Thanks for the swift response.

 

I double checked by completely removing the NerdPack and typing python -v outputs 2.7.11 on my unraid server..

My wake on lan app on android is configured to broadcast the VM's MAC to 10.10.0.255 (10.10.0.1 being my Unraid machine). Also just sending the command to 10.10.0.1 does not work.

Changing the MAC has not changed things either.

 

Seems my fiddling with the VMs somehow broke this plugin. It was working without problems for the last few months.

 

Is there any way I could debug or troubleshoot why it suddenly stopped working?

Link to comment

It's possible if your were not on the latest version or upgraded after updating to 6.2 you have the wrong version of libpcap installed. 6.1 needs 1.4.0 and 6.2 has 1.7.4 included so the plugin doesn't install libpcap for 6.2. But if you have the latest and have rebooted since you should be fine.

 

For further testing you can stop the service from the vm manager settings page then go to the command line. Run this command where br0 is your bridge name. Then try sending a wake on lan. Try from different apps if you can. I have a plugin for wol too or try from your router. The script will show if there's an error.

python /usr/local/emhttp/plugins/libvirtwol/scripts/libvirtwol.py br0

 

Also the pcap interface is set to promiscuous mode so all packets are captured. So you don't need to point wol to your server ip.

Link to comment

Hi, typing python /usr/local/emhttp/plugins/libvirtwol/scripts/libvirtwol.py br0

And using your Wakeonlan plugin from within my unraid server does indeed wake up the vm.

 

I have no idea why my android app suddenly is not getting through to the plugin anymore. Haven't changed any router settings, nor did I apply new iptables rules...

 

Any idea what could be blocking my access?

 

Okay here is the following:

 

Wake on lan from your Wake On Lan support plugin does only work if I have ssh open with the

python /usr/local/emhttp/plugins/libvirtwol/scripts/libvirtwol.py br0

command actively running.

 

Then it still wont work from my phone, but that sounds like the issue.

 

Could it be, that libvirtwol is not listening on the right interface (eth0?) and thus causing issues?

Or could it be that it's not running at all (even though it seems to be running without issues)?!

 

Another addition

 

My domain.cfg

SERVICE="enable"
IMAGE_SIZE="1"
IMAGE_FILE="/mnt/user/system/libvirt/libvirt.img"
DOMAINDIR="/mnt/user/domains/"
MEDIADIR="/mnt/user/isos/"
VIRTIOISO=""
BRNAME="virbr0"
WOL="enable"

 

My network.cfg

# Generated settings:
USE_DHCP="no"
IPADDR="10.10.0.1"
NETMASK="255.255.255.0"
GATEWAY="10.10.0.100"
DHCP_KEEPRESOLV="no"
DNS_SERVER1="8.8.8.8"
DNS_SERVER2="8.8.4.4"
DNS_SERVER3=""
BONDING="no"
BONDING_MODE="1"
BRIDGING="yes"
BRNAME="br0"
BRSTP="yes"
BRFD="0"

 

And my vm is running on br0 also.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.