Home Uncategorized Linux laptop wont connect to wifi after suspend? A quick and dirty solution.

Linux laptop wont connect to wifi after suspend? A quick and dirty solution.

by The Linux Digest Guy
No Wifi?

Recently I had this problem with my Lenovo laptop where it wouldn’t connect to wifi after it resumed from sleep. I’m sharing the quick and dirty hack to resolve the problem in the hopes it will help others to solve the same problem. It should also work for other laptops and wifi adapters.

Damn you Lenovo!

A few months back, I bought a shiny new laptop for my personal projects. I tried searching for laptops with decent value for money that were likely to have decent hardware support in Linux.

I ended up buying the Lenovo L15. Not least because it was supposed to have Ubuntu certification. No store in my area had a laptop with Linux pre-installed in stock. And I didn’t want to wait for one to be shipped to me. So a Ubuntu certified laptop should enable me to just install Ubuntu and start working right away. Right?

Well, it turns out Lenovo had replaced the intel wifi adapter, which was in the ubuntu certified version, with a Realtek one. Otherwise, all the specs were the same.

This didn’t work out well for me since the included RTL8852AE adapter did not have working drivers in the latest ubuntu version. Although I did eventually manage to get it working. I’m not sure where I got newer drivers, but it was probably from lwfinger on GitHub. Which is incidentally the same place where I got the solution to the suspend problem from.

Authentication is required after resuming from suspend

Everything was working fine until I closed the lid and the laptop suspended. After resuming again Network Manager just asked me for my password again and again. The only way for me to connect to wifi again was to either reboot or disable and enable wifi several times.

As far as I can tell, this is a bug in the Realtek driver. So all I could do was wait for a new release. So I endured for a while.

Eventually, I did find a solution. I must confess, this was not my idea. I came across this while looking for newer drivers in this unofficial driver repo.

Essentially we create a script that unloads the driver before the machine is suspended and then loads the driver fresh when it resumes. After I did this, there have been zero problems with wifi.

Find the name of your driver

In my case, the driver is from Realtek so I will look for kernel modules starting with “rt”. But this should work for other adapters with similar problems. Just substitute “rt” with what is appropriate.

$ lsmod | grep rt
rtw89_pci              49152  0
rtw89_core           1003520  1 rtw89_pci
mac80211             1249280  2 rtw89_core,rtw89_pci
cfg80211              974848  2 rtw89_core,mac80211
xt_addrtype            16384  2

In this case, the module is named rtw89_pci. Now we can move to the next step.

Create the script

We need to create a script and place it in the correct directory, so Systemd will run it every time the laptop changes to or from suspend. The script should be located in /usr/lib/systemd/system-sleep/.

vim  /usr/lib/systemd/system-sleep/suspend_wifi

Place the following in your script and replace rtw89_pci with the module name you found in the last step.

#!/bin/sh
if [ "${1}" == "pre" ]; then
  modprobe -rv rtw89_pci
elif [ "${1}" == "post" ]; then
  modprobe -v rtw89_pci
fi

Make the script executable

The last step should be to make sure your script is executable with chmod:

chmod 755 /usr/lib/systemd/system-sleep/suspend_wifi

And we are done! The next time the machine suspends it should unload the driver and load it again when it is turned back on.

0

Related Posts

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy