#查看当前分区情况fdisk-l
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512=8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 11310439183 Linux
/dev/sda2 14261020860402+ 8e Linux LVM
#Create a new partition that takes up the remaining space and is of filesystem type 8e (LVM):fdisk /dev/sda
n (new)
p (primary)3(partition number, since 1st and 2nd partition already exists)select default first available cylinder to the default last cylinder.
t (type)3(partition number)
8e (set type to LVM)
p (view the new partitions layout)
w (write out the new partitions layout to disk)#重启系统#查看更新的分区:重启后,可以看到新增分区,格式为lvm
Fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 11310439183 Linux
/dev/sda2 14261020860402+ 8e Linux LVM
/dev/sda3 2611652731463302+ 8e Linux LVM
格式化硬盘格式(必选,由于不同的硬件环境有不同的格式,因此务必确认现有的磁盘格式,可以通过df -hT查看),如下是虚拟机常用的格式,xfs格式,注意如下命令的后缀代表了文件系统格式。
mkfs.xfs /dev/sda3
pvdisplay 查看VG名称,拓展现有组
#pvcreate命令 用于将物理硬盘分区初始化为物理卷,以便LVM使用。
pvcreate /dev/vda3
#通过 df -hT 查看所需添加到的卷组名称无须加root;或pvdisplay查看
vgextend rhel(卷名) /dev/vda3
(note the free space now in the Volume Group which can now be assigned to a Logical Volume)#vgdisplay确认拓展后结果
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 49.88 GB
PE Size 32.00 MB
Total PE 1596
Alloc PE / Size 636 / 19.88 GB
Free PE / Size 960 / 30.00 GB
VG UUID 0JB6GV-gFJW-onuN-7Xq1-OKim-n5gM-EVPUKB
#拓展挂载点对应的文件系统。
lvextend -L +89G /dev/mapper/rhel-root /dev/vda3或
lvextend -l +100%FREE /dev/mapper/rhel-root /dev/vda3
#可选,立即使用拓展空间。注意这里与上面不一样,这是挂载点,是df命令的最后一列,而非第一列。
xfs_growfs /
#挂载点对应的文件系统名称可以df -h 1G,查看。#Df -h确认根目录已经被拓展。