Linux usb devices dev

USB device detection on /dev directory on Linux

Using the lsusb command in Linux I have come to know about bus and device numbers, along with its name of newly attached USB devices. But how can I know on which device directory (/dev/*) USB device get attached in Linux using command lines only?

I tried dmesg | tail, It is showing only USB details like VID,PID,product name, manufacturer name etc. I can’t know ?, where udev (device manager) is attaching device under /dev/

2 Answers 2

It isn’t a rule that every device has to show up directly under /dev/, but some device classes will be nested under sub-directories inside /dev/.

USB device drivers are a bit different. If you connect a valid USB device, USB HCI would read the VID:PID and will tell the usb-core that the device with VID:PID combination is connected.

If the usbcore detects any registered driver for the VID:PID combination, it will couple it with the device, and the device file creation would happen accordingly

The device will show in /dev/bus/usb/. even if, the corresponding driver is not present, to indicate that the device was detected.

You need to have the device driver to have the device in action/operation.

You can verify whether a device driver is coupled to the device through

Each detected USB device will have an entry here, and also shows the «Driver=» field, to show which driver is associated with your device.

Now, IFF there is a driver, that makes an entry in appropriate /dev tree, you will find the device there.

NOT every device will show up directly under /dev/ in the first level. say, your mouse/keyboard will not show-up directly under /dev, but inside /dev/input/

Likewise, IF the connected USB device is a char/block device, it MAY show up there, that too have exceptions.

If your device is and ethernet/wifi device, the interface device will NOT show up under /dev/, cross-check with your existing eth0, wlan0, they will not appear directly under /dev/, but will in /proc/net/devices

sda/b/c shows up under /dev directly, because they are block devices and are managed by udev, as such.

Источник

4 Useful Way to Know Plugged USB Device Name in Linux

As a newbie, one of the many things you should master in Linux is identification of devices attached to your system. It may be your computer’s hard disk, an external hard drive or removable media such USB drive or SD Memory card.

Читайте также:  Microsoft office 2021 linux

Using USB drives for file transfer is so common today, and for those (new Linux users) who prefer to use the command line, learning the different ways to identify a USB device name is very important, when you need to format it.

Once you attach a device to your system such as a USB, especially on a desktop, it is automatically mounted to a given directory, normally under /media/username/device-label and you can then access the files in it from that directory. However, this is not the case with a server where you have to manually mount a device and specify its mount point.

Linux identifies devices using special device files stored in /dev directory. Some of the files you will find in this directory include /dev/sda or /dev/hda which represents your first master drive, each partition will be represented by a number such as /dev/sda1 or /dev/hda1 for the first partition and so on.

List All Linux Device Names

Now let’s find out device names using some different command-line tools as shown:

Find Out Plugged USB Device Name Using df Command

To view each device attached to your system as well as its mount point, you can use the df command (checks Linux disk space utilization) as shown in the image below:

Find USB Device Name Using df Command

Use lsblk Command to Find USB Device Name

You can also use the lsblk command (list block devices) which lists all block devices attached to your system like so:

List Linux Block Devices

Identify USB Device Name with fdisk Utility

fdisk is a powerful utility which prints out the partition table on all your block devices, a USB drive inclusive, you can run it will root privileges as follows:

List Partition Table of Block Devices

Determine USB Device Name with dmesg Command

dmesg is an important command that prints or controls the kernel ring buffer, a data structure which stores information about the kernel’s operations.

Run the command below to view kernel operation messages which will as well print information about your USB device:

dmesg - Prints USB Device Name

That is all for now, in this article, we have covered different approaches of how to find out a USB device name from the command line. You can also share with us any other methods for the same purpose or perhaps offer us your thoughts about the article via the response section below.

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

Funny Linux Commands

18 thoughts on “4 Useful Way to Know Plugged USB Device Name in Linux”

I still have no idea how to make sure by winchester external drive is the right one. I thought I had it and then formatted my main computer drive by mistake. That was a problem. Reply

@Jim You can always identify drives or partitions by their file system type, size as well mount points, however, taking some time to understand naming of storage media under /dev virtual file system will help you avoid such mistakes in the future. Reply

Читайте также:  Linux команды сетевого окружения

What I need is a name like /dev/somename for a device that is NOT a mass storage device. No luck yet. I did try lsusb, ls /dev/*, df -h, lsblk, sudo fdisk -l. These are all for mass storage devices like memory sticks, camera card readers or external HD Then I tried also usb-devices which lists other devices too, like mouse, printer etc, But it gives some bus number and some device number, no /dev name The reason is that I tried to install the “Samsung unified linux driver” which asks me for the device name of my printer. Unfortunately the names it proposes are crap since they do not exist on my machine ! They propose /dev/mft4 up to /dev/mft11. None of these do exist…
I let it do with /dev/mft4 with a bad presentiment. So finally the installation software affirmed that the driver has been successfully installed and when I click on “testprint” it says that the device can not be found. Of course… Still no solution in sight ! Reply

@Daniel Try to contact the developers of Samsung unified linux driver for any assistance. However, once we find a solution, we will share it with you. Reply

Some of us use external USB-connected drives as system-wide storage. I, for one, would like to mount those file systems elsewhere than /media/. Also, I’d like to use a standard name for some “media” drives instead of a changing label or UUID identifier. For example, the flash storage from my digital camera, I’d like to mount as “…/camera” regardless of the label/UUID. Consider an article that explains how to accomplish that. Reply

What about USB devices that are not for data storage? Cameras, humidity sensors, A-D converters, all kinds of tools for monitoring the physical world. Reply

@Joe Very good question, as of now, we can not tell how that can be done, since we have not dealt with the devices you are talking about. However, we will definitely look for more information concerning this question and find relevant ways or command line tools for listing or identifying such(Cameras, humidity sensors, A-D converters, all kinds of tools for monitoring the physical world) USB devices. Thanks for getting in touch. Reply

Источник

Как посмотреть USB устройства Linux

При подключении USB флешки или любого другого USB устройства к компьютеру создается набор файлов, с помощью которых вы можете получить к ним доступ. Когда вы работаете в файловом менеджере все достаточно просто, но как только дело доходит до консоли все становится намного труднее.

Каждому новичку важно уметь идентифицировать подключенные устройства, будь то usb флешки, SD карты или жесткие диски чтобы не записать что-либо не туда или не отформатировать не тот диск. В этой статье мы рассмотрим несколько способов как посмотреть usb устройства Linux, подключенные к компьютеру.

Читайте также:  1с предприятие alt linux

Список подключенных устройств Linux

В операционной системе Linux используется особенная философия управления. Все объекты, в том числе и устройства считаются файлами. При подключении какого-либо устройства к системе для него создается файл в каталоге /dev/.

Обычно, после того, как вы подключили любую USB флешку или другой накопитель к системе с установленным окружением рабочего стола, устройство автоматически монтируется в папку /media/имя_пользователя/метка_устройства/, а затем вы можете получить доступ к файлам из устройства в этой папке. Тем не менее, бывают ситуации, когда вам нужно вручную монтировать USB и тогда такой вариант не поможет.

Файлы всех устройств находятся в каталоге /dev/. Здесь вы можете найти файлы sda, hda, которые представляют из себя жесткий диск, а также файлы sda1 или hda1, которые позволяют получить доступ к разделам диска. Мы уже подробно рассматривали это все в статье работа с устройствами Linux. Вы можете посмотреть список всех устройств в каталоге /dev/ с помощью команды:

usb0

Теперь осталось понять какие из этих файлов устройств принадлежат USB устройствам и каким устройствам именно.

Как посмотреть USB устройства Linux

Чтобы узнать более подробную информацию о каждом устройстве, подключенном к вашей системе и посмотреть список устройств linux, можно использовать команду df. Она используется для просмотра свободного места на диске:

usb

По общему размеру и занятому пространству вы можете определить какое из устройств является вашей флешкой, но этот способ посмотреть устройства linux не очень удобен и работает он только с уже смонтированной флешкой, есть еще несколько, дающих более точную информацию.

Команда lsblk отображает список всех блочных устройств, подключенных к вашему компьютеру. Утилита отображает не только их размер, но и тип (диск/раздел) а также старший и младший номер устройства. Тут уже немного проще найти флешку, мы видим два диска, и если первый с размером 698 гигабайт это жесткий диск, то второй, — точно флешка:

usb1

Есть еще один способ, это утилита fdisk. Она позволяет посмотреть таблицу разделов на всех блочных устройствах, подключенных к компьютеру. Но утилиту нужно выполнять от имени суперпользователя:

usb2

Также, узнать о подключенном USB устройстве можно посмотрев очередь сообщений ядра dmesg. Здесь хранится информация обо всех операциях, которые происходят в ядре. В том числе здесь будет отображено имя флешки, только что подключенной к компьютеру. Для просмотра сообщений ядра выполните:

usb3

Чтобы посмотреть какие из sd устройств относятся к USB используйте такую команду:

usb4

Попытаться идентифицировать свою флешку в системе через терминал можно с помощью утилиты blkid. Она выводит UUID идентификаторы всех подключенных устройств, а также файловую систему:

usb6

Выводы

В этой статье мы рассмотрели как посмотреть usb устройства linux, а также как узнать имя своей usb флешки в системе. Вы можете использовать любую из команд, которая вам понравилась, или же сразу несколько. Но теперь вы знаете как точно определить имя файла своей флешки.

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

Оцените статью
Adblock
detector