1.查看当前系统磁盘使用情况,可知跟分区空间不足5G
[root@master1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 12M 1.9G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/centos-root 19G 15G 2.9G 84% /
/dev/sda2 1014M 175M 840M 18% /boot
2.查看sda分区未分配空间,还剩余30G
[root@master1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 10G 0 disk
sr0 11:0 1 1024M 0 rom
sda 8:0 0 50G 0 disk
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 19G 0 part
│ └─centos-root 253:0 0 19G 0 lvm /
└─sda1 8:1 0 2M 0 part
3.使用fdisk命令创建新分区sda4,partprobe同步磁盘状态
[root@master1 ~]# 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): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (41943040-104857599, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-104857599, default 104857599): +30G
Value out of range.
Last sector, +sectors or +size{K,M,G} (41943040-104857599, default 104857599):
Using default value 104857599
Partition 4 of type Linux and of size 30 GiB is set
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0009b521
Device Boot Start End Blocks Id System
/dev/sda1 2048 6143 2048 83 Linux
/dev/sda2 * 6144 2103295 1048576 83 Linux
/dev/sda3 2103296 41943039 19919872 8e Linux LVM
/dev/sda4 41943040 104857599 31457280 83 Linux
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.
[root@master1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 10G 0 disk
sr0 11:0 1 1024M 0 rom
sda 8:0 0 50G 0 disk
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 19G 0 part
│ └─centos-root 253:0 0 19G 0 lvm /
└─sda1 8:1 0 2M 0 part
[root@master1 ~]#
[root@master1 ~]# partprobe
[root@master1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 10G 0 disk
sr0 11:0 1 1024M 0 rom
sda 8:0 0 50G 0 disk
├─sda4 8:4 0 30G 0 part
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 19G 0 part
│ └─centos-root 253:0 0 19G 0 lvm /
└─sda1 8:1 0 2M 0 part
[root@master1 ~]#
4.lvm虚拟磁盘扩容
[root@master1 ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
[root@master1 ~]#
[root@master1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 centos lvm2 a-- <19.00g 0
/dev/sda4 lvm2 --- 30.00g 30.00g
[root@master1 ~]#
[root@master1 ~]# vgextend centos /dev/sda4
Volume group "centos" successfully extended
[root@master1 ~]#
[root@master1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 1 0 wz--n- 48.99g <30.00g
[root@master1 ~]#
[root@master1 ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <19.00 GiB (4863 extents) to 48.99 GiB (12542 extents).
Logical volume centos/root successfully resized.
[root@master1 ~]#
[root@master1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 48.99g
[root@master1 ~]#
[root@master1 ~]# resize2fs /dev/centos/root
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/centos/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 7
The filesystem on /dev/centos/root is now 12843008 blocks long.
[root@master1 ~]#
[root@master1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 12M 1.9G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/centos-root 49G 15G 32G 32% /
/dev/sda2 1014M 175M 840M 18% /boot
xfs_growfs
命令执行错误会有如下提示,执行下resize2fs就可以了哈
[root@master1 ~]# xfs_growfs /dev/centos/root
xfs_growfs: /dev/centos/root is not a mounted XFS filesystem
ps:lvextend 扩展后只是扩展了lv的大小,而此时文件系统并未感知到,所有还需要使用xfs_growfs、resize2fs等命令来扩展文件系统,xfs_growf命令是扩展xfs文件系统,resize2fs是扩展ext4文件系统。