diff options
author | Max Gautier | 2022-07-11 16:51:22 +0200 |
---|---|---|
committer | Max Gautier | 2023-02-21 17:39:23 +0100 |
commit | c554030c41ca7a070067102f69ef8c575800b823 (patch) | |
tree | 153fee11a2408acb31d513aa9f5f8064533df38f | |
parent | ded83bc7f31df14b2e9a8d7bdfa1e95eee2bf5c1 (diff) | |
download | aur-c554030c41ca7a070067102f69ef8c575800b823.tar.gz |
Use cp instead of rsync + systemd-tmpfiles for cleaning
This use cp with hardlinks + a bind mount for keeping the removed kernel
modules accessible.
Cleaning up the backup is done by systemd-tmpfiles on next boot.
Cleaning up the mount is either done on shutdown implicitly, or when we
reinstall the running kernel by the pre-hook script.
No systemd service enabling is needed.
-rw-r--r-- | .SRCINFO | 19 | ||||
-rw-r--r-- | 10-linux-modules-post.hook | 8 | ||||
-rw-r--r-- | 10-linux-modules-pre.hook | 8 | ||||
-rw-r--r-- | PKGBUILD | 21 | ||||
-rw-r--r-- | kernel-modules-hook.install | 16 | ||||
-rw-r--r-- | linux-modules-cleanup.conf | 3 | ||||
-rw-r--r-- | linux-modules-cleanup.service | 9 | ||||
-rw-r--r-- | linux-modules-restore | 11 | ||||
-rw-r--r-- | linux-modules-save | 24 |
9 files changed, 63 insertions, 56 deletions
@@ -3,20 +3,17 @@ pkgbase = kernel-modules-hook pkgver = 0.1.7 pkgrel = 1 url = https://github.com/saber-nyan/kernel-modules-hook - install = kernel-modules-hook.install arch = any - license = UNLICENSE - depends = rsync + license = Unlicense source = linux-modules-cleanup.conf - source = linux-modules-cleanup.service source = 10-linux-modules-post.hook source = 10-linux-modules-pre.hook - source = UNLICENSE - sha256sums = 4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf - sha256sums = 5d947290ef8c94b33c79c531e5615f4c9bea38e7649092d34af3bf0af5b1ca24 - sha256sums = 900502d030e925fca6188b9448fbaf6562d6e23cd5c50938cdf00522825f76c2 - sha256sums = f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116 - sha256sums = 7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c + source = linux-modules-restore + source = linux-modules-save + sha256sums = 950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29 + sha256sums = 0492722850f90066d33baf7896eb4625fd812890bdb03f025184c8b4bf0ef94f + sha256sums = 2b86a037a9a394f57279408745bf5b19542f26b0ad862fd514470cd145108c10 + sha256sums = 7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a + sha256sums = 3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424 pkgname = kernel-modules-hook - diff --git a/10-linux-modules-post.hook b/10-linux-modules-post.hook index 55174ac3962a..3f2f930f963a 100644 --- a/10-linux-modules-post.hook +++ b/10-linux-modules-post.hook @@ -1,12 +1,10 @@ [Trigger] -Operation = Install -Operation = Upgrade +Operation = Remove Type = Path Target = usr/lib/modules/*/vmlinuz [Action] Description = Restoring Linux kernel modules... When = PostTransaction -Depends = coreutils -Depends = rsync -Exec = /bin/sh -xc 'KVER="${KVER:-$(uname -r)}"; if test -e "/usr/lib/modules/backup/${KVER}"; then rsync -AHXal --ignore-existing "/usr/lib/modules/backup/${KVER}" /usr/lib/modules/; fi; rm -rf /usr/lib/modules/backup' +Exec = /usr/share/libalpm/scripts/linux-modules-restore +NeedsTarget diff --git a/10-linux-modules-pre.hook b/10-linux-modules-pre.hook index 34e7221feb65..f6ff54a69a53 100644 --- a/10-linux-modules-pre.hook +++ b/10-linux-modules-pre.hook @@ -1,11 +1,11 @@ [Trigger] Operation = Install -Operation = Upgrade +Operation = Remove Type = Path Target = usr/lib/modules/*/vmlinuz [Action] -Description = Saving Linux kernel modules... +Description = Saving Linux kernel modules directory (hardlinks)... When = PreTransaction -Depends = rsync -Exec = /bin/sh -c 'KVER="${KVER:-$(uname -r)}"; if test -e "/usr/lib/modules/${KVER}"; then rsync -AHXal --delete-after "/usr/lib/modules/${KVER}" /usr/lib/modules/backup/; fi' +Exec = /usr/share/libalpm/scripts/linux-modules-save +NeedsTarget @@ -6,20 +6,21 @@ pkgrel=1 pkgdesc="Keeps your system fully functional after a kernel upgrade" arch=('any') url="https://github.com/saber-nyan/kernel-modules-hook" -depends=('rsync') -install="${pkgname}.install" license=('Unlicense') source=("linux-modules-cleanup.conf" - "linux-modules-cleanup.service" - "10-linux-modules-post.hook" - "10-linux-modules-pre.hook") -sha256sums=('4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf' - '5d947290ef8c94b33c79c531e5615f4c9bea38e7649092d34af3bf0af5b1ca24' - '900502d030e925fca6188b9448fbaf6562d6e23cd5c50938cdf00522825f76c2' - 'f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116') + "10-linux-modules-post.hook" + "10-linux-modules-pre.hook" + "linux-modules-restore" + "linux-modules-save" +) +sha256sums=('950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29' + '0492722850f90066d33baf7896eb4625fd812890bdb03f025184c8b4bf0ef94f' + '2b86a037a9a394f57279408745bf5b19542f26b0ad862fd514470cd145108c10' + '7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a' + '3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424') package() { install -Dm644 'linux-modules-cleanup.conf' "${pkgdir}/usr/lib/tmpfiles.d/linux-modules-cleanup.conf" - install -Dm644 'linux-modules-cleanup.service' "${pkgdir}/usr/lib/systemd/system/linux-modules-cleanup.service" install -Dm644 10-linux-modules-{pre,post}.hook -t "${pkgdir}/usr/share/libalpm/hooks/" + install -Dm755 linux-modules-{save,restore} -t "${pkgdir}/usr/share/libalpm/scripts/" } diff --git a/kernel-modules-hook.install b/kernel-modules-hook.install deleted file mode 100644 index b0af4a3ce954..000000000000 --- a/kernel-modules-hook.install +++ /dev/null @@ -1,16 +0,0 @@ -post_install() { - cat << EOF - -Please execute - - $ sudo systemctl daemon-reload - $ sudo systemctl enable linux-modules-cleanup - -Report any issues to: -https://github.com/saber-nyan/kernel-modules-hook/issues - - - ~desu - -EOF -} diff --git a/linux-modules-cleanup.conf b/linux-modules-cleanup.conf index 80bc0cf896e7..1dd8d3bd5cdb 100644 --- a/linux-modules-cleanup.conf +++ b/linux-modules-cleanup.conf @@ -1 +1,2 @@ -R! /usr/lib/modules/.old/* - - - 4w +R! /usr/lib/modules/running-kernel +r /usr/lib/modules/* diff --git a/linux-modules-cleanup.service b/linux-modules-cleanup.service deleted file mode 100644 index 35a60dc2b3bb..000000000000 --- a/linux-modules-cleanup.service +++ /dev/null @@ -1,9 +0,0 @@ -[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 diff --git a/linux-modules-restore b/linux-modules-restore new file mode 100644 index 000000000000..81159408e5db --- /dev/null +++ b/linux-modules-restore @@ -0,0 +1,11 @@ +#!/bin/bash -e + +kver = $(uname -r) +while read -r line; do + # We only care about the running kernel + if [[ "$line" == usr/lib/modules/$kver/vmlinuz && -d "${line/$kver/running-kernel}" ]];then + mount --mkdir --bind --options ro /usr/lib/modules/{running-kernel,$kver} + # Mounting read-only since the only modification here should be unmounting + # when rebooting or reinstalling the running kernel + fi +done diff --git a/linux-modules-save b/linux-modules-save new file mode 100644 index 000000000000..9ccb370d967f --- /dev/null +++ b/linux-modules-save @@ -0,0 +1,24 @@ +#!/bin/bash -e + +kver = $(uname -r) +while read -r line; do + # We only care about the running kernel + if [[ "$line" == "usr/lib/modules/$kver/vmlinuz" ]];then + if [[ mountpoint --nofollow --quiet ${line%vmlinuz} ]];then + # Mount point is already present + # This means we already ran that hook during 'remove case' + # + # Remove the mount so we can reinstall the kernel + umount ${line%vmlinuz} + elif [[ -f "$line" && ! -d "/usr/lib/modules/running-kernel/" ]];then + # Kernel install is present and we do not have a copy + # + # This is the removal case, so we save the kernel + mkdir /usr/lib/modules/running-kernel + cp --archive --link /usr/lib/modules/{$kver}/{kernel,modules*} \ + /usr/lib/modules/running-kernel/ + fi + # If we are re-removing the running kernel, (after removing + reinstalling), + # we already have a backup and this hook is a no-op + fi +done |