# How to Shrink LVM XFS root partition

RedHat 7.8

  1. Reboot the system in Rescue Mode by booting Installation Media

Select Rescue a Oracle Linux system.

Select option 3 - Skip to shell.

  1. Preparing a backup by xfs_dump
~]# lvs --segments -o +devices
  LV      VG      Attr       #Str Type   SSize  Devices
  data_lv data_vg -wi-------    1 linear 10.00g /dev/sdb1(0)
  log_lv  log_vg  -wi-------    1 linear  4.99g /dev/sdc1(0)
  home    rhel    -wi-a-----    1 linear 26.99g /dev/sda2(512)
  root    rhel    -wi-a-----    1 linear 50.00g /dev/sda2(7422)
  root    rhel    -wi-a-----    1 linear <5.00g /dev/sdd1(0)
  swap    rhel    -wi-a-----    1 linear  2.00g /dev/sda2(0)
~]# vgchange -a y rhel
  3 logical volume(s) in volume group "rhel" now active
~]# mkdir /mnt/root
~]# mkdir /mnt/home
~]# mount /dev/rhel/root /mnt/root/
~]# mount /dev/rhel/home /mnt/home/
~]# xfsdump -f /mnt/home/root.dmp /mnt/root
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
 ============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
 -> root
session label entered: "root"
 --------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of localhost.localdomain:/mnt/root
xfsdump: dump date: Wed Mar  9 03:16:07 2022
xfsdump: session id: 8075cffa-e01e-4fd9-a177-23a056ce8be8
xfsdump: session label: "root"
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: 10083792512 bytes
xfsdump: /var/lib/xfsdump/inventory created
 ============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
 -> root
media label entered: "root"
 --------------------------------- 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 9977044328 bytes
xfsdump: dump size (non-dir files) : 9919957304 bytes
xfsdump: dump complete: 436 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /mnt/home/root.dmp OK (success)
xfsdump: Dump Status: SUCCESS
  1. Reduce and format root logical volume, restore the root content.
~]# umount /mnt/root
~]# lvreduce -L -5G /dev/rhel/root
WARNING: Reducing active and open logical volume to 50.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce rhel/root? [y/n]: y
Size of logical volume rhel/root changed from 55.00 GiB (14080 extents) to 50.00 GiB (12800 extents).
Logical volume rhel/root successfully resized.
~]# vgreduce rhel /dev/sdd1
  Removed "/dev/sdd1" from volume group "rhel"
~]# pvremove /dev/sdd1
  Labels on physical volume "/dev/sdd1" successfully wiped.
~]# mkfs.xfs -L root -f /dev/rhel/root
meta-data=/dev/rhel/root         isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
~]# mount /dev/rhel/root /mnt/root/
~]# xfsrestore -f /mnt/home/root.dmp /mnt/root
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (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: localhost.localdomain
xfsrestore: mount point: /mnt/root
xfsrestore: volume: /dev/mapper/rhel-root
xfsrestore: session time: Wed Mar  9 03:16:07 2022
xfsrestore: level: 0
xfsrestore: session label: "root"
xfsrestore: media label: "root"
xfsrestore: file system id: 82d461cb-002a-4bd3-9f33-0870656b154a
xfsrestore: session id: 8075cffa-e01e-4fd9-a177-23a056ce8be8
xfsrestore: media id: 1cf8a3f9-de8d-4125-a3c1-c7305a5b0668
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 12396 directories and 94871 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 316 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /mnt/home/root.dmp OK (success)
xfsrestore: Restore Status: SUCCESS
~]# lsblk -o name,size,mountpoint,uuid
~]# cat /mnt/root/etc/fstab
~]# umount /mnt/root
~]# umount /mnt/home
~]# init 6
Edited on