How to permanently turn off wi-fi power management in Ubuntu – Fixes loss of wi-fi connection when on battery power.
My better half recently installed Ubuntu 11.04 (Natty Narwhal) on her notebook and quickly realised that when she removed the AC power lead the wi-fi connection would cut out, only resuming when she plugged the power lead back in. This meaning she could not access or use wi-fi whilst running on battery power alone – which kind of defeats the purpose of having a laptop/notebook if you need the power cable plugged in at all times to surf the web.
Anyway, the root of the cause is that Ubuntu’s new default power management setting turns ‘on’ the power management for the wi-fi device when on battery power. Meaning you lose the wi-fi connection if you unplug the AC power from your laptop/notebook. There is a simple little solution that can fix this problem.
All we need to do is run a couple of commands and create or edit a file in /etc/pm/power.d that will basically tell Ubuntu to turn the wi-fi power management off and to keep it off permanently when in battery mode, so we can use the wi-fi wherever and whenever we choose to.To apply the fix, follow the steps below but make sure you do NOThave the AC power plugged into your laptop/notebook, follow the steps on battery power.
Step 1 - Check that wi-fi power management is turned on
In order to turn off the power management we first need to ensure that it is turned on.
*Open a terminal window by pressing Ctrl+Alt+t
*Now type: iwconfig and press Enter
‘iwconfig’ will then list all the available wireless devices connected to your system (see below)
Step 2 – Turning Power Management off
*Type: sudo iwconfig wlan0 power off – This disables the wi-fi power management
Step 3 will show us how to make this fix permanent by firstly moving to another directory and then editing or creating (if it doesn’t exist already) the file /etc/pm/power.d/wireless
Step 3 - Making the fix permanent – Moving to /etc/pm/power.d directory
We must now move to the directory/etc/pm/power.d we do this by typing the command below into the terminal (see image below)- Note, if the directory does not exist you must create it by typing: mkdir /etc/pm/power.d
*Type: cd /etc/pm/power.d and press Enter
Above: Moving to the /etc/pm/power.d directory
Step 4 – Creating the wireless file in the /etc/pm/power.d directory
Once we are in /etc/pm/power.d we must create the wireless file.
*Type: sudo pico /etc/pm/power.d/wireless into the terminal command and press enter, this will create the wireless file and open the file for editing as a root user.
Step 5 – Add a couple of lines of code to the wireless file, save and exit and its all done !
Now that you are in /etc/pm/power.d/wireless we add two lines of code (shown below) which tell Ubuntu to stop managing the power management of our wireless device, thus keeping the wi-fi power management permanently turned off (even if we shut down or restart the system)
/sbin/iwconfig wlan0 power off
Above: Add two lines of code to the file: /etc/pm/power.d/wireless
Now save and exit – note if you can’t find a save button (like us) just close the terminal window and restart your laptop/notebook. The changes will take effect. Also note that when you reboot, do it on battery power, reopen the terminal and type iwconfig’ and check that the power management for your wlan0 device reads: OFF.
Sit back and enjoy browsing the web and having your laptop/notebook back to its good old self, without having to have your AC cable plugged in all the time.