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 have any questions, just comment below and we will be glad to assist you!
14 comments
Please check this
https://access.redhat.com/solutions/540013
Hi there, I wish for to subscribe for this blog to take most recent updates, thus where can i do it please help out.
“Hello there! Would you mind if I share your blog with my twitter group? There’s a lot of people that I think would really appreciate your content. Please let me know. Many thanks”
Great workaround/solution! Thank you!!!
hello, could we format the XFS filesystem with a block size 4096 and sector size 512 ? how could we do it ? and then add the entry in /etc/fstab file. could you pls show us the steps.
Hi ikayy,
Use the following command to create an XFS file system
# mkfs.xfs [ -b block_size ] [ -m global_metadata_options ] [ -d data_section_options ] [ -f ] [ -i inode_options ] [ -l log_section_options ] [ -n naming_options ] [ -p protofile ] [ -q ] [ -r realtime_section_options ] [ -s sector_size ] [ -L label ] [ -N ] [ -K ] device
– the block_size:The default value is 4096 bytes (4 KiB), the minimum is 512, and the maximum is 65536 (64 KiB)
– Sector size: Default value is 512 bytes. The minimum value for sector size is 512; the maximum is 32768 (32 KB).
To Mount a partition in /etc/fstab file u can use the UUID of the disk
1./ Use blkid command-line utility to locate/print block device attributes
2. Update /etc/fstab file like the example below
UUID={YOUR-UID} {/path/to/mount/point} {file-system-type} defaults,errors=remount-ro 0 1
Hope we answer to all your question .
This is good and easy solution.
Works like a charm.
Thank you very much
Regards
Hi Stefan,
We are glad tht the workaround solution was helpful, please subscribe to our Youtube Channel .
…great information. Thanks for writing it. I was working toward accomplishing the same goal, but with a virtual disk, which offers greater latitude for easier solutions than a physical disk drive. What I did worked great for a Microsoft Hyper-V virtual machine, and should also work with VMWare. Details are here: http://wiki.terrabase.info/index.php/Shrinking_a_Virtual_Disk_-_The_Easy_Way
Thank you for this solution, but i have a question. can we do this for a root partition? i would like to shrink my root partition. is it possible with this method??
it’s not recommended…
you need also:
– Another partition to Backup the root partition /
– Boot into rescue mode using a DVD
I have successfully did it with my root partition on my Centos8.3 😉
Thank you. It worked great!
Hello,
Thanks for the tutorial, but I have a separate question.
If we have 2 hard drives, one with installed OS and second attached as PV and LV to extend to /root partition on xfs format, is it possible to reduce the size of the second disk and to continue operation normaly without harm the file system?
For example we have 1 hard with 30GB with instaled os and
/dev/mapper/cs-root with size of 20GB
Second hdd with 100GB atached as PV and LV extending /dev/mapper/cs-root to 120GB,
Can we reduce the size of the second hdd to 50GB and also to make /dev/mapper/cs-root 70GB without harm the system?