一、环境说明
如图示实例,红色箭头所指/usr空间已使用80%,对应的LVM分区为rootvg-usr。如何对rootvg-usr分区扩容?
图示实例中rootvg-usr所属的卷组为rootvg,尚有不到6GB的剩余可用空间用于扩容。
若PFree为0,如何对rootvg-usr扩容?
可通过缩减卷组rootvg下其他LVM分区大小(如rootvg-tivoli),腾出可用空间给rootvg-usr去扩容。
下面通过实验环境进行验证并给出具体操作步骤,实验环境如图示:
实验目标:缩减/tivoli空间大小(8GB->4GB),增加/usr空间大小(6GB->10GB)。
二、操作步骤
2.1缩减/tivoli空间大小(8GB->4GB)
2.1.1使用xfsdump备份/tivoli下数据
安装xfsdump:
# yum install xfsdump -y
备份数据到/app下:
# xfsdump -f /app/tivoli.dump /tivoli
提示输入label时不可忽略,过程如下:
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) – type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> tivolidump20210525
session label entered: “tivolidump20210525”
——————————— end dialog ———————————
xfsdump: level 0 dump of localhost.localdomain:/tivoli
xfsdump: dump date: Tue May 25 09:29:51 2021
xfsdump: session id: 50bd343c-6c09-4341-8ecc-434bea9d5006
xfsdump: session label: “tivolidump20210525”
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 19793664 bytes
xfsdump: /var/lib/xfsdump/inventory created
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> tivolidump20210525
media label entered: “tivolidump20210525”
——————————— end dialog ———————————
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 19584736 bytes
xfsdump: dump size (non-dir files) : 19409336 bytes
xfsdump: dump complete: 36 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /app/tivoli.dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost /]#
2.1.2卸载分区
# umount /tivoli
2.1.3使用lvreduce收缩逻辑卷到所需的大小
# lvreduce -L 4G /dev/rootvg/tivoli
WARNING: Reducing active logical volume to 4.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce rootvg/tivoli? [y/n]: y
Size of logical volume rootvg/tivoli changed from 8.00 GiB (2048 extents) to 4.00 GiB (1024 extents).
Logical volume rootvg/tivoli successfully resized.
2.1.4使用xfs文件系统格式化分区
# mkfs.xfs -f /dev/rootvg/tivoli
meta-data=/dev/rootvg/tivoli isize=512 agcount=4, agsize=262144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1048576, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
2.1.5重新挂载分区
# mount /dev/rootvg/tivoli /tivoli
2.1.6使用xfsrestore恢复/tivoli下数据
# xfsrestore -f /app/tivoli.dump /tivoli
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) – type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: localhost.localdomain
xfsrestore: mount point: /tivoli
xfsrestore: volume: /dev/mapper/rootvg-tivoli
xfsrestore: session time: Tue May 25 09:29:51 2021
xfsrestore: level: 0
xfsrestore: session label: “tivolidump20210525”
xfsrestore: media label: “tivolidump20210525”
xfsrestore: file system id: 91c5ee30-dd7e-4dbb-a336-6f3e77003f0b
xfsrestore: session id: 50bd343c-6c09-4341-8ecc-434bea9d5006
xfsrestore: media id: 81eef1ca-d96b-4701-86c1-08c8fb9c2cf6
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 84 directories and 235 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /app/tivoli.dump OK (success)
xfsrestore: Restore Status: SUCCESS
2.1.7检查/tivoli下数据
# ls -l /tivoli
total 4
drwxr-xr-x. 7 1001 1001 4096 Jul 21 2020 zkui
经过上述操作,/tivoli空间已从8GB缩减到4GB。腾出4GB可用空间给rootvg-usr去扩容。
2.2增加/usr空间大小(6GB->10GB)
2.2.1使用lvextend增加逻辑卷到所需的大小
# lvextend -L +4G /dev/rootvg/usr -r
Size of logical volume rootvg/usr changed from 6.00 GiB (1536 extents) to 10.00 GiB (2560 extents).
Logical volume rootvg/usr successfully resized.
meta-data=/dev/mapper/rootvg-usr isize=512 agcount=4, agsize=393216 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1572864, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 1572864 to 2621440
2.2.2查看/usr空间大小
# df -Th /usr
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rootvg-usr xfs 10G 1.5G 8.5G 16% /usr
发现/usr空间已从6GB增加到10GB。
分区调整后的空间如图示。
三、参考文章
3.1HOW TO REDUCE / SHRINK THE SIZE OF A LVM PARTITION FORMATTED WITH XFS FILESYSTEM?
3.2How to Extend a Logical Volume in LVM – for XFS, ext4 and swap filesystem