一、虛擬機上先擴展分區
二、centos系統root登入,新建分區
2.1 【fdisk -l】 最大分區爲/dev/sda2,說明新創建的分區將會是sda3(在後面的步驟會進行選擇)
2.2 輸入【fdisk /dev/sda】
2.2.1命令行提示下輸入【m】
2.2.2輸入命令【n】添加新分區。
2.2.3輸入命令【p】創建主分區。
2.2.4輸入【回車】,選擇默認
2.2.5輸入【回車】,選擇默認
2.2.6輸入【w】,保持修改
2.3 輸入【reboot】 重啓linux,必須reboot,否則/dev/sda3無法格式化。
2.4 這時在/dev/目錄下,才能看到了新的分區比如/dev/sda3
三、擴展/dev/mapper/centos-root
3.1.創建pv(給剛剛新建的分區 /dev/sda3)
1
2
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
3.2.把pv加入vg中,相當於擴充vg的大小
先使用vgs查看vg組
1
2
3
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 19.51g 40.00m<br>
擴展vg,使用vgextend命令
1
2
[root@localhost ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
3.3.我們成功把vg卷擴展了,在用vgs查看一下
1
2
3
4
5
6
7
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 39.50g 20.04g
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.47g
swap centos -wi-ao---- 2.00g 雖然我們把vg擴展了,但是lv還沒有擴展
3.4.擴展lv,使用lvextend命令
1
2
3
[root@localhost ~]# lvextend -L +20G /dev/mapper/centos-root
Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 37.47 GiB (9592 extents).
Logical volume root successfully resized.
查看lv大小
1
2
3
4
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 37.47g
swap centos -wi-ao---- 2.00g
查看df -h中變化沒有
1
2
3
4
5
6
7
8
9
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root 18G 1.1G 17G 6% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0<br><br>沒有變化。
那麼我們要使用[root@localhost ~]# xfs_growfs /dev/mapper/centos-root 命令使系統重新讀取大小
1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1144832 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=4579328, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 4579328 to 9822208
再使用df -h查看
1
2
3
4
5
6
7
8
9
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root 38G 1.1G 37G 3% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
到這裏我們就成功擴展了。
---------------------
原文:https://blog.csdn.net/wangjianqing1/article/details/79164696
399 pvcreate /dev/sda3
400 vgs
401 vgextend centos /dev/sda3
402 vgs
403 lvs
404 lvextend -L +50G /dev/mapper/centos-root
405 lvs
406 df -h
407 xfs_growfs /dev/mapper/centos-root
408 df -h