How to carefully reduce an LVM logical volume and do the calculations

Hello!

Let’s imagine that we want reduce the size of an LVM partiton (logical volume) by 30 GiB.

They are 6 steps to follow:

  • Backup your data (very important in case of calculation error!)
  • Unmount the file system for reducing.
  • Check the file system after unmount.
  • Reduce the file system.
  • Reduce the Logical Volume size than Current size.
  • Recheck the file system for error.

I won’t explain how to do the 2 first steps, they are easy…

Check the file system

Must pass in every 5 steps of file-system check.

Reduce the file system

We have to do some calculation. And to do so, we need to know block count and block size of the partition. We can get them like this:

By calculate [block count] * [block size] , we get the size of our partition in bytes:

As I said before, to we want reduce the size of the partition by 30 GiB which is equal to 32212254720 bytes:

So our new partition size is…

… 287825723392 bytes which is equal to 281079808 KiB:

So we can now set the partition new size:

Reduce the Logical Volume size

We need to know the LVM volume group PE size:

The PE size is 4 MiB.

30 GiB is equal to 30720 MiB:

So 30 GiB is equal to 7680 PE:

Now, we can reduce the logical volume using PE size:

Recheck the file system for error

If these 2 commands didn’t report any error, then it’s fine.

Hope that it helped you! 😃

Online maths tutor and developer — mathcam.ch