• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

RHEL / CentOS : How to shrink LVM volume

by admin

Unlike increasing the LVM volume size, to shrink the volume we need to umount the filesystem. Shrinking LVM volume can not be done online.

Before shrinking the volume make sure you have taken the backup of the mount point. Shrinking volume has a chance of data corruption. Example given in this post applies to both RHEL 6 and 7

1. In the example for this post we have a volume /dev/data_vg/lv_data01 mounted on the mount point /data01 :

# df -hP | grep data01
/dev/mapper/data_vg-lv_data01  976M  2.6M  907M   1% /data01
# lvs
  LV         VG      Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  root       centos  -wi-ao----  17.51g
  swap       centos  -wi-ao----   2.00g
  lv_data01  data_vg -wi-ao----   1.00g

2. Before shrinking the volume, umount the mount point and run fsck on it.

# umount /data01
# e2fsck -f /dev/data_vg/lv_data01
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/data_vg/lv_data01: 11/65536 files (0.0% non-contiguous), 12955/262144 blocks

3. Shrink the file system to the desired size. In our case we will reduce the volume from 1G to 800MB.

# lvreduce -r -L 500M /dev/data_vg/lv_data01
fsck from util-linux 2.23.2
/dev/mapper/data_vg-lv_data01: clean, 11/65536 files, 12955/262144 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/data_vg-lv_data01 to 128000 (4k) blocks.
The filesystem on /dev/mapper/data_vg-lv_data01 is now 128000 blocks long.

  Reducing logical volume lv_data01 to 500.00 MiB
  Logical volume lv_data01 successfully resized

4. Mount the filesystem again and verify the new size.

# mount -t ext4 /dev/data_vg/lv_data01 /data01
# df -hP | grep data01
/dev/mapper/data_vg-lv_data01  460M  1.6M  424M   1% /data01
# lvs
  LV         VG      Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  root       centos  -wi-ao----  17.51g
  swap       centos  -wi-ao----   2.00g
  lv_data01  data_vg -wi-ao---- 500.00m
CentOS / RHEL : How To Shrink LVM Root File System

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to restrict ssh logins by user and client address on CentOS/RHEL
  2. pvremove Command Examples in Linux
  3. Tutorial on Linux Clustering (High Availability)
  4. How to set ulimit values for a systemd service
  5. CentOS / RHEL 7 : Shutting Down, Suspending, or Rebooting Commands (systemctl)
  6. Understanding linux parted utility
  7. find WWN Number of HBA Card in Redhat Linux and CentOS
  8. Nohup Command Examples – Runs a Command that Keeps Running after You Log Out
  9. printk and console log level
  10. How to Change Time Interval to Fall Back to Secondary DNS Server in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright