www.shoeisha.co.jp
/proc/
の確認
- カーネル内のデータへのインタフェース
- カーネルが認識しているH/W
- 実行中のプロセス(process)
- システムリソース
- 擬似的な(pseudo)ファイルシステム
- ブロックデバイス上にファイルが実在するわけではない
- ほとんどRead Only, 中にはWritableなものも
cat
で読める
- リダイレクトで書き込める(設定反映)
ファイル/ディレクトリ名 |
内容 |
数値/ |
PIDごとのプロセス情報 |
bus/pci/ |
PCIバスのデバイス関連 |
bus/usb/ |
USBデバイス関連 |
ide/ |
IDEデバイスに関する情報 |
net/ |
ネットワークについての情報 |
scsi/ |
SCSIデバイスに関する情報 |
sys/ |
システムに関する情報 |
cmdline |
起動時にカーネルに渡された引数 |
cpuinfo |
CPUとシステムアーキテクチャに関する各種情報 |
devices |
メジャーデバイス番号とデバイス名のリスト |
dma |
登録されているDMAチャンネル |
filesystems |
カーネルに組み込まれているファイルシステム |
interrupts |
使用されているIRQごとに割り込み回数 |
ioports |
使用しているI/Oアドレス領域 |
kcore |
システムの物理メモリ |
kmsg |
カーネルのログメッセージ |
meminfo |
物理メモリとスワップに関する情報 |
modules |
ロードされているカーネルモジュール |
mounts |
マウントされているファイルシステム |
partitions |
カーネルが認識しているパーティション |
stat |
カーネルおよびシステムの統計情報 |
swaps |
使用中のスワップ領域 |
uptime |
起動してからの経過時間 |
version |
バージョン |
/proc
以下の情報を効率よく表示するコマンド群がいろいろある
lsdev
コマンド
sudo apt install -y procinfo
FILES
/proc/interrupts
IRQ channels.
/proc/ioports
I/O memory addresses.
/proc/dma
DMA channels.
sudo lsdev
sudo lsdev
Device DMA IRQ I/O Ports
------------------------------------------------
0000:00:02.0 3000-303f
0000:00:19.0 3080-309f
0000:00:1f.2 3060-307f 30a0-30a7 30a8-30af 30b0-30b3 30b4-30b7
0000:00:1f.3 efa0-efbf
acpi 9
ACPI 1800-1803 1804-1805 1808-180b 1810-1815 1850-1850 1880-189f
ahci 3060-307f 30a0-30a7 30a8-30af 30b0-30b3 30b4-30b7
ahci[0000:00:1f.2] 43
cascade 4
dma 0080-008f
dma1 0000-001f
dma2 00c0-00df
EC 0062-0062 0066-0066
ehci_hcd:usb1 23
enp0s25 48
fpu 00f0-00ff
i8042 1 12
i915 44
iTCO_wdt.0.auto 1830-1833 1860-187f
iwlwifi 46
keyboard 0060-0060 0064-0064
mei_me 45
PCI 0000-0cf7 0cf8-0cff 0d00-ffff
pic1 0020-0021
pic2 00a0-00a1
pnp 0800-087f 0880-08ff 0900-097f 0980-09ff 0a00-0a7f 0a80-0aff 0b00-0b7f 0b80-0bff 15e0-15ef 1600-167f 1640-165f 1800-189f
PNP0800:00 0061-0061
PNP0C04:00 00f0-00f0
PNP0C09:00 0062-0062 0066-0066
rtc0 8 0070-0071
rtsx_pci 41
snd_hda_intel:card0 42
snd_hda_intel:card1 40
timer 0
timer0 0040-0043
timer1 0050-0053
xhci_hcd 47
lspci
コマンド
lspci
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b)
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 0b)
00:14.0 USB controller: Intel Corporation 8 Series USB xHCI HC (rev 04)
00:16.0 Communication controller: Intel Corporation 8 Series HECI #0 (rev 04)
00:19.0 Ethernet controller: Intel Corporation Ethernet Connection I218-V (rev 04)
00:1b.0 Audio device: Intel Corporation 8 Series HD Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 6 (rev e4)
00:1c.1 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 3 (rev e4)
00:1d.0 USB controller: Intel Corporation 8 Series USB EHCI #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation 8 Series LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation 8 Series SATA Controller 1 [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation 8 Series SMBus Controller (rev 04)
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS5227 PCI Express Card Reader (rev 01)
03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83)
lspci -vv -s 2:0
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS5227 PCI Express Card Reader (rev 01)
Subsystem: Lenovo ThinkPad X240
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 0, Cache Line Size: 64 bytes
Interrupt: pin A routed to IRQ 41
Region 0: Memory at f0500000 (32-bit, non-prefetchable) [size=4K]
Capabilities: <access denied>
Kernel driver in use: rtsx_pci
Kernel modules: rtsx_pci
- オプション
-v
, -vv
-t
-b
-s [[[[<domain>]:]<bus>]:][<device>][.[<func>]]
-d [<vendor>]:[<device>][:<class>]
lsusb
コマンド
lsusb
Bus 001 Device 002: ID 8087:8000 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 8087:07dc Intel Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
lsusb -t
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/9p, 480M
|__ Port 7: Dev 2, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 7: Dev 2, If 1, Class=Wireless, Driver=btusb, 12M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
-s [[bus]:][devnum]
Show only devices in specified bus and/or devnum. Both
ID's are given in decimal and may be omitted.
-d [vendor]:[product]
Show only devices with the specified vendor and product
ID. Both ID's are given in hexadecimal.
lsusb -s 01:1
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
- 超詳細
- sudoじゃないとwarning出る:
Couldn't open device, some information will be missing
sudo lsusb -s 01:1 -vv
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 0 Full speed (or root) hub
bMaxPacketSize0 64
idVendor 0x1d6b Linux Foundation
idProduct 0x0002 2.0 root hub
bcdDevice 4.15
iManufacturer 3 Linux 4.15.0-47-generic ehci_hcd
iProduct 2 EHCI Host Controller
iSerial 1 0000:00:1d.0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 25
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0 Full speed (or root) hub
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0004 1x 4 bytes
bInterval 12
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 3
wHubCharacteristic 0x000a
No power switching (usb 1.0)
Per-port overcurrent protection
bPwrOn2PwrGood 10 * 2 milli seconds
bHubContrCurrent 0 milli Ampere
DeviceRemovable 0x00
PortPwrCtrlMask 0xff
Hub Port Status:
Port 1: 0000.0507 highspeed power suspend enable connect
Port 2: 0000.0100 power
Port 3: 0000.0100 power
Device Status: 0x0001
Self Powered
- 読んでいるもの
/proc/bus/usb/
ディレクトリ以下
- 最近のUbuntuにはない説
- The folder
/proc/bus/usb
is part of usbfs. Because of conflicts with udev, newer Ubuntu kernels come with usbfs disabled. Your basic options are:
|
ブロックデバイス |
キャラクタデバイス |
バッファ |
持つ |
持たない |
ランダムアクセス |
可能 |
不可能 |
例 |
HDD,FDD,RAMディスク、RAIDボリューム |
デバイスファイル(キーボード、マウス、端末、プリンタ等) |
ls -l でのファイルタイプ |
b |
c |
ls -l /dev/sda*
brw-rw---- 1 root disk 0 2019-05-04 03:37 /dev/sda
brw-rw---- 1 root disk 0 2019-05-04 03:37 /dev/sda1
brw-rw---- 1 root disk 0 2019-05-04 03:37 /dev/sda2
ls -l /dev/{ttyS0,input/mice}
crw-rw---- 1 root input 13, 63 5月 4 03:37 /dev/input/mice
crw-rw---- 1 root dialout 4, 64 5月 4 03:37 /dev/ttyS0```
cat /proc/devices
Character devices:
1 mem
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
5 ttyprintk
6 lp
7 vcs
10 misc
13 input
21 sg
29 fb
89 i2c
99 ppdev
108 ppp
116 alsa
128 ptm
136 pts
180 usb
189 usb_device
204 ttyMAX
216 rfcomm
226 drm
241 mei
242 aux
243 ptp
244 pps
245 ttyDBC
246 bsg
247 hmm_device
248 watchdog
249 rtc
250 dax
251 dimmctl
252 ndctl
253 tpm
254 gpiochip
Block devices:
7 loop
8 sd
9 md
11 sr
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
253 device-mapper
254 mdp
259 blkext
udev
- 現在、udevが必要に応じて動的にデバイスファイルを管理してくれる
- sysfsと連携
- udev自体はユーザ空間で動く
- ので、カーネル内部の情報に直接アクセスできない
/sys/
から情報を得ている
- かつては、利用される可能性のあるデバイスファイル(数千)を
/dev/
以下にあらかじめ置く必要があった
- 流れ
- H/W接続
- カーネルがH/W接続を検知
- udevdデーモンがデバイスファイルを動的に生成
- カーネルが実際に認識しているH/Wに対応するデバイスファイルのみが用意される
- udevの設定ファイル
ls /etc/udev/rules.d/
70-snap.core.rules
/etc/udev/rules.d/70-snap.core.rules
# This file is automatically generated.
# Concatenation of all ModemManager udev rules
# do not edit this file, it will be overwritten on update
ACTION!="add|change|move", GOTO="mm_cinterion_port_types_end"
SUBSYSTEM!="tty", GOTO="mm_cinterion_port_types_end"
ENV{ID_VENDOR_ID}!="1e2d", GOTO="mm_cinterion_port_types_end"
SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}"
ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0053", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_CINTERION_PORT_TYPE_GPS}="1"
...
A rule consists of a comma-separated list of one or more key-value pairs. Each key has a distinct operation, depending on the
used operator. Valid operators are:
"=="
Compare for equality.
"!="
Compare for inequality.
"="
Assign a value to a key. Keys that represent a list are reset and only this single value is assigned.
...
udevadm
コマンド
UDEVADM(8) udevadm UDEVADM(8)
NAME
udevadm - udev management tool
SYNOPSIS
udevadm [--debug] [--version] [--help]
udevadm info [options] [devpath]
...
...
udevadm info [options] [devpath|file]
Queries the udev database for device information stored
in the udev database. It can also query the properties of
a device from its sysfs representation to help creating
udev rules that match this device.
-q, --query=TYPE
Query the database for the specified type of device
data. It needs the --path or --name to identify the
specified device. Valid TYPEs are: name, symlink,
path, property, all.
-p, --path=DEVPATH
The /sys path of the device to query, e.g.
[/sys]/class/block/sda. Note that this option usually
is not very useful, since udev can guess the type of
the argument, so udevadm --devpath=/class/block/sda
is equivalent to udevadm /sys/class/block/sda.
-n, --name=FILE
The name of the device node or a symlink to query,
e.g. [/dev]/sda. Note that this option usually is
not very useful, since udev can guess the type of the
argument, so udevadm --name=sda is equivalent to
udevadm /dev/sda.
-r, --root
Print absolute paths in name or symlink query.
-a, --attribute-walk
Print all sysfs properties of the specified device
that can be used in udev rules to match the specified
device. It prints all devices along the chain, up to
the root of sysfs that can be used in udev rules.
...
/dev/sda1
をsysfsがどう扱っているか調べる
udevadm info -q path -n /dev/sda1
/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
udevadm info -q env -n /dev/sda1
udevadm info --query=env --name=/dev/sda1
DEVLINKS=/dev/disk/by-uuid/9A29-BDC2 /dev/disk/by-partuuid/5352c0a6-f610-48e5-9887-d63a6e227709 /dev/disk/by-partlabel/EFI\x20System\x20Partition /dev/disk/by-path/pci-0000:00:1f.2-ata-1-part1 /dev/disk/by-id/ata-LITEONIT_LCS-256M6S_SD0E97902L1TH46107YF-part1
DEVNAME=/dev/sda1
DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
DEVTYPE=partition
ID_ATA=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=2
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=2
ID_ATA_FEATURE_SET_SECURITY_FROZEN=1
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_ROTATION_RATE_RPM=0
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_BUS=ata
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=9A29-BDC2
ID_FS_UUID_ENC=9A29-BDC2
ID_FS_VERSION=FAT32
ID_MODEL=LITEONIT_LCS-256M6S
ID_MODEL_ENC=LITEONIT\x20LCS-256M6S\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_PART_ENTRY_DISK=8:0
ID_PART_ENTRY_NAME=EFI\x20System\x20Partition
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SCHEME=gpt
ID_PART_ENTRY_SIZE=1048576
ID_PART_ENTRY_TYPE=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
ID_PART_ENTRY_UUID=5352c0a6-f610-48e5-9887-d63a6e227709
ID_PART_TABLE_TYPE=gpt
ID_PART_TABLE_UUID=0b97e339-7cbe-45e5-b86d-e145f77a3e1f
ID_PATH=pci-0000:00:1f.2-ata-1
ID_PATH_TAG=pci-0000_00_1f_2-ata-1
ID_REVISION=2C87901
ID_SERIAL=LITEONIT_LCS-256M6S_SD0E97902L1TH46107YF
ID_SERIAL_SHORT=SD0E97902L1TH46107YF
ID_TYPE=disk
MAJOR=8
MINOR=1
PARTN=1
PARTNAME=EFI System Partition
SUBSYSTEM=block
TAGS=:systemd:
UDISKS_IGNORE=1
USEC_INITIALIZED=3107106
udevadm info -q all -n /dev/sda1
P: /devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
N: sda1
S: disk/by-id/ata-LITEONIT_LCS-256M6S_SD0E97902L1TH46107YF-part1
S: disk/by-partlabel/EFI\x20System\x20Partition
S: disk/by-partuuid/5352c0a6-f610-48e5-9887-d63a6e227709
S: disk/by-path/pci-0000:00:1f.2-ata-1-part1
S: disk/by-uuid/9A29-BDC2
E: DEVLINKS=/dev/disk/by-partlabel/EFI\x20System\x20Partition /dev/disk/by-path/pci-0000:00:1f.2-ata-1-part1 /dev/disk/by-partuuid/5352c0a6-f610-48e5-9887-d63a6e227709 /dev/disk/by-id/ata-LITEONIT_LCS-256M6S_SD0E97902L1TH46107YF-part1 /dev/disk/by-uuid/9A29-BDC2
E: DEVNAME=/dev/sda1
E: DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
E: DEVTYPE=partition
E: ID_ATA=1
E: ID_ATA_DOWNLOAD_MICROCODE=1
E: ID_ATA_FEATURE_SET_HPA=1
E: ID_ATA_FEATURE_SET_HPA_ENABLED=1
E: ID_ATA_FEATURE_SET_PM=1
E: ID_ATA_FEATURE_SET_PM_ENABLED=1
E: ID_ATA_FEATURE_SET_SECURITY=1
E: ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=2
E: ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=2
E: ID_ATA_FEATURE_SET_SECURITY_FROZEN=1
E: ID_ATA_FEATURE_SET_SMART=1
E: ID_ATA_FEATURE_SET_SMART_ENABLED=1
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_ATA_SATA=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN1=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1
E: ID_ATA_WRITE_CACHE=1
E: ID_ATA_WRITE_CACHE_ENABLED=1
E: ID_BUS=ata
E: ID_FS_TYPE=vfat
E: ID_FS_USAGE=filesystem
E: ID_FS_UUID=9A29-BDC2
E: ID_FS_UUID_ENC=9A29-BDC2
E: ID_FS_VERSION=FAT32
E: ID_MODEL=LITEONIT_LCS-256M6S
E: ID_MODEL_ENC=LITEONIT\x20LCS-256M6S\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_PART_ENTRY_DISK=8:0
E: ID_PART_ENTRY_NAME=EFI\x20System\x20Partition
E: ID_PART_ENTRY_NUMBER=1
E: ID_PART_ENTRY_OFFSET=2048
E: ID_PART_ENTRY_SCHEME=gpt
E: ID_PART_ENTRY_SIZE=1048576
E: ID_PART_ENTRY_TYPE=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
E: ID_PART_ENTRY_UUID=5352c0a6-f610-48e5-9887-d63a6e227709
E: ID_PART_TABLE_TYPE=gpt
E: ID_PART_TABLE_UUID=0b97e339-7cbe-45e5-b86d-e145f77a3e1f
E: ID_PATH=pci-0000:00:1f.2-ata-1
E: ID_PATH_TAG=pci-0000_00_1f_2-ata-1
E: ID_REVISION=2C87901
E: ID_SERIAL=LITEONIT_LCS-256M6S_SD0E97902L1TH46107YF
E: ID_SERIAL_SHORT=SD0E97902L1TH46107YF
E: ID_TYPE=disk
E: MAJOR=8
E: MINOR=1
E: PARTN=1
E: PARTNAME=EFI System Partition
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: UDISKS_IGNORE=1
E: USEC_INITIALIZED=3107106
- この結果をもとに、
/etc/udev/rules.d/*.conf
の条件を記述できる
ENV{ID_VENDOR_ID}!="1e2d"
とか
- デバイスを再装着すると反映される
- デバイスの検知をモニタリング
udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent