How to Reduce XFS File System /var in Linux and remove physical volume from the Volume group-
Task -
We have additional physical disk into varlv which is unused and want to remove the disk from Logical volume and Volume group.
[root@rhel8-node2 var]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 0 1.4G 0% /dev/shm
tmpfs 1.4G 8.6M 1.4G 1% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/sda1 49G 5.3G 42G 12% /
/dev/mapper/rootvg-varlv 16G 1.1G 15G 7% /var
tmpfs 279M 0 279M 0% /run/user/0
[root@rhel8-node2 var]#
[root@rhel8-node2 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
varlv rootvg -wi-ao---- <8.11g
[root@rhel8-node2 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g 1.98g
/dev/sdc1 rootvg lvm2 a-- <5.02g <5.02g
[root@rhel8-node2 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 2 1 0 wz--n- <15.11g 7.00g
[root@rhel8-node2 ~]#
As per above logs, we can remove easily remove /dev/sdc1 because /var utilization is only 1.1 Gb and LV having 10G and 5G disks.
So we can remove any disk which we want. Here I am taking example to remove /dev/sdc1 disk from /var xfs file system.
Warning: -
As /var is a root file system, and it is using by running process so before performing any activity, we need to take downtime for services
as well as need to check latest backup.
– Install the xfsdump package
[root@rhel8-node2 /]# yum install xfsdump -y
Updating Subscription Management repositories.
-
-
-
Installed products updated.
Upgraded:
xfsdump-3.1.8-7.el8_9.x86_64
Complete!
[root@rhel8-node2 /]#
- Backup the Data using xfsdump
[root@rhel8-node2 /]# xfsdump -f /tmp/var.dump /var
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> d
session label entered: "d"
--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of rhel8-node2:/var
xfsdump: dump date: Sun Apr 6 12:35:33 2025
xfsdump: session id: 83e15d09-b78a-4d8f-97f0-9569c5d7529e
xfsdump: session label: "d"
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: 984386048 bytes
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> var
media label entered: "var"
--------------------------------- 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 981625112 bytes
xfsdump: dump size (non-dir files) : 979741224 bytes
xfsdump: dump complete: 63 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /tmp/var.dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@rhel8-node2 /]#
Now unmount the /var File system-
[root@rhel8-node2 /]# umount /var
[root@rhel8-node2 /]#
Now reduce the Logical volume and give the desired size of /var File system
[root@rhel8-node2 /]# lvreduce -L 5G /dev/mapper/rootvg-varlv
WARNING: Reducing active and open logical volume to 5.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce rootvg/varlv? [y/n]: yes
Size of logical volume rootvg/varlv changed from <15.11 GiB (3867 extents) to 5.00 GiB (1280 extents).
Logical volume rootvg/varlv successfully resized.
[root@rhel8-node2 /]#
Format the partition with XFS File system-
[root@rhel8-node2 /]# mkfs.xfs -f /dev/rootvg/varlv
meta-data=/dev/rootvg/varlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=1310720, 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
[root@rhel8-node2 /]#
Post that remount File system-
[root@rhel8-node2 /]# mount /dev/rootvg/varlv /var
Now we can restore the backup-
[root@rhel8-node2 tmp]# xfsrestore -f /tmp/var.dump /var
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.8 (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: rhel8-node2
xfsrestore: mount point: /var
xfsrestore: volume: /dev/mapper/rootvg-varlv
xfsrestore: session time: Sun Apr 6 12:35:33 2025
xfsrestore: level: 0
xfsrestore: session label: "d"
xfsrestore: media label: "var"
xfsrestore: file system id: 38ca1029-5051-45ae-ad1d-84bafeeeede0
xfsrestore: session id: 83e15d09-b78a-4d8f-97f0-9569c5d7529e
xfsrestore: media id: 504c1e39-55dd-4f9b-bf7e-f2e30b22999b
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 772 directories and 2822 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 3 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /tmp/var.dump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@rhel8-node2 tmp]#
Post that validate the content of /var File system-
[root@rhel8-node2 tmp]# df -Th /var
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rootvg-varlv xfs 5.0G 1008M 4.1G 20% /var
[root@rhel8-node2 tmp]#
Validate the reduced size and free space-
[root@rhel8-node2 tmp]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 2 1 0 wz--n- <15.11g <10.11g
[root@rhel8-node2 tmp]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g <5.09g
/dev/sdc1 rootvg lvm2 a-- <5.02g <5.02g
[root@rhel8-node2 tmp]#
Now we can reduce volume group-
[root@rhel8-node2 tmp]# vgreduce rootvg /dev/sdc1
Removed "/dev/sdc1" from volume group "rootvg"
[root@rhel8-node2 tmp]#
[root@rhel8-node2 tmp]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 1 1 0 wz--n- <10.09g <5.09g
[root@rhel8-node2 tmp]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g <5.09g
/dev/sdc1 lvm2 --- <5.02g <5.02g
[root@rhel8-node2 tmp]#
Finally, we can remove physical volume from the server and as well as ask VM Team to remove /dev/sdc1 disk from VM
[root@rhel8-node2 tmp]# pvremove /dev/sdc1
Labels on physical volume "/dev/sdc1" successfully wiped.
[root@rhel8-node2 tmp]#
[root@rhel8-node2 tmp]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g <5.09g
[root@rhel8-node2 tmp]#
No comments:
Post a Comment