106

Is there a standard way to list the parameter values of a loaded Linux module? I'm essentially probing for another answer to this Linux kernel module parameters question, because the module I'm interested in doesn't have a /sys/modules/<module_name>/parameters interface.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
cdleary
  • 1,635
  • 4
  • 17
  • 11
  • 16
    All answers up to now deserve a down-vote, because they did not read the OP carefully ("the module I'm interested in does *not* have a .../parameters interface")! :-( – Dirk Mar 21 '18 at 16:53
  • If you only want to find out what is the modified values are instead of the default values, then you can check [here](https://unix.stackexchange.com/a/710903/77353), use modprobe to achieve this. – Wang Jul 22 '22 at 15:07

7 Answers7

68

You can do it by using this simple one way command, which uses the /proc/modules and /sys virtual filesystems:

cat /proc/modules | cut -f 1 -d " " | while read module; do \
 echo "Module: $module"; \
 if [ -d "/sys/module/$module/parameters" ]; then \
  ls /sys/module/$module/parameters/ | while read parameter; do \
   echo -n "Parameter: $parameter --> "; \
   cat /sys/module/$module/parameters/$parameter; \
  done; \
 fi; \
 echo; \
done

You will obtain an output like this:

...
...
Module: vboxnetadp

Module: vboxnetflt

Module: vboxdrv
Parameter: force_async_tsc --> 0

Module: binfmt_misc

Module: uinput

Module: fuse
Parameter: max_user_bgreq --> 2047
Parameter: max_user_congthresh --> 2047

Module: md_mod
Parameter: new_array --> cat: /sys/module/md_mod/parameters/new_array: Permission denied
Parameter: start_dirty_degraded --> 0
Parameter: start_ro --> 0

Module: loop
Parameter: max_loop --> 0
Parameter: max_part --> 0

Module: kvm_intel
Parameter: emulate_invalid_guest_state --> N
Parameter: ept --> Y
Parameter: fasteoi --> Y
Parameter: flexpriority --> Y
Parameter: nested --> N
Parameter: ple_gap --> 0
Parameter: ple_window --> 4096
Parameter: unrestricted_guest --> Y
Parameter: vmm_exclusive --> Y
Parameter: vpid --> Y
Parameter: yield_on_hlt --> Y

Module: kvm
Parameter: allow_unsafe_assigned_interrupts --> N
Parameter: ignore_msrs --> N
Parameter: min_timer_period_us --> 500

Module: tpm_infineon

Module: joydev

Module: snd_hda_codec_hdmi
Parameter: static_hdmi_pcm --> N
...
...

Hope this helps.

RaSca
  • 705
  • 5
  • 2
  • Thanks! That is very useful diagnosing all kind of problems with problematic hardware ! – oz123 Dec 10 '12 at 06:54
  • Amazing, and if you pass $module as e.g. function parameter instead of getting it from /proc/modules you easily get all params of a given module. – igordcard May 18 '14 at 11:14
  • @RaSca - Did any of these answers work for you? – Dan Garthwaite Feb 02 '15 at 02:47
  • At first this didn't work for me as I had `alias ls='ls -lah'`. Removing the alias or running the solution as a script worked great though. – David Farrell Jan 15 '17 at 15:42
  • Combining this with a grep in lsmod: lsmod | grep -i bluetooth > lsmodpattern.txt;cat lsmodpattern.txt | sed 's/|/ /' | awk '{print $4}' > patternmodules.txt;cat patternmodules.txt|tr , '\n' | while read module; do echo "Module: $module"; if [ -d "/sys/module/$module/parameters" ]; then ls /sys/module/$module/parameters/ | while read parameter; do echo -n "Parameter: $parameter = "; cat /sys/module/$module/parameters/$parameter; done; fi; done – Ferroao Aug 30 '17 at 17:36
  • The "parameters" directory only appears if the module is loaded with parameters. Defaults will not be shown here. – Rolf Apr 13 '18 at 23:36
  • 3
    This answer does not answer the question at all. The OP _specifically_ asked for a way for modules which do *not* export their parameters. – bot47 Dec 19 '18 at 08:57
  • 2
    @Rolf I currently have exactly the problem where the Module is loaded WITH non defaults and it does not present them. – bot47 Dec 19 '18 at 08:58
53

You can use the command systool -vm <Module name>. It comes with the sysfsutils package on most systems.

This is what the output will look like, there is a section Parameters:

linux ~ # systool -vm btusb
Module = "btusb"

  Attributes:
    coresize            = "40960"
    initsize            = "0"
    initstate           = "live"
    refcnt              = "0"
    srcversion          = "D69A7EC073BC0145C2DE5C3"
    taint               = ""
    uevent              = <store method only>
    version             = "0.8"

  Parameters:
    disable_scofix      = "N"
    force_scofix        = "N"
    reset               = "Y"

  Sections:
    .bss                = "0xffffffffa090d800"
    .data               = "0xffffffffa090d000"
    .exit.text          = "0xffffffffa09096ff"
    .gnu.linkonce.this_module= "0xffffffffa090d4c0"
    .init.text          = "0xffffffffa0910000"
    .note.gnu.build-id  = "0xffffffffa090a000"
    .rodata             = "0xffffffffa090b060"
    .rodata.str1.1      = "0xffffffffa090a024"
    .rodata.str1.8      = "0xffffffffa090a2b0"
    .smp_locks          = "0xffffffffa090af84"
    .strtab             = "0xffffffffa0912668"
    .symtab             = "0xffffffffa0911000"
    .text               = "0xffffffffa0905000"
    __mcount_loc        = "0xffffffffa090c3d8"
    __param             = "0xffffffffa090c360"
    __verbose           = "0xffffffffa090d0f8"
cdauth
  • 861
  • 9
  • 18
  • 4
    The command `systool` is part of the package `sysfsutils`. And this is the answer I think, (but could have an example output) – Volker Siegel Jun 20 '14 at 07:22
  • 4
    Using this to query a handful of modules on my system, it seems the `Parameters:` section is only present in the output for modules that expose a `/sys/modules//parameters` interface. So, unfortunately, this doesn't satisfy the premise of the question. – Lance U. Matthews Aug 13 '19 at 20:05
  • this only show online modules (loaded ones) – Wang Jul 22 '22 at 14:46
17
grep -H '' /sys/module/ath9k*/parameters/*

/sys/module/ath9k/parameters/blink:1
/sys/module/ath9k/parameters/bt_ant_diversity:0
/sys/module/ath9k/parameters/btcoex_enable:0
/sys/module/ath9k/parameters/nohwcrypt:1
/sys/module/ath9k/parameters/ps_enable:0

grep -H '' /sys/module/acpi_cpufreq/parameters/*
/sys/module/acpi_cpufreq/parameters/acpi_pstate_strict:0
jumapico
  • 3
  • 2
Dan Garthwaite
  • 2,922
  • 18
  • 29
  • 3
    The OP specifically said that the module in question does *not* present the current parameter values via `/sys`. Therefore this answer is correct for other cases, but does not answer the original question at all. – Binarus Dec 20 '20 at 10:09
12

You could use the "modinfo(8)" command to get available load time parameters for a module. For instance:

# modinfo e100 | grep parm
parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           eeprom_bad_csum_allow:Allow bad eeprom checksums (int)
parm:           use_io:Force use of i/o access mode (int)

As for getting the parameters of loaded modules, try combining the modinfo command with a simple "lsmod | awk '{ print $1 }'"

As in:

lsmod | awk '{print $1 }'combi > myfile.txt
tail -n +2 myfile.txt > myfile.txt.tmp && mv myfile.txt.tmp myfile.txt
while read -r LINE; do echo "$LINE">>results.txt;modinfo "$LINE" | grep ^desc>>results.txt;modinfo "$LINE" | grep parm>> results.txt; done < myfile.txt
Ferroao
  • 103
  • 4
katriel
  • 4,407
  • 22
  • 20
1

Would come out ugly as a comment, but I did this check on my system..

cat /proc/modules  | cut -d " " -f1 | while read mod; do
   test -d /sys/module/$mod/parameters || echo modinfo $mod | grep parm; 
done

To check if modules without parameters in /sys show up as having parameters in modinfo but I couldnt find any.?

I am no expert, but the difference here is that modinfo reads the module file itself for the parameters by looking in the .modinfo elf headers, whereas sys is reading these from its runtime variant.

It may be possible to have parameters you can modify at runtime which dont appear as a modinfo parameter value, but since the module format should be pretty fixed I dont imagine its possible for you to pass a option parameter to a module when loading without there being a .modinfo structure for it linked in.

Does your module suggest there are parameters passable with modinfo when you check it that way but there are none in /sys for it? Certainly on my system I was unable to find any examples of this using the command provided above.

EDIT: All this is wrong given that if you do actually check what I did, you'll note that echo mod $mod | grep parm will never actually result in a answer.

If you do the following instead..

cat /proc/modules  | cut -d " " -f1 | while read mod; do
    test -d /sys/module/$mod/parameters || (modinfo $mod | grep parm && echo $mod)
done

You'll find all sorts of modules that dont contain a parameters directory in /sys/module/$mod but have parameters contained inside of their instances at run time.

Inversely, you can also do this:

for mod in $(cat /proc/modules | cut -d" " -f1; do
  if [ -d /sys/module/$mod/parameters ]; then 
    for p in /sys/module/$mod/parameters/*; do 
      p=$(basename $p)
      modinfo $mod -F parm | grep -q $p || echo $mod $p
    done;
  fi;
done

To find examples of modules that do have a parameters value in /sys/module/$mod/parameters but dont have a parameter set in modinfo.

Matthew Ife
  • 22,927
  • 2
  • 54
  • 71
  • 3
    The OP specifically said that the module in question does not expose the current parameter values via `/sys`. Therefore, this answer is interesting, but does not answer the original question. – Binarus Dec 20 '20 at 10:12
  • @Binarus I mean, its a 9 year old answer but I dont think you actually read what I wrote before downvoting it! – Matthew Ife Dec 23 '20 at 14:10
  • After re-reading your answer, I apologize. That was too quick, and I will convert the downvote into an upvote. Thanks for showing me my mistake (however, I believe that the age of the answer does not matter here :-)) – Binarus Dec 23 '20 at 15:20
  • Turned out that I can't cast an upvote right now because my "vote is locked until the answer is edited". I have slightly edited it and now I am waiting until it has passed the review queue. I hope I then finally can turn my downvote into an upvote. – Binarus Dec 23 '20 at 15:25
  • 1
    O.K., done .... – Binarus Dec 23 '20 at 20:51
  • 1
    [`e1000e`](https://www.kernel.org/doc/html/v4.20/networking/e1000e.html) is a good example for a module for which `modinfo` lists a bunch of parameters but `ls /sys/module/e1000e/parameters/` only lists `copybreak`. – maxschlepzig May 08 '21 at 21:07
-1

For iwlwifi and other modules I used this:

 grep [[:alnum:]] /sys/module/iwl*/parameters/*

and I get this output:

 /sys/module/iwlmvm/parameters/init_dbg:N
 /sys/module/iwlmvm/parameters/power_scheme:2
 /sys/module/iwlmvm/parameters/tfd_q_hang_detect:Y
 /sys/module/iwlwifi/parameters/11n_disable:0
 /sys/module/iwlwifi/parameters/amsdu_size:0
 /sys/module/iwlwifi/parameters/antenna_coupling:0
 /sys/module/iwlwifi/parameters/bt_coex_active:Y
 /sys/module/iwlwifi/parameters/d0i3_disable:Y
 /sys/module/iwlwifi/parameters/d0i3_timeout:1000
 /sys/module/iwlwifi/parameters/disable_11ac:N
 /sys/module/iwlwifi/parameters/fw_monitor:N
 /sys/module/iwlwifi/parameters/fw_restart:Y
 /sys/module/iwlwifi/parameters/lar_disable:N
 /sys/module/iwlwifi/parameters/led_mode:0
 /sys/module/iwlwifi/parameters/nvm_file:(null)
 /sys/module/iwlwifi/parameters/power_level:0
 /sys/module/iwlwifi/parameters/power_save:N
 /sys/module/iwlwifi/parameters/swcrypto:0
 /sys/module/iwlwifi/parameters/uapsd_disable:3

So I guess you could try something like:

 grep [[:alnum:]] /sys/module/<module_name>/parameters/*

Let me know if this works for you.

  • `grep .` would probably also work just as well with less typing. :) – dannysauer Feb 27 '19 at 17:38
  • Yes, in this case, `grep . /sys/module//parameters/*` – Homero Esmeraldo Feb 27 '19 at 18:44
  • Something I just noticed - if you use a wildcard and there's only one parameter, it just shows the file contents - no file name. However, if you use `grep -R` and leave the wildcard off of the parameters directory, it always shows the filename. Bonus points: also add `--color` to the grep and get the filename + value differentiated by colors. ;) For example `grep -R --color '.' /sys/module/block/parameters/` – dannysauer Feb 27 '19 at 22:29
  • 1
    (never mind that the person asking the question specifically asked about modules which don't expose the /parameters API :D) – dannysauer Feb 27 '19 at 22:30
-2

Working off of katriel's work, you can get a (admittedly ugly) one-liner by combining the two of them in a bash loop:

for i in `lsmod | awk '{print $1}'`; do echo "$i: "; modinfo $i | grep parm; done
Scrivener
  • 3,106
  • 1
  • 20
  • 23
  • 2
    using awk for just returning the first argument via `print` is somewhat gross - use the `while read` syntax instead: `lsmod | while read a b; do echo $a:; modinfo $a | grep parm | sed -e 's/parm://'; done` - it does not change the fact that modinfo does not return the parameter values, though... – the-wabbit Jun 14 '11 at 15:21
  • 9
    and I think the original question was about the _used_ parameters, not the _available_ ones. – asdmin Feb 17 '12 at 12:51