
udevinfo Command in Linux
Linux has long been known for its robust handling of hardware devices. In early Unix systems, device files (like those in /dev) were static and manually maintained. As hardware grew more dynamic and systems began to support hot-plugging and multiple driver types, a need arose for a system that could automatically detect hardware changes and update the device tree on the fly.
Enter udev, a subsystem in Linux that listens for kernel-emitted device events (often called "uevents") and dynamically creates device nodes, sets permissions, and even assigns user-friendly symlinks as required. As part of this subsystem, there was a tool known as udevinfo (and later evolved to udevadm info).
The purpose of udevinfo was to query the udev database for a given device's details, allowing system administrators, developers, and hobbyists to understand how the Linux kernel and udev recognized the underlying hardware.
Table of Contents
Here is a comprehensive guide to the options available with the udevinfo command −
- How to Use udevinfo Command in Linux?
- Basic Syntax and Modes of Operation
- Detailed Explanation of udevinfo Options
- Examples of udevinfo Command in Linux
How to Use udevinfo Command in Linux?
At its core, udevinfo is used to query device information from the udev database. This tool allows you to see −
- The device node name.
- Any symlinks associated with that device.
- The sysfs path that represents the device.
- A full list of environment variables (such as ID_MODEL, ID_VENDOR, etc.).
- The entire chain of device attributes (from the device itself to all parent devices).
Basic Syntax and Modes of Operation
The general syntax of udevinfo is similar to other Unix-like query tools. It can be invoked with various options that tailor the output to your needs.
A typical command-line structure might look like −
udevinfo [OPTIONS]
Often you supply either a device node name or a sysfs path to identify the device in question. The two primary ways to query a device are −
Query by device node name −
udevinfo --name=/dev/sda
Query by sysfs path −
udevinfo --path=/sys/class/block/sda
In addition, you can specify which type of information you want returnedâsuch as the device name, symlink, or full set of environment variablesâby using the query option.
Detailed Explanation of udevinfo Options
Letâs now deconstruct the command-line options. Each one is essential in tailoring your query to return the desired information.
The -q or --query Option
The -q (or --query) option tells udevinfo what kind of information you would like to query from the udev database. You must use this option in conjunction with one of the device-identifying options (-n or -p). Valid query types include −
Example − To see all the device information for /dev/sda, you can use −
udevinfo --query=all --name=/dev/sda
Explanation − This command tells udevinfo to query the udev database for all types of information available for the device node /dev/sda. The output will include the device node name, the sysfs path, any symlinks, and the full set of environment variables.
The -r Option (udev root)
The -r option allows you to specify the udev root directory. In many contexts, the udev root is /dev, but this option can be useful if you are working in an environment where devices are managed in a different subtree or if you want to convert a relative reference into an absolute one.
Example − Querying a device by name while also considering the udev root −
udevinfo --query=all --name=/dev/sda -r
Explanation − In this instance, -r tells udevinfo to return the absolute path according to the udev root (which is typically /dev). This can be useful for confirming that the device node is correctly resolved.
Examples of udevinfo Command in Linux
Let's review several practical examples aimed at illustrating real-world usage.
Retrieving Complete Device Information
Suppose you want all the details about a storage device represented by /dev/sda. Here's the command:
udevinfo --query=all --name=/dev/sda
Explanation − This output gives you a complete overview of /dev/sda. The P: line shows the physical path in sysfs, the N: line shows the node name, and the S: lines designate symbolic links. The E: lines are the environment variables that have been exported for the device. If you're writing a udev rule, you might use any of these properties to match a specific disk.
Querying by Sysfs Path
Sometimes you'd rather specify the device using its sysfs path, which comes in handy when the device node is ambiguous or when scripting guided by sysfs. Here's the command −
udevinfo --query=all --path=/sys/class/block/sda
Explanation − This alternative approach is particularly useful in scripts that iterate over devices available in /sys/class or when device nodes in /dev might be symlinked or renamed dynamically. It ensures you are looking at the source information as provided by the kernel.
Using Attribute-Walk for Detailed Debugging
When writing custom udev rules, it is not enough to know just the device's attributes; sometimes you need to see the entire hierarchy of parent devices to pick the best identifier. Here's the command −
udevinfo --attribute-walk --name=/dev/sda
Explanation − This output is immensely useful when you need to write a udev rule that matches on a parent attribute. Perhaps the disk itself does not carry a unique identifier, but its parent SCSI device does. With the attribute-walk, you can see the entire chain and decide which attributes to match on.
Exporting the Entire udev Database
At times, you might want to see everything that udev knows about every device, perhaps for troubleshooting or for a system audit. Here's the command −
udevinfo --export
Let's see what this command does –
- Full Export − This command dumps the entire udev database to your terminal, which might include hundreds (or thousands) of lines if the system has many devices.
- Usage − Due to the volume of data, it's often combined with output redirection to log files.
udevinfo --export > /tmp/udev_database_dump.txt
Explanation − This method is best used for detailed audits or when you expect that some devices might have misconfigured attributes. A full export allows you to search through the entire device tree for anomalies.
Querying Environment Variables Only
When you're specifically interested in the environment variables that udev has set for a device, you can narrow down your query. Here's the command −
udevinfo --query=env --name=/dev/sda
Let's see what this command does −
- Environment Variables − The command filters out everything except the environment variables.
- Output − You'll see lines beginning with E: which list key-value pairs. This can include properties such as the device model, vendor, serial number, and other identifiers that are useful for rule matching.
Conclusion
For system administrators, developers, or curious learners, udevinfo (and by extension, udevadm info) offers a transparent view into how Linux abstracts physical hardware into manageable software objects.
Whether you're fine-tuning device configurations, writing robust udev rules to automate hardware management, or simply learning more about how your Linux system interacts with the world of physical devices, a deep dive into this tool provides both immediate practical benefits and long-term insight into one of the core aspects of Linux.