虚拟机分配硬盘

先在虚拟机增加硬盘。

分配新加的硬盘

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

Command (m for help): p ← 你输入 p

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

Command (m for help): d ← 你输入 d
Partition number (1,2, default 2): 2 ← 你输入 2
Partition 2 is deleted

Command (m for help): n ← 你输入 n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p ← 你输入 p
Partition number (1-4, default 2): 2 ← 你输入 2
First sector (2048-167772159, default 2048): 2099200 ← 你输入起始扇区(你之前记下的数字)
Last sector, +sectors or +size{K,M,G} (2099200-167772159, default 167772159): ← 直接回车

Command (m for help): t ← 你输入 t
Partition number (1,2, default 2): 2 ← 你输入 2
Hex code (type L to list all codes): 8e ← 你输入 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w ← 你输入 w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

识别挂在硬盘

[root@localhost ~]# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 80.00 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 20479
Free PE 16640
Allocated PE 3839
PV UUID vHeZCZ-Gxfs-wb1z-Wejc-6hBo-BStr-EvbOHd

[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 79.99 GiB (20479 extents).
Logical volume centos/root successfully resized.

[root@localhost ~]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=877824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=3511296, 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 3511296 to 20970496

[root@localhost ~]# df -h /
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 80G 5.0G 75G 7% /