- 操作系统:CentOS 7
- 数据很重要,操作之前一定备份数据,操作的时候最好是在没有业务或者业务量尽可能小的时候操作,降低风险!!!
查看磁盘信息
[root@test-server-7 ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000366ef
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 125829119 61864960 8e Linux LVM
磁盘 /dev/mapper/centos-root:39.8 GB, 39766196224 字节,77668352 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:19.4 GB, 19415433216 字节,37920768 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘并未被识别,可以直接重启服务器或者在线刷新磁盘,在线刷新磁盘
for i in /sys/class/scsi_host/*; do echo "- - -" > $i/scan; done
再次查看磁盘信息
[root@test-server-7 ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000366ef
........................................................
磁盘 /dev/sdb:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
查看PV
[root@test-server-7 ~]# pvscan
PV /dev/sda2 VG centos lvm2 [<59.00 GiB / 4.00 MiB free]
Total: 1 [<59.00 GiB] / in use: 1 [<59.00 GiB] / in no VG: 0 [0 ]
查看VG
[root@test-server-7 ~]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
查看LV
[root@test-server-7 ~]# lvscan
ACTIVE '/dev/centos/swap' [<3.88 GiB] inherit
ACTIVE '/dev/centos/home' [18.08 GiB] inherit
ACTIVE '/dev/centos/root' [<37.04 GiB] inherit
查看挂载情况
[root@test-server-7 ~]# df -lh
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 38G 1.8G 36G 5% /
/dev/mapper/centos-home 19G 33M 19G 1% /home
/dev/sda1 1014M 150M 865M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0
[root@test-server-7 ~]# cat /etc/fstab
# /etc/fstab
# Created by anaconda on Thu Aug 6 00:07:59 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=5404409d-04ea-4e8d-bf40-ec422b69ff11 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
扩展PV
[root@test-server-7 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
###查看PV扩展情况
[root@test-server-7 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <59.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 15103
Free PE 1
Allocated PE 15102
PV UUID GhfjhZ-51Ds-c76b-DSot-1hXM-HFHe-7hhKHC
"/dev/sdb" is a new physical volume of "50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID T8X7kd-l4AH-x23v-SQtP-RJWq-ywgV-lCrZ0v
扩展VG
[root@test-server-7 ~]# vgextend centos /dev/sdb
Volume group "centos" successfully extended
###查看VG扩展情况
[root@test-server-7 ~]# vgdisplay
--- 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 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 108.99 GiB
PE Size 4.00 MiB
Total PE 27902
Alloc PE / Size 15102 / 58.99 GiB
Free PE / Size 12800 / 50.00 GiB
VG UUID d2G1Sc-ChDs-gErg-NlH0-FNeJ-OSNS-geGsG8
可以看到Free PE空间已经增加了磁盘sdb的容量,接下来扩展LV
[root@test-server-7 ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <37.04 GiB (9481 extents) to <87.04 GiB (22281 extents).
Logical volume centos/root successfully resized.
###查看LV扩展情况
[root@test-server-7 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
...............................................................
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID dtfzmW-3twd-NCxx-eUPW-TeKh-BCYE-YGC1FS
LV Write Access read/write
LV Creation host, time test-server, 2020-08-06 00:07:57 -0400
LV Status available
# open 1
LV Size <87.04 GiB
Current LE 22281
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
重新调整分区大小,使用resize2fs命令重新调整分区大小,否则扩展空间依旧未能识别
####如果是xfs分区,会发现使用resize2fs命令后报如下错误,反之则会直接提示成功
[root@test-server-7 ~]# resize2fs /dev/centos/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/centos/root 时
找不到有效的文件系统超级块.
这里使用的是XFS格式分区,XFS分区格式使用xfs_growfs命令
[root@test-server-7 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2427136 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9708544, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4740, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9708544 to 22815744
查看扩展后的情况
[root@test-server-7 ~]# df -lh|grep root
/dev/mapper/centos-root 88G 1.8G 86G 3% /
可以看到根分区容量已经成功扩展。
###懒人方法:
采用cockpit来更新,可以一键操作,省去很多步骤,但是需要注意网络安全。
###安装cockpit
yum install cockpit cockpit-storaged -y
systemctl enable --now cockpit
###打开防火墙端口
[root@test-server-7 ~]# firewall-cmd --add-service=cockpit
success
[root@test-server-7 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens32
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
###在线刷新磁盘接口
for i in /sys/class/scsi_host/*; do echo "- - -" > $i/scan; done
打开浏览器,输入https://ip:9090 ,并输入账号密码登陆,账号密码就是有权限操作系统的系统账号,比如root账户,之后打开存储页面。

点击相应挂载点,进入存储操作子页面

点击物理卷旁边的+号,添加新增的磁盘

此时根分区下面的增长按钮变的可用,点击增长然后选择需要的容量即可

登陆系统查看根分区扩展情况,根分区容量成功扩展
[root@test-server-7 ~]# df -lh |grep root
/dev/mapper/centos-root 138G 1.9G 136G 2% /