All files in /dev
are special files... they represent devices of the computer. They were created with the mknod
syscall. My question is: How can I know the minor and major numbers that were used to create this special file?
/ dev中的所有文件都是特殊文件......它们代表计算机的设备。它们是使用mknod系统调用创建的。我的问题是:我如何知道用于创建此特殊文件的次要和主要数字?
5 个解决方案
#1
26
The list is called the LANANA Linux Device List, and it is administered by Alan Cox.
该列表称为LANANA Linux设备列表,由Alan Cox管理。
You can find the latest copy online (direct link), or in the Linux source. Its filename in the kernel tree is Documentation/devices.txt
.
您可以在线(直接链接)或在Linux源中找到最新的副本。它在内核树中的文件名是Documentation / devices.txt。
To see the major and minor numbers that created a node in /dev
(or any device node for that matter), simply use ls
with the -l
option:
要查看在/ dev(或任何设备节点)中创建节点的主要和次要编号,只需使用带-l选项的ls:
22:26 jsmith@undertow% ls -l /dev/xvd?
brw-rw---- 1 root disk 202, 0 Nov 1 20:31 /dev/xvda
brw-rw---- 1 root disk 202, 16 Nov 1 20:31 /dev/xvdb
brw-rw---- 1 root disk 202, 32 Nov 1 20:31 /dev/xvdc
In this example, 202
is the three devices' major number, and 0
, 16
, and 32
are minors. The b
at left indicates that the node is a block device. The alternative is c
, a character device:
在这个例子中,202是三个设备的主要号码,0,16和32是未成年人。左边的b表示节点是块设备。替代方案是c,一个字符设备:
crw-rw-rw- 1 root tty 5, 0 Nov 22 00:29 /dev/tty
#2
8
$ ls -l /dev/fd0 /dev/null brw-rw---- 1 root floppy 2, 0 Nov 22 19:48 /dev/fd0 crw-rw-rw- 1 root root 1, 3 Nov 22 19:48 /dev/null $ stat -c '%n: %F, major %t minor %T' /dev/fd0 /dev/null /dev/fd0: block special file, major 2 minor 0 /dev/null: character special file, major 1 minor 3
Most device numbers are fixed (i.e. /dev/null
will always be character device 1:3
) but on Linux, some are dynamically allocated.
大多数设备号是固定的(即/ dev / null将始终是字符设备1:3),但在Linux上,一些是动态分配的。
$ cat /proc/devices Character devices: ... 10 misc ... Block devices: ... 253 mdp 254 device-mapper $ cat /proc/misc ... 57 device-mapper ...
For example, on this system, it just so happens that /dev/mapper/control
will be c:10:57
while the rest of /dev/mapper/*
will be b:254:*
, and this could differ from one boot cycle to another -- or even as modules are loaded/unloaded and devices are added/removed.
例如,在这个系统上,恰好/ dev / mapper / control将是c:10:57,而/ dev / mapper / *的其余部分将是b:254:*,这可能与一次启动不同循环到另一个 - 或者甚至在加载/卸载模块并添加/移除设备时。
You can explore these device registrations further in /sys
.
您可以在/ sys中进一步探索这些设备注册。
$ readlink /sys/dev/block/2:0 ../../devices/platform/floppy.0/block/fd0 $ cat /sys/devices/platform/floppy.0/block/fd0/dev 2:0 $ readlink /sys/dev/char/1:3 ../../devices/virtual/mem/null $ cat /sys/devices/virtual/mem/null/dev 1:3
#3
3
You can also use stat.
你也可以使用stat。
$ stat -c 'major: %t minor: %T' <file>
#4
1
Especially for block devices:
特别是对于块设备:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 90G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
├─sda2 8:2 0 4G 0 part /
#5
1
Alternative that doesn't depend on stat
:
替代不依赖于stat:
$ cat /sys/class/*/random/dev
1:8
#1
26
The list is called the LANANA Linux Device List, and it is administered by Alan Cox.
该列表称为LANANA Linux设备列表,由Alan Cox管理。
You can find the latest copy online (direct link), or in the Linux source. Its filename in the kernel tree is Documentation/devices.txt
.
您可以在线(直接链接)或在Linux源中找到最新的副本。它在内核树中的文件名是Documentation / devices.txt。
To see the major and minor numbers that created a node in /dev
(or any device node for that matter), simply use ls
with the -l
option:
要查看在/ dev(或任何设备节点)中创建节点的主要和次要编号,只需使用带-l选项的ls:
22:26 jsmith@undertow% ls -l /dev/xvd?
brw-rw---- 1 root disk 202, 0 Nov 1 20:31 /dev/xvda
brw-rw---- 1 root disk 202, 16 Nov 1 20:31 /dev/xvdb
brw-rw---- 1 root disk 202, 32 Nov 1 20:31 /dev/xvdc
In this example, 202
is the three devices' major number, and 0
, 16
, and 32
are minors. The b
at left indicates that the node is a block device. The alternative is c
, a character device:
在这个例子中,202是三个设备的主要号码,0,16和32是未成年人。左边的b表示节点是块设备。替代方案是c,一个字符设备:
crw-rw-rw- 1 root tty 5, 0 Nov 22 00:29 /dev/tty
#2
8
$ ls -l /dev/fd0 /dev/null brw-rw---- 1 root floppy 2, 0 Nov 22 19:48 /dev/fd0 crw-rw-rw- 1 root root 1, 3 Nov 22 19:48 /dev/null $ stat -c '%n: %F, major %t minor %T' /dev/fd0 /dev/null /dev/fd0: block special file, major 2 minor 0 /dev/null: character special file, major 1 minor 3
Most device numbers are fixed (i.e. /dev/null
will always be character device 1:3
) but on Linux, some are dynamically allocated.
大多数设备号是固定的(即/ dev / null将始终是字符设备1:3),但在Linux上,一些是动态分配的。
$ cat /proc/devices Character devices: ... 10 misc ... Block devices: ... 253 mdp 254 device-mapper $ cat /proc/misc ... 57 device-mapper ...
For example, on this system, it just so happens that /dev/mapper/control
will be c:10:57
while the rest of /dev/mapper/*
will be b:254:*
, and this could differ from one boot cycle to another -- or even as modules are loaded/unloaded and devices are added/removed.
例如,在这个系统上,恰好/ dev / mapper / control将是c:10:57,而/ dev / mapper / *的其余部分将是b:254:*,这可能与一次启动不同循环到另一个 - 或者甚至在加载/卸载模块并添加/移除设备时。
You can explore these device registrations further in /sys
.
您可以在/ sys中进一步探索这些设备注册。
$ readlink /sys/dev/block/2:0 ../../devices/platform/floppy.0/block/fd0 $ cat /sys/devices/platform/floppy.0/block/fd0/dev 2:0 $ readlink /sys/dev/char/1:3 ../../devices/virtual/mem/null $ cat /sys/devices/virtual/mem/null/dev 1:3
#3
3
You can also use stat.
你也可以使用stat。
$ stat -c 'major: %t minor: %T' <file>
#4
1
Especially for block devices:
特别是对于块设备:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 90G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
├─sda2 8:2 0 4G 0 part /
#5
1
Alternative that doesn't depend on stat
:
替代不依赖于stat:
$ cat /sys/class/*/random/dev
1:8