aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-03-11 16:23:09 +0100
committerKatharina Fey <kookie@spacekookie.de>2018-03-11 16:23:09 +0100
commit504a641898d5f9b9b30c457df24daac900eb05af (patch)
treef75ce492da7d58a545f2f11c2b1bfff9c633b92b
parent780202052610d3f46fc155baaaca420d458168eb (diff)
Renaming the order of articles
-rw-r--r--content/blog/101_rust_is_awesome.md2
-rw-r--r--content/blog/102_arch_kernel_updates.md71
2 files changed, 72 insertions, 1 deletions
diff --git a/content/blog/101_rust_is_awesome.md b/content/blog/101_rust_is_awesome.md
index 6078cd6..f4c9f95 100644
--- a/content/blog/101_rust_is_awesome.md
+++ b/content/blog/101_rust_is_awesome.md
@@ -2,7 +2,7 @@ Title: Failure. Or: why Rust is probably the best programming language ever crea
Category: Blog
Tags: /dev/diary, reflections, programming, rust
Date: 2018-01-28
-Status: Draft
+<!-- Status: Draft -->
*This post is two stories.* One is about accepting and recognising personal failure, reflecting and growing from it; the other is about an incredibly and seemingly endlessly powerful programming language, called *Rust*.
diff --git a/content/blog/102_arch_kernel_updates.md b/content/blog/102_arch_kernel_updates.md
new file mode 100644
index 0000000..3a1eb65
--- /dev/null
+++ b/content/blog/102_arch_kernel_updates.md
@@ -0,0 +1,71 @@
+Title: The Kernel is dead! Long live the Kernel
+Category: Blog
+Tags: /dev/diary, linux, arch linux, pacman
+Date: 2018-02-08
+
+
+So I run Arch Linux and mostly I love it (I'm weird, I know 😝). But there is one thing that's really been annoying me which happens after some `pacman -Syyu` runs: all of my old kernel modules become unavailable, forcing me to do a reboot. But recently I found some stuff online to prevent that from happening so let's document all of it here.
+
+I have similar hooks, with a slight difference - keep `/usr/lib/modules/$(uname -r)` looking exactly the same as before the upgrade.
+
+We need a hook that is run before a pacman transaction
+
+```
+# /etc/pacman.d/hooks/linux-modules-pre.hook
+
+[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'
+```
+
+And another hook that is run after a pacman transaction (duh 😜)
+
+```
+# /etc/pacman.d/hooks/linux-modules-post.hook
+
+[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'
+```
+
+But that's only half of the problem. When we eventually reboot we want to clean up the old modules. This means writing a systemd service which cleas up our old modules when we finally start the new kernel.
+
+```
+# /etc/systemd/system/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
+```
+
+You can specify how long you want to keep your old kernel modules in this config file as well
+
+```
+# /etc/tmpfiles.d/linux-modules-cleanup.conf
+
+R! /usr/lib/modules/.old/* - - - 4w
+```
+
+
+I use `rsync --ignore-existing` to merge the backup even if `/lib/modules/$(uname -r)` still exists, in case most of its contents have disappeared in the upgrade but the directory still exists due to a stray file untracked by pacman.