• 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 change a system’s machine-ID in Oracle Enterprise Linux 7
  2. How to install and configure MariaDB in CentOS / RHEL 7
  3. a2enconf: command not found
  4. CentOS / RHEL 6 : How to setup yum repository using locally mounted DVD
  5. qsub: command not found
  6. CentOS / RHEL 6 : How to configure 802.1q VLAN On NIC
  7. slop Command Examples in Linux
  8. fstrim Command Examples in Linux
  9. notify-send: command not found
  10. cryptsetup: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright