Skip to content

Instantly share code, notes, and snippets.

@Alanaktion
Created April 16, 2018 14:12
Show Gist options
  • Save Alanaktion/9e412b88cade277f836a0e4e0cb9c6d3 to your computer and use it in GitHub Desktop.
Save Alanaktion/9e412b88cade277f836a0e4e0cb9c6d3 to your computer and use it in GitHub Desktop.
Pacman hooks to keep kernel modules

These Pacman hooks can be used to keep old kernel modules active without rebooting. This can work around issues like new USB devices and Docker images not working properly after a kernel upgrade, but before a reboot.

Add the files to /etc/pacman.d/hooks to enable the functionality. It works by making a backup of your current kernel's /lib/modules/... directory before the new kernel is installed, and then moving it back to the /lib/modules directory after the installation completes, working around the default behavior of deleting the old modules.

You can manually clean up the files after a reboot if you're concerned about the disk space used.

[Trigger]
Operation = Upgrade
Type = Package
Target = linux
[Action]
Description = Restore Linux kernel modules
When = PostTransaction
Depends = coreutils
Depends = rsync
Exec = /bin/sh -xc 'KVER="${KVER:-$(uname -r)}"; if test -e "/lib/modules/backup/${KVER}"; then rsync -AHXal --ignore-existing "/lib/modules/backup/${KVER}" /lib/modules/; fi; rm -rf /lib/modules/backup'
[Trigger]
Operation = Upgrade
Type = Package
Target = linux
[Action]
Description = Save Linux kernel modules
When = PreTransaction
Depends = rsync
Exec = /bin/sh -c 'KVER="${KVER:-$(uname -r)}"; if test -e "/lib/modules/${KVER}"; then rsync -AHXal --delete-after "/lib/modules/${KVER}" /lib/modules/backup/; fi'
@Alanaktion
Copy link
Author

I actually recommend using saber-nyan's kernel-modules-hook package from the AUR to solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment