Course contentsShow
← Linux
Lesson 651 of 1,8197. Storage Management and Logical VolumesFree lesson

Dynamic storage device naming

Use udev rules and persistent symlinks to ensure consistent mount points after hardware reboots.

In this lesson, you will learn how to ensure your storage devices maintain consistent mount points across reboots using udev rules and persistent symlinks.

The Problem with Traditional Names

In Linux, devices like /dev/sda or /dev/sdb are assigned dynamically at boot. If you add a new hard drive or change the port a cable is plugged into, your system might swap the device names. If your /etc/fstab file points to /dev/sdb1 for your data partition, a name swap could lead to a system that fails to boot or, worse, mounts the wrong disk to the wrong location.

Creating Persistent Symlinks with udev

udev is the Linux subsystem that manages device nodes in /dev. To make your device naming "dynamic" yet predictable, you can create custom udev rules. These rules instruct the kernel to identify your disk by its unique hardware attributes—such as its serial number—and create a persistent symbolic link to it.

  1. First, find your disk's unique identifier using lsblk -o NAME,SERIAL:
    lsblk -o NAME,SERIAL /dev/sdb
    
  2. Create a new rules file in /etc/udev/rules.d/99-my-storage.rules:
    SUBSYSTEM=="block", ATTRS{serial}=="S123456789", SYMLINK+="my_data_drive"
    

After reloading your rules with udevadm control --reload-rules, the system will automatically create a device node at /dev/my_data_drive whenever that specific hardware is detected.

Why This Matters

By using /dev/my_data_drive in your mount configurations instead of /dev/sdb1, you decouple your filesystem configuration from the volatile physical port the disk happens to be plugged into. Even if the hardware order changes, the symbolic link will always point to the correct device based on its unique identity. This creates a resilient storage environment where the infrastructure adapts to the hardware, rather than forcing you to update your mount points every time a drive is moved.

Key Takeaway: By creating persistent udev symlinks based on unique hardware attributes, you guarantee that your storage mount points remain consistent regardless of how the system reorders hardware ports during boot.