Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I bind specific usb out to specific /dev/sd* value?

Each time that I plugged in some device in specific usb out it binds to different /dev/sd* location. How can I avoid it to set mounting option in fstab?

share|improve this question
    
Do you want to bind to a specific device name an usb port or an usb device? –  andcoz Jan 28 '12 at 23:04

1 Answer 1

up vote 2 down vote accepted

Assuming that you're running Linux, Udev decides what device name to assign to a block device.

The Udev rule /lib/udev/rules.d/60-persistent-storage.rules tries to assign names for each block device that depend on a unique identifier of the filesystem that it contains. The directories /dev/disk/by-* contain symbolic links to the actual device file (e.g. /dev/sd*). Mount one of these, e.g. /dev/disk/by-label/joe_photos or /dev/disk/by-id/ata-ACME1789-ZRM3OTV8KRJ1OAAN-part7.

If you want to mount the device automatically, you can do it by writing a udev rule, like this:

KERNEL=="sd?", PROGRAM=="/sbin/blkid -o value -s UUID %N1", RESULT=="1234-5678", SYMLINK+="removable/mydisk", RUN="mkdir /media/mydisk && mount /dev/removable/mydisk /media/mydisk"

Don't forget to unmount the device before unplugging it. Udev can't help there since it can only react after the unplugging.

Run udevadm info -a -n /dev/sdz42 to see how you might be able to identify the specified disk.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.