虚拟机磁盘扩容
    参考:https://blog.csdn.net/qq_26963433/article/details/79467959
    lsblk -f查看连接的磁盘设备和文件格式

    假设原虚拟机使用xfs格式的逻辑卷

    1. 扩容硬盘,假设扩容设备为/dev/vdb,从100g扩容到200g
    2. 增加分区fdisk,类型为8e (如果使用整块盘,此步骤非必要)
      1. fdisk -l 查看分区
      2. fdisk /dev/vdb,n新建分区其他默认,
      3. p查看类型,类型不对用t修改
      4. w保存
      5. partprobe启用分区表
    3. 创建物理卷
      1. pvdisplay查看
      2. pvcreate /dev/vdb2
    4. 扩展卷组
      1. vgdisplay查看 ,原vg名为vg_data
      2. vgextend vg_data /dev/vdb2
    5. 扩展逻辑卷
      1. lvdisplay查看,copy原lv路径
      2. lvextend -l +100%FREE /dev/vg_data/lv_data
    6. 刷新文件系统大小
      1. 扩容文件系统xfs_growfs /dev/vg_data/lv_data
      2. 其他文件格式是用resize2fs /dev/vg_data/lv_data
    7. 查看生效 df

    举例:

    1. [root@srd-code-gerrit-2 ~]# fdisk -l
    2. Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    3. Units = sectors of 1 * 512 = 512 bytes
    4. Sector size (logical/physical): 512 bytes / 512 bytes
    5. I/O size (minimum/optimal): 512 bytes / 512 bytes
    6. Disk label type: dos
    7. Disk identifier: 0x000bcc64
    8. Device Boot Start End Blocks Id System
    9. /dev/vda1 2048 8390655 4194304 82 Linux swap / Solaris
    10. /dev/vda2 * 8390656 83886046 37747695+ 83 Linux
    11. Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
    12. Units = sectors of 1 * 512 = 512 bytes
    13. Sector size (logical/physical): 512 bytes / 512 bytes
    14. I/O size (minimum/optimal): 512 bytes / 512 bytes
    15. Disk label type: dos
    16. Disk identifier: 0x19260f80
    17. Device Boot Start End Blocks Id System
    18. /dev/vdb1 2048 419430399 209714176 8e Linux LVM
    19. Disk /dev/mapper/vg_data-lv_data: 214.7 GB, 214744170496 bytes, 419422208 sectors
    20. Units = sectors of 1 * 512 = 512 bytes
    21. Sector size (logical/physical): 512 bytes / 512 bytes
    22. I/O size (minimum/optimal): 512 bytes / 512 bytes
    23. [root@srd-code-gerrit-2 ~]# fdisk /dev/vdb
    24. Welcome to fdisk (util-linux 2.23.2).
    25. Changes will remain in memory only, until you decide to write them.
    26. Be careful before using the write command.
    27. Command (m for help): p
    28. Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
    29. Units = sectors of 1 * 512 = 512 bytes
    30. Sector size (logical/physical): 512 bytes / 512 bytes
    31. I/O size (minimum/optimal): 512 bytes / 512 bytes
    32. Disk label type: dos
    33. Disk identifier: 0x19260f80
    34. Device Boot Start End Blocks Id System
    35. /dev/vdb1 2048 419430399 209714176 8e Linux LVM
    36. Command (m for help): n
    37. Partition type:
    38. p primary (1 primary, 0 extended, 3 free)
    39. e extended
    40. Select (default p):
    41. Using default response p
    42. Partition number (2-4, default 2):
    43. First sector (419430400-1048575999, default 419430400):
    44. Using default value 419430400
    45. Last sector, +sectors or +size{K,M,G} (419430400-1048575999, default 1048575999):
    46. Using default value 1048575999
    47. Partition 2 of type Linux and of size 300 GiB is set
    48. Command (m for help): p
    49. Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
    50. Units = sectors of 1 * 512 = 512 bytes
    51. Sector size (logical/physical): 512 bytes / 512 bytes
    52. I/O size (minimum/optimal): 512 bytes / 512 bytes
    53. Disk label type: dos
    54. Disk identifier: 0x19260f80
    55. Device Boot Start End Blocks Id System
    56. /dev/vdb1 2048 419430399 209714176 8e Linux LVM
    57. /dev/vdb2 419430400 1048575999 314572800 83 Linux
    58. Command (m for help): t
    59. Partition number (1,2, default 2):
    60. Hex code (type L to list all codes): 8e
    61. Changed type of partition 'Linux' to 'Linux LVM'
    62. Command (m for help): p
    63. Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
    64. Units = sectors of 1 * 512 = 512 bytes
    65. Sector size (logical/physical): 512 bytes / 512 bytes
    66. I/O size (minimum/optimal): 512 bytes / 512 bytes
    67. Disk label type: dos
    68. Disk identifier: 0x19260f80
    69. Device Boot Start End Blocks Id System
    70. /dev/vdb1 2048 419430399 209714176 8e Linux LVM
    71. /dev/vdb2 419430400 1048575999 314572800 8e Linux LVM
    72. Command (m for help): w
    73. The partition table has been altered!
    74. Calling ioctl() to re-read partition table.
    75. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    76. The kernel still uses the old table. The new table will be used at
    77. the next reboot or after you run partprobe(8) or kpartx(8)
    78. Syncing disks.
    79. [root@srd-code-gerrit-2 ~]# partprobe
    80. [root@srd-code-gerrit-2 ~]# pvdisplay
    81. --- Physical volume ---
    82. PV Name /dev/vdb1
    83. VG Name vg_data
    84. PV Size <200.00 GiB / not usable 3.00 MiB
    85. Allocatable yes (but full)
    86. PE Size 4.00 MiB
    87. Total PE 51199
    88. Free PE 0
    89. Allocated PE 51199
    90. PV UUID mmVYBe-1OHD-PZSJ-KyBd-IgIM-cMNz-hlYl0y
    91. [root@srd-code-gerrit-2 ~]# pvcreate /dev/vdb2
    92. Physical volume "/dev/vdb2" successfully created.
    93. [root@srd-code-gerrit-2 ~]# lvdisplay
    94. --- Logical volume ---
    95. LV Path /dev/vg_data/lv_data
    96. LV Name lv_data
    97. VG Name vg_data
    98. LV UUID OT7IYK-xaSX-KbPs-k8zb-bjWb-N9od-uNE1oE
    99. LV Write Access read/write
    100. LV Creation host, time srd-code-gerrit-2, 2021-06-17 16:19:12 +0800
    101. LV Status available
    102. # open 1
    103. LV Size <200.00 GiB
    104. Current LE 51199
    105. Segments 1
    106. Allocation inherit
    107. Read ahead sectors auto
    108. - currently set to 8192
    109. Block device 252:0
    110. [root@srd-code-gerrit-2 ~]# vgdisplay
    111. --- Volume group ---
    112. VG Name vg_data
    113. System ID
    114. Format lvm2
    115. Metadata Areas 1
    116. Metadata Sequence No 2
    117. VG Access read/write
    118. VG Status resizable
    119. MAX LV 0
    120. Cur LV 1
    121. Open LV 1
    122. Max PV 0
    123. Cur PV 1
    124. Act PV 1
    125. VG Size <200.00 GiB
    126. PE Size 4.00 MiB
    127. Total PE 51199
    128. Alloc PE / Size 51199 / <200.00 GiB
    129. Free PE / Size 0 / 0
    130. VG UUID c3ZqAV-TBt7-nG4W-XYao-d407-sZib-U3QAyc
    131. [root@srd-code-gerrit-2 ~]# vgextend vg_data /dev/vdb2
    132. Volume group "vg_data" successfully extended
    133. [root@srd-code-gerrit-2 ~]# lvextend -l +100%FREE /dev/vg_data/lv_data
    134. Size of logical volume vg_data/lv_data changed from <200.00 GiB (51199 extents) to 499.99 GiB (127998 extents).
    135. Logical volume vg_data/lv_data successfully resized.
    136. [root@srd-code-gerrit-2 ~]# df -h
    137. Filesystem Size Used Avail Use% Mounted on
    138. devtmpfs 126G 0 126G 0% /dev
    139. tmpfs 126G 0 126G 0% /dev/shm
    140. tmpfs 126G 17M 126G 1% /run
    141. tmpfs 126G 0 126G 0% /sys/fs/cgroup
    142. /dev/vda2 36G 3.6G 30G 11% /
    143. /dev/mapper/vg_data-lv_data 197G 110G 78G 59% /data
    144. sfs-nas1.cn-sz1.internal.ctclouds.com:/share-d5c508dc 1000G 90G 911G 9% /mnt/gerritgit
    145. overlay 197G 110G 78G 59% /data/docker/overlay2/af9b9127e31a43d2fcf827b12169de493a14197d91ddc6c402618e31c1067be2/merged
    146. shm 64M 0 64M 0% /data/docker/containers/0b0d772defa1335aff1e9c0d58f1a81b0a2b7c1fc3635e07d85051941f31321a/shm
    147. tmpfs 26G 0 26G 0% /run/user/0
    148. [root@srd-code-gerrit-2 ~]# resize2fs /dev/vg_data/lv_data
    149. resize2fs 1.42.9 (28-Dec-2013)
    150. Filesystem at /dev/vg_data/lv_data is mounted on /data; on-line resizing required
    151. old_desc_blocks = 25, new_desc_blocks = 63
    152. The filesystem on /dev/vg_data/lv_data is now 131069952 blocks long.
    153. [root@srd-code-gerrit-2 ~]# df -h
    154. Filesystem Size Used Avail Use% Mounted on
    155. devtmpfs 126G 0 126G 0% /dev
    156. tmpfs 126G 0 126G 0% /dev/shm
    157. tmpfs 126G 17M 126G 1% /run
    158. tmpfs 126G 0 126G 0% /sys/fs/cgroup
    159. /dev/vda2 36G 3.6G 30G 11% /
    160. /dev/mapper/vg_data-lv_data 493G 110G 361G 24% /data
    161. sfs-nas1.cn-sz1.internal.ctclouds.com:/share-d5c508dc 1000G 90G 911G 9% /mnt/gerritgit
    162. overlay 493G 110G 361G 24% /data/docker/overlay2/af9b9127e31a43d2fcf827b12169de493a14197d91ddc6c402618e31c1067be2/merged
    163. shm 64M 0 64M 0% /data/docker/containers/0b0d772defa1335aff1e9c0d58f1a81b0a2b7c1fc3635e07d85051941f31321a/shm
    164. tmpfs 26G 0 26G 0% /run/user/0
    165. [root@srd-code-gerrit-2 ~]#