Override / rename your usb hard drive's device name with udev rules

            ISSN 1836-5930

This website is maintained by a non-profit organization. Please consider participating, or simply helping us by linking to www.linuxconfig.org from your web site or blog.

From Linux Config Wiki

Jump to: navigation, search


Very often happens, that your Linux system detects same USB hard drive with different device name every time you plug it in. This may not be useful, if you are running certain backup scripts or you want to have fixed entry in your /etc/fstab file for that particular device. One solution can be to rename your hard drive's device name by creating udev policy which force Linux system recognize it with the same name, each time you plug your USB drive in. In this config we make our Linux system to recognize our USB hard drive as /dev/myusbdrive.

Detect USB hard drive attributes

First we need to detect some attributes of our USB hard drive. For this we can use command udevmonitor. Simply run command:

udevmonitor --env

and plug in the USB hard drive. You should end up with similar result as shown below.

detect USB hard drive attributes

take the note of the following:


Writing udev rules

First ls /etc/udev/rules.d/ to see what sequence number is available for us:

ls /etc/udev/rules.d/

Now that we have sufficient information about our USB hard drive we can write udev rule:

echo 'SUBSYSTEM=="block", ID_SERIAL_SHORT=="101A9041C67D182E", NAME="myusbdrive"' > /etc/udev/rules.d/S96-mydrive.rules

Create udev rules for USB hard drive

Reload udev rules

New udev rules are in the place so now we need to just apply them by reloading them with udevcontrol command:

udevcontrol reload_rules

reload udev rules with udevcontrol command

Plug in USB hard drive

If you still have your USB hard drive pluged in take it out and plug it back. The system now should recognize your disk as /dev/myusbdrive:

USB drive with new name specified by udev rules

From now on, this particular USB hard drive will be always recognized and ready to mount as /dev/myusbdrive device.

Related topics

Other Topics

Personal tools
Linux Commands
Publications Archives