码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2020-07-28 10:21:39      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:img   after   byte   logic   mamicode   extend   def   sector   技术   

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

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

1.VMware控制器添加磁盘

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

技术图片

2.登录查看磁盘

fdisk -l

技术图片
可以看到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.

技术图片

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.

技术图片

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

技术图片

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

xfs_growfs /dev/mapper/centos-root

技术图片

8.查看扩容情况

df -h

技术图片

扩容完成

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

标签:img   after   byte   logic   mamicode   extend   def   sector   技术   

原文地址:https://blog.51cto.com/11442747/2513898

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!