VMware基於LVM實現根目錄磁盤擴容

VMware基於LVM實現根目錄磁盤擴容

VMware虛擬機上的磁盤空間若是不夠用了,可使用LVM自行擴容

1.VMware控制器添加磁盤

將VM關機,並將20G磁盤擴容爲40Gnode

VMware基於LVM實現根目錄磁盤擴容

2.登陸查看磁盤

fdisk -llinux

VMware基於LVM實現根目錄磁盤擴容
能夠看到sda已經擴容到40G,但實際只分配了20Gshell

3.建立新磁盤

fdisk /dev/sdacentos

[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.重啓操做系統

rebootapp

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-rootide

VMware基於LVM實現根目錄磁盤擴容

報錯,xfs文件系統的擴容須要使用下面的命令ui

xfs_growfs /dev/mapper/centos-root操作系統

VMware基於LVM實現根目錄磁盤擴容

8.查看擴容狀況

df -hcode

VMware基於LVM實現根目錄磁盤擴容

擴容完成blog

相關文章
相關標籤/搜索