vmware虚拟机扩容centos根目录

环境信息:
vmware
虚拟机操作系统: CentOS Linux release 7.9.2009 (Core)
根目录使用LVM挂载
目标: 把根分区从19G扩容到45G, 因为swap和根分区公用一共磁盘,所以磁盘容量扩容到50G

vmware虚拟机扩容磁盘

需要先关闭虚拟机
然后编辑虚拟机设置
扩容磁盘,保存后开启虚拟机
在这里插入图片描述

centos中扩容对应的分区

首先确认需要扩容的分区号,发现根分区/使用的lvm /dev/mapper/centos-root

> ```[root@k8s-node2 ~]# df -h Filesystem               Size  Used
> Avail Use% Mounted on devtmpfs                 7.8G     0  7.8G   0%
> /dev tmpfs                    7.8G     0  7.8G   0% /dev/shm tmpfs    
> 7.8G   23M  7.8G   1% /run tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup /dev/mapper/centos-root   17G   14G  3.2G  82% /
> /dev/sda1               1014M  197M  818M  20% /boot ```

检查对应的pv,因为只有一个pv,可以确认对应的分区是 /dev/sda2,如果有多个可以查看对应vg和lv。最终确认是使用的哪个PV


[root@k8s-node2 ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               5yhx3G-f6dy-k79H-6igu-ljtT-CLMz-zm54sp

扩容/dev/sda2分区

[root@k8s-node2 ~]# fdisk /dev/sda  
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00095b14

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM   

Command (m for help): d   #删除/dev/sda2对应分区
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n  #重建/dev/sda2 primary分区
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (2099200-104857599, default 2099200): 
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-104857599, default 104857599): 
Using default value 104857599
Partition 2 of type Linux and of size 49 GiB is set

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00095b14

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   83  Linux

Command (m for help): w   #保存
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@k8s-node2 ~]# partprobe 
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

检查确认/dev/sda2的磁盘空间已经完成扩容
看到sda2已经是49G,之前是20G。

[root@k8s-node2 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   49G  0 part 
  ├─centos-root 253:0    0 44.1G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  
sr0              11:0    1  988M  0 rom  

扩容lvm

查看pv的size还是19G

[root@k8s-node2 ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               5yhx3G-f6dy-k79H-6igu-ljtT-CLMz-zm54sp

扩容pv size,检查pv和vg的size都已经扩到49G了

[root@k8s-node2 ~]# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@k8s-node2 ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <49.00 GiB
  PE Size               4.00 MiB
  Total PE              12543
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       7680 / 30.00 GiB
  VG UUID               khefIm-jNwB-MjBr-GYvL-kdit-p8v5-6GezNk

查看lvsize

  [root@k8s-node2 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                sj5yNO-Txwf-E3B2-ncNf-Xx9o-rCYx-IZbz6O
  LV Write Access        read/write
  LV Creation host, time localhost, 2024-04-15 03:22:01 +0800
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                38qiZa-dirq-itNC-aIhK-7tcP-dTap-8AUz2i
  LV Write Access        read/write
  LV Creation host, time localhost, 2024-04-15 03:22:01 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

扩容lvsize,确认根分区的大小已经扩容到了45G

[root@k8s-node2 ~]# lvextend -l 90%VG /dev/centos/root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <44.10 GiB (11289 extents).
  Logical volume centos/root successfully resized.
  [root@k8s-node2 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 11559936

[root@k8s-node2 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G   15M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   45G   14G   31G  31% /
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值