4

I'm doing virtualization with KVM and managing it via the Libvirt daemon.

How do I configure Libvirt or KVM to listen for Wake-On-Lan packets sent the the Virtual Machine's NIC's MAC address and to start the Virtual Machine when such a packet is received?

3

I've found Libvirt-wakeonlan which seems to do it. I have no idea how mature it is and how well it works. The approach seems right. https://github.com/simoncadman/libvirt-wakeonlan

2
  • 1
    From the author when asked about maturity: It's not particularly mature, it lacks things like logging, and has only really been properly tested under Gentoo Linux. I've been using it for a development environment for about 9 months and it's been completely stable so far, but as far as I know nobody has used in a production environment.
    – user130356
    Feb 2 '13 at 22:41
  • I made this: gitlab.com/-/snippets/2183494
    – Gotschi
    Oct 1 at 13:05
2

you can use my script which essentialy does the same as libvirt-wakeonlan, I made it because I could not get libvirt-wakeonlan to work... this is just a simple script which you can put in a startup script and have it running on boot.

It listens to udp port 9 (port 7 is also used sometimes afaik but guacamole - the remote vnc/rdp I use - sends at port 9) and checks the MAC adress when it sees a magic packet. If there is a vm in virsh with this MAC adress it will wake the machine up.

https://gitlab.com/-/snippets/2183494

#!/bin/bash

nc -dknl -p 9 -u | # listen to udp port 9 for packets, check if it is a magic packet
 stdbuf -o0 xxd -c 6 -p |
 stdbuf -o0 uniq |
 stdbuf -o0 grep -v 'ffffffffffff' |
 while read ; do
    mac="${REPLY:0:2}:${REPLY:2:2}:${REPLY:4:2}:${REPLY:6:2}:${REPLY:8:2}:${REPLY:10:2}"
    # parse mac found in magic packet
    for i in $(virsh list --all --name); do # loop through libvirt machines
        vmmac=$(virsh dumpxml $i | grep "mac address" | awk -F\' '{ print $2}') # get each machines MAC
        if [ $vmmac = $mac ]; then # compare MACs, if match do;
            echo $mac;
            echo $i;
            virsh start $i
            virsh resume $i
        fi
    done
done
1
  • Could use some comments, like which packets it acts on (udp/9) and which mac address it will wake up (not just those sent repeatedly, right?)
    – anx
    Oct 1 at 13:20
-1

Wake-On-LAN is Wake-On-LAN, wether you use a virtual machine or a physical machine. If your virtualization software supports it then just use a WoL tool against the MAC address.

3
  • But how do I do this with KVM+libvirt?
    – user130356
    Feb 1 '13 at 12:15
  • 6
    About as helpful as is is is. He knows what wake on lan is. You answer made no attempt to answer the question. How to start a vm with wake on lan, assuming kvm and libvirt support it. As I would still very much like to know, I'll need to look else ware for an answer Oct 21 '15 at 23:37
  • 1
    downvoted for precisely the reasons given by @KeithReynolds - this answer was not helpful and, further, inaccurate - hypervisors usually do not have a dedicated physical NIC attached to each guest, so WoL would differ from a physical machine and would have to be handled by the hypervisor itself. Nov 20 '19 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.