VMware基于LVM实现根目录磁盘扩容 [操作系统入门]

编程

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

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

1.VMware控制器添加磁盘

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

2.登录查看磁盘

fdisk -l


可以看到sda已经扩容到40G,但实际只分配了20G

3.创建新磁盘

fdisk /dev/sda

[[email protected] ~]# 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

[[email protected] ~]# 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组,并将根目录卷扩容

[[email protected] ~]# 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实现根目录磁盘扩容

以上是 VMware基于LVM实现根目录磁盘扩容 [操作系统入门] 的全部内容, 来源链接: utcz.com/z/518770.html

回到顶部