An XFS filesystem can reside on a regular disk partition or a logical volume. An XFS filesystem has three parts: a data section, a log section, and a real-time section.
The data section contains all the filesystem metadata (inodes, directories, indirect blocks) and the user file data.
The log section is used to store changes to filesystem metadata while the filesystem is running until those changes are made to the data section.
The real-time section is used to store the data of real-time files. These files had an attribute bit set through xfsctl(3) after the file creation, before any data was written to the file.
Using the following procedure :
1) Backup the data using xfsdump
2) Unmount the filesystem
3) Shrink logical volume to the desired size using lvreduce
4) Format the partition with xfs filesystem
5) Remount the filesystem
6) Restore the data using xfsrestore
– Create a primary lvm partition using fdisk with 2 Gib size:
# fdisk /dev/sdb # partprobe
– Create a physical volume:
# pvcreate /dev/sdb1 # create a physical volume
– Create a volume group with an extent size of 16M:
# vgcreate -s 16M vg00 /dev/sdb1
– Create logical volume with the size of 800M (50 extents)
# lvcreate -L 800M -n lv00 vg00
– Convert the logical volume to xfs file system
# mkfs.xfs /dev/vg00/lv00
– Mount the partition to a directory
# mkdir /test # mount /dev/vg00/pv00 /test
– Create some file in the directory
# dd if=/dev/zero of=/test/file01 bs=1024k count=10 # dd if=/dev/zero of=/test/file02 bs=1024k count=10 # dd if=/dev/zero of=/test/file03 bs=1024k count=10
– Install the xfsdump package
# yum install xfsdump -y
Backup The Data
# xfsdump -f /tmp/test.dump /test
Unmount The Partition
# umount /test
Reduce The Partition Size
# lvreduce -L 400M /dev/vg00/lv00
Format The Partition With XFS Filesystem
# mkfs.xfs -f /dev/vg00/lv00
Remount the Partition
# mount /dev/vg00/lv00 /test
Restore The Data
# xfsrestore -f /tmp/test.dump /test
– check the content of the partition
# ls -l /test
That’s it, we have completed Shrinking an XFS filesystem and a logical volume with the help of xfsdump and xfsrestore utility.
For any technical support, hire our expert.