Assign static device name using udev rules

How can you assign static device name using udev rules to a USB device? Why do you need it?

Imagine you made a script which refers to a particular device you could plugin trough USB port: sometimes this device could be mounted as /dev/sdb1, sometimes as /dev/sdc1, and so on. You may need a static reference to it because you didn’t know which name it will use.

Another scenario could be a startup mount of a drive as discussed in

To achieve this, let first discover some attributes of our device using the command

sudo lsusb

We will receive an output like this:

emanuele@ubuntu:~$ lsusb

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 001 Device 004: ID 1058:107c Western Digital Technologies, Inc.

Have a look at the Western Digital Technologies row, this is the device we are looking for: 1058 is the Vendor ID and 107c is the Product ID! We will use these information to uniquely identify our device.

Now, let’s create a new udev rule typing

sudo nano /etc/udev/rules.d/99-my_rules.rules

and writing the following into the file

ACTION==”add”, ATTRS{idVendor}==”1058″, ATTRS{idProduct}==”107c”, SYMLINK+=”my_wd_usb_hd”

where the ATTRS numbers are the ones we discovered before, while my_wd_usb_hd is the name we choose for our device.

Now let’s reboot our pc! Everytime it reboots this rule will be applied and we will always find our device under /dev/my_wd_usb_hd


Mount NTFS partition at startup

In this post we will learn how to mount NTFS partition at startup in a very simple way.

You can use the following command to retrieve a list of your partitions and their UUID.

ls -l /dev/disk/by-uuid

Pick the one you want to automatically mount and open the file /etc/fstab by using

sudo nano /etc/fstab

Add a new row like:

UUID=XXXXXXXXXXX  /hd_mount_point       ntfs-3g defaults        0       0

where XXXXXXXXXXX is your partition UUID and /hd_mount_point is a folder on your disk you will use to access that partition.

Simply reboot and you are done!


Force Ubuntu boot after power failure


in this blog post I will show a little trick to avoid your Ubuntu installation got stuck on GRUB boot menu waiting for you to choose an option after a power failure.

To force Ubuntu boot you can edit your /etc/default/grub with your favourite text editor, e.g. running this command from your terminal:

nano /etc/default/grub

and then add this line in the file:


Afterwards, remember to run:

sudo update-grub

Next time your pc will have a power failure it will reboot without getting stuck on GRUB!