Linux에서는 다음이 제공됩니다.
/dev/sda
, 장치 ,8, 0
,어떤 모듈 / 드라이버가 "구동"하는지 어떻게 알 수 있습니까?
그것을 파헤 치 /sys
거나 /proc
발견 할 수 있습니까?
sysfs
장치 파일에 대해이 정보를 얻으려면 먼저의 출력을보고 주 / 부 번호를 확인합니다 ls -l
. 예 :
$ ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 Apr 17 12:26 /dev/sda
는 8, 0
주 번호는 것을 우리에게 알려줍니다 8
그리고 미성년자입니다 0
. b
목록의 시작은 또한 블록 디바이스 것을 우리에게 알려줍니다. 다른 장치는 c
처음에 for character 장치를 가질 수 있습니다 .
그런 다음 아래를 보면 /sys/dev
두 개의 디렉토리가 있음을 알 수 있습니다. 하나는 전화 block
했고 다른 하나는 char
. 여기서 당연한 사실은 이들이 각각 블록 및 문자 장치 용이라는 것입니다. 그러면 각 장치는이 디렉토리에있는 주 / 부 번호로 액세스 할 수 있습니다. 장치에 사용할 수있는 드라이버가있는 driver
경우이 또는 device
하위 디렉토리 에서 링크 대상을 읽어서 찾을 수 있습니다 . 예를 들어, /dev/sda
나는 간단히 할 수 있습니다.
$ readlink /sys/dev/block/8\:0/device/driver
../../../../../../../bus/scsi/drivers/sd
이것은 sd
드라이버가 장치에 사용됨을 나타냅니다 . 장치가 블록 또는 문자 장치인지 확실하지 않은 경우 셸에서이 부분을 *
. 이것은 잘 작동합니다.
$ readlink /sys/dev/*/8\:0/device/driver
../../../../../../../bus/scsi/drivers/sd
블록 디바이스는 또한 중 하나를 통해 자신의 이름을 통해 직접 액세스 할 수 있습니다 /sys/block
또는 /sys/class/block
. 예 :
$ readlink /sys/block/sda/device/driver
../../../../../../../bus/scsi/drivers/sd
다양한 디렉토리의 존재 /sys
는 커널 구성에 따라 변경 될 수 있습니다. 또한 모든 장치에 device
하위 폴더 가있는 것은 아닙니다 . 예를 들어, /dev/sda1
. 여기에서 전체 디스크에 대한 장치에 액세스해야합니다 (불행히도 이에 대한 sys
링크 가 없습니다 ).
유용한 마지막 작업은 사용 가능한 모든 장치의 드라이버를 나열하는 것입니다. 이를 위해 glob을 사용하여 드라이버 링크가있는 모든 디렉토리를 선택할 수 있습니다. 예 :
$ ls -l /sys/dev/*/*/device/driver && ls -l /sys/dev/*/*/driver
lrwxrwxrwx 1 root root 0 Apr 17 12:27 /sys/dev/block/11:0/device/driver -> ../../../../../../../bus/scsi/drivers/sr
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/block/8:0/device/driver -> ../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/block/8:16/device/driver -> ../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/block/8:32/device/driver -> ../../../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:0/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:1024/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:128/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:256/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:384/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/189:512/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/189:513/driver -> ../../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/189:514/driver -> ../../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/189:640/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/189:643/driver -> ../../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:768/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 20:38 /sys/dev/char/189:896/driver -> ../../../../bus/usb/drivers/usb
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/21:0/device/driver -> ../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/21:1/device/driver -> ../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:27 /sys/dev/char/21:2/device/driver -> ../../../../../../../bus/scsi/drivers/sr
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/21:3/device/driver -> ../../../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/250:0/device/driver -> ../../../../../../../bus/hid/drivers/hid-generic
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/250:1/device/driver -> ../../../../../../../bus/hid/drivers/hid-generic
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/250:2/device/driver -> ../../../../../../../bus/hid/drivers/hid-generic
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/252:0/device/driver -> ../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/252:1/device/driver -> ../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 12:27 /sys/dev/char/252:2/device/driver -> ../../../../../../../bus/scsi/drivers/sr
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/252:3/device/driver -> ../../../../../../../../../bus/scsi/drivers/sd
lrwxrwxrwx 1 root root 0 Apr 17 19:53 /sys/dev/char/254:0/device/driver -> ../../../bus/pnp/drivers/rtc_cmos
lrwxrwxrwx 1 root root 0 Apr 17 19:53 /sys/dev/char/29:0/device/driver -> ../../../bus/platform/drivers/simple-framebuffer
lrwxrwxrwx 1 root root 0 Apr 17 19:53 /sys/dev/char/4:64/device/driver -> ../../../bus/pnp/drivers/serial
lrwxrwxrwx 1 root root 0 Apr 17 19:53 /sys/dev/char/4:65/device/driver -> ../../../bus/platform/drivers/serial8250
lrwxrwxrwx 1 root root 0 Apr 17 19:53 /sys/dev/char/4:66/device/driver -> ../../../bus/platform/drivers/serial8250
lrwxrwxrwx 1 root root 0 Apr 17 19:53 /sys/dev/char/4:67/device/driver -> ../../../bus/platform/drivers/serial8250
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/6:0/device/driver -> ../../../bus/pnp/drivers/parport_pc
lrwxrwxrwx 1 root root 0 Apr 17 12:26 /sys/dev/char/99:0/device/driver -> ../../../bus/pnp/drivers/parport_pc
마지막으로, 질문에서 조금 벗어나기 위해 다른 /sys
glob 트릭을 추가 하여 어떤 장치에서 어떤 드라이버를 사용하고 있는지에 대해 훨씬 더 넓은 관점을 얻을 것입니다 (장치 파일이있는 것은 아니지만).
find /sys/bus/*/drivers/* -maxdepth 1 -lname '*devices*' -ls
의 출력을 더 자세히 살펴보면 udevadm
표준 /sys
디렉토리 를 찾은 다음 (위의 주 / 부 디렉토리를 역 참조하면 얻을 수있는 것처럼), 디렉토리 트리 위로 올라가서 찾은 정보를 인쇄 하여 작동하는 것처럼 보입니다 . 이렇게하면 상위 장치와 이들이 사용하는 모든 드라이버에 대한 정보를 얻을 수 있습니다.
이를 실험하기 위해 아래 스크립트를 작성하여 디렉토리 트리를 살펴보고 각 관련 수준에서 정보를 표시했습니다. udev
각 수준에서 읽을 수있는 파일을 찾는 것처럼 보이며 이름과 내용이 ATTRS
. 이 작업을 수행하는 대신 uevent
각 수준에서 파일 의 내용을 표시합니다 (이의 존재는 단순한 하위 디렉터리가 아닌 고유 한 수준을 정의하는 것처럼 보입니다). 또한 내가 찾은 모든 하위 시스템 링크의 기본 이름과 장치가이 계층 구조에 어떻게 맞는지 보여줍니다. udevadm
동일한 정보를 표시하지 않으므로 이것은 훌륭한 보완 도구입니다. 상위 장치 정보 (예 : PCI
정보)는 lshw
상위 수준 장치 와 같은 다른 도구의 출력을 일치시키려는 경우에도 유용 합니다.
#!/bin/bash
dev=$(readlink -m $1)
# test for block/character device
if [ -b "$dev" ]; then
mode=block
elif [ -c "$dev" ]; then
mode=char
else
echo "$dev is not a device file" >&2
exit 1
fi
# stat outputs major/minor in hex, convert to decimal
data=( $(stat -c '%t %T' $dev) ) || exit 2
major=$(( 0x${data[0]} ))
minor=$(( 0x${data[1]} ))
echo -e "Given device: $1"
echo -e "Canonical device: $dev"
echo -e "Major: $major"
echo -e "Minor: $minor\n"
# sometimes nodes have been created for devices that are not present
dir=$(readlink -f /sys/dev/$mode/$major\:$minor)
if ! [ -e "$dir" ]; then
echo "No /sys entry for $dev" >&2
exit 3
fi
# walk up the /sys hierarchy one directory at a time
# stop when there are three levels left
while [[ $dir == /*/*/* ]]; do
# it seems the directory is only of interest if there is a 'uevent' file
if [ -e "$dir/uevent" ]; then
echo "$dir:"
echo " Uevent:"
sed 's/^/ /' "$dir/uevent"
# check for subsystem link
if [ -d "$dir/subsystem" ]; then
subsystem=$(readlink -f "$dir/subsystem")
echo -e "\n Subsystem:\n ${subsystem##*/}"
fi
echo
fi
# strip a subdirectory
dir=${dir%/*}
done
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다