Skip to content

Instantly share code, notes, and snippets.

@varqox
Forked from ephemient/⁄etc⁄pacman.d⁄hooks⁄linux-modules-post.hook
Last active February 16, 2023 16:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varqox/a4e5abd490059844e0e521db531a9d8f to your computer and use it in GitHub Desktop.
Save varqox/a4e5abd490059844e0e521db531a9d8f to your computer and use it in GitHub Desktop.
(Arch Linux) Keep current modules around during kernel upgrade ("30" is in the name to run before DMKS remove ("90" for install) when upgrading kernel)
#/bin/sh
# Run: curl 'https://gist.githubusercontent.com/varqox/a4e5abd490059844e0e521db531a9d8f/raw/e69686e6b63791ef82fc3e182689986ffe838a53/INSTALL.sh' | sudo sh
curl 'https://gist.githubusercontent.com/varqox/a4e5abd490059844e0e521db531a9d8f/raw/85e25433f2f67576ea82b38a7cd461d424376901/%25E2%2581%2584usr%25E2%2581%2584share%25E2%2581%2584libalpm%25E2%2581%2584hooks%25E2%2581%258430-linux-modules-pre.hook' | sudo tee /usr/share/libalpm/hooks/30-linux-modules-pre.hook
curl 'https://gist.githubusercontent.com/varqox/a4e5abd490059844e0e521db531a9d8f/raw/85e25433f2f67576ea82b38a7cd461d424376901/%25E2%2581%2584usr%25E2%2581%2584share%25E2%2581%2584libalpm%25E2%2581%2584hooks%25E2%2581%258490-linux-modules-post.hook' | sudo tee /usr/share/libalpm/hooks/90-linux-modules-post.hook
curl 'https://gist.githubusercontent.com/varqox/a4e5abd490059844e0e521db531a9d8f/raw/85e25433f2f67576ea82b38a7cd461d424376901/%25E2%2581%2584etc%25E2%2581%2584tmpfiles.d%25E2%2581%2584linux-modules-cleanup.conf' | sudo tee /etc/tmpfiles.d/linux-modules-cleanup.conf
curl 'https://gist.githubusercontent.com/varqox/a4e5abd490059844e0e521db531a9d8f/raw/85e25433f2f67576ea82b38a7cd461d424376901/%25E2%2581%2584etc%25E2%2581%2584systemd%25E2%2581%2584system%25E2%2581%2584linux-modules-cleanup.service' | sudo tee /etc/systemd/system/linux-modules-cleanup.service
systemctl enable linux-modules-cleanup.service
[Unit]
Description=Clean up modules from old kernels
[Service]
Type=oneshot
ExecStart=/bin/bash -exc 'for i in /usr/lib/modules/[0-9]*; do if [[ $${i##*/} = \'%v\' ]] || pacman -Qo "$${i}"; then continue; fi; rsync -AHXal "$${i}" /usr/lib/modules/.old/; rm -rf "$${i}"; done'
[Install]
WantedBy=basic.target
[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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment