0% found this document useful (0 votes)
65 views1 page

How To Shrink XFS Partition For The Root Filesystem - 1 Easy Guide

Uploaded by

Szutor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views1 page

How To Shrink XFS Partition For The Root Filesystem - 1 Easy Guide

Uploaded by

Szutor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Linux Sysadmins – Linux Guides, Nix Guides, Tutorials, Tips & Tricks.

Home Linux Distros Linux Servers How to Guides Monitoring Tools Unix & Unix Like Linux Misc

Subscribe

How to Shrink XFS Partition for the root


lesystem | 1 Easy guide
December 23, 2020 by Babin Lonston

Subscribe To Our
0 0 0 0
Newsletter
Join our mailing list to receive the latest
news and updates from our team.

Email

SUBSCRIBE!

Table of Contents 

 Read Time: 7 Minute

Introduction
In our previous how-to guide, we have seen how to reduce a “/” lesystem with ext4 le system type.
In this guide let’s focus on how to Shrink XFS partition for a root logical volume. To be clear the
lesystem reduce word is not applicable yet for the XFS le system. However, if you need to reduce XFS
lesystem on a logical volume is possible only by taking a backup and restore and recreating the logical
volume.

Recent Posts

Migrate from CentOS 8.x to Rocky


If you are looking for more Logical Volume Management guide search in below search box with Linux 8.x | 1 Easy guide
keyword “Logical Volume“.
Step by step Rocky Linux 8.x
Installation easy guide with
Logical Volume Keyword
screenshots
Search
Integrating RHEV or Ovirt with Red Hat
IDM for User Authentication | 1 Easy

The Current lesystem Layout guide


Solution for IPA Error 4203
This is the current lesystem layout in my home lab. Currently “/” lesystem was created with 64 GB. DatabaseError
Using Podman on CentOS and RHEL 8 |
[root@prod-srv-01 ~]# df -hPT Easy Guide
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 889M 0 889M 0% /dev
tmpfs tmpfs 909M 0 909M 0% /dev/shm
tmpfs tmpfs 909M 8.6M 900M 1% /run
tmpfs tmpfs 909M 0 909M 0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs 64G 1.8G 62G 3% /
/dev/sda2 xfs 1014M 187M 828M 19% /boot
/dev/mapper/rhel-home xfs 31G 254M 31G 1% /home
/dev/sda1 vfat 599M 6.9M 592M 2% /boot/e
tmpfs tmpfs 182M 0 182M 0% /run/user/0
[root@prod-srv-01 ~]#

Our intention is only to reduce the size of “/” partition which running with XFS lesystem.

[root@prod-srv-01 ~]# df -hPT /


Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs 64G 1.8G 62G 3% /
[root@prod-srv-01 ~]#

Right now the logical volume size is 64 GB. On our rst single disk there are 3 partitions created and
“/” is assigned with more space which is not required at all.
Recent Comments

Tom D on Install Kubernetes Cluster


with Ansible on Ubuntu in 5 minutes

Manoel on Installing Git from


kernel.org on CentOS, RHEL & Oracle
[root@prod-srv-01 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 6/7/8 Linux
home rhel -wi-ao---- 30.98g
Mal Woods on Recover a failed or
root rhel -wi-ao---- 63.46g
swap rhel -wi-ao---- 3.96g deleted Physical Volume (PV) in LVM | 1
[root@prod-srv-01 ~]# Easy guide

[root@prod-srv-01 ~]# lsblk Tony on 1 stop solution for setfacl


NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT “Operation not supported” in Linux
sda 8 0 0 100G 0 disk
├─sda1 8 1 0 600M 0 part /boot/e Donovan on Con gure a PXE Boot
├─sda2 8 2 0 1G 0 part /boot
Server with Kickstart on CentOS 8 –
└─sda3 8 3 0 98.4G 0 part
├─rhel-root 253 0 0 63.5G 0 lvm / Easy guide
├─rhel-swap 253 1 0 4G 0 lvm [SWAP]
└─rhel-home 253 2 0 31G 0 lvm /home
sr0 11 0 1 1024M 0 rom
[root@prod-srv-01 ~]#

Backup your Data


Before performing shrink XFS or reduce XFS make sure to take a full backup of yours lesystem. In the
worst case, we need to rollback from the backup if something goes wrong.

Booting to Rescue Mode


Boot from any ISO/DVD and select the “Troubleshooting” option.

Choose to get rescue menu

By following select the “Rescue a Red Hat Enterprise Linux system” to boot into rescue environment.

Choose to boot from rescue mode

As we mentioned in the previous guide to perform a Shrink XFS we should not mount the lesystem.
Type 3 and enter into Rescue shell. To perform any actions on logical volumes we shouldn’t enter into
chroot environment.

Entering rescue shell using no 3

The lesystem is not mounted.

# ls -lthr /mnt/sysimage/

None of the le systems are mounted

Activate the volume group


To start with XFS reduce rst we need to activate the volume group.

# vgchange -ay

Activate the Volume group

Temporarily Mount the Logical volumes


Starting with backup, rst, we need to mount the logical volumes under some location. By temporarily
mounting it we can do a backup of “/” partition to any other location and it needs to be accessed while
we perform the restore.

Now, create two directories under /mnt/sysimage/. 1 will be used to mount the actual “/” lesystem of
this server and another one is to store the backup of “/” lesystem.

# mkdir /mnt/sysimage/rt
# mkdir /mnt/sysimage/backup
# mount /dev/mapper/rhel-root /mnt/sysimage/rt/
# mount /dev/mapper/rhel-home /mnt/sysimage/backup/

We have enough free space on “/home” lesystem, so instead of adding a new disk, we are going to use
it for taking the backup.

Create mount point and mount the existing lesystems

xfsdump to backup the lesystem


Initiate the backup by running xfsdump command.

# xfsdump -l 0 -L "root lv backup" -M "backup" -f /mnt/sysimage/backup/root_backup.img


/mnt/sysimage/rt

While taking the dump use level 0 which will dump all the les, It will prompt to enter a dump session
label and media label, we can avoid the prompt by adding -L and -M by the following use -f to save the
dump as a le.

-l 0 – Dump level is set to 0, A level 0 dump is absolute, all les are dumped.
-L – Speci es a label for the dump session
-M – Speci es a label for the rst media object
-f – Speci es a dump destination to a le or device like tape drives

xfsdump completed the backup

At the end of dump output we can see the dump status as SUCCESS

Unmount the lesystems


Once completed with backup we can unmount the lesystem. If you face any issue similar to below

unmount only the old root le system

Find what currently using the lesystem and kill the PIDS.

Clear the open le and unmount

Once the PIDS are cleared, now unmount only the current “/” le system.

# umount /mnt/sysimage/rt/

Shrink XFS | Recreating Logical volume


The 64 GB of logical volume need to be deleted. Use lvremove to delete the logical volume.

Create a logical volume with the new desired size for the root “/” le system. Use -Zy to zero the rst
4KiB of data in the new LV.

-Z --zero
-y - yes

To delete the logical volume use

# lvremove /dev/mapper/rhel-root

Right after that, create the desired size of the logical volume. I’m creating with a 15 GB of the logical
volume in the same existing (rhel) volume group.

# lvcreate -Zy -L 15G -n root rhel

Finally, print the created logical volume using lvs command.

Shrink XFS and recreating Logical volume

Remove the root logical volume with 64 GB in size.


Use lvremove to delete the logical volume
Recreate the logical volume
Newly created logical volume

Creating an XFS le System


Now format the newly created logical volume and create the XFS le system.

Creating XFS le system

Mount and Restore


Once the le system is ready, mount it under the same mount point at /mnt/sysimage/rt

# mount /dev/mapper/rhel-root /mnt/sysimage/rt

Start with the restore by pointing to existing back le

# xfsrestore -f /mnt/sysimage/backup/root_backup.img /mnt/sysimage/rt

The restore will take some time depends on how many GB of data have in the dump le.

We could see the restore from .img le was SUCCESS.

Unmount all the lesystems


We are almost done with shrink XFS, now unmount all the lesystem which ever we have mounted in
earlier steps.

Exit and reboot from the rescue shell by typing “exit“.

Up and Running with new LV size


After the reboot, we could see the desired size for “/” lesystem as 15 GB and logical volumes too with
the same size.

[root@prod-srv-01 ~]# lvs


LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home rhel -wi-ao---- 30.98g
root rhel -wi-ao---- 15.00g
swap rhel -wi-ao---- 3.96g
[root@prod-srv-01 ~]#

[root@prod-srv-01 ~]# df -hPT /


Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs 15G 1.5G 14G 10% /
[root@prod-srv-01 ~]#

[root@prod-srv-01 ~]# lsblk


NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8 0 0 100G 0 disk
├─sda1 8 1 0 600M 0 part /boot/e
├─sda2 8 2 0 1G 0 part /boot
└─sda3 8 3 0 98.4G 0 part
├─rhel-root 253 0 0 15G 0 lvm /
├─rhel-swap 253 1 0 4G 0 lvm [SWAP]
└─rhel-home 253 2 0 31G 0 lvm /home
sr0 11 0 1 8.8G 0 rom
[root@prod-srv-01 ~]#

That’s it, we have completed with Shrinking an XFS lesystem and a logical volume with the help of
xfsdump and xfsrestore utility.

Conclusion
To reduce a root LVM with XFS lesystem is not possible by running lvreduce, Instead, we need to
back up the les and restore from the dump using xfsdump and xfsrestore. In our one of the previous
guide, we have covered with XFS lesystem dump and restore, However, this guide is focused on how
to resize the root logical volume with XFS.

To perform the LV reduce, rst, we need to boot into rescue mode, then we need to activate the
volume group and mount the old lesystem which is about to dump. Then remove the old logical
volume and create a new logical volume with the desired size. Right after that create the XFS le
system and restore the dump using xfsrestore command. Finally, reboot the server to back online with
the new size of LV and XFS lesystem with the existing data.

Subscribe to our newsletter for more guide related to nix, stay safe and stay tune. If you like the above
write-up provide your feedback in below comment section.

Share
Facebook Twitter Pinterest LinkedIn

About Author
Babin Lonston
Overall 14+ Years of experience in the IT eld, currently working as a
Senior Linux administration with Virtualization & Cloud. Being
numismatist for a long time.

Happy Sad Excited Sleepy Angry Surprise

75 % 0% 0% 0% 25 % 0%

Storage Servers
Logical Volume Management
Resize root LVM Partition in RHEL and Oracle Linux 7/8 | Easy guide
Centralized Syslog server with Syslog-ng in 3 easy steps

1 thought on “How to Shrink XFS Partition for the root


lesystem | 1 Easy guide”

martin2665
September 8, 2021 at 2 55 am

Thanks a lot. Great article. /device/mapper/root-name did not work for me.
Instead I use /dev/Volname/ root-name

Reply

Leave a Comment

Name

Email

Website

Save my name, email, and website in this browser for the next time I comment.

Post Comment

Migrate from CentOS 8.x to


Ansible Apache Apache Virtual Host
Rocky Linux 8.x | 1 Easy guide
AWS CentOS Linux Con guration Management
Step by step Rocky Linux 8.x
Docker Filesystem foreman ftp
Installation easy guide with
Google Cloud Google cloud instance Google GCP
screenshots
grub IDM Server iSCSI
Integrating RHEV or Ovirt
with Red Hat IDM for User Kubernetes linux
Authentication | 1 Easy guide
commands Linux
Solution for IPA Error 4203
DatabaseError
networking Linux Security
Using Podman on CentOS and Logical Volume
RHEL 8 | Easy Guide
Management Log
management monitoring tools NFS nginx

OpenFiler Oracle Database


pacemaker cluster Python Red Hat
Virtualization RHEVM Security sftp solaris 10

Solaris 11 Solaris OS Spacewalk


Splunk Splunk Forwarder Splunk Log
Analyser VMware VMware vSAN vsftpd
yum zpool

© 2022 • Built with GeneratePress Copyright Policy Contact About Privacy Policy

You might also like