WiFi problems after waking up from sleep, Ubuntu 16.10

After installing Ubuntu 16.10 I occasionally had problems with WiFi after waking up from sleep.

But of course there’s a workaround (credit to Joakim Koed on askubuntu.com and the solution).

sudo bash -c 'cat >/etc/systemd/system/wake-up.service <<EOF
[Unit]
Description=Restart networkmanager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target
EOF'
sudo systemctl enable wake-up.service

Hibernate in Ubuntu 14.04, with iwlwifi

Update: After a lot of troubleshooting and testing different combinations of my kernel parameters; I conclude that it works a lot better when leaving pcie_aspm=force (think I got it from an Arch wiki?), and also never resume when docked if the computer was hibernated on battery. This seems to be working even with the linux-image-generic-lts-xenial kernel. You can check this pastebin with the results and combination that I’ve tested.

To enable hibernate in the menu, create /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla with the following content:

[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate
ResultActive=yes

[Re-enable hibernate for multiple users by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate-multiple-sessions
ResultActive=yes

Update /etc/default/grub and add RESUME parameter set to your swap partition in GRUB_CMDLINE_LINUX_DEFAULT. Example:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash i915.enable_fbc=1 i915.enable_rc6=7"

Don’t forget to run sudo update-grub2.

Check if iwlwifi has any dependencies:

$ lsmod | egrep "^iwlwifi"
iwlwifi               196608  1 iwlmvm

Add, in this case, iwlwifi and iwlmvm to /etc/pm/config.d/modules:

SUSPEND_MODULES="iwlmvm iwlwifi"

Create /etc/pm/sleep.d/99_wpa_supplicant:

#!/bin/sh

case "$1" in
resume|thaw)
/usr/bin/pkill wpa_supplicant
;;
esac

Don’t forget to make it executable, chmod +x /etc/pm/sleep.d/99_wpa_supplicant.

Killing wpa_supplicant on resume and thaw is needed due to bug #1311257.

And lastly, if you have TLP, make sure to restore previous device state on startup:

$ egrep "^RESTORE_" /etc/default/tlp
RESTORE_DEVICE_STATE_ON_STARTUP=1

Note: I had hibernate working perfect, but then I upgraded to linux-image-generic-lts-xenial which caused KernelOops on every thawn. After reverting back it worked great again. I’m guessing the reason is that the gfx stack (xserver-xorg-video-intel-xenial etc.) isn’t available in 14.04 (yet?).