VMware基于LVM实现根目录磁盘扩容

VMware基于LVM实现根目录磁盘扩容

VMware虚拟机上的磁盘空间如果不够用了,可以使用LVM自行扩容

1.VMware控制器添加磁盘

将VM关机,并将20G磁盘扩容为40G

VMware基于LVM实现根目录磁盘扩容

2.登录查看磁盘

fdisk -l

VMware基于LVM实现根目录磁盘扩容
可以看到sda已经扩容到40G,但实际只分配了20G

3.创建新磁盘

fdisk /dev/sda

[root@k8s-node01 ~]# 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: 42.9 GB, 42949672960 bytes, 83886080 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: 0x00013140

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648    41943039    20765696   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (41943040-83886079, default 41943040): 
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079): 
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set

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.

VMware基于LVM实现根目录磁盘扩容

4.更改分区类型为Linux LVM

[root@k8s-node01 ~]# 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): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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.

VMware基于LVM实现根目录磁盘扩容

5.重启操作系统

reboot

6.添加LVM到LVM组,并将根目录卷扩容

[root@k8s-node01 ~]# lvm
lvm> pvcreate /dev/sda3  
  Physical volume "/dev/sda3" successfully created.
lvm> vgextend centos /dev/sda3
  Volume group "centos" successfully extended
lvm> lvextend -L +19G /dev/mapper/centos-root   
  Size of logical volume centos/root changed from 19.30 GiB (4941 extents) to 38.30 GiB (9805 extents).
  Logical volume centos/root successfully resized.
lvm> pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               19.80 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5069
  Free PE               0
  Allocated PE          5069
  PV UUID               VuaN5u-jbeg-Qrxt-iu2R-9WdZ-RYhg-OZaPHO

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               255
  Allocated PE          4864
  PV UUID               Z4giaI-h4f3-PeU0-AExT-C0p7-vAdR-wCyXqL

lvm> quit

7.扩容文件系统

resize2fs /dev/mapper/centos-root

VMware基于LVM实现根目录磁盘扩容

报错,xfs文件系统的扩容需要使用下面的命令

xfs_growfs /dev/mapper/centos-root

VMware基于LVM实现根目录磁盘扩容

8.查看扩容情况

df -h

VMware基于LVM实现根目录磁盘扩容

扩容完成

猜你喜欢

转载自blog.51cto.com/11442747/2513898
今日推荐