Many of the Linux beginners coming from Windows know how to manage devices on their Windows systems. But they do not know how to do the same on Linux unfortunately. This is not because Linux is different, rather they are new and unaware of where to find the right help. Here I am going to help you how to detect and manage devices in your Linux system. I will be using Ubuntu 20.04 distribution. All commands are valid for related distribution which uses the apt package manager.
What is Udev?
We use Udev as our device manager for the Linux kernel. It helps with creating and removing device nodes in the /dev directory. It is Udev that enables the plugging of USB devices and network disks. It helps a system admin to manage devices connected to a Linux system.
We apply rules in /etc/udev/rules.d/ directory, and Udev processes the changes once a device is connected.
I will use the udevadm tool to interact with the Udev device manager. Let’s do it.
How to detect a disk?
Using the following command you will be able to see a lot of data regarding a particular device. Usually, disks start with /dev/sda or /dev/sdb so we will also use the same format to detect our disk too.
$ udevadm info /dev/sda2
You’ll see an output like below:
This gives us a lot of information. You can see that it shows us each and every bit of the information available related to our disk. In the last lines of the terminal, if you take notice then you will find that it shows a disk running under VBOX. It also shows the related UUID of the disk.
Using Udev, you can also change the name of your disk, USB devices, and network cards.
For instance: If you go to the rules list, you will find out that there are a number of devices available to update their names.
Here is a demo of the rules list file. Type the following command and check your rules file.
$ cd /etc/udev/rules.d/
I am using a nano text editor on my Ubuntu server, therefore I will use the following command to open up the rules file.
It is important to remember that Udevadm info starts with the device specified by the devpath and then takes us to the chain of parent devices.
The file shows each and every device available. It can be disabled, removed, and renamed.
Why rename a device?
When it comes to team management, it is better to rename a device. This helps your team members to figure out which devices are connected to which system in an array of connected Linux machines.
This was all for now. In this tutorial, we discussed different aspects of the Udev program to see how we can manipulate our hardware in the best way possible. In future guides, We will help you with how to make complex changes to your hardware. We also ran operations using simple commands to find out all connected hardware with your system.