# USB devices and their name in /dev



## ikbendeman (Sep 17, 2010)

Is there a way in FreeBSD to ensure that, for example, a specific usb drive (or any device for that matter) is always configured as (for example) /dev/da1?


----------



## wblock@ (Sep 17, 2010)

Not that I know of, but there are other ways to get a device to have an absolute name.  You can label the filesystem with tunefs(8) or glabel(8), and then the label will show up in /dev/ufs/ or /dev/label.  Examples here.

Or you can can use devd(8) to do something when a specific device is attached, like create a link with a specific name.


----------



## ikbendeman (Sep 17, 2010)

I've tried using tunefs -l label /dev/device but I get the following:

```
tunefs: /dev/da0s1d: failed to write superblock
```


----------



## ikbendeman (Sep 17, 2010)

If anyone can tell me how I would get the info for the following (from devd.conf man page):


> Variables that can be used with the match statement
> A partial list of variables and their possible values that can be used
> together with the match statement.
> 
> ...



...specifically vendor, product, device-name, etc... something specific I can use to have devd run a script to make a symlink in /dev... I would like, for example a way of identifying my sony walkman and then having a script from devd run to make a symlink /dev/walkman to /dev/da1s1 (for example).


----------



## wblock@ (Sep 17, 2010)

Here's an example:

```
attach 100 {
        device-name "ugen[0-9].[0-9]";
        match "vendor" "0x04b8";
        match "product" "0x010a";
        action "usb_devaddr=`echo $device-name | sed 's#^ugen##'` && \
                chown root:wheel /dev/usb/${usb_devaddr}.* && \
                chmod 0660 /dev/usb/${usb_devaddr}.* && \
                ln -s /dev/usb/${usb_devaddr} /dev/walkman";
};
```

(Untested, variation of one of my existing devices.) You'll have to change the vendor and product IDs for your device.  And you need a detach entry to remove the link when you unplug the device.

Edit: no, this isn't going to work, at least not directly, because it needs to be a link to /dev/da*, not to /dev/usb/*.  Use labels with tunefs(8).


----------



## Beastie (Sep 17, 2010)

ikbendeman said:
			
		

> I've tried using tunefs -l label /dev/device but I get the following:
> 
> ```
> tunefs: /dev/da0s1d: failed to write superblock
> ```


I am not sure about the error (perhaps the filesystem is mounted?), but the labeling option is *capital* *-L*.
Read man pages very carefully. You will end up b0rking a system one day this way.


----------



## ikbendeman (Sep 17, 2010)

Beastie said:
			
		

> I am not sure about the error (perhaps the filesystem is mounted?), but the labeling option is *capital* *-L*.
> Read man pages very carefully. You will end up b0rking a system one day this way.



sorry I ran it with -L I just typed it wrong on the forums.


----------



## ikbendeman (Sep 17, 2010)

wblock said:
			
		

> Here's an example:
> 
> ```
> attach 100 {
> ...



Thanks for that, I just... where do you get the vendor and product flags? How do I figure those out?


----------



## wblock@ (Sep 17, 2010)

Sorry, I just edited that to say it won't work for a disk device (or at least I haven't figured out the right way to do it).  You can find vendor and product IDs from /var/log/messages or usbconfig(8), though.


----------

