55

I am affected by this bug: 869502.

A workaround which seems to stop the kernel panics for me is to disable wlan0 power management:

sudo iwconfig wlan0 power off

However it seems to automatically turn power management back on when I unplug the power cable and I think at many other times, too.

Is there something that might be causing this? Does anyone know how I can prevent it?

Eric Carvalho
  • 54,385
Alex
  • 2,044

11 Answers11

40

Type iwconfig and look at the output. You should see the name of your chip-set as well as the whether power management is off or on. If it doesn't say, it is probably off.

To turn off power management, go to /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf and you will see

[connection]
wifi.powersave = 3

Change the 3 to a 2 and reboot.

Then run iwconfig and if it worked you should see Power Management:off.

Source: https://sites.google.com/site/easylinuxtipsproject/internet

  • 1
    This seemed to turn off my power management! – user3273814 Dec 15 '16 at 01:59
  • 1
    this also seems to be the right way to do it – Ufos Jan 25 '18 at 09:32
  • This worked for me on Ubuntu 17.10. Seems far more straightforward and easily reversible than the other approaches (e.g. blacklisting). – josephwb Jan 31 '18 at 19:46
  • 2
    worked perfectly in Ubuntu 20.04 for Qualcomm atheros QCA9377 – Abdul Rauf Jun 22 '20 at 17:20
  • 1
    Here are all the possible values and the meaning: NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (0): use the default value NM_SETTING_WIRELESS_POWERSAVE_IGNORE (1): don't touch existing setting NM_SETTING_WIRELESS_POWERSAVE_DISABLE (2): disable powersave NM_SETTING_WIRELESS_POWERSAVE_ENABLE (3): enable powersave. The source: https://gist.github.com/jcberthon/ea8cfe278998968ba7c5a95344bc8b55. – Danijel Jan 25 '21 at 10:58
  • Great answer. Thanks a lot! – djhurio Apr 11 '21 at 10:32
  • This answer seems limited to Network Manager usage... – Mehdi May 04 '21 at 15:10
27

If turning off power management for your wireless interface speeds up internet like this:

sudo iwconfig wlan0 power off

Than to make it permanent run command as follows:

  1. cd /etc/pm/power.d

  2. sudo gedit wifi_pwr_off

    This will open an empty file, copy the code below into it:

    #!/bin/sh 
    /sbin/iwconfig wlan0 power off
    
  3. Save the file, remember to

    sudo chmod +x wifi_pwr_off
    

    and restart.

Eric Carvalho
  • 54,385
  • 2
    When i write sudo iwconfig wlan0 power off i get this message : Error for wireless request "Set Power Management" (8B2C) : SET failed on device wlan0 ; No such device. – Murhaf Sousli Feb 16 '14 at 10:41
  • 3
    Run iwconfig without any agrument sudo iwconfig and check which interface has wireless extension. Sometimes it is eth1. – Dilawar Mar 26 '14 at 07:14
27

Wireless powermanagement is run by a hook in pm-utils. You can turn it off in any of the following way:

Create a file in /etc/pm/config.d. I have named it blacklist:

gksu gedit /etc/pm/config.d/blacklist

and inside the file keep:

HOOK_BLACKLIST="wireless"

If you want to disable any other hooks, default hooks are located at /usr/lib/pm-utils/power.d/.

OR

You can just create an empty hook in either /etc/pm/sleep.d or /etc/pm/power.d. See which one works for you. i.e.

Just do

sudo touch /etc/pm/sleep.d/wireless

OR

sudo touch /etc/pm/power.d/wireless
d a i s y
  • 5,511
sagarchalise
  • 23,988
7

My preferred way is to add the following line in /etc/network/interfaces to my wireless interface's settings:

post-up iwconfig wlan0 power off

Here's a complete example:

auto wlan0
iface wlan0 inet static
 address 192.168.1.2
 network 192.168.1.0
 netmask 255.255.255.0
 broadcast 192.168.1.255
 gateway 192.168.1.254
 post-up iwconfig wlan0 power off
 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Note that man interfaces says the behaviour of post-up may change in the future.

RobM
  • 320
  • This solution is far better than scripting a power off. The solutions involving a sleep before the power off is that if the client fails to associate before the sleep expires wlan0 stays down, even when the network comes within range. – MerlinTheMagic Sep 22 '17 at 11:58
  • This option works like a charm on Raspbian Stretch. For me is the better option. – Jagoliveira Dec 13 '17 at 12:07
3

For some reason, the top-voted solutions didn't work for me and power management kept turning back on. I ended up doing the following:

sudo gedit /etc/rc.local

And added the following line before exit 0:

( sleep 30 && iwconfig wlan0 power off )&

That turns off power management 30 seconds after logging in...

Edit: Actually that wasn't enough. I kept trying a bunch of stuff, including https://askubuntu.com/a/614245 which I think solved my problem (I hope).

Anis Abboud
  • 769
  • 5
  • 7
3

Another approach is to add an explicit directive (wireless-power) to control power management in the /etc/network/interfaces configuration file (e.g. Disable it for wlan0 with DHCP):

auto wlan0
iface wlan0 inet dhcp     
  wireless-power off
Pierz
  • 3,063
  • 1
  • 25
  • 15
2

A better approach (at least on Ubuntu 16.04) is to create /etc/network/if-up.d/wifi-powerman-off with the following contents:

#!/bin/sh

IWCONFIG=/sbin/iwconfig
WLAN_IFACE=<your wireless device here>

if [ ! -x $IWCONFIG ]; then
    exit 1
fi

if [ "$IFACE" = $WLAN_IFACE ]; then
    $IWCONFIG $IFACE power off
fi

and set it as executable. Power management will be off from the next time you connect to a network.

This works well with NetworkManager.

  • I hope this works. I hope, I hope, I hope!!! Tired of Linux tossing my wifi connection at random times. /rant Ubuntu 16.04 has some major issues here /endrant – RyanNerd Nov 08 '16 at 18:57
  • Nope didn't work. Intel 7260 is a piece of crap! I've given up. – RyanNerd Mar 14 '17 at 09:15
1

I created the following systemd service to PERSISTENTLY kill Power Management on WiFi across reboots. Tested and known to work. Just paste the below bash script into a file, chmod 700 the file and sudo ./yourFileName.sh :

if [ -d /root/scripts ]; then
    mkdir /root/scripts
fi

apt-get -y install iw
apt-get -y install wireless-tools

cat <<EOF> /root/scripts/pwr-mgmnt-wifi-disable.sh
#!/bin/bash
iw dev wlan0 set power_save off
EOF

chmod 700 /root/scripts/pwr-mgmnt-wifi-disable.sh


cat <<EOF> /etc/systemd/system//pwr-mgmnt-wifi-disable.service
[Unit]
Description=Disable WiFi Power Management
Requires=network-online.target
After=hostapd.service

[Service]
User=root
Group=root
Type=oneshot
ExecStart=/root/scripts/pwr-mgmnt-wifi-disable.sh

[Install]
WantedBy=multi-user.target

EOF

chmod 644 /etc/systemd/system/pwr-mgmnt-wifi-disable.service

systemctl enable pwr-mgmnt-wifi-disable.service
systemctl start pwr-mgmnt-wifi-disable.service
F1Linux
  • 1,066
1

Why not open crontab and add the command at boot/reboot. This seems like the easiest and most universal method:

sudo crontab -e

and then add

@reboot iwconfig wlan0 power off

Could be that you have to install iwconfig first: sudo apt install wireless-tools

Punnerud
  • 121
1

Great advice. 'sudo iwconfig wlan0 power off' seems the only way to get my ath9k module stabily working (with kernel 3.2 - curiously in kernel > 3.5 there seems to be no problem, but that kernels because of their suspend-to-ram/disk problems with amd64 seem to be a no go, unfortunately . . . :-( )

1

If you use laptop-mode-tools, then you can disable wireless power management by editing /etc/laptop-mode/conf.d/wireless-iwl-power.conf (Ubuntu 14.04):

# Control Intel IWL wireless power?
# Set to 0 to disable
CONTROL_IWL_POWER=0
chriscz
  • 71