From d0b94285084da57b9ac24c17a22a30301c09a917 Mon Sep 17 00:00:00 2001 From: nop Date: Mon, 3 Aug 2026 18:53:34 +0900 Subject: [PATCH] Install the built module into /lib/modules so it survives a reboot The build scripts end with `sudo insmod rtmouse.ko`, which loads the module straight out of the build directory and never installs it. After a reboot the module is gone, so anything that loads the driver at boot has to compile it again -- on a Raspberry Pi 4 that is several minutes of CPU on every single boot. Install the module into `/lib/modules/$(uname -r)/extra/` and run `depmod` so `modprobe rtmouse` works, then load it with `modprobe` instead of `insmod`. Using `modprobe` also makes the scripts idempotent: `insmod` fails with "File exists" when the module is already loaded, and with `set -e` that aborts the script. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01V3ZzEzNKDxANptPX4QNnHn --- utils/build_install_header_from_apt_raspi2.bash | 4 +++- utils/build_install_header_from_apt_raspi4.bash | 4 +++- utils/build_install_header_from_source_raspi2.bash | 4 +++- utils/build_install_header_from_source_raspi4.bash | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/build_install_header_from_apt_raspi2.bash b/utils/build_install_header_from_apt_raspi2.bash index 0826cd3..40cccba 100755 --- a/utils/build_install_header_from_apt_raspi2.bash +++ b/utils/build_install_header_from_apt_raspi2.bash @@ -11,7 +11,9 @@ rm Makefile ln -s Makefile.header_from_apt Makefile make clean make -sudo insmod rtmouse.ko +sudo install -D -m 644 rtmouse.ko /lib/modules/$(uname -r)/extra/rtmouse.ko +sudo depmod -a +sudo modprobe rtmouse # initialize the driver sleep 1 diff --git a/utils/build_install_header_from_apt_raspi4.bash b/utils/build_install_header_from_apt_raspi4.bash index 482d675..a048e34 100755 --- a/utils/build_install_header_from_apt_raspi4.bash +++ b/utils/build_install_header_from_apt_raspi4.bash @@ -13,7 +13,9 @@ make clean # Update for Raspberry Pi 4 sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c make -sudo insmod rtmouse.ko +sudo install -D -m 644 rtmouse.ko /lib/modules/$(uname -r)/extra/rtmouse.ko +sudo depmod -a +sudo modprobe rtmouse # initialize the driver sleep 1 diff --git a/utils/build_install_header_from_source_raspi2.bash b/utils/build_install_header_from_source_raspi2.bash index 1bf52ba..98a4010 100755 --- a/utils/build_install_header_from_source_raspi2.bash +++ b/utils/build_install_header_from_source_raspi2.bash @@ -11,7 +11,9 @@ rm Makefile ln -s Makefile.header_from_source Makefile make clean make -sudo insmod rtmouse.ko +sudo install -D -m 644 rtmouse.ko /lib/modules/$(uname -r)/extra/rtmouse.ko +sudo depmod -a +sudo modprobe rtmouse # initialize the driver sleep 1 diff --git a/utils/build_install_header_from_source_raspi4.bash b/utils/build_install_header_from_source_raspi4.bash index a09aabb..b4f67a5 100755 --- a/utils/build_install_header_from_source_raspi4.bash +++ b/utils/build_install_header_from_source_raspi4.bash @@ -13,7 +13,9 @@ make clean # Update for Raspberry Pi 4 sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c make -sudo insmod rtmouse.ko +sudo install -D -m 644 rtmouse.ko /lib/modules/$(uname -r)/extra/rtmouse.ko +sudo depmod -a +sudo modprobe rtmouse # initialize the driver sleep 1