devinteske

Automating gmultipath label creation on FreeBSD

Apr 28th, 2017
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.18 KB | None | 0 0
  1. # FreeBSD high-speed pool setup
  2.  
  3. # Automatically create gmultipath labels for serialized disks
  4. echo da{0..47} | sr xargs -n1 sh -c 'echo $( camcontrol inquiry $1 -S ) $1' /bin/sh | sed -e 's/\([^0-9]\)\([0-9]\)$/\10\2/' | awk 'D[$1]=D[$1](D[$1]?" ":"")$2{}END{for(S in D)print S,D[S]}' | sort -k2 | awk 'gsub(/da0/,"da"){}$1=sprintf("d%02u-%s",N++,substr($1,1,11))' | while read LABEL DISKS; do gmultipath status $LABEL > /dev/null 2>&1 || sudo gmultipath label $LABEL $DISKS; done
  5.  
  6. # Results in the following sub-commands being executed
  7. sudo gmultipath label d00-Z4D3WM7A000 da0 da24
  8. sudo gmultipath label d01-Z4D3RYTJ000 da1 da25
  9. sudo gmultipath label d02-Z4D3RYVW000 da2 da26
  10. sudo gmultipath label d03-Z4D3RYTL000 da3 da27
  11. sudo gmultipath label d04-Z4D3RYZY000 da4 da28
  12. sudo gmultipath label d05-Z4D3RYQX000 da5 da29
  13. sudo gmultipath label d06-Z4D3WMQB000 da6 da30
  14. sudo gmultipath label d07-Z4D3WLV6000 da7 da31
  15. sudo gmultipath label d08-Z4D3WLYN000 da8 da32
  16. sudo gmultipath label d09-Z4D3WMA0000 da9 da33
  17. sudo gmultipath label d10-Z4D3RZ27000 da10 da34
  18. sudo gmultipath label d11-Z4D3WMLY000 da11 da35
  19. sudo gmultipath label d12-Z4D3WM1F000 da12 da36
  20. sudo gmultipath label d13-Z4D3W7M9000 da13 da37
  21. sudo gmultipath label d14-Z4D3WMAF000 da14 da38
  22. sudo gmultipath label d15-Z4D3WM45000 da15 da39
  23. sudo gmultipath label d16-Z4D3W7NZ000 da16 da40
  24. sudo gmultipath label d17-Z4D3W7QE000 da17 da41
  25. sudo gmultipath label d18-Z4D3VBQD000 da18 da42
  26. sudo gmultipath label d19-Z4D3RYSK000 da19 da43
  27. sudo gmultipath label d20-Z4D3RYY0000 da20 da44
  28. sudo gmultipath label d21-Z4D3RZ1M000 da21 da45
  29. sudo gmultipath label d22-Z4D3RYRQ000 da22 da46
  30. sudo gmultipath label d23-Z4D3W76C000 da23 da47
  31.  
  32. # Automatically creating the cache pool from the multipath device labels
  33. cd /dev
  34. sudo zpool create cache $( \ls multipath/* | sort | awk '(A=$0)&&getline,$0=sprintf("mirror %s %s",A,$0)' )
  35.  
  36. # Results in the following single command being executed
  37. sudo zpool create cache mirror multipath/d00-Z4D3WM7A000 multipath/d01-Z4D3RYTJ000 mirror multipath/d02-Z4D3RYVW000 multipath/d03-Z4D3RYTL000 mirror multipath/d04-Z4D3RYZY000 multipath/d05-Z4D3RYQX000 mirror multipath/d06-Z4D3WMQB000 multipath/d07-Z4D3WLV6000 mirror multipath/d08-Z4D3WLYN000 multipath/d09-Z4D3WMA0000 mirror multipath/d10-Z4D3RZ27000 multipath/d11-Z4D3WMLY000 mirror multipath/d12-Z4D3WM1F000 multipath/d13-Z4D3W7M9000 mirror multipath/d14-Z4D3WMAF000 multipath/d15-Z4D3WM45000 mirror multipath/d16-Z4D3W7NZ000 multipath/d17-Z4D3W7QE000 mirror multipath/d18-Z4D3VBQD000 multipath/d19-Z4D3RYSK000 mirror multipath/d20-Z4D3RYY0000 multipath/d21-Z4D3RZ1M000 mirror multipath/d22-Z4D3RYRQ000 multipath/d23-Z4D3W76C000
  38.  
  39. # The results are a raid10 cache array
  40. zpool status cache
  41.  
  42. #   pool: cache
  43. #  state: ONLINE
  44. #   scan: none requested
  45. # config:
  46. #
  47. #   NAME                           STATE     READ WRITE CKSUM
  48. #   cache                          ONLINE       0     0     0
  49. #     mirror-0                     ONLINE       0     0     0
  50. #       multipath/d00-Z4D3WM7A000  ONLINE       0     0     0
  51. #       multipath/d01-Z4D3RYTJ000  ONLINE       0     0     0
  52. #     mirror-1                     ONLINE       0     0     0
  53. #       multipath/d02-Z4D3RYVW000  ONLINE       0     0     0
  54. #       multipath/d03-Z4D3RYTL000  ONLINE       0     0     0
  55. #     mirror-2                     ONLINE       0     0     0
  56. #       multipath/d04-Z4D3RYZY000  ONLINE       0     0     0
  57. #       multipath/d05-Z4D3RYQX000  ONLINE       0     0     0
  58. #     mirror-3                     ONLINE       0     0     0
  59. #       multipath/d06-Z4D3WMQB000  ONLINE       0     0     0
  60. #       multipath/d07-Z4D3WLV6000  ONLINE       0     0     0
  61. #     mirror-4                     ONLINE       0     0     0
  62. #       multipath/d08-Z4D3WLYN000  ONLINE       0     0     0
  63. #       multipath/d09-Z4D3WMA0000  ONLINE       0     0     0
  64. #     mirror-5                     ONLINE       0     0     0
  65. #       multipath/d10-Z4D3RZ27000  ONLINE       0     0     0
  66. #       multipath/d11-Z4D3WMLY000  ONLINE       0     0     0
  67. #     mirror-6                     ONLINE       0     0     0
  68. #       multipath/d12-Z4D3WM1F000  ONLINE       0     0     0
  69. #       multipath/d13-Z4D3W7M9000  ONLINE       0     0     0
  70. #     mirror-7                     ONLINE       0     0     0
  71. #       multipath/d14-Z4D3WMAF000  ONLINE       0     0     0
  72. #       multipath/d15-Z4D3WM45000  ONLINE       0     0     0
  73. #     mirror-8                     ONLINE       0     0     0
  74. #       multipath/d16-Z4D3W7NZ000  ONLINE       0     0     0
  75. #       multipath/d17-Z4D3W7QE000  ONLINE       0     0     0
  76. #     mirror-9                     ONLINE       0     0     0
  77. #       multipath/d18-Z4D3VBQD000  ONLINE       0     0     0
  78. #       multipath/d19-Z4D3RYSK000  ONLINE       0     0     0
  79. #     mirror-10                    ONLINE       0     0     0
  80. #       multipath/d20-Z4D3RYY0000  ONLINE       0     0     0
  81. #       multipath/d21-Z4D3RZ1M000  ONLINE       0     0     0
  82. #     mirror-11                    ONLINE       0     0     0
  83. #       multipath/d22-Z4D3RYRQ000  ONLINE       0     0     0
  84. #       multipath/d23-Z4D3W76C000  ONLINE       0     0     0
  85. #
  86. # errors: No known data errors
  87.  
  88. # Other minor adjustments
  89. sudo zfs set mountpoint=none cache
  90. sudo zfs create cache/d0
  91. sudo zfs set mountpoint=/d0 cache/d0
  92.  
  93. # Results are a /d0 cache bucket
  94. df -hT
  95.  
  96. # Filesystem          Type     Size    Used   Avail Capacity  Mounted on
  97. # zroot/ROOT/default  zfs      213G    878M    212G     0%    /
  98. # devfs               devfs    1.0K    1.0K      0B   100%    /dev
  99. # zroot/tmp           zfs      212G    120K    212G     0%    /tmp
  100. # zroot/usr/home      zfs      212G    3.0M    212G     0%    /usr/home
  101. # zroot/usr/ports     zfs      212G     96K    212G     0%    /usr/ports
  102. # zroot/usr/src       zfs      212G     96K    212G     0%    /usr/src
  103. # zroot/var/audit     zfs      212G     96K    212G     0%    /var/audit
  104. # zroot/var/crash     zfs      212G     96K    212G     0%    /var/crash
  105. # zroot/var/log       zfs      212G    464K    212G     0%    /var/log
  106. # zroot/var/mail      zfs      212G    136K    212G     0%    /var/mail
  107. # zroot/var/tmp       zfs      212G    104K    212G     0%    /var/tmp
  108. # cache/d0            zfs       63T     96K     63T     0%    /d0
Add Comment
Please, Sign In to add comment