简体   繁体   中英

How to rename a kernel module name without renaming the .ko passed to insmod?

I need to rename a kernel module (the name that get displayed with lsmod) of an already existing driver without changing the name of the source file.

eg

# insmod xxx.ko
<<module loads successfully>>
# lsmod
Module                  Size  Used by    Tainted: P
xxx                   191527  0
#
  • I want to rename xxx to yyy .

  • Now I know that changing the name of the driver source file (when it involves a single file) changes the name of the module.

  • But I don't want to change the name of a source file.

Rename your obj-m in Makefile and set dependency of obj-m to original module.

For example, I have file hello.c that contain all of my source code. But I want module to be mynewname .

Here is whole Makefile that does this:

obj-m := mynewname.o 
mynewname-objs := hello.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD  := $(shell pwd)

default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) clean

I set obj-m to mynewname.o and make mynewname.o dependant on hello.o . After invoking make you'll get mynewname.ko .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM