1、原磁盘大小
2、扩容后磁盘
3、使用sudo fdisk -l是否增加40G磁盘
4、使用 sudo fidsk /dev/sda对新增40G空间进行分区
[root@docker ~]# sudo fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
已选择分区 4
起始 扇区 (125829120-209715199,默认为 125829120):
将使用默认值 125829120
Last 扇区, +扇区 or +size{K,M,G} (125829120-209715199,默认为 209715199):
将使用默认值 209715199
分区 4 已设置为 Linux 类型,大小设为 40 GiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
5、查看卷分组,得知卷组名为"centos"
[root@docker ~]# sudo vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
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 58.99 GiB
PE Size 4.00 MiB
Total PE 15102
Alloc PE / Size 15101 / <58.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID P53Hyg-c8eU-ULyp-syrG-iCoe-eovF-fgLLk2
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 1kehce-AXda-dX2C-pjoV-sJfK-fUyf-Imr7uh
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2020-06-17 15:57:01 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID cOQdeQ-ULkv-7gaF-jVUt-C3O5-c4ur-70PIZp
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2020-06-17 15:57:01 +0800
LV Status available
# open 1
LV Size <56.99 GiB
Current LE 14589
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID a22Uci-fiA3-bmrN-SpL0-5IAS-cUGu-bs1ae9
PV Status allocatable
Total PE / Free PE 9983 / 0
PV Name /dev/sda3
PV UUID OOc3lc-IyGu-xkvm-S3hm-OVgO-vFfk-2HfYc2
PV Status allocatable
Total PE / Free PE 5119 / 1
6、为新增分区创建物理卷,如出现未发现设备,需要重启系统
[root@docker ~]# sudo pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
7、扩容/dev/sda4分区到centos卷组
[root@docker ~]# sudo vgextend centos /dev/sda4
Volume group "centos" successfully extended
8、查看根目录路径,并扩容到根目录
#查看挂载
[root@docker ~]# sudo df -h
#扩容到根目录,虽然磁盘扩容40G,但是磁盘可使用不足40G,所以扩容时写入的是39.99G,如写40G会导致扩容失败
[root@docker ~]# sudo lvextend -L +39.99G /dev/mapper/centos-root
Rounding size to boundary between physical extents: 39.99 GiB.
Size of logical volume centos/root changed from <56.99 GiB (14589 extents) to 96.98 GiB (24827 extents).
Logical volume centos/root successfully resized
9、执行xfs_growfs /dev/mapper/centos-root
[root@docker ~]# sudo xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=7, agsize=2424576 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=14939136, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4735, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 14939136 to 25422848
10、查看
[root@docker ~]# sudo df -h