Chinaunix首页 | 论坛 | 博客
  • 博客访问: 396557
  • 博文数量: 36
  • 博客积分: 1998
  • 博客等级: 上尉
  • 技术积分: 486
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-23 13:48
文章分类

全部博文(36)

文章存档

2012年(11)

2011年(13)

2010年(12)

分类: LINUX

2011-07-17 12:22:56

  曾经道听途说,Linux下的磁盘设备号(/dev/sda、/dev/sdb……)会在操作系统重启后发生编号混乱,尤其是这些磁盘是外置存储盘的时候。最近一次机缘巧合的机会,让我也碰到了这样的情况,做了些简单的实验,找到了些规律。

  1. [root@Smswas1 ~]# fdisk -l

  2. Disk /dev/cciss/c0d0: 146.7 GB, 146778685440 bytes
  3. 255 heads, 63 sectors/track, 17844 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes

  5. Device Boot Start End Blocks Id System
  6. /dev/cciss/c0d0p1 * 1 13 104391 83 Linux
  7. /dev/cciss/c0d0p2 14 17844 143227507+ 8e Linux LVM

  8. Disk /dev/sda: 107.3 GB, 107374182400 bytes
  9. 255 heads, 63 sectors/track, 13054 cylinders
  10. Units = cylinders of 16065 * 512 = 8225280 bytes

  11. Device Boot Start End Blocks Id System
  12. /dev/sda1 1 13054 104856223+ 5 Extended
  13. /dev/sda5 1 7 56164+ 83 Linux
  14. /dev/sda6 8 616 4891761 83 Linux
  15. /dev/sda7 617 6696 48837568+ 83 Linux

  16. Disk /dev/sdb: 36.3 GB, 36354129920 bytes
  17. 64 heads, 32 sectors/track, 34670 cylinders
  18. Units = cylinders of 2048 * 512 = 1048576 bytes

  19. Device Boot Start End Blocks Id System
  20. /dev/sdb1 1 34670 35502064 5 Extended
  21. /dev/sdb5 1 34670 35502048 83 Linux

  22. Disk /dev/sdc: 107.3 GB, 107374182400 bytes
  23. 255 heads, 63 sectors/track, 13054 cylinders
  24. Units = cylinders of 16065 * 512 = 8225280 bytes

  25. Disk /dev/sdc doesn't contain a valid partition table

  26. Disk /dev/sdd: 107.3 GB, 107374182400 bytes
  27. 255 heads, 63 sectors/track, 13054 cylinders
  28. Units = cylinders of 16065 * 512 = 8225280 bytes

  29. Disk /dev/sdd doesn't contain a valid partition table
  30. [root@Smswas1 ~]# ls -l /dev/disk/by-id
  31. total 0
  32. lrwxrwxrwx 1 root root 9 Jun 16 19:14 scsi-1HITACHI_D60055750011 -> ../../sdc
  33. lrwxrwxrwx 1 root root 9 Jun 16 19:05 scsi-1HITACHI_D60055750012 -> ../../sda
  34. lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part1 -> ../../sda1
  35. lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part5 -> ../../sda5
  36. lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part6 -> ../../sda6
  37. lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750012-part7 -> ../../sda7
  38. lrwxrwxrwx 1 root root 9 Jun 16 19:18 scsi-1HITACHI_D60055750013 -> ../../sdd
  39. lrwxrwxrwx 1 root root 9 Jun 16 19:05 scsi-1HITACHI_D60055750016 -> ../../sdb
  40. lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750016-part1 -> ../../sdb1
  41. lrwxrwxrwx 1 root root 10 Jun 16 19:05 scsi-1HITACHI_D60055750016-part5 -> ../../sdb5
  42. [root@Smswas1 ~]# ls -l /dev/disk/by-path
  43. total 0
  44. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:00:1f.2-scsi-0:0:0:0 -> ../../scd0
  45. lrwxrwxrwx 1 root root 9 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000 -> ../../sda
  46. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part1 -> ../../sda1
  47. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part5 -> ../../sda5
  48. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part6 -> ../../sda6
  49. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part7 -> ../../sda7
  50. lrwxrwxrwx 1 root root 9 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000 -> ../../sdb
  51. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part1 -> ../../sdb1
  52. lrwxrwxrwx 1 root root 10 Jun 16 19:05 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part5 -> ../../sdb5
  53. lrwxrwxrwx 1 root root 9 Jun 16 19:18 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0002000000000000 -> ../../sdd
  54. 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,操作系统重启后的输出如下:

  1. [root@Smswas1 ~]# fdisk -l

  2. Disk /dev/cciss/c0d0: 146.7 GB, 146778685440 bytes
  3. 255 heads, 63 sectors/track, 17844 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes

  5. Device Boot Start End Blocks Id System
  6. /dev/cciss/c0d0p1 * 1 13 104391 83 Linux
  7. /dev/cciss/c0d0p2 14 17844 143227507+ 8e Linux LVM

  8. Disk /dev/sda: 107.3 GB, 107374182400 bytes
  9. 255 heads, 63 sectors/track, 13054 cylinders
  10. Units = cylinders of 16065 * 512 = 8225280 bytes

  11. Device Boot Start End Blocks Id System
  12. /dev/sda1 1 13054 104856223+ 5 Extended
  13. /dev/sda5 1 7 56164+ 83 Linux
  14. /dev/sda6 8 616 4891761 83 Linux
  15. /dev/sda7 617 6696 48837568+ 83 Linux

  16. Disk /dev/sdb: 36.3 GB, 36354129920 bytes
  17. 64 heads, 32 sectors/track, 34670 cylinders
  18. Units = cylinders of 2048 * 512 = 1048576 bytes

  19. Device Boot Start End Blocks Id System
  20. /dev/sdb1 1 34670 35502064 5 Extended
  21. /dev/sdb5 1 34670 35502048 83 Linux

  22. Disk /dev/sdc: 107.3 GB, 107374182400 bytes
  23. 255 heads, 63 sectors/track, 13054 cylinders
  24. Units = cylinders of 16065 * 512 = 8225280 bytes

  25. Disk /dev/sdc doesn't contain a valid partition table

  26. Disk /dev/sdd: 107.3 GB, 107374182400 bytes
  27. 255 heads, 63 sectors/track, 13054 cylinders
  28. Units = cylinders of 16065 * 512 = 8225280 bytes

  29. Disk /dev/sdd doesn't contain a valid partition table
  30. [root@Smswas1 ~]# ls -l /dev/disk/by-id
  31. total 0
  32. lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750011 -> ../../sdd
  33. lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750012 -> ../../sda
  34. lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part1 -> ../../sda1
  35. lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part5 -> ../../sda5
  36. lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part6 -> ../../sda6
  37. lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750012-part7 -> ../../sda7
  38. lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750013 -> ../../sdc
  39. lrwxrwxrwx 1 root root 9 Jun 16 19:24 scsi-1HITACHI_D60055750016 -> ../../sdb
  40. lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750016-part1 -> ../../sdb1
  41. lrwxrwxrwx 1 root root 10 Jun 16 19:24 scsi-1HITACHI_D60055750016-part5 -> ../../sdb5
  42. [root@Smswas1 ~]# ls -l /dev/disk/by-label
  43. total 0
  44. lrwxrwxrwx 1 root root 18 Jun 16 19:23 boot -> ../../cciss/c0d0p1
  45. [root@Smswas1 ~]# ls -l /dev/disk/by-path
  46. total 0
  47. lrwxrwxrwx 1 root root 10 Jun 16 19:23 pci-0000:00:1f.2-scsi-0:0:0:0 -> ../../scd0
  48. lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000 -> ../../sda
  49. lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part1 -> ../../sda1
  50. lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part5 -> ../../sda5
  51. lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part6 -> ../../sda6
  52. lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0000000000000000-part7 -> ../../sda7
  53. lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000 -> ../../sdb
  54. lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part1 -> ../../sdb1
  55. lrwxrwxrwx 1 root root 10 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0001000000000000-part5 -> ../../sdb5
  56. lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0002000000000000 -> ../../sdc
  57. lrwxrwxrwx 1 root root 9 Jun 16 19:24 pci-0000:0b:00.0-fc-0x50060e800043cd71:0x0003000000000000 -> ../../sdd
  58. [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的输出即可。



阅读(8927) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~