当前位置:   article > 正文

虚拟化场景下Centos7.x 下的 LVM分区扩容_centos7虚拟机lvm扩容

centos7虚拟机lvm扩容

目录

1、前提说明

2、操作步骤

2.1 备份系统当前情况(很重要)

2.2 虚拟机的磁盘扩容

2.3 系统的新磁盘容量识别更新

2.4 对LVM使用的分区sda2扩容

2.5LVM的PV磁盘更新

2.6 磁盘逻辑卷扩容和文件系统扩容

3、总结:


1、前提说明

       本文适用于虚拟化或者云平台场景下的LINUX分区扩容,虚拟机平台的磁盘支持扩容操作,虚拟机的操作系统采用了LVM的分区格式。本文以常见的VMWARE ESXI虚拟机为例。

2、操作步骤

       思路:虚拟机的磁盘扩容---->虚拟机的磁盘容量更新识别---->虚拟机的分区扩容resize---->LVM的PV磁盘更新------>LogicVolume的扩容----> 文件系统xfs扩容

2.1 备份系统当前情况(很重要)

       主要是数据备份、收集配置备份,扩容是对数据的高危操作,要十分谨慎。

  1. #lsblk
  2. #df -h
  3. #pvdisplay
  4. #vgdisplay
  5. #lvdisplay
  6. #parted -l
  7. #fdisk -l

2.2 虚拟机的磁盘扩容

     比如原先是虚拟机是300的磁盘,扩容到600G。直接右键编辑虚拟机设置硬盘的新的容量。确认后保存。

2.3 系统的新磁盘容量识别更新

  1. 刷新磁盘容量:
  2. [root@localhost ~]# ls /sys/class/scsi_device/
  3. 0:0:0:0 3:0:0:0
  4. [root@localhost ~]# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
  5. [root@localhost ~]# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
  6. [root@localhost ~]# lsblk
  7. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  8. sda 8:0 0 600G 0 disk
  9. ├─sda1 8:1 0 1G 0 part /boot
  10. └─sda2 8:2 0 296.1G 0 part
  11. ├─centos-root 253:0 0 270G 0 lvm /
  12. ├─centos-swap 253:1 0 16G 0 lvm [SWAP]
  13. └─centos-home 253:2 0 10.1G 0 lvm /home
  14. sr0 11:0 1 4.4G 0 rom

2.4 对LVM使用的分区sda2扩容

  1. [root@opscenter log]# parted (此处案例不是600G,主要是演示resize过程)
  2. GNU Parted 3.1
  3. Using /dev/sda
  4. Welcome to GNU Parted! Type 'help' to view a list of commands.
  5. (parted) p
  6. Model: VMware Virtual disk (scsi)
  7. Disk /dev/sda: 1100GB
  8. Sector size (logical/physical): 512B/512B
  9. Partition Table: msdos
  10. Disk Flags:
  11. Number Start End Size Type File system Flags
  12. 1 1049kB 1075MB 1074MB primary xfs boot
  13. 2 1075MB 1002GB 1001GB primary lvm
  14. (parted) 2
  15. align-check TYPE N check partition N for TYPE(min|opt) alignment
  16. help [COMMAND] print general help, or help on COMMAND
  17. mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
  18. mkpart PART-TYPE [FS-TYPE] START END make a partition
  19. name NUMBER NAME name partition NUMBER as NAME
  20. print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
  21. quit exit program
  22. rescue START END rescue a lost partition near START and END
  23. resizepart NUMBER END resize partition NUMBER
  24. rm NUMBER delete partition NUMBER
  25. select DEVICE choose the device to edit
  26. disk_set FLAG STATE change the FLAG on selected device
  27. disk_toggle [FLAG] toggle the state of FLAG on selected device
  28. set NUMBER FLAG STATE change the FLAG on partition NUMBER
  29. toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
  30. unit UNIT set the default unit to UNIT
  31. version display the version number and copyright information of GNU Parted
  32. (parted) resizepart #(调整分区功能)
  33. Partition number? 2 #(选择分区2)
  34. End? [1002GB]? 1052G #(写入新的容量,不需要管起始位置)
  35. (parted) p
  36. Model: VMware Virtual disk (scsi)
  37. Disk /dev/sda: 1100GB
  38. Sector size (logical/physical): 512B/512B
  39. Partition Table: msdos
  40. Disk Flags:
  41. Number Start End Size Type File system Flags
  42. 1 1049kB 1075MB 1074MB primary xfs boot
  43. 2 1075MB 1052GB 1051GB primary lvm
  44. (parted) w #(保存分区表)
  45. align-check TYPE N check partition N for TYPE(min|opt) alignment
  46. help [COMMAND] print general help, or help on COMMAND
  47. mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
  48. mkpart PART-TYPE [FS-TYPE] START END make a partition
  49. name NUMBER NAME name partition NUMBER as NAME
  50. print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
  51. quit exit program
  52. rescue START END rescue a lost partition near START and END
  53. resizepart NUMBER END resize partition NUMBER
  54. rm NUMBER delete partition NUMBER
  55. select DEVICE choose the device to edit
  56. disk_set FLAG STATE change the FLAG on selected device
  57. disk_toggle [FLAG] toggle the state of FLAG on selected device
  58. set NUMBER FLAG STATE change the FLAG on partition NUMBER
  59. toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
  60. unit UNIT set the default unit to UNIT
  61. version display the version number and copyright information of GNU Parted
  62. (parted) q
  63. Information: You may need to update /etc/fstab.
  64. [root@opscenter log]# parted # (确认生效)
  65. GNU Parted 3.1
  66. Using /dev/sda
  67. Welcome to GNU Parted! Type 'help' to view a list of commands.
  68. (parted) p
  69. Model: VMware Virtual disk (scsi)
  70. Disk /dev/sda: 1100GB
  71. Sector size (logical/physical): 512B/512B
  72. Partition Table: msdos
  73. Disk Flags:
  74. Number Start End Size Type File system Flags
  75. 1 1049kB 1075MB 1074MB primary xfs boot
  76. 2 1075MB 1052GB 1051GB primary lvm
  77. (parted)
  78. (parted) q

2.5LVM的PV磁盘更新

分区扩容完毕后,需要LVM重新识别PV容量

  1. [root@opscenter log]# pvresize /dev/sda2 #(调整识别新的pvsize分区大小)
  2. Physical volume "/dev/sda2" changed
  3. 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
  4. [root@opscenter log]# pvdisplay
  5. --- Physical volume ---
  6. PV Name /dev/sda2
  7. VG Name rhel
  8. PV Size <978.75 GiB / not usable 3.38 MiB
  9. Allocatable yes
  10. PE Size 4.00 MiB
  11. Total PE 250559
  12. Free PE 11968
  13. Allocated PE 238591
  14. PV UUID V25Vwm-yFff-Kcft-s69N-JKyb-mCV8-9O7XM9
  15. [root@opscenter ~]# vgdisplay #(查看free空间是否增加)

2.6 磁盘逻辑卷扩容和文件系统扩容

   首先要扩容逻辑卷block设备。然后再扩容对应的文件系统。

  1. [root@opscenter ~]# lvextend -L +40G /dev/mapper/rhel-root # (演示扩容分区40G)
  2. Size of logical volume rhel/root changed from 900.00 GiB (230400 extents) to 940.00 GiB (240640 extents).
  3. Logical volume rhel/root successfully resized.
  4. [root@opscenter ~]# xfs_growfs /dev/mapper/rhel-root # (演示根分区/扩容xfs文件系统,如果是ext的话,应该采用resize2fs 命令来扩文件系统)
  5. meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=58982400 blks
  6. = sectsz=512 attr=2, projid32bit=1
  7. = crc=1 finobt=0 spinodes=0
  8. data = bsize=4096 blocks=235929600, imaxpct=25
  9. = sunit=0 swidth=0 blks
  10. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
  11. log =internal bsize=4096 blocks=115200, version=2
  12. = sectsz=512 sunit=0 blks, lazy-count=1
  13. realtime =none extsz=4096 blocks=0, rtextents=0
  14. data blocks changed from 235929600 to 246415360
  15. [root@opscenter ~]# df -h #(演示检查扩容结果)
  16. Filesystem Size Used Avail Use% Mounted on
  17. /dev/mapper/rhel-root 940G 9.9G 930G 2% /
  18. devtmpfs 7.8G 0 7.8G 0% /dev
  19. tmpfs 7.8G 0 7.8G 0% /dev/shm
  20. tmpfs 7.8G 25M 7.8G 1% /run
  21. tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
  22. /dev/sda1 1014M 150M 865M 15% /boot
  23. tmpfs 1.6G 0 1.6G 0% /run/user/0

至此整个扩容结束。

3、总结:

   本文是扩容直接磁盘的方式。此外还有往系统再增加一个物理硬盘,加入到rootvg中,再扩容LVM逻辑卷的方案。

对于采用Linux标准物理分区的系统,可能也可以适用,采用growpart工具扩容分区,等下次有空测试一下。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/126405
推荐阅读
相关标签
  

闽ICP备14008679号