- How to Use Linux to Find the Names of the Devices on Your Computer
- Try these commands to show devices on your computer
- Use the ‘mount’ Command
- Use ‘lsblk’ to List Block Devices
- How to List PCI Devices
- List the USB Devices Attached to the Computer
- Summary
- Linux allocated devices (4.x+ version)В¶
- Additional /dev/ directory entriesВ¶
- Compulsory linksВ¶
- Recommended linksВ¶
- Locally defined linksВ¶
- Sockets and pipesВ¶
- Mount pointsВ¶
- Terminal devicesВ¶
- Virtual consoles and the console deviceВ¶
- Serial portsВ¶
- Pseudoterminals (PTYs)В¶
- Linux: How to find the device driver used for a device?
- 8 Answers 8
How to Use Linux to Find the Names of the Devices on Your Computer
Try these commands to show devices on your computer
Listing the devices, drives, PCI devices, and USB devices on your computer involves a series of commands easily invoked from a shell prompt in Linux.
Use the ‘mount’ Command
The most simple syntax you can use is as follows:
The output from the above command is fairly verbose and will be something like this:
Hard drives generally start with /dev/sda or /dev/sdb, so use the grep command to reduce the output as follows:
The results show something like this:
This doesn’t list your drives but it does list your mounted partitions. It doesn’t list partitions that aren’t yet mounted.
The device /dev/sda usually stands for the first hard drive on your system, and if you have a second hard drive, then it will be mounted to /dev/sdb. If you have an SSD, then this will likely be mapped to /dev/sda and the hard drive mapped to /dev/sdb.
Use ‘lsblk’ to List Block Devices
Mount is fine for listing mounted devices, but it doesn’t show every device you have, and the output is verbose, making it difficult to read.
The best way to list the drives in Linux is to use lsblk as follows:
The information displays in a tree format with the following information:
- Name
- Major Minor device number
- Is it removable
- Size
- Is it read-only
- Is it a disk or a partition
- Where is the partition mounted
The display looks something like this:
The information is easier to read. It displays one drive called sda, which offers 50 G of storage. It splits into one partition, called sda1.
The drives fd0 (floppy) and sr0 (CD-ROM) appear in this listing. The particular machine this listing drew from, called mint-vm, is a Linux Mint virtual machine running in the Hyper-V system on a Windows 10 computer. Hyper-V provisions a virtual floppy and CD-ROM drive by default.
How to List PCI Devices
To list the PCI devices use the lspci command as follows:
The output from the above command is verbose, meaning you probably get more information than you need.
Here’s a short snapshot as an example:
The listing lists devices, including VGA controllers, USB controllers, sound, Bluetooth, wireless, and Ethernet controllers.
The standard lspci listing is considered basic, and if you want more detailed information about each device, run the following command:
The information for each device looks something like this:
The output from the lspci -v command is more readable.
You can get even more verbose output by using the following command:
If that isn’t enough information, try the following:
The most useful aspect of lspci, other than listing devices, is the kernel driver used for that device. If the device isn’t working, it is worth researching whether there is a better driver available for the device.
List the USB Devices Attached to the Computer
To list the USB devices available for your computer, use the following command:
The output will be something like this:
If you insert a USB device into the computer, such as an external hard drive, and then run the lsusb command, the device appears on the list.
Summary
The best way to list anything in Linux is to remember the following ls commands:
Источник
Linux allocated devices (4.x+ version)В¶
This list is the Linux Device List, the official registry of allocated device numbers and /dev directory nodes for the Linux operating system.
This document is included by reference into the Filesystem Hierarchy Standard (FHS). The FHS is available from https://www.pathname.com/fhs/.
Allocations marked (68k/Amiga) apply to Linux/68k on the Amiga platform only. Allocations marked (68k/Atari) apply to Linux/68k on the Atari platform only.
This document is in the public domain. The authors requests, however, that semantically altered versions are not distributed without permission of the authors, assuming the authors can be contacted without an unreasonable effort.
DEVICE DRIVERS AUTHORS PLEASE READ THIS
Linux now has extensive support for dynamic allocation of device numbering and can use sysfs and udev ( systemd ) to handle the naming needs. There are still some exceptions in the serial and boot device area. Before asking for a device number make sure you actually need one.
To have a major number allocated, or a minor number in situations where that applies (e.g. busmice), please submit a patch and send to the authors as indicated above.
Keep the description of the device in the same format as this list. The reason for this is that it is the only way we have found to ensure we have all the requisite information to publish your device and avoid conflicts.
Finally, sometimes we have to play “namespace police.” Please don’t be offended. We often get submissions for /dev names that would be bound to cause conflicts down the road. We are trying to avoid getting in a situation where we would have to suffer an incompatible forward change. Therefore, please consult with us before you make your device names and numbers in any way public, at least to the point where it would be at all difficult to get them changed.
Your cooperation is appreciated.
Additional /dev/ directory entriesВ¶
This section details additional entries that should or may exist in the /dev directory. It is preferred that symbolic links use the same form (absolute or relative) as is indicated here. Links are classified as “hard” or “symbolic” depending on the preferred type of link; if possible, the indicated type of link should be used.
Compulsory linksВ¶
These links should exist on all systems:
stdin file descriptor
stdout file descriptor
stderr file descriptor
Required by iBCS-2
Required by iBCS-2
Recommended linksВ¶
It is recommended that these links exist on all systems:
Alternate SCSI CD-ROM name
Locally defined linksВ¶
The following links may be established locally to conform to the configuration of the system. This is merely a tabulation of existing practice, and does not constitute a recommendation. However, if they exist, they should have the following uses.
Current mouse device
Current tape device
Current CD-ROM device
Current CD-writer device
Current scanner device
Current dialout device
Current root filesystem
Current swap device
/dev/modem should not be used for a modem which supports dialin as well as dialout, as it tends to cause lock file problems. If it exists, /dev/modem should point to the appropriate primary TTY device (the use of the alternate callout devices is deprecated).
For SCSI devices, /dev/tape and /dev/cdrom should point to the cooked devices ( /dev/st* and /dev/sr* , respectively), whereas /dev/cdwriter and /dev/scanner should point to the appropriate generic SCSI devices (/dev/sg*).
/dev/mouse may point to a primary serial TTY device, a hardware mouse device, or a socket for a mouse driver program (e.g. /dev/gpmdata ).
Sockets and pipesВ¶
Non-transient sockets and named pipes may exist in /dev. Common entries are:
lpd local socket
syslog local socket
gpm mouse multiplexer
Mount pointsВ¶
The following names are reserved for mounting special filesystems under /dev. These special filesystems provide kernel interfaces that cannot be provided with standard device nodes.
PTY slave filesystem
POSIX shared memory maintenance access
Terminal devicesВ¶
Terminal, or TTY devices are a special class of character devices. A terminal device is any device that could act as a controlling terminal for a session; this includes virtual consoles, serial ports, and pseudoterminals (PTYs).
All terminal devices share a common set of capabilities known as line disciplines; these include the common terminal line discipline as well as SLIP and PPP modes.
All terminal devices are named similarly; this section explains the naming and use of the various types of TTYs. Note that the naming conventions include several historical warts; some of these are Linux-specific, some were inherited from other systems, and some reflect Linux outgrowing a borrowed convention.
A hash mark ( # ) in a device name is used here to indicate a decimal number without leading zeroes.
Virtual consoles and the console deviceВ¶
Virtual consoles are full-screen terminal displays on the system video monitor. Virtual consoles are named /dev/tty# , with numbering starting at /dev/tty1 ; /dev/tty0 is the current virtual console. /dev/tty0 is the device that should be used to access the system video card on those architectures for which the frame buffer devices ( /dev/fb* ) are not applicable. Do not use /dev/console for this purpose.
The console device, /dev/console , is the device to which system messages should be sent, and on which logins should be permitted in single-user mode. Starting with Linux 2.1.71, /dev/console is managed by the kernel; for previous versions it should be a symbolic link to either /dev/tty0 , a specific virtual console such as /dev/tty1 , or to a serial port primary ( tty* , not cu* ) device, depending on the configuration of the system.
Serial portsВ¶
Serial ports are RS-232 serial ports and any device which simulates one, either in hardware (such as internal modems) or in software (such as the ISDN driver.) Under Linux, each serial ports has two device names, the primary or callin device and the alternate or callout one. Each kind of device is indicated by a different letter. For any letter X, the names of the devices are /dev/ttyX# and /dev/cux# , respectively; for historical reasons, /dev/ttyS# and /dev/ttyC# correspond to /dev/cua# and /dev/cub# . In the future, it should be expected that multiple letters will be used; all letters will be upper case for the “tty” device (e.g. /dev/ttyDP# ) and lower case for the “cu” device (e.g. /dev/cudp# ).
The names /dev/ttyQ# and /dev/cuq# are reserved for local use.
The alternate devices provide for kernel-based exclusion and somewhat different defaults than the primary devices. Their main purpose is to allow the use of serial ports with programs with no inherent or broken support for serial ports. Their use is deprecated, and they may be removed from a future version of Linux.
Arbitration of serial ports is provided by the use of lock files with the names /var/lock/LCK..ttyX# . The contents of the lock file should be the PID of the locking process as an ASCII number.
It is common practice to install links such as /dev/modem which point to serial ports. In order to ensure proper locking in the presence of these links, it is recommended that software chase symlinks and lock all possible names; additionally, it is recommended that a lock file be installed with the corresponding alternate device. In order to avoid deadlocks, it is recommended that the locks are acquired in the following order, and released in the reverse:
The symbolic link name, if any ( /var/lock/LCK..modem )
The “tty” name ( /var/lock/LCK..ttyS2 )
The alternate device name ( /var/lock/LCK..cua2 )
In the case of nested symbolic links, the lock files should be installed in the order the symlinks are resolved.
Under no circumstances should an application hold a lock while waiting for another to be released. In addition, applications which attempt to create lock files for the corresponding alternate device names should take into account the possibility of being used on a non-serial port TTY, for which no alternate device would exist.
Pseudoterminals (PTYs)В¶
Pseudoterminals, or PTYs, are used to create login sessions or provide other capabilities requiring a TTY line discipline (including SLIP or PPP capability) to arbitrary data-generation processes. Each PTY has a master side, named /dev/pty[p-za-e][0-9a-f] , and a slave side, named /dev/tty[p-za-e][0-9a-f] . The kernel arbitrates the use of PTYs by allowing each master side to be opened only once.
Once the master side has been opened, the corresponding slave device can be used in the same manner as any TTY device. The master and slave devices are connected by the kernel, generating the equivalent of a bidirectional pipe with TTY capabilities.
Recent versions of the Linux kernels and GNU libc contain support for the System V/Unix98 naming scheme for PTYs, which assigns a common device, /dev/ptmx , to all the masters (opening it will automatically give you a previously unassigned PTY) and a subdirectory, /dev/pts , for the slaves; the slaves are named with decimal integers ( /dev/pts/# in our notation). This removes the problem of exhausting the namespace and enables the kernel to automatically create the device nodes for the slaves on demand using the “devpts” filesystem.
© Copyright The kernel development community.
Источник
Linux: How to find the device driver used for a device?
If my target has one device connected and many drivers for that device loaded, how can I understand what device is using which driver?
8 Answers 8
Example. I want to find the driver for my Ethernet card:
First I need to find coordinates of the device using lspci ; then I find driver that is used for the devices with these coordinates.
sudo lspci -v will show it. like this:
You can also combine it with grep like this:
For USB based devices you can see the driver name by using the lsusb command:
And/or you use lshw which enumerates the devices on all buses including USB, PCI, etc so you can see which driver it uses:
If you just want to plainly use sysfs and doesn’t want to deal with all these commands which eventually looks inside sysfs anyways, here’s how:
say, what is the module/driver for eth6? «sfc» it is
or better yet.. let readlink resolve the path for you.
so. to figure out what are the drivers for all of your network interfaces:
You can use the lsmod command to get the status of loaded modules / devices drivers in the Linux Kernel.
For a specific device, you can use dmesg |grep to get the details too.
Источник