您现在的位置是:首页 > 文章详情

centos6.x 使用raid5构建lvm逻辑卷

日期:2018-05-11点击:660

1、将之前实验环境还原:

a、利用umount先卸载之前挂载的文件系统;

b、修改/etc/fstab里面的数据,让开机不会自动挂载;

c、利用fdisk将该分区删除;

整合raid5和lvm实验
实验环境:
一块6G的盘,分成5个分区,每个分区1G。

其中4个作为active态,一个为spare态。

fdisk -l

开始磁盘分区:

[plain]  view plain  copy

  1. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  2. 255 heads, 63 sectors/track, 783 cylinders
  3. Units = cylinders of 16065 * 512 = 8225280 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk identifier: 0x00000000
[plain]  view plain  copy

  1. [root@srcxtts ~]# fdisk /dev/sdd
  2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  3. Building a new DOS disklabel with disk identifier 0x95cc4770.
  4. Changes will remain in memory only, until you decide to write them.
  5. After that, of course, the previous content won't be recoverable.
  6. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  7. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  8.          switch off the mode (command 'c') and change display units to
  9.          sectors (command 'u').
  10. Command (m for help): p
  11. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  12. 255 heads, 63 sectors/track, 783 cylinders
  13. Units = cylinders of 16065 * 512 = 8225280 bytes
  14. Sector size (logical/physical): 512 bytes / 512 bytes
  15. I/O size (minimum/optimal): 512 bytes / 512 bytes
  16. Disk identifier: 0x95cc4770
  17.    Device Boot      Start         End      Blocks   Id  System
  18. Command (m for help): n
  19. Command action
  20.    e   extended
  21.    p   primary partition (1-4)
  22. p
  23. Partition number (1-4): 1
  24. First cylinder (1-783, default 1):
  25. Using default value 1
  26. Last cylinder, +cylinders or +size{K,M,G} (1-783, default 783): +1G
  27. Command (m for help): p
  28. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  29. 255 heads, 63 sectors/track, 783 cylinders
  30. Units = cylinders of 16065 * 512 = 8225280 bytes
  31. Sector size (logical/physical): 512 bytes / 512 bytes
  32. I/O size (minimum/optimal): 512 bytes / 512 bytes
  33. Disk identifier: 0x95cc4770
  34.    Device Boot      Start         End      Blocks   Id  System
  35. /dev/sdd1               1         132     1060258+  83  Linux
  36. Command (m for help): n
  37. Command action
  38.    e   extended
  39.    p   primary partition (1-4)
  40. p
  41. Partition number (1-4): 2
  42. First cylinder (133-783, default 133):
  43. Using default value 133
  44. Last cylinder, +cylinders or +size{K,M,G} (133-783, default 783): +1G
  45. Command (m for help): p
  46. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  47. 255 heads, 63 sectors/track, 783 cylinders
  48. Units = cylinders of 16065 * 512 = 8225280 bytes
  49. Sector size (logical/physical): 512 bytes / 512 bytes
  50. I/O size (minimum/optimal): 512 bytes / 512 bytes
  51. Disk identifier: 0x95cc4770
  52.    Device Boot      Start         End      Blocks   Id  System
  53. /dev/sdd1               1         132     1060258+  83  Linux
  54. /dev/sdd2             133         264     1060290   83  Linux
  55. Command (m for help): n
  56. Command action
  57.    e   extended
  58.    p   primary partition (1-4)
  59. p
  60. Partition number (1-4): 3
  61. First cylinder (265-783, default 265):
  62. Using default value 265
  63. Last cylinder, +cylinders or +size{K,M,G} (265-783, default 783): +1G
  64. Command (m for help): p
  65. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  66. 255 heads, 63 sectors/track, 783 cylinders
  67. Units = cylinders of 16065 * 512 = 8225280 bytes
  68. Sector size (logical/physical): 512 bytes / 512 bytes
  69. I/O size (minimum/optimal): 512 bytes / 512 bytes
  70. Disk identifier: 0x95cc4770
  71.    Device Boot      Start         End      Blocks   Id  System
  72. /dev/sdd1               1         132     1060258+  83  Linux
  73. /dev/sdd2             133         264     1060290   83  Linux
  74. /dev/sdd3             265         396     1060290   83  Linux
  75. Command (m for help): n
  76. Command action
  77.    e   extended
  78.    p   primary partition (1-4)
  79. e
  80. Selected partition 4
  81. First cylinder (397-783, default 397):
  82. Using default value 397
  83. Last cylinder, +cylinders or +size{K,M,G} (397-783, default 783):
  84. Using default value 783
  85. Command (m for help): p
  86. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  87. 255 heads, 63 sectors/track, 783 cylinders
  88. Units = cylinders of 16065 * 512 = 8225280 bytes
  89. Sector size (logical/physical): 512 bytes / 512 bytes
  90. I/O size (minimum/optimal): 512 bytes / 512 bytes
  91. Disk identifier: 0x95cc4770
  92.    Device Boot      Start         End      Blocks   Id  System
  93. /dev/sdd1               1         132     1060258+  83  Linux
  94. /dev/sdd2             133         264     1060290   83  Linux
  95. /dev/sdd3             265         396     1060290   83  Linux
  96. /dev/sdd4             397         783     3108577+   5  Extended
  97. Command (m for help): n
  98. First cylinder (397-783, default 397):
  99. Using default value 397
  100. Last cylinder, +cylinders or +size{K,M,G} (397-783, default 783): +1G
  101. Command (m for help): p
  102. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  103. 255 heads, 63 sectors/track, 783 cylinders
  104. Units = cylinders of 16065 * 512 = 8225280 bytes
  105. Sector size (logical/physical): 512 bytes / 512 bytes
  106. I/O size (minimum/optimal): 512 bytes / 512 bytes
  107. Disk identifier: 0x95cc4770
  108.    Device Boot      Start         End      Blocks   Id  System
  109. /dev/sdd1               1         132     1060258+  83  Linux
  110. /dev/sdd2             133         264     1060290   83  Linux
  111. /dev/sdd3             265         396     1060290   83  Linux
  112. /dev/sdd4             397         783     3108577+   5  Extended
  113. /dev/sdd5             397         528     1060258+  83  Linux
  114. Command (m for help): n
  115. First cylinder (529-783, default 529):
  116. Using default value 529
  117. Last cylinder, +cylinders or +size{K,M,G} (529-783, default 783): +1G
  118. Command (m for help): p
  119. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  120. 255 heads, 63 sectors/track, 783 cylinders
  121. Units = cylinders of 16065 * 512 = 8225280 bytes
  122. Sector size (logical/physical): 512 bytes / 512 bytes
  123. I/O size (minimum/optimal): 512 bytes / 512 bytes
  124. Disk identifier: 0x95cc4770
  125.    Device Boot      Start         End      Blocks   Id  System
  126. /dev/sdd1               1         132     1060258+  83  Linux
  127. /dev/sdd2             133         264     1060290   83  Linux
  128. /dev/sdd3             265         396     1060290   83  Linux
  129. /dev/sdd4             397         783     3108577+   5  Extended
  130. /dev/sdd5             397         528     1060258+  83  Linux
  131. /dev/sdd6             529         660     1060258+  83  Linux
  132. Command (m for help): w
  133. The partition table has been altered!
  134. Calling ioctl() to re-read partition table.
  135. Syncing disks.

2、创建raid5磁盘

[plain]  view plain  copy

  1. [root@srcxtts ~]# mdadm --create --auto=yes /dev/md0 --level=5 \
  2. > --raid-devices=4 --spare-devices=1 /dev/sdd{1,2,3,5,6}
  3. mdadm: Defaulting to version 1.2 metadata
  4. mdadm: array /dev/md0 started.
  5. [root@srcxtts ~]# ll /dev/md0
  6. brw-rw----. 1 root disk 9, 0 5月  10 09:26 /dev/md0
  7. [root@srcxtts ~]# cat /proc/mdstat
  8. Personalities : [raid6] [raid5] [raid4]
  9. md0 : active raid5 sdd5[5] sdd6[4](S) sdd3[2] sdd2[1] sdd1[0]
  10.       3176448 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
  11. unused devices: <none>

3、对raid5磁盘/dev/md0创建pv

[plain]  view plain  copy

  1. [root@srcxtts ~]# pvcreate /dev/md0
  2.   Physical volume "/dev/md0" successfully created
  3. [root@srcxtts ~]# pvdisplay /dev/md0
  4.   "/dev/md0" is a new physical volume of "3.03 GiB"
  5.   --- NEW Physical volume ---
  6.   PV Name               /dev/md0
  7.   VG Name
  8.   PV Size               3.03 GiB
  9.   Allocatable           NO
  10.   PE Size               0
  11.   Total PE              0
  12.   Free PE               0
  13.   Allocated PE          0
  14.   PV UUID               GjGVBh-z3h6-uyD0-xNjQ-LflN-j1gb-XvR4I7

4、根据生成的pv创建vg,参数默认,pe大小默认4M

[plain]  view plain  copy

  1. [root@srcxtts ~]# vgcreate raidvg /dev/md0
  2.   Volume group "raidvg" successfully created
[plain]  view plain  copy

  1. [root@srcxtts ~]# vgdisplay raidvg
  2.   --- Volume group ---
  3.   VG Name               raidvg
  4.   System ID
  5.   Format                lvm2
  6.   Metadata Areas        1
  7.   Metadata Sequence No  1
  8.   VG Access             read/write
  9.   VG Status             resizable
  10.   MAX LV                0
  11.   Cur LV                0
  12.   Open LV               0
  13.   Max PV                0
  14.   Cur PV                1
  15.   Act PV                1
  16.   VG Size               3.03 GiB
  17.   PE Size               4.00 MiB
  18.   Total PE              775
  19.   Alloc PE / Size       0 / 0
  20.   Free  PE / Size       775 / 3.03 GiB
  21.   VG UUID               Jx2ZNz-juP4-g8fx-oPJ5-F3Mg-QYn4-WoZ5HO

 

5、把vg中全部的pe都分配给lv,创建lv

[plain]  view plain  copy

  1. [root@srcxtts ~]# lvcreate -l 775 -n raidlv raidvg
  2.   Logical volume "raidlv" created
  3. [root@srcxtts ~]# lvscan
  4.   ACTIVE            '/dev/vg_srcxtts/lv_root' [21.58 GiB] inherit
  5.   ACTIVE            '/dev/vg_srcxtts/lv_swap' [3.94 GiB] inherit
  6.   ACTIVE            '/dev/raidvg/raidlv' [3.03 GiB] inherit
  7. [root@srcxtts ~]# lvdisplay /dev/raidvg/raidlv
  8.   --- Logical volume ---
  9.   LV Path                /dev/raidvg/raidlv
  10.   LV Name                raidlv
  11.   VG Name                raidvg
  12.   LV UUID                rOaylO-3Br7-sUo3-3IRZ-Rf4D-O5V8-A98KGh
  13.   LV Write Access        read/write
  14.   LV Creation host, time srcxtts, 2018-05-10 09:29:36 +0800
  15.   LV Status              available
  16.   # open                 0
  17.   LV Size                3.03 GiB
  18.   Current LE             775
  19.   Segments               1
  20.   Allocation             inherit
  21.   Read ahead sectors     auto
  22.   - currently set to     6144
  23.   Block device           253:2

6、将lv格式化为ext3文件系统

[plain]  view plain  copy

  1. [root@srcxtts ~]# mkfs.ext3 /dev/raidvg/raidlv
  2. mke2fs 1.41.12 (17-May-2010)
  3. 文件系统标签=
  4. 操作系统:Linux
  5. 块大小=4096 (log=2)
  6. 分块大小=4096 (log=2)
  7. Stride=128 blocks, Stripe width=384 blocks
  8. 198400 inodes, 793600 blocks
  9. 39680 blocks (5.00%) reserved for the super user
  10. 第一个数据块=0
  11. Maximum filesystem blocks=813694976
  12. 25 block groups
  13. 32768 blocks per group, 32768 fragments per group
  14. 7936 inodes per group
  15. Superblock backups stored on blocks:
  16.     32768, 98304, 163840, 229376, 294912
  17. 正在写入inode表: 完成
  18. Creating journal (16384 blocks): 完成
  19. Writing superblocks and filesystem accounting information: 完成
  20. This filesystem will be automatically checked every 33 mounts or
  21. 180 days, whichever comes first.  Use tune2fs -c or -i to override.

7、创建挂载点并挂载lv

[plain]  view plain  copy

  1. [root@srcxtts ~]# mkdir /mnt/raidlvm
  2. [root@srcxtts ~]# mount /dev/raidvg/raidlv /mnt/raidlvm
[plain]  view plain  copy

  1. [root@srcxtts ~]# df -h
  2. 文件系统          容量  已用  可用 已用%% 挂载点
  3. /dev/mapper/vg_srcxtts-lv_root
  4.                        22G   11G  9.4G  54% /
  5. tmpfs                 2.0G   84K  2.0G   1% /dev/shm
  6. /dev/sda1             477M   60M  392M  14% /boot
  7. /dev/mapper/raidvg-raidlv
  8.                       3.0G   69M  2.8G   3% /mnt/raidlvm
  9. [root@srcxtts ~]#

到此整合就完成了。

实验还原:

1、卸载lv文件系统

[plain]  view plain  copy

  1. [root@srcxtts ~]# umount /mnt/raidlvm
  2. [root@srcxtts ~]# df -h
  3. 文件系统          容量  已用  可用 已用%% 挂载点
  4. /dev/mapper/vg_srcxtts-lv_root
  5.                        22G   11G  9.4G  54% /
  6. tmpfs                 2.0G   84K  2.0G   1% /dev/shm
  7. /dev/sda1             477M   60M  392M  14% /boot

2、移除lv

[plain]  view plain  copy

  1. [root@srcxtts ~]# lvremove /dev/raidvg/raidlv
  2. Do you really want to remove active logical volume raidlv? [y/n]: y
  3.   Logical volume "raidlv" successfully removed

3、改变vg的状态为非active

[plain]  view plain  copy

  1. [root@srcxtts ~]# vgchange -an raidvg
  2.   0 logical volume(s) in volume group "raidvg" now active

4、移除vg

[plain]  view plain  copy

  1. [root@srcxtts ~]# vgremove raidvg
  2.   Volume group "raidvg" successfully removed

5、移除pv

[plain]  view plain  copy

  1. [root@srcxtts ~]# pvremove /dev/md0
  2.   Labels on physical volume "/dev/md0" successfully wiped

6、停md0 raid磁盘

[plain]  view plain  copy

  1. [root@srcxtts ~]# mdadm --stop /dev/md0
  2. mdadm: stopped /dev/md0

7、使用fdisk将磁盘还原

[plain]  view plain  copy

  1. [root@srcxtts ~]# fdisk /dev/sdd
  2. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  3.          switch off the mode (command 'c') and change display units to
  4.          sectors (command 'u').
  5. Command (m for help): p
  6. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  7. 255 heads, 63 sectors/track, 783 cylinders
  8. Units = cylinders of 16065 * 512 = 8225280 bytes
  9. Sector size (logical/physical): 512 bytes / 512 bytes
  10. I/O size (minimum/optimal): 512 bytes / 512 bytes
  11. Disk identifier: 0x95cc4770
  12.    Device Boot      Start         End      Blocks   Id  System
  13. /dev/sdd1               1         132     1060258+  83  Linux
  14. /dev/sdd2             133         264     1060290   83  Linux
  15. /dev/sdd3             265         396     1060290   83  Linux
  16. /dev/sdd4             397         783     3108577+   5  Extended
  17. /dev/sdd5             397         528     1060258+  83  Linux
  18. /dev/sdd6             529         660     1060258+  83  Linux
  19. Command (m for help): d
  20. Partition number (1-6): 1
  21. Command (m for help): d
  22. Partition number (1-6): 2
  23. Command (m for help): d
  24. Partition number (1-6): 3
  25. Command (m for help): d
  26. Partition number (1-6): 4
  27. Command (m for help): d
  28. No partition is defined yet!
  29. Command (m for help): 5
  30. 5: unknown command
  31. Command action
  32.    a   toggle a bootable flag
  33.    b   edit bsd disklabel
  34.    c   toggle the dos compatibility flag
  35.    d   delete a partition
  36.    l   list known partition types
  37.    m   print this menu
  38.    n   add a new partition
  39.    o   create a new empty DOS partition table
  40.    p   print the partition table
  41.    q   quit without saving changes
  42.    s   create a new empty Sun disklabel
  43.    t   change a partition's system id
  44.    u   change display/entry units
  45.    v   verify the partition table
  46.    w   write table to disk and exit
  47.    x   extra functionality (experts only)
  48. Command (m for help): w
  49. The partition table has been altered!
  50. Calling ioctl() to re-read partition table.
  51. Syncing disks.
  52. [root@srcxtts ~]# fdisk /dev/sdd
  53. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  54.          switch off the mode (command 'c') and change display units to
  55.          sectors (command 'u').
  56. Command (m for help): q
  57. [root@srcxtts ~]# fdisk /dev/sdd -l
  58. Disk /dev/sdd: 6442 MB, 6442450944 bytes
  59. 255 heads, 63 sectors/track, 783 cylinders
  60. Units = cylinders of 16065 * 512 = 8225280 bytes
  61. Sector size (logical/physical): 512 bytes / 512 bytes
  62. I/O size (minimum/optimal): 512 bytes / 512 bytes
  63. Disk identifier: 0x95cc4770
  64.    Device Boot      Start         End      Blocks   Id  System
  65. [root@srcxtts ~]#
原文链接:https://www.centoschina.cn/course/config-centos/10562.html
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章