Linux Commands

How do I shrink my LVM volume?

One of the most challenging decisions a new user faces when installing Linux is partitioning the disc drive. The requirement to predict how much space will be required for system and user files puts the installation more complicated than it needs to be, as well as some users easily take all of their data into one huge partition to avoid the problem. Logical Volume Management, or LVM, is a packing device management technique that allows users to pool and encapsulate the physical layout of component storage systems for easier and more flexible management. Logical volume management is quite alike to virtualization in that it allows you to build as many virtual storage volumes as you need on top of a particular storage device. The logical storage volumes that result can be increased or decreased to meet your changing storage requirements. In laptop storage, logical volume management (LVM) is a mechanism for allocating space on devices significantly more flexible than traditional partitioning schemes for storage space. Increased abstraction, adaptability, and control are the key benefits of LVM.

The names of logical volumes can be meaningful. On a running system, volumes can be enlarged dynamically as storage space vary, and they can be readily transferred between physical devices inside the pool or exported. One of the advantages of LVM systems is the ability to efficiently and rapidly scale storage capacity. Of yet, sysadmins frequently need to scale up (increase capacity). It’s also worth noting that LVM can be used to reduce storage capacity. This means you can reduce storage capacity if it is over-allocated (you configured considerably more storage than required). In this guide, we will go over the process to shrink LVM volume in Ubuntu 20.04 system.

Method to shrink LVM volume in Ubuntu 20.04 system

As the LVM utility is not included on the Live CD, we should first install it by executing the cited command in the terminal of the Ubuntu 20.04 Linux system.

$ sudo apt-get install lvm2

That’s always a good idea to check what physical volumes are already set up on your system. Utilize the pvs command to achieve this task.

$ sudo pvs

To check out the complete information of physical volume, execute the appended command.

$ sudo pvdisplay

Forming a New Volume Group in Ubuntu 20.04 Linux system from Physical Volumes

Utilize the vgcreate instruction to establish a new volume group from LVM physical volumes. Execute the below-mentioned command to establish a new volume group in Ubuntu 20.04 Linux system.

$ sudo vgcreate LVMgTEST /dev/sda1

We have created a volume group named “LVMgTEST.” You can create any other as per your work requirements. The vgscan instruction can be utilized to search for currently accessible volume groups on the system. If necessary, it additionally rebuilds the cache file. When transferring a volume group into a new system, this command is useful. To execute it as :

$ sudo vgscan

Creating a Logical Volume in Ubuntu 20.04 Linux system

Utilize the lvcreate command to build a logical volume from the volume group storage pool. The -L option specifies the logical volume’s size, the -n option specifies a name, and the -v option specifies the volume group from which space will be allocated.

To make a 20MB logical volume called test from the LVMgTEST volume group, for example, type the below-appended command in the terminal:

$ sudo lvcreate –L 20MB –n test LVMgTEST

Presenting Information related to Logical Volumes

LVM has a collection of tools for displaying information about logical volumes. The lvscan option, as the other LVM elements, scans the system and provides minimum information on the logical volumes. Execute the affixed command as:

$ sudo lvscan

The lvreduce command can be used to reduce the size of a logical volume. Reduce this to the size of the volume that you desire, as indicated by the -L flag. So run the cited below command in the shell

Sudo lvreduce –L 5MB /dev/ LVMgTEST/test

When you run the lvreduce command, you will get a warning about the size you’ve chosen to reduce to. Use this as a chance to double-check that you’re lowering the logical volume to a size that isn’t smaller than the file system size. Enter ‘y’ and hit enter once you’ve confirmed it’s okay to go forward.

Conclusion

In this tutorial, we have explained the concept of physical and logical volumes in the Ubuntu 20.04 Linux system. Also, we have created logical volume groups as well. The process to shrink LVM volume in Ubuntu 20.04 system is also elaborated. I am hopeful you will easily understand this guide and implement it conveniently.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content