How to make a systemtap kernel module load persistently across reboots?
Environment
- Red Hat Enterprise Linux 6
- systemtap-runtime
Issue
- How to make a systemtap kernel module load automatically on system boot?
- Is it possible to have a systemtap kernel module load on production system without installing kernel-debuginfo and kernel-devel packages?
Resolution
-
It is possible to have a systemtap kernel module load across reboots using an init service, following the below steps:
-
Follow steps in this solution to compile the systemtap script as a kernel module on a
development machineand prepareproduction machineswithsystemtap-runtimepackage.- Note: development and production machines' kernels must match.
-
Copy generated systemtap module(s) to production machines.
-
Deploy the below init script on production machines as
/etc/init.d/systemtap_service# chkconfig: 345 99 01 # description: sample systemtap service #!/bin/bash PATH=/bin:/usr/bin:/sbin:/usr/sbin case "$1" in start) echo -n "Starting systemtap service" /sbin/insmod /root/uprobes.ko /usr/bin/staprun /root/systemtap_module.ko -D -o /root/systemtap_module.log ;; stop) echo -n "Stopping systemtap service" kill -9 `ps ax | grep "stapio" | grep -v grep | awk '{ print $1 }'` /sbin/rmmod systemtap_module /sbin/rmmod uprobes.ko ;; *) echo "Usage: /etc/init.d/systemtap_service {start|stop}" exit 1 ;; esac exit 0 -
Change init script permissions, enable and start the service.
# chmod 755 /etc/init.d/systemtap_service # chkconfig systemtap_service on # /etc/init.d/systemtap_service start
-
Diagnostic Steps
-
Check if
stapioprocess is running after activating the service# ps auxf|grep stapio root 2033 0.0 0.0 123632 528 ? Ssl 17:13 0:00 /usr/libexec/systemtap/stapio -D -o /root/systemtap_module.log /root/systemtap_module.ko -F3
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.