Hey folks! I'm working on a custom Linux kernel module designed to shut down the system when USB ports are tampered with. The issue I'm facing is that every time I power cycle the machine, the module unloads automatically, which means I have to load it again manually after each startup. Is there a way to make the module persist across reboots through adjustments to the code alone, without relying on user space scripts like systemd? For more context, here's my module on GitHub: https://github.com/yogeshwaran5/usb-shutdown-kernel-module
3 Answers
It's important to note that different Linux distributions have varying init systems and service management, which means that relying on userspace could require different scripts for each. I'm also on the lookout for a kernel-side solution that wouldn't entail a complete kernel rebuild just to get this little driver working. Does anyone have insights into that?
If you really want to avoid any userspace scripts to load your module (for whatever reason), then you'll need to compile your module as a built-in driver. That way, it gets loaded with the kernel itself. How flexible is the USB_DEVICE_ADD function? If this is a concern, you could explore building your module into an initramfs to see if that will let it load before the xhci driver kicks in.
It sounds like your module isn't actually getting unloaded. When the system powers off, the kernel stops running, which means anything loaded with `insmod` will indeed disappear after a reboot. On the other hand, other modules load automatically at boot thanks to utilities like udev that handle plug-and-play devices. For your module, to ensure it loads automatically, you might want to create a configuration file in `/etc/modules-load.d/` and place your module in a location where `modprobe` can find it.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String