13

in the linux, lsmod lists a lot of modules. but how can we find where those module loaded from. for some modules,linux command "modprobe -l" shows a path but some are not.
edited i also tried "find" and "locate". both of them lists all kind of versions

locate fake
/svf/SVDrv/kernel/linux/.fake.ko.cmd
/svf/SVDrv/kernel/linux/.fake.mod.o.cmd
/svf/SVDrv/kernel/linux/.fake.o.cmd
/svf/SVDrv/kernel/linux/fake.ko
/svf/SVDrv/kernel/linux/fake.mod.o
/svf/SVDrv/kernel/linux/fake.o
/svf/SVDrv.03.11.2014.16.00/kernel/linux/.fake.ko.cmd
/svf/SVDrv.03.11.2014.16.00/kernel/linux/.fake.mod.o.cmd
/svf/SVDrv.03.11.2014.16.00/kernel/linux/.fake.o.cmd
/svf/SVDrv.03.11.2014.16.00/kernel/linux/fake.ko
/svf/SVDrv.03.11.2014.16.00/kernel/linux/fake.mod.o
/svf/SVDrv.03.11.2014.16.00/kernel/linux/fake.o
/svf/SVDrv.04.29.2014.17.39/kernel/linux/.fake.ko.cmd
/svf/SVDrv.04.29.2014.17.39/kernel/linux/.fake.mod.o.cmd
/svf/SVDrv.04.29.2014.17.39/kernel/linux/.fake.o.cmd
/svf/SVDrv.04.29.2014.17.39/kernel/linux/fake.ko
/svf/SVDrv.04.29.2014.17.39/kernel/linux/fake.mod.o
/svf/SVDrv.04.29.2014.17.39/kernel/linux/fake.o
/svf/SVDrv.05.05.2014.11.25/kernel/linux/.fake.ko.cmd
/svf/SVDrv.05.05.2014.11.25/kernel/linux/.fake.mod.o.cmd
/svf/SVDrv.05.05.2014.11.25/kernel/linux/.fake.o.cmd
/svf/SVDrv.05.05.2014.11.25/kernel/linux/fake.ko
/svf/SVDrv.05.05.2014.11.25/kernel/linux/fake.mod.o
/svf/SVDrv.05.05.2014.11.25/kernel/linux/fake.o
/svf/SVDrv.05.05.2014.17.43/kernel/linux/.fake.ko.cmd
/svf/SVDrv.05.05.2014.17.43/kernel/linux/.fake.mod.o.cmd
/svf/SVDrv.05.05.2014.17.43/kernel/linux/.fake.o.cmd
/svf/SVDrv.05.05.2014.17.43/kernel/linux/fake.ko
/svf/SVDrv.05.05.2014.17.43/kernel/linux/fake.mod.o
/svf/SVDrv.05.05.2014.17.43/kernel/linux/fake.o
/svf/SVDrv.05.07.2014.14.59/kernel/linux/.fake.ko.cmd
/svf/SVDrv.05.07.2014.14.59/kernel/linux/.fake.mod.o.cmd
/svf/SVDrv.05.07.2014.14.59/kernel/linux/.fake.o.cmd
/svf/SVDrv.05.07.2014.14.59/kernel/linux/fake.ko
/svf/SVDrv.05.07.2014.14.59/kernel/linux/fake.mod.o
/svf/SVDrv.05.07.2014.14.59/kernel/linux/fake.o
cppython
  • 1,209
  • 3
  • 20
  • 30

3 Answers3

17

Sorry if the answer comes a bit late but I just stumbled across this particular question myself today...

To minimize manual labor here is my listing of the paths curretly loaded modules are loaded from:

awk '{ print $1 }' /proc/modules | xargs modinfo -n | sort

I needed this to create a minimal kernel image containg only the modules i really need. Unfortunately lsmod only displays the name field which does not alwys match the modules# file name (e.g phy-am335x-control.ko and phy_am335x_control). I hope this helps.

kreddkrikk
  • 389
  • 3
  • 12
Mateusz Gwara
  • 171
  • 1
  • 2
4

You can use "locate" or "find" command on these modules to find where they are , for example

[root@localhost core_src]# lsmod
Module                  Size  Used by
iptable_filter          2793  0
ipt_MASQUERADE          2466  1
iptable_nat             6158  1
vmware_balloon          7199  0
i2c_piix4              12608  0
i2c_core               31276  1 i2c_piix4
shpchp                 33482  0
ext4                  371331  2
mbcache                 8144  1 ext4
jbd2                   93312  1 ext4
sd_mod                 39488  4
crc_t10dif              1541  1 sd_mod
sr_mod                 16228  0
cdrom                  39803  1 sr_mod
mptspi                 17051  3
mptscsih               36828  1 mptspi
mptbase                94005  2 mptspi,mptscsih
scsi_transport_spi     26151  1 mptspi
pata_acpi               3701  0
ata_generic             3837  0
ata_piix               22846  0
dm_mirror              14101  0
dm_region_hash         12170  1 dm_mirror
dm_log                 10122  2 dm_mirror,dm_region_hash
dm_mod                 81692  2 dm_mirror,dm_log
[root@localhost core_src]# locate vmware_balloon
/lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/misc/vmware_balloon.ko
Jain Rach
  • 4,069
  • 1
  • 16
  • 25
  • 2
    thanks, but this method only works when you have one version of the driver. in my system, there are a lot of different version.Both locate and find show all of versions, therefore, i still can't tell which one is loadd – cppython May 14 '14 at 04:56
  • 2
    Oh , okay. Guess "modinfo" will help you in case of multiple modules on your system – Jain Rach May 14 '14 at 05:06
  • 1
    sorry.no. modinfo did work for some modules but doesnt work for the module I am searching. "ERROR: modinfo: could not find module fake" – cppython May 14 '14 at 05:31
  • @cppython Try modinfo gives out the detailed description of the module. – Gautham Kantharaju May 15 '14 at 14:40
  • 1
    @JainRach your comment is exactly what I needed, thanks. should have gone into the main answer page as well. – Peter Teoh Jun 29 '21 at 03:54
  • @cppython It seems that `modinfo` only works for modules in `/lib/modules`. – alephalpha Jun 07 '22 at 01:55
1

Get the paths from the list of loaded modules. Without the need for awk.

while IFS= read -r line;
    do modinfo -n "${line%% *}"
done < /proc/modules | sort
nggit
  • 611
  • 8
  • 8