├── .SRCINFO ├── .gitignore ├── 10-linux-modules-pre.hook ├── 70-linux-modules-post.hook ├── PKGBUILD ├── README.md ├── UNLICENSE ├── kernel-modules-hook.install ├── linux-modules-cleanup.conf └── linux-modules-cleanup.service /.SRCINFO: -------------------------------------------------------------------------------- 1 | pkgbase = kernel-modules-hook-reflink 2 | pkgdesc = Keeps your system fully functional after a kernel upgrade (forked version using `cp --reflink`, maybe better for btrfs) 3 | pkgver = 0.1.11 4 | pkgrel = 1 5 | url = https://github.com/lideming/kernel-modules-hook 6 | install = kernel-modules-hook.install 7 | arch = any 8 | license = UNLICENSE 9 | depends = coreutils 10 | conflicts = kernel-modules-hook 11 | source = linux-modules-cleanup.conf 12 | source = linux-modules-cleanup.service 13 | source = 70-linux-modules-post.hook 14 | source = 10-linux-modules-pre.hook 15 | source = UNLICENSE 16 | sha256sums = 4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf 17 | sha256sums = 023464fbc648365d64b96626eeef2628bb10cae757a00db3a2624b0a61d0e41e 18 | sha256sums = 53c0f59a1934d5a3ff5a3e7f9a22971832bf2ce7685210238fe2a92bea80663f 19 | sha256sums = c11ca188aef5c4de0a416708c0a944af48f068724edae8a19abb081fd945849b 20 | sha256sums = 7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c 21 | 22 | pkgname = kernel-modules-hook-reflink 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore everything 2 | * 3 | !.gitignore 4 | 5 | # except PKGBUILD needed files 6 | !PKGBUILD 7 | !.SRCINFO 8 | !*.install 9 | 10 | # common wing-man files 11 | !*.diff 12 | !*.patch 13 | 14 | # add files that don't have an online source 15 | kernel-modules-hook.install 16 | linux-modules-cleanup.conf 17 | linux-modules-cleanup.service 18 | 70-linux-modules-post.hook 19 | 10-linux-modules-pre.hook 20 | UNLICENSE 21 | -------------------------------------------------------------------------------- /10-linux-modules-pre.hook: -------------------------------------------------------------------------------- 1 | [Trigger] 2 | Operation = Install 3 | Operation = Upgrade 4 | Type = Path 5 | Target = usr/lib/modules/*/vmlinuz 6 | 7 | [Action] 8 | Description = Saving Linux kernel modules... 9 | When = PreTransaction 10 | Exec = /bin/sh -xc 'KVER="${KVER:-$(uname -r)}"; if test -d "/usr/lib/modules/${KVER}"; then mkdir -p /usr/lib/modules/backup ; cp -an --reflink=auto "/usr/lib/modules/${KVER}" /usr/lib/modules/backup/; fi' 11 | -------------------------------------------------------------------------------- /70-linux-modules-post.hook: -------------------------------------------------------------------------------- 1 | [Trigger] 2 | Operation = Install 3 | Operation = Upgrade 4 | Type = Path 5 | Target = usr/lib/modules/*/vmlinuz 6 | 7 | [Action] 8 | Description = Restoring Linux kernel modules... 9 | When = PostTransaction 10 | Depends = coreutils 11 | Exec = /bin/sh -xc 'KVER="${KVER:-$(uname -r)}"; if test -d "/usr/lib/modules/backup/${KVER}" && ! test -f "/usr/lib/modules/${KVER}/vmlinuz"; then cp -an --reflink=auto "/usr/lib/modules/backup/${KVER}" /usr/lib/modules/; fi; rm -rf /usr/lib/modules/backup' 12 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: Deming Li 2 | # Hooks: https://www.reddit.com/r/archlinux/comments/4zrsc3/keep_your_system_fully_functional_after_a_kernel/d6yin0r/ 3 | pkgname=kernel-modules-hook-reflink 4 | pkgver=0.1.11 5 | pkgrel=1 6 | pkgdesc="Keeps your system fully functional after a kernel upgrade (forked version using \`cp --reflink\`, maybe better for btrfs)" 7 | arch=('any') 8 | url="https://github.com/lideming/kernel-modules-hook" 9 | license=('UNLICENSE') 10 | depends=('coreutils') 11 | conflicts=('kernel-modules-hook') 12 | install="kernel-modules-hook.install" 13 | source=("linux-modules-cleanup.conf" 14 | "linux-modules-cleanup.service" 15 | "70-linux-modules-post.hook" 16 | "10-linux-modules-pre.hook" 17 | "UNLICENSE") 18 | sha256sums=('4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf' 19 | '023464fbc648365d64b96626eeef2628bb10cae757a00db3a2624b0a61d0e41e' 20 | '53c0f59a1934d5a3ff5a3e7f9a22971832bf2ce7685210238fe2a92bea80663f' 21 | 'c11ca188aef5c4de0a416708c0a944af48f068724edae8a19abb081fd945849b' 22 | '7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c') 23 | 24 | package() { 25 | install -Dm644 'linux-modules-cleanup.conf' "${pkgdir}/usr/lib/tmpfiles.d/linux-modules-cleanup.conf" 26 | install -Dm644 'linux-modules-cleanup.service' "${pkgdir}/usr/lib/systemd/system/linux-modules-cleanup.service" 27 | install -Dm644 '70-linux-modules-post.hook' "${pkgdir}/usr/share/libalpm/hooks/70-linux-modules-post.hook" 28 | install -Dm644 '10-linux-modules-pre.hook' "${pkgdir}/usr/share/libalpm/hooks/10-linux-modules-pre.hook" 29 | install -Dm644 'UNLICENSE' "${pkgdir}/usr/share/licenses/${pkgname}/UNLICENSE" 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #

kernel-modules-hook-reflink

2 | 3 | **-reflink** is forked from [the original hook](https://github.com/saber-nyan/kernel-modules-hook). 4 | It uses `cp --reflink` to copy modules, saving time and space for Btrfs. 5 | 6 | --- 7 | 8 | Tired of missing modules when updating the kernel?
9 | Annoyed by `modprobe: FATAL: Module smth not found in directory /lib/modules/new-kernel`?
10 | Losing uptime after reboots due to kernel update? 11 | 12 | *The solution is here.* 13 | 14 | * Save.
15 | ![Save](https://i.imgur.com/3YHtBRB.png)
16 | * Update.
17 | ![Update](https://i.imgur.com/uxySEMY.png)
18 | * Restore.
19 | ![Restore](https://i.imgur.com/AJeBw0n.png)
20 | * Enjoy.
21 | ![Enjoy](https://i.imgur.com/WQAYSSR.png) 22 | 23 | Do not worry, backups are automatically cleaned. 24 | 25 | ## Installation 26 | [AUR link](https://aur.archlinux.org/packages/kernel-modules-hook-reflink/) 27 | ```bash 28 | $ ${your_aur_helper} -S kernel-modules-hook-reflink 29 | 30 | # Or from git: 31 | 32 | $ git clone https://github.com/lideming/kernel-modules-hook.git kmh 33 | $ cd kmh 34 | $ makepkg -sci 35 | $ sudo systemctl daemon-reload 36 | $ sudo systemctl enable linux-modules-cleanup 37 | ``` 38 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /kernel-modules-hook.install: -------------------------------------------------------------------------------- 1 | post_install() { 2 | cat << EOF 3 | 4 | Please execute 5 | 6 | $ sudo systemctl daemon-reload 7 | $ sudo systemctl enable linux-modules-cleanup 8 | 9 | Report any issues to: 10 | https://github.com/lideming/kernel-modules-hook/issues 11 | 12 | This package is forked from: 13 | https://github.com/saber-nyan/kernel-modules-hook 14 | 15 | 16 | ~arigatou 17 | 18 | EOF 19 | } 20 | -------------------------------------------------------------------------------- /linux-modules-cleanup.conf: -------------------------------------------------------------------------------- 1 | R! /usr/lib/modules/.old/* - - - 4w 2 | -------------------------------------------------------------------------------- /linux-modules-cleanup.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Clean up modules from old kernels 3 | 4 | [Service] 5 | Type=oneshot 6 | ExecStart=/bin/bash -exc 'for i in /usr/lib/modules/[0-9]*; do if [[ $${i##*/} = \'%v\' ]] || pacman -Qo "$${i}"; then continue; fi; mv "$${i}" /usr/lib/modules/.old/; done' 7 | 8 | [Install] 9 | WantedBy=basic.target 10 | --------------------------------------------------------------------------------