Linux: How to find the device driver used for a device?
Just use /sys
.
Example. I want to find the driver for my Ethernet card:
$ sudo lspci
...
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 01)
$ find /sys | grep drivers.*02:00
/sys/bus/pci/drivers/r8169/0000:02:00.0
That is r8169
.
First I need to find coordinates of the device using lspci
; then I find driver that is used for the devices with these coordinates.
Here's a little script I wrote:
#!/bin/bash
for f in /sys/class/net/*; do
dev=$(basename $f)
driver=$(readlink $f/device/driver/module)
if [ $driver ]; then
driver=$(basename $driver)
fi
addr=$(cat $f/address)
operstate=$(cat $f/operstate)
printf "%10s [%s]: %10s (%s)\n" "$dev" "$addr" "$driver" "$operstate"
done
Sample output:
$ ~/what_eth_drivers.sh
eth0 [52:54:00:aa:bb:cc]: virtio_net (up)
eth1 [52:54:00:dd:ee:ff]: virtio_net (up)
eth2 [52:54:00:99:88:77]: virtio_net (up)
lo [00:00:00:00:00:00]: (unknown)
sudo lspci -v
will show it. like this:
$ sudo lspci -v
00:01.0 VGA compatible controller: Advanced Micro Devices, Inc......
...
Kernel driver in use: radeon
Kernel modules: radeon
You can also combine it with grep
like this:
$ sudo lspci -v | grep -A 20 VGA