Join WhatsApp
Join Now
Join Telegram
Join Now

Persistent udev Rules: Ensure Stable Device Names for Servers and NAS

Avatar for Noman Mohammad

By Noman Mohammad

Published on:

Your rating ?

Why Your Server Keeps Losing Its Mind (and How to Stop It)

Picture this: it’s 3 AM. Your phone buzzes. The monitoring system screams that your NAS is down. You reboot the machine. Everything comes back up… except your storage. Why? Because that trusty /dev/sdb you’ve been mounting for months is now /dev/sdc. Linux got confused. Your server followed suit.

That story isn’t rare. It happens to a friend of mine—let’s call him Dave—every time he plugs in a new thumb drive. His five-disk RAID always shows up in a different order after a reboot. One Friday night the names shifted, the RAID refused to assemble, and the backup job trashed itself trying to write to thin air. We spent 8 hours piecing it back together. Eight hours that could have been avoided with a single udev rule.

The Problem in Plain English

Linux hands out device names as it finds hardware. First disk? /dev/sda. Second? /dev/sdb. Plug in a USB stick before boot and—boom—your second disk is now /dev/sdc. Mount scripts break. Applications throw tantrums. You drink coffee and curse.

That’s musical chairs with terabytes of data.

How Much Trouble Can This Cause?

  • Mount failures/etc/fstab points to the wrong device.
  • Broken backups – rsync dumps data into the void.
  • RAID nightmares – arrays go degraded or off-line.
  • Weekend ruined – ask Dave.

One bad reboot can cost you hours of downtime and an entire pot of coffee.

A Tiny Fix That Sticks

We’re going to write a rule that says: “Hey Linux, whenever this exact drive shows up, always call it /dev/nas-disk-01—no matter where it sits on the bus.”

Step 1 – Find the Drive’s Fingerprint

Plug in the drive you want to lock down and run:

udevadm info --query=all --name=/dev/sdX | grep SERIAL

Replace the X with your actual letter. Copy the serial number—mine looks like WD-WCC123456789.

Step 2 – Create the Rule

Open a new file:

sudo nano /etc/udev/rules.d/99-nas-storage.rules

Drop in one line:

ATTRS{serial}=="WD-WCC123456789", SYMLINK+="nas-disk-01"

Save. Exit. That’s it.

Step 3 – Reload and Reboot

sudo udevadm control --reload-rules
sudo udevadm trigger

Now reboot. Your drive will appear as /dev/nas-disk-01—every. single. time.

Make It Even Safer

Instead of symlinks, you can mount by UUID. Run:

lsblk -f

Copy the UUID, then edit /etc/fstab:

UUID=14d4b4c8-4f9a-4b2d-8e1a-1c2f3c4d5e6f  /mnt/data  ext4  defaults  0  2

UUIDs never change, even if the device name does.

Scaling Up Without Losing Your Mind

  • Name the rules clearly99-nas-storage.rules, 99-backup-disk.rules, etc.
  • Add comments – future you will thank present you.
  • Keep a master list – a simple text file that maps each serial to its job.

At the university where I used to work, we had 12 JBOD enclosures. Reboots meant a whack-a-mole game of re-labeling drives. After we rolled out udev rules, the post-patch reboot window fell from 45 minutes to 5 minutes. Nobody missed the excitement.

What If I Screw Up?

Relax. The rule only creates a symlink. The original /dev/sdX names still exist. If something looks weird, delete the rule file and reload udev:

sudo rm /etc/udev/rules.d/99-nas-storage.rules
sudo udevadm control --reload-rules

Reboot again. You’re back to square one.

Quick FAQ

Q: Do I need to do this for every disk?
A: Only the ones you mount by hand or put in /etc/fstab.

Q: Older kernel—will this still work?
A: Anything from the last decade supports udev just fine.

Q: How do I find the UUID of a disk?
A: Run blkid /dev/sdX and copy the UUID=”…” bit.

Take 15 Minutes, Save 15 Hours

Next time you add a drive, spend a coffee break on a udev rule. Your Saturday self will celebrate. Your boss won’t even know there was a problem. And Dave? He finally sleeps through the night.

Leave a Comment