起源:
准备测试tfs分布式存储,发现一台服务器24块大盘,还有好几台服务器, 想想那么碰分区格式化,UUID自动挂载,还好有自动脚本。
1,yes能在你需要输入y时帮你操作,要不一台服务器不间断24次y还不知道什么时候敲击
2,UUID也能自动获取,这样才能自动挂载且盘符能固定
  1. #!bin/bash
  2. #mkfs.ext4
  3. mkdir /data/disk{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}
  4. yes | mkfs.ext4 /dev/sdb
  5. yes | mkfs.ext4 /dev/sdc
  6. yes | mkfs.ext4 /dev/sdd
  7. yes | mkfs.ext4 /dev/sde
  8. yes | mkfs.ext4 /dev/sdf
  9. yes | mkfs.ext4 /dev/sdg
  10. yes | mkfs.ext4 /dev/sdh
  11. yes | mkfs.ext4 /dev/sdi
  12. yes | mkfs.ext4 /dev/sdj
  13. yes | mkfs.ext4 /dev/sdk
  14. yes | mkfs.ext4 /dev/sdl
  15. yes | mkfs.ext4 /dev/sdm
  16. yes | mkfs.ext4 /dev/sdn
  17. yes | mkfs.ext4 /dev/sdo
  18. yes | mkfs.ext4 /dev/sdp
  19. yes | mkfs.ext4 /dev/sdq
  20. yes | mkfs.ext4 /dev/sdr
  21. yes | mkfs.ext4 /dev/sds
  22. yes | mkfs.ext4 /dev/sdt
  23. yes | mkfs.ext4 /dev/sdu
  24. yes | mkfs.ext4 /dev/sdv
  25. yes | mkfs.ext4 /dev/sdw
  26. yes | mkfs.ext4 /dev/sdx
  27. yes | mkfs.ext4 /dev/sdy
  28. #mount
  29. mount -t ext4 /dev/sbb /data/disk1
  30. mount -t ext4 /dev/sdc /data/disk2
  31. mount -t ext4 /dev/sdd /data/disk3
  32. mount -t ext4 /dev/sde /data/disk4
  33. mount -t ext4 /dev/sdf /data/disk5
  34. mount -t ext4 /dev/sdg /data/disk6
  35. mount -t ext4 /dev/sdh /data/disk7
  36. mount -t ext4 /dev/sdi /data/disk8
  37. mount -t ext4 /dev/sdj /data/disk9
  38. mount -t ext4 /dev/sdk /data/disk10
  39. mount -t ext4 /dev/sdl /data/disk11
  40. mount -t ext4 /dev/sdm /data/disk12
  41. mount -t ext4 /dev/sdn /data/disk13
  42. mount -t ext4 /dev/sdo /data/disk14
  43. mount -t ext4 /dev/sdp /data/disk15
  44. mount -t ext4 /dev/sdq /data/disk16
  45. mount -t ext4 /dev/sdr /data/disk17
  46. mount -t ext4 /dev/sds /data/disk18
  47. mount -t ext4 /dev/sdt /data/disk19
  48. mount -t ext4 /dev/sdu /data/disk20
  49. mount -t ext4 /dev/sdv /data/disk21
  50. mount -t ext4 /dev/sdw /data/disk22
  51. mount -t ext4 /dev/sdx /data/disk23
  52. mount -t ext4 /dev/sdy /data/disk24
  53. #auto mount
  54. cp /etc/fstab /etc/fstab.bak
  55. blkid /dev/sdb |awk '{print $2 " /data/disk1 ext4 defaults 0 0"}' >>/etc/fstab
  56. blkid /dev/sdc |awk '{print $2 " /data/disk2 ext4 defaults 0 0"}' >>/etc/fstab
  57. blkid /dev/sdd |awk '{print $2 " /data/disk3 ext4 defaults 0 0"}' >>/etc/fstab
  58. blkid /dev/sde |awk '{print $2 " /data/disk4 ext4 defaults 0 0"}' >>/etc/fstab
  59. blkid /dev/sdf |awk '{print $2 " /data/disk5 ext4 defaults 0 0"}' >>/etc/fstab
  60. blkid /dev/sdg |awk '{print $2 " /data/disk6 ext4 defaults 0 0"}' >>/etc/fstab
  61. blkid /dev/sdh |awk '{print $2 " /data/disk7 ext4 defaults 0 0"}' >>/etc/fstab
  62. blkid /dev/sdi |awk '{print $2 " /data/disk8 ext4 defaults 0 0"}' >>/etc/fstab
  63. blkid /dev/sdj |awk '{print $2 " /data/disk9 ext4 defaults 0 0"}' >>/etc/fstab
  64. blkid /dev/sdk |awk '{print $2 " /data/disk10 ext4 defaults 0 0"}' >>/etc/fstab
  65. blkid /dev/sdl |awk '{print $2 " /data/disk11 ext4 defaults 0 0"}' >>/etc/fstab
  66. blkid /dev/sdm |awk '{print $2 " /data/disk12 ext4 defaults 0 0"}' >>/etc/fstab
  67. blkid /dev/sdn |awk '{print $2 " /data/disk13 ext4 defaults 0 0"}' >>/etc/fstab
  68. blkid /dev/sdo |awk '{print $2 " /data/disk14 ext4 defaults 0 0"}' >>/etc/fstab
  69. blkid /dev/sdp |awk '{print $2 " /data/disk15 ext4 defaults 0 0"}' >>/etc/fstab
  70. blkid /dev/sdq |awk '{print $2 " /data/disk16 ext4 defaults 0 0"}' >>/etc/fstab
  71. blkid /dev/sdr |awk '{print $2 " /data/disk17 ext4 defaults 0 0"}' >>/etc/fstab
  72. blkid /dev/sds |awk '{print $2 " /data/disk18 ext4 defaults 0 0"}' >>/etc/fstab
  73. blkid /dev/sdt |awk '{print $2 " /data/disk19 ext4 defaults 0 0"}' >>/etc/fstab
  74. blkid /dev/sdu |awk '{print $2 " /data/disk20 ext4 defaults 0 0"}' >>/etc/fstab
  75. blkid /dev/sdv |awk '{print $2 " /data/disk21 ext4 defaults 0 0"}' >>/etc/fstab
  76. blkid /dev/sdw |awk '{print $2 " /data/disk22 ext4 defaults 0 0"}' >>/etc/fstab
  77. blkid /dev/sdx |awk '{print $2 " /data/disk23 ext4 defaults 0 0"}' >>/etc/fstab
  78. blkid /dev/sdy |awk '{print $2 " /data/disk24 ext4 defaults 0 0"}' >>/etc/fstab



08-30 01:19