����Linux�Ż�
Linux����

CentOS 5�ϲ���udev

����ʱ��:2014-11-03 15:37:47��Դ:linux��վ����:ylw6006

��������Ҫ�Ľ�����ʲô��udev,udev��Linux kernel 2.6ϵ�е�ͨ���ں��豸������,���ػ����̵ķ�ʽ������Linuxϵͳ�������������豸��ʼ�����豸��ϵͳ���Ƴ�ʱ���ںˣ�ͨ��netlink socket����������uevent���򵥵㽲���ǵ��ж����̵�ʱ�򣬿�����udev���̶����̶�Ӧ���豸����֮ǰ�ڲ���11g rac��ʱ��ƫ��ʹ��asmlib�������һ�εIJ�����asmlib���������⣬����û��ʱ��ȥ�Ŵ����������udev���𣬹ʶ��򵥼�¼��udev�����ù��̣�


һ��ģ�⹲��������������Ȼ���lvm����ͨ��iscsi�����ķ�ʽ��ģ��

[root@db1 ~]# pvcreate /dev/sdb  
Physical volume "/dev/sdb" successfully created 
[root@db1 ~]# vgcreate data /dev/sdb 
/dev/hdc: open failed: Read-only file system 
/dev/cdrom: open failed: Read-only file system 
Attempt to close device '/dev/cdrom' which is not open. 
Volume group "data" successfully created 
[root@db1 ~]# lvcreate -n crs1 -L 2G data 
Logical volume "crs1" created 
[root@db1 ~]# lvcreate -n crs2 -L 2G data 
Logical volume "crs2" created 
[root@db1 ~]# lvcreate -n crs3 -L 2G data 
Logical volume "crs3" created 
[root@db1 ~]# lvcreate -n data -L 10G data 
Logical volume "data" created 
[root@db1 ~]# lvcreate -n fra -L 10G data 
Logical volume "fra" created 
 
[root@db1 ~]# lvs 
LV   VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert 
crs1 data -wi-a-  2.00G
crs2 data -wi-a-  2.00G
crs3 data -wi-a-  2.00G
data data -wi-a- 10.00G
fra  data -wi-a- 10.00G
 
[root@db1 ~]# service tgtd start 
Starting SCSI target daemon: [  OK  ] 
 
[root@db1 ~]# cat iscsi.sh  
tgtadm  --lld iscsi --op new --mode target --tid 1 -T iqn.2012-07-04.com.yang.rac:crs1 
tgtadm  --lld iscsi --op new --mode target --tid 2 -T iqn.2012-07-04.com.yang.rac:crs2 
tgtadm  --lld iscsi --op new --mode target --tid 3 -T iqn.2012-07-04.com.yang.rac:crs3 
tgtadm  --lld iscsi --op new --mode target --tid 4 -T iqn.2012-07-04.com.yang.rac:data 
tgtadm  --lld iscsi --op new --mode target --tid 5 -T iqn.2012-07-04.com.yang.rac:fra 
 
tgtadm  --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/data/crs1 
tgtadm  --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /dev/data/crs2 
tgtadm  --lld iscsi --op new --mode logicalunit --tid 1 --lun 3 -b /dev/data/crs3 
tgtadm  --lld iscsi --op new --mode logicalunit --tid 1 --lun 4 -b /dev/data/data 
tgtadm  --lld iscsi --op new --mode logicalunit --tid 1 --lun 5 -b /dev/data/fra 
 
tgtadm  --lld iscsi --op bind --mode target --tid 1 -I ALL 
tgtadm  --lld iscsi --op bind --mode target --tid 2 -I ALL 
tgtadm  --lld iscsi --op bind --mode target --tid 3 -I ALL 
tgtadm  --lld iscsi --op bind --mode target --tid 4 -I ALL 
tgtadm  --lld iscsi --op bind --mode target --tid 5 -I ALL 
 
[root@db1 ~]# tgtadm --lld iscsi -o show -m target 
[root@db1 ~]# sh iscsi.sh  
[root@db1 ~]# tgtadm --lld iscsi -o show -m target 
Target 1: iqn.2012-07-04.com.yang.rac:crs1 
System information: 
Driver: iscsi 
State: ready 
I_T nexus information: 
LUN information: 
LUN: 0 
Type: controller 
SCSI ID: deadbeaf1:0 
SCSI SN: beaf10 
Size: 0 MB 
Online: Yes 
Removable media: No 
Backing store: No backing store 
LUN: 1 
Type: disk 
SCSI ID: deadbeaf1:1 
SCSI SN: beaf11 
Size: 2147 MB 
Online: Yes 
Removable media: No 
Backing store: /dev/data/crs1 
LUN: 2 
Type: disk 
SCSI ID: deadbeaf1:2 
SCSI SN: beaf12 
Size: 2147 MB 
Online: Yes 
Removable media: No 
Backing store: /dev/data/crs2 
LUN: 3 
Type: disk 
SCSI ID: deadbeaf1:3 
SCSI SN: beaf13 
Size: 2147 MB 
Online: Yes 
Removable media: No 
Backing store: /dev/data/crs3 
LUN: 4 
Type: disk 
SCSI ID: deadbeaf1:4 
SCSI SN: beaf14 
Size: 10737 MB 
Online: Yes 
Removable media: No 
Backing store: /dev/data/data 
LUN: 5 
Type: disk 
SCSI ID: deadbeaf1:5 
SCSI SN: beaf15 
Size: 10737 MB 
Online: Yes 
Removable media: No 
Backing store: /dev/data/fra 
Account information: 
ACL information: 
ALL 
Target 2: iqn.2012-07-04.com.yang.rac:crs2 
System information: 
Driver: iscsi 
State: ready 
I_T nexus information: 
LUN information: 
LUN: 0 
Type: controller 
SCSI ID: deadbeaf2:0 
SCSI SN: beaf20 
Size: 0 MB 
Online: Yes 
Removable media: No 
Backing store: No backing store 
Account information: 
ACL information: 
Target 3: iqn.2012-07-04.com.yang.rac:crs3 
System information: 
Driver: iscsi 
State: ready 
I_T nexus information: 
LUN information: 
LUN: 0 
Type: controller 
SCSI ID: deadbeaf3:0 
SCSI SN: beaf30 
Size: 0 MB 
Online: Yes 
Removable media: No 
Backing store: No backing store 
Account information: 
ACL information: 
Target 4: iqn.2012-07-04.com.yang.rac:data 
System information: 
Driver: iscsi 
State: ready 
I_T nexus information: 
LUN information: 
LUN: 0 
Type: controller 
SCSI ID: deadbeaf4:0 
SCSI SN: beaf40 
Size: 0 MB 
Online: Yes 
Removable media: No 
Backing store: No backing store 
Account information: 
ACL information: 
Target 5: iqn.2012-07-04.com.yang.rac:fra 
System information: 
Driver: iscsi 
State: ready 
I_T nexus information: 
LUN information: 
LUN: 0 
Type: controller 
SCSI ID: deadbeaf5:0 
SCSI SN: beaf50 
Size: 0 MB 
Online: Yes 
Removable media: No 
Backing store: No backing store 
Account information: 
ACL information:


��:�ڿͻ����Ϲ���ǰ��ģ����Ĺ�����������

[root@db2 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.123.10 
192.168.123.10:3260,1 iqn.2012-07-04.com.yang.rac:fra 
192.168.123.10:3260,1 iqn.2012-07-04.com.yang.rac:crs1 
192.168.123.10:3260,1 iqn.2012-07-04.com.yang.rac:crs3 
192.168.123.10:3260,1 iqn.2012-07-04.com.yang.rac:data 
192.168.123.10:3260,1 iqn.2012-07-04.com.yang.rac:crs2 
 
[root@db2 ~]# iscsiadm --mode node --targetname iqn.2012-07-04.com.yang.rac:crs1 --portal 192.168.123.10 --login 
[root@db2 ~]# iscsiadm --mode node --targetname iqn.2012-07-04.com.yang.rac:crs2 --portal 192.168.123.10 --login 
[root@db2 ~]# iscsiadm --mode node --targetname iqn.2012-07-04.com.yang.rac:crs3 --portal 192.168.123.10 --login 
[root@db2 ~]# iscsiadm --mode node --targetname iqn.2012-07-04.com.yang.rac:data --portal 192.168.123.10 --login 
[root@db2 ~]# iscsiadm --mode node --targetname iqn.2012-07-04.com.yang.rac:fra  --portal 192.168.123.10 --login 
 
[root@db2 ~]# fdisk -l 
Disk /dev/sda: 85.8 GB, 85899345920 bytes 
255 heads, 63 sectors/track, 10443 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
 
Device Boot  Start End  Blocks   Id  System 
/dev/sda1   *   1  13  104391   83  Linux 
/dev/sda2  14 523 4096575   82  Linux swap / Solaris 
/dev/sda3 524   1044379682400   83  Linux 
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes 
67 heads, 62 sectors/track, 1009 cylinders 
Units = cylinders of 4154 * 512 = 2126848 bytes 
 
Disk /dev/sdb doesn't contain a valid partition table 
 
Disk /dev/sdc: 2147 MB, 2147483648 bytes 
67 heads, 62 sectors/track, 1009 cylinders 
Units = cylinders of 4154 * 512 = 2126848 bytes 
 
Disk /dev/sdc doesn't contain a valid partition table 
 
Disk /dev/sdd: 2147 MB, 2147483648 bytes 
67 heads, 62 sectors/track, 1009 cylinders 
Units = cylinders of 4154 * 512 = 2126848 bytes 
 
Disk /dev/sdd doesn't contain a valid partition table 
 
Disk /dev/sde: 10.7 GB, 10737418240 bytes 
64 heads, 32 sectors/track, 10240 cylinders 
Units = cylinders of 2048 * 512 = 1048576 bytes 
 
Disk /dev/sde doesn't contain a valid partition table 
 
Disk /dev/sdf: 10.7 GB, 10737418240 bytes 
64 heads, 32 sectors/track, 10240 cylinders 
Units = cylinders of 2048 * 512 = 1048576 bytes 
 
Disk /dev/sdf doesn't contain a valid partition table


������ʼ����udev

[root@db2 ~]# uname -r  //�ڱ����в���ϵͳ�İ汾λCentOS5.4 64bit 
2.6.18-164.el5 
[root@db2 ~]# 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: CentOS 
Description:CentOS release 5.4 (Final) 
Release:5.4 
Codename:   Final 
 
[root@db2 ~]# rpm -qa |grep udev 
udev-095-14.21.el5 
 
[root@db2 ~]# ps -ef |grep udev 
root  4646 1  0 10:14 ?00:00:00 /sbin/udevd -d 
root  6023  3039  0 10:32 pts/000:00:00 grep udev 
 
[root@db2 ~]# grep -v ^# /etc/udev/udev.conf  |grep -v ^$ 
udev_log="err"
 
[root@db2 ~]# scsi_id -g -u -s /block/sdb 
S_beaf11 
[root@db2 ~]# scsi_id -g -u -s /block/sdc 
S_beaf12 
[root@db2 ~]# scsi_id -g -u -s /block/sdd 
S_beaf13 
[root@db2 ~]# scsi_id -g -u -s /block/sde 
S_beaf14 
[root@db2 ~]# scsi_id -g -u -s /block/sdf 
S_beaf15 
 
[root@db2 ~]# cat /etc/udev/rules.d/99-raw.rules  
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="S_beaf11", NAME="asmdisk1", OWNER="grid",  
 
GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="S_beaf12", NAME="asmdisk2", OWNER="grid",  
 
GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="S_beaf13", NAME="asmdisk3", OWNER="grid",  
 
GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="S_beaf14", NAME="asmdisk4", OWNER="grid",  
 
GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="S_beaf15", NAME="asmdisk5", OWNER="grid",  
 
GROUP="asmadmin", MODE="0660"
 
[root@db2 ~]# ll /dev/asm* 
ls: /dev/asm*: No such file or directory 
[root@db2 ~]# /sbin/udevcontrol reload_rules 
[root@db2 ~]# /sbin/start_udev  
Starting udev: [  OK  ] 
[root@db2 ~]# ll /dev/asm* 
brw-rw---- 1 grid asmadmin 8, 16 Jul  4 12:05 /dev/asmdisk1 
brw-rw---- 1 grid asmadmin 8, 32 Jul  4 12:05 /dev/asmdisk2 
brw-rw---- 1 grid asmadmin 8, 48 Jul  4 12:05 /dev/asmdisk3 
brw-rw---- 1 grid asmadmin 8, 64 Jul  4 12:05 /dev/asmdisk4 
brw-rw---- 1 grid asmadmin 8, 80 Jul  4 12:05 /dev/asmdisk5

��ע��
1����vmware�У�scsi_id -g -u -s /block/sdbĬ���Dz������uuid�ģ���Ҫ�޸�vmx�ļ�������disk.EnableUUID����
2��/block/sdbʵ�����Ǹ������ڵ�·����ʵ�ʾ���·����/sys/block/sdb����ʹ��scsi_id�����ʱ�������/block/sdb·����