使用UDEV繫結裝置名

xiexingzhi發表於2012-09-02
UUID的獲取方法:
1、 ls -l /dev/disk/by-uuid/ 
2、 blkid 
3、scsi_id -g -s /block/sdc

Red Hat Enterprise Linux ES 4 (x86) - How To Create Persistent Device Names Using UDEV

Information

In cases where we need to assign a persistent device name to a LUN or a tape device, udev comes handy. Applicable to RHEL4 only as udev is found in RHEL4 and later.

Details

Instead of udev assigning a device name at the time of booting, we can assign persistent device name using the UUID of the device. Steps are as follows:

- To allow udev to acquire the UUIDs for device,

edit /etc/scsi_id.config and change the "options=-b" line to:"options=-g"

This tells udev to assume that all the SCSI devices on the system will return a UUID. 

- To get the UUID, run this command:

  
 # scsi_id -g -s /block/sdc   

The output will look something like the following:

       
[root@devices]# scsi_id -g -s /block/sdc   
3600a0b800013275100000015427b625e     

The result (the long string of characters) will be the UUID. Verify that the UUID ID is the same for each path to the device. The UUID is what the device names will be keyed off of. UUIDs do not change if a device is added to the system. 

- Now, rules need to be created for naming the device. Create the /etc/udev/rules.d/20-names.rules file.

Within this file, the naming rule will be added. Any subsequent rules will be added in this file with the same format. 

Rules should have the following format: 

  
KERNEL="sd*", BUS="scsi", PROGRAM="/sbin/scsi_id", RESULT="UUID", NAME="devicename%n"   

Replace UUID and device-name with the UUID retrieved above, and the desired name for the device. In the example, the rule would look as follows: 

  
KERNEL="sd*", BUS="scsi", PROGRAM="/sbin/scsi_id", RESULT="3600a0b800013275100000015427b625e", NAME="mydevice"   

This will cause the system to check all devices which match /dev/sd* to be checked for the given UUID. When it finds a matching device, it will create a device node named /dev/devicename. In this example, the device node would be /dev/mydevice. 

To confirm that the rule is working correctly, run 

The device should appear as /dev/mydevice

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22531473/viewspace-742483/,如需轉載,請註明出處,否則將追究法律責任。

相關文章