The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 36,393β€…    Votes:  23β€…    βœ… Solution
Tags: networking   wireless   suspend  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1035370
Title: How to prevent wifi sleep after suspend
ID: /2018/05/12/How-to-prevent-wifi-sleep-after-suspend
Created: May 12, 2018    Edited:  April 5, 2019
Upload: April 8, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


There are two ways of enabling WiFi after sleep. The first is a common patch to Network Manager as you can see I’ve made by listing the file:

Turn off or enable power savings as illustrated below:

$ cat /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
[connection]
wifi.powersave = 3
# Slow sleep fix: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1670041
#wifi.powersave = 2

The second is a systemd script which reloads the WiFi kernel module when resuming from suspend. It comes from this answer: Wifi available networks not showing up suddenly

This script is written for iwlwifi` which is the common Intel driver name. If your’s is different change that name below:

#!/bin/sh

# NAME: /lib/systemd/system-sleep/iwlwifi-reset
# DESC: Resets Intel WiFi which can be flakey after a long suspend.
# DATE: Apr 1, 2017. Modified August 30, 2017.

MYNAME=$0

restart_wifi() {
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'
    /sbin/modprobe -v -r iwldvm # This removes iwlwifi too
    /sbin/modprobe -v iwlwifi   # This starts iwldvm too
#    systemctl restart NetworkManager.service
    /usr/bin/logger 'systemctl restart NetworkManager.service (SUPPRESSED)'
    /usr/bin/logger $MYNAME 'restart_wifi END'
}

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'
case "${1}/${2}" in
    hibernate|suspend|pre*)
      ;;
    resume|thaw|post*)
      restart_wifi;;
esac

NOTE: Sometimes simply resetting network manager is all that is needed. In that case un-comment the line above by removing #. Then comment out the two lines above it by putting # at the beginning of those two lines.

You’ll need to create this script, called iwlwifi-reset, with sudo powers and save it into the directory /lib/systemd/system-sleep. Then mark it executable using:

chmod a+x /lib/systemd/system-sleep/iwlwifi-reset
⇧ Is a clean install better than upgrading? Can I report about bug in system that I don't use?  β‡©