• 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

How to Reduce an LVM volume on Ubuntu

by admin

Question: How can I shrink an existing LVM volume to free up some space on my Ubuntu Machine?

Backup existing data

Before modifying any system, it is always recommended to create a backup first as there is an elevated risk of data corruption with reducing an LVM size. In most cases, the lvreduce command warns about possible data loss and asks for a confirmation. However, you should not rely on these confirmation prompts to prevent data loss because in some cases you will not see these prompts, such as when the logical volume is inactive or the –resizefs option is not used. Note that using the –test option of thelvreduce command does not indicate where the operation is safe, as this option does not check the file system or test the file system resize.

Find the name of the logical volume that you would like to shrink (This example uses logical volume /dev/vg0/lv_data):

# lvs

For this example here is the current and expected volume size.

Current Volume Size: 100GB
Expected Volume size: 80GB

Run FS check

To perform a lvreduce, the disk must be unmounted, so this must be done when there is no need for activity on the disk. Then run a filesystem check to verify data integrity:

# umount /dev/vg0/lv_data
# e2fsck -f /dev/vg0/lv_data

Reduce the Volume

Resize the logical volume using the lvreduce command. This command can shrink the file system along with the logical volume.

# lvreduce -r -L 80G /dev/vg0/lv_data

Notice the -r flag here. As per man page of lvreduce:

-r|--resizefs
       Resize underlying filesystem together with the LV using fsadm.

Mount the Volume

You can mount the logical volume again:

# mount /dev/vg0/lv_data

Now the volume group has 20G of free space. You can then use lvcreate to create your new logical volume using the 20G free space.

Conclusion

In older Linux systems, lvreduce was missing “-r” option, which takes care of resizing underlying filesystem, hence, resize2fs is mandatory before shrinking logical volume. But this is not required any more.

Filed Under: Linux, Ubuntu

Some more articles you might also be interested in …

  1. How to Configure Interface bonding (NIC Teaming) on Oracle Linux 6
  2. How to burn an ISO to CD or DVD using Wodim
  3. cp: omitting directory – error while copying a directory in Linux
  4. /var/cache/yum Constantly Filling Files System in CentOS/RHEL
  5. sftp Command Examples in Linux
  6. Anonymous User Fails to Upload File to VSFTP Server
  7. CentOS / RHEL 5 : How to Boot into Rescue Mode
  8. CentOS / RHEL 7 : How to set default target (default runlevel)
  9. how to rotate Tang Server Keys and update the Clevis Client
  10. Command line parameters in shell scripts

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