Difference between revisions of "Hwdetect"

From ArchWiki
Jump to: navigation, search
(use new package templates, see Help:Style)
(update interlanguage links)
(Tag: wiki-scripts)
 
(52 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[[Category:Hardware detection and troubleshooting (English)]]
+
[[Category:Hardware detection and troubleshooting]]
{{i18n|Hwdetect}}
+
[[ja:Hwdetect]]
 +
{{Related articles start}}
 +
{{Related|mkinitcpio}}
 +
{{Related articles end}}
 +
[https://projects.archlinux.org/svntogit/packages.git/tree/hwdetect/trunk/hwdetect hwdetect] is a hardware detection script primarily used to load or list modules for use in [[mkinitcpio.conf]]. As such, it informs its user about which kernel modules are required to drive the hardware. This is in contrast to many other tools, that only query the hardware, and show raw information, leaving the user with the task to associate that information with the required drivers. The script makes use of information exported by the [[Wikipedia:Sysfs|sysfs]] subsystem employed by the Linux kernel.
  
hwdetect is a hardware detection script primarily used to load or list modules for use in [[rc.conf]] or [[mkinitcpio]].conf. The script makes use of information exported by the [[Wikipedia:Sysfs|sysfs]] subsystem employed by the Linux kernel.
+
== Installation ==
  
==Installation==
+
[[Install]] the {{Pkg|hwdetect}} package.
  
The {{Pkg|hwdetect}} package is available in [extra]:
+
== Usage ==
  
# pacman -S hwdetect
+
See the [https://projects.archlinux.org/svntogit/packages.git/tree/hwdetect/trunk/hwdetect hwdetect source], or run {{ic|hwdetect --help}}.
  
==Usage==
+
=== Examples ===
  
Options:
+
You can use the following method to populate {{Ic|MODULES}} in [[mkinitcpio.conf]].
  --kernel_version=      use kernel version (no autodetect)
+
 
  --ide-legacy          use old ide modules instead of pata
+
# hwdetect --show-modules
  --load-modules        load all detected modules
+
 
  --unload-modules      unload all detected modules
+
The command should have similar output to the following (system-dependant):
  --show-modules        show all detected modules
+
 
  --show-modules-order  shows load order of detected modules
+
SOUND    : pcspkr
  --show-agp            show AGP modules
+
OTHER   : 8139cp 8139too ac
  --show-ide            show IDE modules
+
 
  --show-scsi            show SCSI modules
+
Depending on what is used, copy the module names to replace the {{ic|MODULES}} section in {{ic|/etc/mkinitcpio.conf}}. The system should now boot faster, as some, or all, of the hardware detection and modules dependencies calculations is already stated.
  --show-sata            show SATA modules
+
 
  --show-usb            show USB modules
+
{{Note|
  --show-fw              show FIREWIRE modules
+
* The tool has dedicated output for usage within {{ic|/etc/mkinitcpio.conf}}.
  --show-net            show NETWORK modules
+
* If any of the module names change because newer kernels have newer modules, or you install new hardware on your computer, you will need to generate the list of modules again and update {{ic|MODULES}}.
  --show-input          show INPUT modules
+
}}
  --show-irda            show IRDA modules
+
 
  --show-isdn            show ISDN modules
+
== Tips and tricks ==
  --show-pcmcia          show PCMCIA modules
 
  --show-sound          show SOUND modules
 
   --show-video          show VIDEO modules
 
   --show-other          show OTHER modules
 
 
For /etc/mkinitcpio.conf use:
 
  --hostcontroller      show MODULES= for all hostcontrollers
 
  --vmware              add BusLogic to MODULES for vmware
 
 
  --hooks                show HOOKS=
 
  --hooks-dir            use this directory for HOOKS check
 
  --dsdt                add dsdt to HOOKS=
 
  --raid                add raid to HOOKS=
 
  --raid-partitions      add raid-partitions to HOOKS=
 
  --encrypt              add encrypt to HOOKS=
 
  --lvm2                add lvm2 to HOOKS=
 
  --keymap              add keymap to HOOKS=
 
  --usb                  add usb to HOOKS=
 
  --fw                  add fw to HOOKS=
 
  --pcmcia              add pcmcia to HOOKS=
 
  --nfs                  add net to HOOKS=
 
 
For /etc/rc.conf use:
 
  --net                  show network MODULES
 
  --modules              show all detected MODULES
 
  
==Example==
+
=== Unused modules ===
  
You can use the following method to disable {{Ic|MOD_AUTOLOAD}} in [[rc.conf]]. This should improve boot times, as time will not be spent discovering modules.
+
To generate a list of modules currently not used, use the following script:
# hwdetect --modules
 
  
The command should output something similar to the following (of course, output depends on the system):
+
#!/bin/bash
MODULES=(ac battery button processor thermal video cdrom ....)  
+
modules=($(awk '{print $1}' /proc/modules))
 +
 +
for hw in $(hwdetect --show-modules | awk -F: '{gsub("-","_"); print $2}'); do
 +
    if ! grep -q "$hw" <(printf '%s\n' "${modules[@]}"); then
 +
        printf '%s\n' "$hw";
 +
    fi
 +
done
  
Copy this output to replace the {{Ic|MODULES}} section in {{ic|/etc/rc.conf}} and change {{Ic|MOD_AUTOLOAD}} from "yes" to "no". The system should now skip the auto-load and boot faster.
+
=== Higher level modules ===
  
==Tips==
+
The converse script is also of interest as it lists modules which are higher level, in the sense that they are less related to specific pieces of hardware:
  
 +
#!/bin/bash
 +
lowlevel=($(hwdetect --show-modules | awk -F: '{gsub("-","_"); print $2}'))
 +
 +
for mod in $(awk '{print $1}' /proc/modules); do
 +
    if ! grep -q "$mod" <(printf '%s\n' "${lowlevel[@]}"); then
 +
        printf '%s\n' "$mod";
 +
    fi
 +
done
  
List generated with "hwdetect --modules" is very long.
+
== See also ==
You might be interested only with those which are not actually loaded.
 
Script does the job:
 
  
  eval $(hwdetect --modules)
+
* [[wikipedia:Lspci|lspci, and other hardware detection related tools]]
  for m in ${MODULES[*]}; do
 
    if ! grep -sq $(echo $m|tr - _) <(lsmod); then
 
      echo $m;
 
    fi
 
  done
 

Latest revision as of 21:40, 13 December 2017

hwdetect is a hardware detection script primarily used to load or list modules for use in mkinitcpio.conf. As such, it informs its user about which kernel modules are required to drive the hardware. This is in contrast to many other tools, that only query the hardware, and show raw information, leaving the user with the task to associate that information with the required drivers. The script makes use of information exported by the sysfs subsystem employed by the Linux kernel.

Installation

Install the hwdetect package.

Usage

See the hwdetect source, or run hwdetect --help.

Examples

You can use the following method to populate MODULES in mkinitcpio.conf.

# hwdetect --show-modules

The command should have similar output to the following (system-dependant):

SOUND    : pcspkr
OTHER    : 8139cp 8139too ac

Depending on what is used, copy the module names to replace the MODULES section in /etc/mkinitcpio.conf. The system should now boot faster, as some, or all, of the hardware detection and modules dependencies calculations is already stated.

Note:
  • The tool has dedicated output for usage within /etc/mkinitcpio.conf.
  • If any of the module names change because newer kernels have newer modules, or you install new hardware on your computer, you will need to generate the list of modules again and update MODULES.

Tips and tricks

Unused modules

To generate a list of modules currently not used, use the following script:

#!/bin/bash
modules=($(awk '{print $1}' /proc/modules))

for hw in $(hwdetect --show-modules | awk -F: '{gsub("-","_"); print $2}'); do
    if ! grep -q "$hw" <(printf '%s\n' "${modules[@]}"); then
        printf '%s\n' "$hw";
    fi
done

Higher level modules

The converse script is also of interest as it lists modules which are higher level, in the sense that they are less related to specific pieces of hardware:

#!/bin/bash
lowlevel=($(hwdetect --show-modules | awk -F: '{gsub("-","_"); print $2}'))

for mod in $(awk '{print $1}' /proc/modules); do
    if ! grep -q "$mod" <(printf '%s\n' "${lowlevel[@]}"); then
        printf '%s\n' "$mod";
    fi
done

See also