How to Reduce / Shrink the Size of a LVM Partition Formatted with XFS Filesystem

0
510

Issue:

– How to reduce the size a partition formatted with xfs filesystem?
– How can I reduce the size of a LVM partition formatted with xfs filesystem?

It is actually possible to reduce the size of a logical volume formatted with xfs filesystem using the following procedure :

1) Backup the data using xfsdump
2) Unmount the filesystem
3) Shrink logical volume to desired size using lvreduce
4) Format the partition with xfs filesystem
5) Remount the filesystem
6) Restore the data using xfsrestore

In this tutorial, we are going to show you how to reduce the size of a LVM partition formatted with xfs filesystem

Step 0. Lab Preparation:

– 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 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

Step 1. Backup The Data

# xfsdump -f /tmp/test.dump /test

Step 2. Unmount The Partition

# umount /test

Step 3. Reduce The Partition Size

# lvreduce -L 400M /dev/vg00/lv00

Step 4. Format The Partition With XFS Filesystem

# mkfs.xfs -f /dev/vg00/lv00

Step 5. Remount the Parition

# mount /dev/vg00/lv00 /test

Step 6. Restore The Data

# xfsrestore -f /tmp/test.dump /test

– check the content of partition

# ls -l /test

We hope this tutorial was enough Helpful. If you need more information or you have any questions, just comment below and we will be glad to assist you!

LEAVE A REPLY

Please enter your comment!
Please enter your name here