2021-08-30

xfs文件系统lvm扩容

作者 关文津

查看文件系统报告
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 18M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 50G 28K 100% /
/dev/sda1 1014M 186M 829M 19% /boot
/dev/mapper/centos-home 965G 238G 728G 25% /home
tmpfs 1.6G 0 1.6G 0% /run/user/1001
tmpfs 1.6G 0 1.6G 0% /run/user/1000
tmpfs 1.6G 0 1.6G 0% /run/user/0

查看分区挂载情况,xfs文件系统只能增大,无法缩小
[root@localhost dpdump]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Aug 30 09:28:16 2021
#
# 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=7561ece3-605c-4093-9562-8ecac4b9e238 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0

查看vg剩余空闲4M
[root@localhost dpdump]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <1023.00 GiB PE Size 4.00 MiB Total PE 261887 Alloc PE / Size 261886 / 1022.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID ea4H5a-uAH8-dKjG-MaZu-IVVB-YNl7-OMdFWK

查看块设备,只有一块1T磁盘
[root@localhost dpdump]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1T 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 1023G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:2 0 965.1G 0 lvm /home
sr0 11:0 1 1024M 0 rom

增加一块50G磁盘
[root@localhost dpdump]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1T 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 1023G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:2 0 965.1G 0 lvm /home
sdb 8:16 0 50G 0 disk
sr0 11:0 1 1024M 0 rom

初始化物理块设备为LVM用途
[root@localhost dpdump]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.

将物理卷添加到卷组centos
[root@localhost dpdump]# vgextend centos /dev/sdb
Volume group "centos" successfully extended

卷组空闲空间为50G
[root@localhost dpdump]# 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 <1.05 TiB PE Size 4.00 MiB Total PE 274686 Alloc PE / Size 261886 / 1022.99 GiB Free PE / Size 12800 / 50.00 GiB VG UUID ea4H5a-uAH8-dKjG-MaZu-IVVB-YNl7-OMdFWK

添加空间到根目录的逻辑卷
[root@localhost dpdump]# lvextend -L +50G /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 100.00 GiB (25600 extents).
Logical volume centos/root successfully resized.

扩展xfs文件系统
[root@localhost dpdump]# xfs_growfs -d /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 26214400

查看文件系统报告
[root@localhost dpdump]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 17M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 100G 14G 87G 14% /
/dev/sda1 1014M 186M 829M 19% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/1001
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home 965G 238G 728G 25% /home

调整物理磁盘/dev/sdb由50G到300G
[root@localhost]# lvm
lvm> pvresize /dev/sdb
Physical volume "/dev/sdb" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

查看vg空闲空间增加了250G
[root@localhost dpdump]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
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 1.29 TiB
PE Size 4.00 MiB
Total PE 338686
Alloc PE / Size 274686 / <1.05 TiB Free PE / Size 64000 / 250.00 GiB VG UUID ea4H5a-uAH8-dKjG-MaZu-IVVB-YNl7-OMdFWK

增加250G到逻辑卷
[root@localhost dpdump]# lvextend -L +250G /dev/mapper/centos-root
Size of logical volume centos/root changed from 100.00 GiB (25600 extents) to 350.00 GiB (89600 extents).
Logical volume centos/root successfully resized.

扩展xfs文件系统
[root@localhost dpdump]# xfs_growfs -d /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=8, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 26214400 to 91750400

查看文件系统磁盘空间报告
[root@localhost dpdump]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 350G 19G 332G 6% /
/dev/sda1 1014M 199M 816M 20% /boot
/dev/mapper/centos-home 965G 157G 809G 17% /home
tmpfs 1.6G 0 1.6G 0% /run/user/0