[LINUX] Enable WOL (Wake On LAN) on Manjaro KDE

Introduction

KDE doesn't have a WOL item in the GUI network settings Let ethtool run automatically with systemd. It's a little complicated to do by hand, so I made it a script.

A shell script that enables WOL

#!/bin/bash
#systemd configuration file save folder
SYSTEMD_PATH="/etc/systemd/system/"
SERVICE_NAME="wol.service"
FILE_PATH=${SYSTEMD_PATH}${SERVICE_NAME}

#Change tlp settings
sudo sed -i -e "s/WOL_DISABLE=Y/WOL_DISABLE=N/g" /etc/default/tlp
#Check the set value
echo "Confirmation of tlp setting change: WOL_DISABLE=Success with N"
sudo grep "^WOL_DISABLE" /etc/default/tlp

#Install ethtool
sudo pacman -S --noconfirm ethtool

#Look up the interface name and put it in a variable
NIC_LIST=($(for DEV in `find /sys/devices -name net | grep -v virtual`; do ls $DEV/; done))
#Specify the first interface
INTERFACE=${NIC_LIST[0]}

#Verification
echo "Interface name:"${INTERFACE}
echo ${FILE_PATH}

#File overwrite confirmation
if [ -e ${FILE_PATH} ]; then
    echo "Do you want to overwrite the file?[Y/n]"
    read -p "answer[y or n]:" ANSWER
    ANSWER=`echo $ANSWER | tr y Y | tr -d '[\[\]]'`
    if [ ${ANSWER} != "Y" ]; then
        exit 0
    fi
    #If there is a setting, stop the service
    sudo systemctl stop ${FILE_NAME}
    sudo systemctl disable ${FILE_NAME}
fi

sudo tee ${FILE_PATH} <<EOF >/dev/null
[Unit]
Description=Configure Wake-up on LAN
Requires=network.target
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/ethtool -s ${INTERFACE} wol g

[Install]
WantedBy=basic.target
EOF

#Reload settings
sudo systemctl daemon-reload
#Service start
sudo systemctl start ${SERVICE_NAME}
#Auto start settings
sudo systemctl enable ${SERVICE_NAME}

#final confirmation
echo "Confirmation of WOL activation: Wake-on:Valid with g"
sudo ethtool ${INTERFACE} | grep Wake-on

Explanation of shell script

--Manajro has TLP (Power Management) on by default and WOL is disabled so enable it --Install ethtool --Look up the network interface name --Create a systemd configuration file --Enable systemd services

Notes

WOL seems to consume a lot of battery, so it is better not to use it on a laptop. This script assumes a desktop PC with only one wired LAN.

Operating environment

Manjaro KDE Edition 19.0.0 Linux Kernel 5.5.2-1

Finally

I was also using the same KDE kubuntu, but it didn't have TLP. It's hard to write a script, but I'll do my best to write it because I can enjoy it from the next time.

Recommended Posts

Enable WOL (Wake On LAN) on Manjaro KDE
Wake on lan on Linux
Boot CentOS 8 from Windows 10 with Wake On LAN
I want to do Wake On LAN fully automatically
Create a Python script for Wake on LAN (NAT traversal Wake on LAN [5])