fooninja.net

Notes on Linux/BSD/Unix and other digital matters

How to fix wifi after suspend/resume in Ubuntu

published

Problem: After suspending and then resuming my Thinkpad X61s running Ubuntu 10.04 (Lucid), the wireless would no longer work. Networks were detected but I couldn’t connect - nothing happened. The wifi card is an “Intel PRO/Wireless 4965 AG or AGN”, according to lspci. (I had the same problem with Ubuntu 9.10 (Karmic)).

Solution: I still don’t know the cause, but restarting networking and unloading/reloading the module for the wireless interface fixed the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh
# Stop networking and network-manager
stop network-manager
service networking stop

# Remove and reload the module for the wifi card
# (replace iwlagn with your own if you have a different one)
modprobe -r -f iwlagn
modprobe iwlagn

# Start networking and network-manager again
service networking start
start network-manager

Save the file as fixwifi.sh, run chmod +x fixwifi.sh and run it as root. Voila! (Hopefully.)

To make things smoother, if you always have this problem after resuming, you can have the script run automatically after resume. In earlier versions of Ubuntu you would put the script in /etc/acpi/resume.d. This has changed with 10.04 Lucid. You now have to put the script in /etc/pm/sleep.d, but you will have to make some modifications. After looking at the scripts in /usr/lib/pm-utils/sleep.d for guidance, I came up with the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

. "${PM_FUNCTIONS}"

resume_wifi()
{
        # Stop networking and network-manager
        stop network-manager
        service networking stop

        # Remove and reload the module for the wifi card
        modprobe -r -f iwlagn
        modprobe iwlagn

        # Start networking and network-manager again
        service networking start
        start network-manager
}

case "$1" in
        thaw|resume)
                resume_wifi
                ;;
        *) exit $NA
                ;;
esac

Save the file as 99fixwifi.sh, put it in /etc/pm/sleep.d and make it executable (chmod +x 99fixwifi.sh). Crude? Yes, but it works for me. If you have a nicer solution, let me know!

Comments