Run insmod on the wrong file and you are not debugging a program, you are debugging the running kernel. You will load one module from a file, pass it only the arguments that module documents, and check the kernel log when the short error from insmod is not enough. Allow 10 to 15 minutes, plus time to identify the correct module and arrange a recovery window. The examples assume the installed kmod 31 tools on Linux 6.8.0-139-generic.
Safety boundary: Inserting a module changes the running kernel. A faulty, incompatible or malicious module can crash the machine, weaken its security boundary or disrupt hardware. Use a tested module from a trusted source, keep console or out-of-band access available, and do not experiment on a production host. You normally need elevated privileges for the insertion and removal commands.
First confirm which executable will run and record its version. This is an unprivileged check and changes nothing:
$ command -v insmod
/usr/sbin/insmod
$ insmod --version
kmod version 31
+ZSTD +XZ -ZLIB +LIBCRYPTO -EXPERIMENTAL
The version line describes kmod, the package that supplies this insmod. Option support and diagnostics can differ between releases, so keep the local output with your change record.
Checkpoint: You have confirmed the binary and package version. If command -v insmod returns nothing, stop and install or repair the normal kmod package through your distribution's package manager.
insmod takes a filename, not just a module's short name. Do not guess the filename or substitute an untrusted path. Use a path supplied by your distribution, the module vendor or your build process, then inspect it before using it:
$ MODULE_FILE='/path/to/trusted-module.ko'
$ printf '%s\n' "$MODULE_FILE"
/path/to/trusted-module.ko
$ test -r "$MODULE_FILE" && echo 'module file is readable'
module file is readable
Replace the placeholder with a real path before running the commands, and keep the quotes if the path comes from a variable. A readable file is not automatically safe or compatible: check its provenance, target kernel and documented parameters separately.
Do not unpack, rename or edit a module merely to make the command accept it. If the file is missing, fix the path first. If you only have a module name and need dependency handling, use modprobe instead of turning the name into a guessed filename.
The syntax is a filename followed by zero or more module options. The option names are module-specific; insmod cannot tell you which values are appropriate. Read the module documentation or the deployment instructions and copy only the parameters they specify.
$ sudo insmod /path/to/trusted-module.ko documented_option=VALUE
documented_option=VALUE is a placeholder, not a universal option. Remove it if the module takes no arguments. Do not paste a whole shell command after the filename: every remaining shell word is passed as a module option, and an unknown option can make the load fail.
Before pressing Enter, check the target kernel with uname -r and confirm the module was built for it. A module built for another kernel or with an incompatible configuration may be rejected, or may load and behave incorrectly.
Insertion is the state-changing step. Save the exact command and arrange a rollback before running it. The command prints little on success:
$ sudo insmod "$MODULE_FILE" documented_option=VALUE
$ printf 'insmod exit status: %s\n' "$?"
insmod exit status: 0
Use the real option set from the previous step, or omit it entirely. An exit status of zero means the insertion request completed. It is not proof that the driver is configured for your hardware or that a service using it is healthy.
If the module exposes devices, networking or storage, expect dependent services to change behaviour immediately. Watch the service and application checks that matter for your host. Keep the previous configuration available so you can return to it without guessing.
The manpage describes insmod errors as deliberately general, because the kernel does the actual linking work. The kernel log usually holds the useful reason. First capture the exit status, then inspect recent messages:
$ sudo insmod "$MODULE_FILE"
insmod: ERROR: could not insert module trusted-module.ko: Invalid module format
$ printf 'insmod exit status: %s\n' "$?"
insmod exit status: 1
$ sudo dmesg | tail -n 30
The error text and the final log lines vary. Look for messages about the kernel release, vermagic, missing symbols, signatures, permissions or a parameter the module rejected. Do not repeatedly retry an unknown failure on a production system. Compare the module's build target with uname -r, verify the file came from the expected source, and ask the module or distribution maintainer for the correct build.
If the command says the filename is missing, the invocation is incomplete. The installed command confirms that case without touching the kernel:
$ insmod
insmod: ERROR: missing filename.
$ printf 'insmod exit status: %s\n' "$?"
insmod exit status: 1
After a successful load, verify the module using your system's normal module inspection tools and the device or service that should be using it. Treat a loaded module as a live kernel change, not a completed file operation. If the module was inserted by a service or boot process, record that fact before removing it.
Warning: To undo a manually inserted module, use rmmod with the module name, not the path. Removing a module can interrupt the hardware or service that depends on it, and the kernel may refuse while it is busy:
$ sudo rmmod MODULE_NAME
$ printf 'rmmod exit status: %s\n' "$?"
rmmod exit status: 0
Replace MODULE_NAME with the name documented for the module, normally the filename without its directory and module suffix. Confirm dependent services are stopped or that the maintenance plan covers the interruption. If removal fails because the module is in use, stop the owning service and investigate its users; do not force an unsafe removal.
insmod is intentionally simple. It loads the file you name and does not provide the dependency management most users need. Prefer modprobe when a module depends on other modules, when it should be selected by name from the system's module configuration, or when you need the normal distribution workflow. Use insmod when you specifically need to test or load one known file and understand the dependency boundary.
This distinction heads off a common distraction: changing the filename until a direct load works while a required dependency is still absent. If the kernel log reports an unresolved symbol or the driver does not initialise, check the dependency-aware workflow before changing module code or boot settings.
insmod executable.dmesg after a failure instead of relying on its short error alone.rmmod, or you chose modprobe for dependency handling.