| Both sides previous revision Previous revision Next revision | Previous revision |
| wake_on_lan [2022/01/13 17:27] – grandmabetty | wake_on_lan [2022/09/28 08:52] (current) – [Machine will not wake up] clarification on what batocera does automatically atari |
|---|
| ====== Wake on Lan (WoL) ====== | ====== Wake on LAN (WoL) ====== |
| ===== General information ===== | |
| Since Batocera V33 Beta there is a tool called [[https://mirrors.edge.kernel.org/pub/software/network/ethtool/|ethtool]] included into Batocera, which basically is a small but powerful advanced network configuration tool. In this case, //ethtool// is being used to enable [[https://en.wikipedia.org/wiki/Wake_On_LAN|Wake on Lan (WoL)]] functionality on your Batocera system, which is not enabled by default in Batocera (yet), so you have to configure it manually. Follow the instructions below to do so. | The [[wp>Wake_On_LAN|Wake-on-LAN (WoL)]] feature was implemented in Batocera **v33** where it is enabled on any WoL capable system by default (if you want to disable WoL for your system for whatever reason, then just disable WoL in your system's BIOS). With WoL it is possible to turn on/off your Batocera machine by sending a "magic packet" (or something else, more info later) from a remote WoL client via a network cable. This could be used for [[homeautomation|automation purposes]], for example to turn on your Batocera system at a specific time at night to backup all your userdata and games to a NAS and then shutdown again. And many other things! |
| |
| ===== Requirements ===== | ===== Requirements ===== |
| On your Batocera system, the functionality of WoL is dependent on three things that must support WoL: | |
| - **BIOS**: Your system's BIOS must support WoL and you have to enable WOL within your system's BIOS. | |
| - **NIC**: Your system's network adapter must support WoL to stay "awake" while the system is powered off. | |
| - **OS**: You typically need a device driver and/or tool for the specific NIC to be able to enable the hardware's WoL capability. Loading the OS (//Batocera.linux// in this case) usually gives you such a device driver (//ethtool// in this case). | |
| |
| After enabling WoL within the BIOS you can boot your Batocra system, log in via SSH into the shell and check by command line whether your NIC supports WoL or not by executing the following command: | On the Batocera machine, the functionality of WoL is dependent on two components supporting it: |
| <code>ethtool eth0</code> | * **BIOS**: The system's BIOS must support WoL (you may have to enable WoL within your system's [[:install_batocera#bios_settings_if_batocera_fails_to_boot|BIOS settings]]). |
| <WRAP center round tip 60%> | * **NIC**: The system's network adapter must support WoL to stay "awake" while the system is powered off. |
| Fortunately, Batocera.linux's underlying network system has [[https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/|Predictable Network Interface Names]]. Therefore, if you have multiple NICs installed your system you can just use the according ongoing ''eth<x>'' number of your specific network interface you want to check, e.g. ''eth1'', ''eth2'' and so on, without any hassle. You can list all of them up by executing: <code>ifconfig</code> | |
| </WRAP> | |
| |
| Now look out for the following two output lines: \\ | WoL is designed for use with wired Ethernet connections, but there are wireless NICs which may support Wake-on-Wireless (WoW). This article assumes you are using a standard wired connection. |
| ''Supports Wake-on:'' → Implifies whether and which WoL capabilities your NIC supports (you cannot change those values) \\ | |
| and \\ | |
| ''Wake-on:'' → Implifies which of them WoL capabilities are enabled for your NIC by the system (//may// be enabled by default, you can change those values as shown below) \\ \\ | |
| Example output: \\ | |
| ''Supports Wake-on: g'' \\ | |
| ''Wake-on: g'' \\ \\ | |
| The value ''g'' means that your NIC supports receiving magic packets and therefore //is// WoL capable. \\ | |
| Note that your NIC could also support multiple WoL functions and therefore you would get multiple output values, e.g. ''Supports Wake-on: pumbg''. \\ | |
| Here is a full list of output possibilities (from the ''man ethtool'' command): | |
| * p → Wake on PHY activity | |
| * u → Wake on unicast messages | |
| * m → Wake on multicast messages | |
| * b → Wake on broadcast messages | |
| * a → Wake on ARP | |
| * g → Wake on MagicPacket™ | |
| * s → Enable SecureOn™ password for MagicPacket™ | |
| * d → Disable (wake on nothing). This option clears all previous options. | |
| The most important value is the ''g'' within ''pumb**g**'' which is the minimal WoL capability we need here. Without it being shown, your NIC does not support WoL at all. | |
| \\ | |
| \\ | |
| Now: If for example your output looks like this: \\ | |
| ''Supports Wake-on: g'' \\ | |
| ''Wake-on:'' \\ | |
| it means your system's NIC is indeed WoL capable but not yet enabled. To enable the according option persistently you have to create an according [[udev_rules|udev rule]]. We will configure this rule to take place whenever a NIC is detected by the system on startup or even on-the-fly, for example if you plugin a USB-LAN adapter into your system while it is running: \\ | |
| {{:wakeonlan01.png|USB-LAN adapter}} | |
| |
| ===== Configuring WoL ===== | <WRAP center round tip> |
| To do so, create the following file... | If you are dual-booting with Windows on the same machine, you may need to also [[:troubleshooting#ethernet_connected_but_no_data|tell Windows to not disable the WoL shutdown procedure in its drivers]]. |
| <code>nano /etc/udev/rules.d/99-wol.rules</code> | |
| ...and paste the following content (if you want deeper explanation about udev rules, visit [[udev_rules|this]] page): | |
| <WRAP center round tip 60%> | |
| Note: The code below will enable WoL for all of your system's WoL capable NICs. If for some reason you want to enable WoL only for a specific NIC, replace ''eth*'' with the according NIC name on the ''ACTION==...'' code line. | |
| </WRAP> | </WRAP> |
| |
| <code> | ===== Setting up the BIOS ===== |
| ACTION!="add|change", GOTO="end" | |
| SUBSYSTEM!="net", GOTO="end" | |
| ENV{INTERFACE}!="eth*", GOTO="end" | |
| |
| TEST=="/sys/class/net/$env{INTERFACE}/device/power/wakeup", RUN+="/bin/sh -c 'echo enabled >/sys/class/net/$env{INTERFACE}/device/power/wakeup'" | This section can not be specific to your motherboard's BIOS configuration, so the instructions can only remain broad. With that said, here are the options you must generally set: |
| |
| ACTION=="add|change", SUBSYSTEM=="net", ENV{INTERFACE}=="eth*", RUN+="/usr/sbin/ethtool -s $env{INTERFACE} wol g" | * **Wake-on LAN**: Any setting that's related to this should be **enabled**/activated/unblocked. |
| | * **Wake-on PCI**: The same as above (**enabled**), if this option is separated out from the previous one then it usually refers to the powered state of the NIC when the rest of the machine is shut down. |
| | * **Network stack**: Set to **disabled**. Usually, this setting is in relation to whether or not the BIOS itself gains control of the network connection; if it does then WoL cannot function. |
| | * **IP configuration**: When done in the context of the BIOS, this means the Network Stack is enabled. If there's no explicit option to turn off the network stack, leaving all the IP-related fields empty should disable it. |
| | * **Power savings profile**: When mentioned in relation to the shutting down of devices when the machine is in S3/4, **disable** this. It may cause the NIC to shutdown after a period of inactivity. |
| |
| LABEL="end" | When done, save and reboot to apply. |
| </code> | |
| Save the file and quit the editor (Sidenote: No need to make the file executable). Because of [[modify_the_system_while_it_s_running|Batocera.linux's overlay based system]], to make the changes persistent, you have to execute the following command: | |
| <code>batocera-save-overlay</code> | |
| Now reboot your system. \\ From now on, when shutting down your system, it can be woken up by every magic packet based WoL client **within the same subnet** by sending a magic packet to the according unique MAC address of your NIC. | |
| |
| ===== Wake up your Batocera device remotely ===== | <WRAP center round info> |
| <WRAP center round tip 60%> | You may be wondering if you also need to enable the Wake-on-LAN feature in the NIC's settings as well. You don't, Batocera will automatically take care of enabling it for you. |
| Note: It is important to have your WoL client and your Batocera system within the same [[https://en.wikipedia.org/wiki/OSI_model#Layer_2:_Data_link_layer|Layer 2]] subnet of your network, otherwise WoL will not work as WoL packages are not going to be routed over different subnets! WoL is a Layer 2 protocol which actually can only be routed with additional and advanced workaround configurations which we are not going to cover here! | |
| </WRAP> | </WRAP> |
| |
| To find out the unique MAC address of your Batocera system's NIC, execute the following command on your Batocera system... | ===== Wake up your Batocera device remotely ===== |
| <code>ip link show</code> | |
| ...which will give you a similiar output as the following example screenshot: \\ | <WRAP center round important> |
| {{:wakeonlan02.png|MAC address}} \\ | Note: It is important to have your WoL client and your Batocera system within the same [[https://en.wikipedia.org/wiki/OSI_model#Layer_2:_Data_link_layer|Layer 2]] subnet of your network, otherwise WoL will not work by default. |
| As you can see on the screenshot above, the MAC address for the NIC ''eth0'' is ''f0:1f:af:25:dc:8b''. <WRAP center round tip 60%> | |
| Note: A MAC address is always based on twelve characters (48 bit) where every character pair is divided to its next character pair by a '':'' or a ''-'' symbol. | It is possible to set up a dynamic DNS and port forwardings on your router to send WoL from other subnets but that is outside of the scope of this article. |
| </WRAP> | </WRAP> |
| You can now use the given MAC address to wake your Batocera system up remotely from another device (e.g. PC, Smartphone, ...) which is **within the same Layer 2 subnet** and has a WoL client ([[https://www.pcwdld.com/free-wake-on-lan-tools#wbounce-modal|GUI based]] or [[https://www.cyberciti.biz/tips/linux-send-wake-on-lan-wol-magic-packets.html|command line based]] WoL client) installed. \\ | |
| Example of a basic GUI based WoL client for Windows (which you can download [[https://www.depicus.com/wake-on-lan/wake-on-lan-gui|here]]): \\ | To find out the unique MAC address of your Batocera system's NIC, run ''ip link show''. |
| | |
| | {{:wakeonlan02.png|MAC address}} |
| | |
| | The MAC address for this NIC (''eth0'') is ''f0:1f:af:25:dc:8b''. |
| | |
| | You can now use the given MAC address to wake the Batocera machine up remotely from another device (e.g. PC, Smartphone, ...) which is **within the same Layer 2 subnet** and has a WoL client ([[https://www.pcwdld.com/free-wake-on-lan-tools#wbounce-modal|GUI based]] or [[https://www.cyberciti.biz/tips/linux-send-wake-on-lan-wol-magic-packets.html|command line based]] WoL client) installed. |
| | |
| | Example of a WoL client for Windows ([[https://www.depicus.com/wake-on-lan/wake-on-lan-gui|Depicus Wake on Lan for Windows GUI]]): |
| {{:wakeonlan03.png|WoL client settings}} | {{:wakeonlan03.png|WoL client settings}} |
| * **Mac Address** → MAC address of your NIC on your Batocera system you want to wake up | |
| * **Internet Address** → Insert the IP address of your according Batocera system's NIC (If you only have one NIC on your WoL client, you can leave this empty) | Most utilities require the following information (or similar enough to it): |
| * **Subnet Mask** → [[https://en.wikipedia.org/wiki/Subnetwork|Netmask]] of your network's subnet | * **Mac Address** => MAC address of your NIC on the Batocera machine. |
| * **Send options** → Choose ''Local Subnet'' | * **Internet Address** => The IP of the NIC on the Batocera machine (if only one NIC is present on the WoL client, you can leave this empty). |
| * **Remote Port Number** → Choose ''9'' (default) or ''7'' | * **Subnet Mask** => [[wp>Subnetwork|Netmask]] of the network's subnet. |
| Click on ''Wake Up'' to wake your Batocera system up. | * **Send options** => Choose ''Local Subnet''. |
| | * **Remote Port Number** => The port to send the traffic on. Acceptable values are generally 9 (default) or 7. |
| | |
| | Click on **Wake Up** to wake the Batocera machine up. |
| |
| ===== Troubleshooting ===== | ===== Troubleshooting ===== |
| If you have followed the instructions on this page precisely and still are not able to wake your device up, try to play around with your WoL client its settings (e.g. change **Remote Port Number** from ''7'' to ''9'' or vice versa. Or, in the example above, you could try to change **Send Options** from ''Local Subnet'' to ''Internet'' which sometimes helps.). | |
| | ==== Machine will not wake up ==== |
| | |
| | * Try changing the port number from 9 to 7. If the machine uses an esoteric port this will usually be noted in its documentation. |
| | * Try sending the packet via **Internet** instead of **Local Subnet** if you are using the GUI based WoL client mentioned above. |
| | * Check if your system does even support WoL by [[:access_the_batocera_via_ssh|running]] ''ifconfig'' which helps you to identify the network interface name of your according connection (e.g. ''eth0''), and then run the appropriate ''ethtool eth0'' command. It should give you an output similar to this: |
| | <code> |
| | Settings for eth0: |
| | Supported ports: [ TP ] |
| | Supported link modes: 10baseT/Half 10baseT/Full |
| | 100baseT/Half 100baseT/Full |
| | 1000baseT/Full |
| | Supported pause frame use: No |
| | Supports auto-negotiation: Yes |
| | Advertised link modes: 10baseT/Half 10baseT/Full |
| | 100baseT/Half 100baseT/Full |
| | 1000baseT/Full |
| | Advertised pause frame use: No |
| | Advertised auto-negotiation: Yes |
| | Speed: 1000Mb/s |
| | Duplex: Full |
| | Port: Twisted Pair |
| | PHYAD: 1 |
| | Transceiver: internal |
| | Auto-negotiation: on |
| | MDI-X: on (auto) |
| | Supports Wake-on: pumbg |
| | Wake-on: g |
| | Current message level: 0x00000007 (7) |
| | drv probe link |
| | Link detected: yes |
| | </code> |
| | |
| | The important two parts for getting information about your NIC's WoL capability are: |
| | ^ Property ^ Notes ^ |
| | | ''Supports Wake-on:'' | Shows which hardware WoL capabilities the NIC supports (these values cannot be changed by the user) | |
| | | ''Wake-on:'' | Shows which software WoL capabilities are currently enabled (these can be turned on/off by the user) | |
| | |
| | The value ''g'' means that your NIC supports receiving magic packets and therefore //is// WoL capable. Note that your NIC could also support multiple WoL functions and therefore you would get multiple output values as shown above, e.g. ''Supports Wake-on: pumbg''. |
| | |
| | Here is a full list of output possibilities (more info at https://linux.die.net/man/8/ethtool or the ''man ethtool'' command): |
| | * ''p'' => Wake on PHY activity |
| | * ''u'' => Wake on unicast messages |
| | * ''m'' => Wake on multicast messages |
| | * ''b'' => Wake on broadcast messages |
| | * ''a'' => Wake on ARP |
| | * ''g'' => Wake on MagicPacket(tm) |
| | * ''s'' => Enable SecureOn(tm) password for MagicPacket(tm) |
| | * ''d'' => Disable (wake on nothing). This option clears all previous options. |
| | |
| | The most important value is ''g''. Without it being shown, the NIC does not support WoL at all. |
| | |
| | Batocera should automatically turn on the MagicPacket(tm) feature when the connection is established. If that fails, in order to turn on WoL manually run the following: |
| | |
| | <code> |
| | ethtool -s eth0 wol g |
| | </code> |
| | |
| | where ''eth0'' is the name of your network interface. |
| | |
| | ==== It works great the first time! But not any time after... ==== |
| | |
| | If dual booting, the cause is most likely the second operating system turning WoL back off. On Windows, [[:troubleshooting#ethernet_connected_but_no_data|turn off the shutdown WoL feature]]. |
| | |
| | ==== Machine will not wake up anymore ==== |
| | |
| | If you were successfully using WoL but suddenly it does not work anymore, a power outage of your Batocera system could be the issue. Since WoL functionality relies on a "sleeping" NIC state issued when shutting down the system, the NIC will not be in "sleeping" state anymore after power outage. Therefore you can only make WoL work again by manually booting and then shutdown the system once. |