Detecting devices in linux

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.

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.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

Читайте также:  New tablet with windows 10

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Detect and mount USB devices in Linux from console

Mount pendrives with commands in the Linux terminal

Overview

This is a small guide to detect a newly attached device to an USB port and mount it in Linux.

We will explore different strategies that will help when some of the tools isn’t available.

First of all, some definitions:

Understanding

What does exactly mount means?

All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount(8) command will detach it again. The filesystem is used to control how data is stored on the device or provided in a virtual way by network or another services.

To attach these new devices filesystems we use the mount command in the form: mount -t type device dir .

In the above command, Devices (block special devices 1 ) can be indicated in one of the following three ways:

  1. Filename
    • using the filename that is associated with the device.
    • e.g.: /dev/sdb2
  2. Filesystem label
    • Using the label associated with the device.
    • e.g.: PENDRIVE
  3. UUID
    • Universally Unique IDentifier (UUID) Uniform Resource Namespace 2 .
    • e.g.: ba108o135-80bf-1cci-b2za-082eafd02y0g

Listing

To list the currently mounted devices/filesystems, findmnt (find a filesystem).

For example, in Ubuntu 18.10 it shows:

There is also the old way, maintained for compatibility only but widely used: mount -l or just mount .

Now we have just connected a pendrive (flash drive), how do we know which label or UUID it has to be able to mount the filesystem?

1. Identify the newly attached device

After we plug a pendrive, we need a method to locate the new device so we can get its label or UUID .

The following list shows the available alternatives to do it, any of them would be help you find the device information, listing most complete and easier to use first.

1.1 Using blk commands

The command lsblk prints all block devices (except RAM disks) in a tree-like format by default.

We can have a look at it to try to spot the new device with the filesystem parameter: —fs to print info of each filesystem, LABELs and UUID s on available block devices.

To directly find out the connected pendrive, save the above listing in a temporal folder and then look for the differences with the same command after plugging the pendrive:

1.2 Inspect Kernel ring buffer

Immediately after plugging the device, we can examine the kernel ring buffer with the command dmesg

There we can look for the string of type sda , or sdb , etc, that will belong to the most recent connected device.

In this case we can spot the sda: sda1 sda2 line that indicates it has two partitions: sda1 and sda2 .

Then we use the command blkid -p device to find out its UUID , label and more properties.

1.3 dev-by- directories

And a similar approach can be done to know which one was plugged in, saving the list before and after plugging the device:

2. Mount the device

Which method should we use?

Device names depend on which (physical) slot you connect the device, and if there are other devices already attached or not, so the filename to refer to them may change over time.

Labels are more stable than filenames, but they may change or have the same name as other label.

We will mount it at /media/usb-stick .

Читайте также:  What is windows search index

For this, create the directory: sudo mkdir /media/usb-stick

And then mount it with one of these methods, preferably UUID :

3. Make it permanent

There is a special file /etc/fstab , in which each line describes:

  • what devices are usually mounted,
  • where,
  • using which options.

After reboot each line will be mounted automatically if the device is connected.

As we are working mostly with pendrives, we should use the special option: nofail. This avoids reporting any errors for the device if it does not exist at booting time when it tries to mount them and probably the device won’t be plugged..

3.1 Mount a pendrive just by specifying a directory

Personally, I like to have each pendrive or device identified like /media/kingstone-2gb so I can easily mount it with the directory name after plugging it.

4. Remove pendrive

sudo umount /media/usb-stick

Optional

Set pendrive label

To set create or rename the label of a pendrive there are several programs:

  • e2label — Change the label on an ext2/ext3/ext4 filesystem
  • tune2fs — adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems
  • mke2fs — create an ext2/ext3/ext4 filesystem

To set a pendrive label as usb-stick

Or create filesystem:

And change the label

Summary

Summarizing the commands used above in a single list:

Resources

block special file: A block special file is normally distinguished from a character special file by providing access to the device in a manner such that the hardware characteristics of the device are not visible. http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_79 ↩︎

A Universally Unique IDentifier (UUID) URN Namespace https://tools.ietf.org/html/rfc4122 ↩︎

Marcelo Canina

Articles

  • Adding a swap memory to Linux from command line in 6 steps April 2, 2020
  • Free up space in Linux (Ubuntu) March 27, 2020
  • Switch between languages in Linux with xkb. Write in multiple languages with same keyboard. March 21, 2020
  • How to make Ubuntu display emojis February 12, 2020
  • Detect and mount USB devices in Linux from console
  • How to make screencasts in Ubuntu Linux January 21, 2019
  • Using i3 window manager in Linux January 7, 2019
  • Setting Up A Fresh Linux Server August 25, 2018
  • How To Download A Website With Wget The Right Way June 30, 2017
  • Replicate Installed Package Selections From One Ubuntu System To Another April 24, 2017
  • Using Clamav Antivirus In Ubuntu January 25, 2017
  • How to Type Spanish Characters, Accents and Symbols in Linux June 6, 2016

Subcategories

Ubuntu
  • How to activate tap to click touchpad’s feature in Ubuntu in 4 steps March 4, 2021
  • Difference between suspend and hibernate in Ubuntu and how to execute them from command line April 12, 2020
  • Solving Google Chrome’s gpu-process error message in Ubuntu Linux January 7, 2019
  • Solving Google Chrome’s secret service operation error message in Ubuntu Linux January 7, 2019
  • Start Emacs In Ubuntu The Right Way June 10, 2017
  • Unix Shell
    • Connect to a Bluetooth device from command line in Ubuntu Linux June 23, 2020
    • Add Infolinks Script To An Existing Website From Console With Sed Command April 4, 2017
    • How to change all files permissions to 644 and directories to 755 January 10, 2017
    • Shell Redirect Output And Errors To The Null Device In Bash December 9, 2016
    • Prevent Running Of Duplicate Cron Jobs December 8, 2016
    • Delete All Backup Files Recursively In Bash November 28, 2016
    • Bash Script to Find Out If MySQL Is Running Or Not November 9, 2016
  • A comprehensive guide to manually mount a USB pendrive in Linux.

    Источник

    16 Commands to Check Hardware Information on Linux

    Hardware information

    Like for every thing, there are plenty of commands to check information about the hardware of your linux system.

    Some commands report only specific hardware components like cpu or memory while the rest cover multiple hardware units.

    This post takes a quick look at some of the most commonly used commands to check information and configuration details about various hardware peripherals and devices.

    The list includes lscpu, hwinfo, lshw, dmidecode, lspci etc.

    1. lscpu

    The lscpu command reports information about the cpu and processing units. It does not have any further options or functionality.

    Читайте также:  Windows 10 сменить картинку при входе

    2. lshw — List Hardware

    A general purpose utility, that reports detailed and brief information about multiple different hardware units such as cpu, memory, disk, usb controllers, network adapters etc. Lshw extracts the information from different /proc files.

    Check out the following post to learn more about lshw

    3. hwinfo — Hardware Information

    Hwinfo is another general purpose hardware probing utility that can report detailed and brief information about multiple different hardware components, and more than what lshw can report.

    4. lspci — List PCI

    The lspci command lists out all the pci buses and details about the devices connected to them.
    The vga adapter, graphics card, network adapter, usb ports, sata controllers, etc all fall under this category.

    Filter out specific device information with grep.

    5. lsscsi — List scsi devices

    Lists out the scsi/sata devices like hard drives and optical drives.

    6. lsusb — List usb buses and device details

    This command shows the USB controllers and details about devices connected to them. By default brief information is printed. Use the verbose option «-v» to print detailed information about each usb port

    On the above system, 1 usb port is being used by the mouse.

    7. Inxi

    Inxi is a 10K line mega bash script that fetches hardware details from multiple different sources and commands on the system, and generates a beautiful looking report that non technical users can read easily.

    8. lsblk — List block devices

    List out information all block devices, which are the hard drive partitions and other storage devices like optical drives and flash drives

    9. df — disk space of file systems

    Reports various partitions, their mount points and the used and available space on each.

    10. Pydf — Python df

    An improved df version written in python, that displays colored output that looks better than df

    11. fdisk

    Fdisk is a utility to modify partitions on hard drives, and can be used to list out the partition information as well.

    12. mount

    The mount is used to mount/unmount and view mounted file systems.

    Again, use grep to filter out only those file systems that you want to see

    13. free — Check RAM

    Check the amount of used, free and total amount of RAM on system with the free command.

    14. dmidecode

    The dmidecode command is different from all other commands. It extracts hardware information by reading data from the SMBOIS data structures (also called DMI tables).

    Check out the man page for more details.

    15. /proc files

    Many of the virtual files in the /proc directory contain information about hardware and configurations. Here are some of them

    16. hdparm

    The hdparm command gets information about sata devices like hard disks.

    Summary

    Each of the command has a slightly different method of extracting information, and you may need to try more than one of them, while looking for specific hardware details. However they are available across most linux distros, and can be easily installed from the default repositories.

    On the desktop there are gui tools, for those who do not want to memorise and type commands. Hardinfo, I-nex are some of the popular ones that provide detailed information about multiple different hardware components.

    A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

    48 thoughts on “ 16 Commands to Check Hardware Information on Linux ”

    How i can check memory in CPU. Example OPT, Efuse

    Thanks for this. I’m just getting going on a VPS and this helped me discover they’d not given me the extra 1Gb I ordered. Very well explained.

    Super happy with
    inxi -Fx

    more accurate than some of the other utilities.. for instance hwinfo was inaccurate for my Lenovo

    Thanks for the great post!

    Thank you! Your descriptions were useful and well explained!

    Источник

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