使用udev重命名usb设备(rhel5.5)

[root@localhost rules.d]# lsb_release -a
LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID:    RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Release:    5.5
Codename:    Tikanga
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.7G  2.2G  7.1G  24% /
/dev/sda1             190M   12M  169M   7% /boot
tmpfs                 501M     0  501M   0% /dev/shm
/dev/sdb1            31G  4.6G   26G  16% /media/SSK
[root@localhost ~]# udevinfo -q path -p /dev/sdb
no record for '/dev/sdb' in database
[root@localhost ~]# udevinfo -q path -n /dev/sdb
/block/sdb
[root@localhost ~]# udevinfo -a -p /block/sdb
...
  looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:02.0/usb1/1-1':
    ID=="1-1"
    BUS=="usb"
    DRIVER=="usb"
    SYSFS{configuration}==""
    SYSFS{serial}=="AA00000000000605"
    SYSFS{product}=="USB DISK"
    SYSFS{manufacturer}=="SMI Corporation"
    SYSFS{maxchild}=="0"
    SYSFS{version}==" 2.00"
    SYSFS{devnum}=="2"
    SYSFS{speed}=="480"
    SYSFS{bMaxPacketSize0}=="64"
    SYSFS{bNumConfigurations}=="1"
    SYSFS{bDeviceProtocol}=="00"
    SYSFS{bDeviceSubClass}=="00"
    SYSFS{bDeviceClass}=="00"
    SYSFS{bcdDevice}=="1100"
    SYSFS{idProduct}=="1000"
    SYSFS{idVendor}=="090c"
    SYSFS{bMaxPower}=="500mA"
    SYSFS{bmAttributes}=="80"
    SYSFS{bConfigurationValue}=="1"
    SYSFS{bNumInterfaces}==" 1"
...

vim /etc/udev/rules.d/99-myusb.rules
US=="usb" SYSFS{serial}=="AA00000000000605" SYSFS{manufacturer}=="SMI Corporation" SYMLINK+="myulink%n"

[root@localhost rules.d]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.7G  2.2G  7.1G  24% /
/dev/sda1             190M   12M  169M   7% /boot
tmpfs                 501M     0  501M   0% /dev/shm
/dev/myusb1            31G  4.6G   26G  16% /media/SSK
[root@localhost rules.d]# ll /dev/my*
lrwxrwxrwx 1 root root       5 May 27 00:30 /dev/myulink -> myusb
lrwxrwxrwx 1 root root       7 May 27 00:30 /dev/myulink00 -> myusb00
lrwxrwxrwx 1 root root       7 May 27 00:30 /dev/myulink02 -> myusb02
lrwxrwxrwx 1 root root       6 May 27 00:30 /dev/myulink1 -> myusb1
lrwxrwxrwx 1 root root       7 May 27 00:30 /dev/myulink81 -> myusb81
brw-r----- 1 root disk   8, 16 May 27 00:30 /dev/myusb
crw------- 1 root root 442,  8 May 27 00:30 /dev/myusb00
crw------- 1 root root 442,  8 May 27 00:30 /dev/myusb02
brw-r----- 1 root disk   8, 17 May 27 00:30 /dev/myusb1
crw------- 1 root root 442,  8 May 27 00:30 /dev/myusb81

可以看到sdb已经被改成myusb,并创建出了myulink的链接,不过那三个字符型设备是怎么出来的暂时没搞清楚。

简单排错:
可以通过udevmonitor这个命令来看udev产生的一些事件和消息。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4dae8035017a7c637f0cb67f7947c49a.html