kvm虚拟机centos8磁盘扩容

34 篇文章 2 订阅

通过PVE搭建虚拟机,系统盘只有30G,发现使用的时候已经不足,需要进行扩容,

虚拟机关机状态,在PVE增加磁盘大小之后,虚机开机之后,还需要在虚拟机里面进行扩容操作

 

 开机检查磁盘大小

lsblk

  1. [root@localhost ~]# fdisk -l
  2. Disk /dev/vda: 132 GiB, 141733920768 bytes, 276824064 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. Disklabel type: dos
  7. Disk identifier: 0x79cee493
  8. Device Boot Start End Sectors Size Id Type
  9. /dev/vda1 * 2048 2099199 2097152 1G 83 Linux
  10. /dev/vda2 2099200 67108863 65009664 31G 8e Linux LVM
  11. Disk /dev/mapper/cs-root: 29 GiB, 31079792640 bytes, 60702720 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 /dev/mapper/cs-swap: 2.1 GiB, 2202009600 bytes, 4300800 sectors
  16. Units: sectors of 1 * 512 = 512 bytes
  17. Sector size (logical/physical): 512 bytes / 512 bytes
  18. I/O size (minimum/optimal): 512 bytes / 512 bytes

开始扩容

1.创建一个新的分区

依次输入以下指令

  1. n [添加分区]
  2. p [主分区]
  3. 3 [分区号,回车默认也是3]
  4. 默认 [直接回车]
  5. 默认 [直接回车]
  6. w [保存分区]
  1. [root@localhost ~]# fdisk /dev/vda
  2. Welcome to fdisk (util-linux 2.32.1).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Command (m for help): n
  6. Partition type
  7. p primary (2 primary, 0 extended, 2 free)
  8. e extended (container for logical partitions)
  9. Select (default p): p
  10. Partition number (3,4, default 3):
  11. First sector (67108864-276824063, default 67108864):
  12. Last sector, +sectors or +size{K,M,G,T,P} (67108864-276824063, default 276824063):
  13. Created a new partition 3 of type 'Linux' and of size 100 GiB.
  14. Command (m for help): w
  15. The partition table has been altered.
  16. Syncing disks.

 可以看到新的分区已经出现了

 2.将vda3分区初始化为物理卷

  1. partprobe
  2. pvcreate /dev/vda3

 3.查看跟分区所在的卷组信息

  1. vgdisplay
  2. # vgs

 

 4.扩容cs卷组

vgextend cs /dev/vda3

 5.扩容文件系统

lvextend -l +100%FREE /dev/mapper/cs-root

  1. [root@localhost ~]# pvdisplay
  2. --- Physical volume ---
  3. PV Name /dev/vda2
  4. VG Name cs
  5. PV Size <31.00 GiB / not usable 3.00 MiB
  6. Allocatable yes (but full)
  7. PE Size 4.00 MiB
  8. Total PE 7935
  9. Free PE 0
  10. Allocated PE 7935
  11. PV UUID Oaojfu-XAyd-ick0-U7nZ-2YFt-VBUk-FGgStv
  12. --- Physical volume ---
  13. PV Name /dev/vda3
  14. VG Name cs
  15. PV Size 100.00 GiB / not usable 4.00 MiB
  16. Allocatable yes (but full)
  17. PE Size 4.00 MiB
  18. Total PE 25599
  19. Free PE 0
  20. Allocated PE 25599
  21. PV UUID 597ofc-wiTD-8lM3-h2JL-fXlR-alFZ-f12G2n

6.同步文件系统

xfs_growfs /

 

文章知识点与官方知识档案匹配,可进一步学习相关知识
云原生入门技能树首页概览20442 人正在系统学习中
隐藏侧栏 新手引导 客服 举报 返回顶部
搜索 AI提问 评论 笔记