In this lesson, you will learn how to troubleshoot and debug scenarios where udev rules fail to assign the consistent device names you expect for your storage hardware.
The Problem with Dynamic Naming
In Linux, device names like /dev/sdb or /dev/sdc are assigned dynamically based on the order in which the kernel detects your hardware. If you plug in a new drive or reboot after a hardware change, these letters can shuffle, causing your storage provisioning scripts or mount points to fail. While udev is designed to create persistent symlinks (like those found in /dev/disk/by-uuid/), these rules sometimes conflict or fail to trigger when hardware is hot-plugged or mapped via virtual storage device layers.
Debugging udev Resolution
When your custom udev rules aren't creating the symlinks you expect, the first step is to simulate the event to see exactly what udev "sees" when the device is detected. You can use the udevadm test command to trace the event processing for a specific device path:
# Replace /sys/block/sdb with your actual device path
udevadm test /sys/block/sdb
This command prints a verbose log of every rule file being parsed. Look for lines that mention IMPORT or SYMLINK. If a rule isn't matching, it is usually because the environment variables (like ID_SERIAL or ID_WWN) are missing or differ from what your rule expects.
Identifying Inconsistencies
Often, the issue isn't the rule itself, but the timing of when the device properties become available. If your rule depends on a property that the kernel hasn't finished probing, the rule will skip. Check the current attributes of your device with:
udevadm info --query=all --name=/dev/sdb
Compare the output of this command against your rule's conditions. If your rule uses ATTR{model}, but the attribute is empty during the initial probe, the rule will fail. Ensure your rules are specific enough to distinguish between similar hardware, but broad enough to account for the actual attributes reported by your specific bus interface (like NVMe vs. SATA).
Key Takeaway: Use udevadm test to inspect the property environment of your storage devices, ensuring your persistent naming rules match the actual attributes reported by the kernel during the hardware detection phase.