曾经道听途说,Linux下的磁盘设备号(/dev/sda、/dev/sdb……)会在操作系统重启后发生编号混乱,尤其是这些磁盘是外置存储盘的时候。最近一次机缘巧合的机会,让我也碰到了这样的情况,做了些简单的实验,找到了些规律。
- [root@Smswas1 ~]# fdisk -l
-
-
Disk /dev/cciss/c0d0: 146.7 GB, 146778685440 bytes
-
255 heads, 63 sectors/track, 17844 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
-
/dev/cciss/c0d0p2 14 17844 143227507+ 8e Linux LVM
-
-
Disk /dev/sda: 107.3 GB, 107374182400 bytes
-
255 heads, 63 sectors/track, 13054 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sda1 1 13054 104856223+ 5 Extended
-
/dev/sda5 1 7 56164+ 83 Linux
-
/dev/sda6 8 616 4891761 83 Linux
-
/dev/sda7 617 6696 48837568+ 83 Linux
-
-
Disk /dev/sdb: 36.3 GB, 36354129920 bytes
-
64 heads, 32 sectors/track, 34670 cylinders
-
Units = cylinders of 2048 * 512 = 1048576 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sdb1 1 34670 35502064 5 Extended
-
/dev/sdb5 1 34670 35502048 83 Linux
-
-
Disk /dev/sdc: 107.3 GB, 107374182400 bytes
-
255 heads, 63 sectors/track, 13054 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Disk /dev/sdc doesn't contain a valid partition table
-
-
Disk /dev/sdd: 107.3 GB, 107374182400 bytes
-
255 heads, 63 sectors/track, 13054 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Disk /dev/sdd doesn't contain a valid partition table
-
[root@Smswas1 ~]# ls -l /dev/disk/by-id
-
total 0
-
lrwxrwxrwx 1 root root 9 Jun 16 19:14 scsi-1HITACHI_D60055750011 -> ../../sdc
-
lrwxrwxrwx 1 root root 9 Jun 16 19:05 scsi-1HITACHI_D60055750012 -> ../../sda
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part1 -> ../../sda1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part5 -> ../../sda5
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part6 -> ../../sda6
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part7 -> ../../sda7
-
lrwxrwxrwx 1 root root 9 Jun 16 19:18 scsi-1HITACHI_D60055750013 -> ../../sdd
-
lrwxrwxrwx 1 root root 9 Jun 16 19:05 scsi-1HITACHI_D60055750016 -> ../../sdb
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750016-part1 -> ../../sdb1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750016-part5 -> ../../sdb5
-
[root@Smswas1 ~]# ls -l /dev/disk/by-path
-
total 0
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:00:1f.2-scsi-0:0:0:0 -> ../../scd0
-
lrwxrwxrwx 1 root root 9 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000 -> ../../sda
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part1 -> ../../sda1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part5 -> ../../sda5
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part6 -> ../../sda6
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part7 -> ../../sda7
-
lrwxrwxrwx 1 root root 9 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000 -> ../../sdb
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part1 -> ../../sdb1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part5 -> ../../sdb5
-
lrwxrwxrwx 1 root root 9 Jun 16 19:18 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0002000000000000 -> ../../sdd
-
lrwxrwxrwx 1 root root 9 Jun 16 19:14 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0003000000000000 -> ../../sdc
命令的输出可以看到,有4块从同一光纤通道(pci-0000:0b:00.0-fc-0x50060e800043cd71)认到的存储磁盘sda、sdb、sdc、sdd,操作系统重启后的输出如下:- [root@Smswas1 ~]# fdisk -l
-
-
Disk /dev/cciss/c0d0: 146.7 GB, 146778685440 bytes
-
255 heads, 63 sectors/track, 17844 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
-
/dev/cciss/c0d0p2 14 17844 143227507+ 8e Linux LVM
-
-
Disk /dev/sda: 107.3 GB, 107374182400 bytes
-
255 heads, 63 sectors/track, 13054 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sda1 1 13054 104856223+ 5 Extended
-
/dev/sda5 1 7 56164+ 83 Linux
-
/dev/sda6 8 616 4891761 83 Linux
-
/dev/sda7 617 6696 48837568+ 83 Linux
-
-
Disk /dev/sdb: 36.3 GB, 36354129920 bytes
-
64 heads, 32 sectors/track, 34670 cylinders
-
Units = cylinders of 2048 * 512 = 1048576 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sdb1 1 34670 35502064 5 Extended
-
/dev/sdb5 1 34670 35502048 83 Linux
-
-
Disk /dev/sdc: 107.3 GB, 107374182400 bytes
-
255 heads, 63 sectors/track, 13054 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Disk /dev/sdc doesn't contain a valid partition table
-
-
Disk /dev/sdd: 107.3 GB, 107374182400 bytes
-
255 heads, 63 sectors/track, 13054 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Disk /dev/sdd doesn't contain a valid partition table
-
[root@Smswas1 ~]# ls -l /dev/disk/by-id
-
total 0
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750011 -> ../../sdd
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750012 -> ../../sda
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part1 -> ../../sda1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part5 -> ../../sda5
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part6 -> ../../sda6
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part7 -> ../../sda7
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750013 -> ../../sdc
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750016 -> ../../sdb
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750016-part1 -> ../../sdb1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750016-part5 -> ../../sdb5
-
[root@Smswas1 ~]# ls -l /dev/disk/by-label
-
total 0
-
lrwxrwxrwx 1 root root 18 Jun 16 19:23 boot -> ../../cciss/c0d0p1
-
[root@Smswas1 ~]# ls -l /dev/disk/by-path
-
total 0
-
lrwxrwxrwx 1 root root 10 Jun 16 19:23 pci-0000:00:1f.2-scsi-0:0:0:0 -> ../../scd0
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000 -> ../../sda
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part1 -> ../../sda1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part5 -> ../../sda5
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part6 -> ../../sda6
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part7 -> ../../sda7
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000 -> ../../sdb
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part1 -> ../../sdb1
-
lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part5 -> ../../sdb5
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0002000000000000 -> ../../sdc
-
lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0003000000000000 -> ../../sdd
-
[root@Smswas1 ~]# ls -l /dev/disk/by-uuid
请仔细观察上面的蓝色字和红色字的磁盘,你会发现,在操作系统重启后,磁盘的设备编号发生了变化,sdc和sdd对换了。
而且如果你更仔细的观察就会发现,设备编号sdX是由红色字部分决定的,ls -l /dev/disk/by-path的输出决定了sdX的编号,换句话说,sdX的编号是由“光纤卡的物理位置+光纤卡的WWN+映射到主机的LUN ID”决定的。
如果想判断重启后,sdX的编号是否会发生变化,只要ls -l /dev/disk/by-path的输出即可。
阅读(8974) | 评论(0) | 转发(1) |