How can i increase and reduce the sizes of LVM partition?

Server Administration ForumHow can i increase and reduce the sizes of LVM partition?
On_God asked 1 week ago PPU : 5




1 Answers
MaCrush answered 1 week ago

Hi, your question is pretty vague.

For instance, you didn’t mention the type of Linux distribution that you are using, the file system, or if it’s for a rooted or non-rooted volume. But I’ll answer as much as I can.

FOR INCREASING LVM PARTITION

Let’s say from 8G to 10G, using the CentOS 7 Linux distribution and for an LVM that is already mounted to /mnt. Check if yours is also mounted.

Make sure that you already have the needed space that you want to increase to. (in this case, the extra 2G needed to make it up to 10G). you can checkcheck this with the vgdisplay command.

Use the lvdisplay command to recheck the name of the Logical Volume name and size that you want to increase.

Then use “lvextend –L +2G/dev/centos/var” to increase by 2G.

Or “lvextend –L 10G/dev/centos/var” to increase to 10G.

Or “lvextend –L +100%FREE /dev/centos/var” to use all the free space.

After that, use the lvdisplay command to do a recheck.

Next, resize the file system.

For ext3 or ext4 file system, use: “resize2fs/dev/centos/var”.

For xfs file system, use: “xfs_growfs/dev/centos/var”.

FOR DECREASING LVM PARTITION.

From 10G to 8G.

First, you have to back up youyourr file against data corruption in case you type in an incorrect command.

FOR ROOT VOLUME

Since your O.S is using your file, you can’t unmount it. Instead, you should boot from a live CD.

check if your LVM has loaded automatically. If it hasn’t, then run the “vgchange –a y” command to load it.

use the e2fsck command to the file for errors; “e2fsck –fy/dev/centos/var”

to avoid data corruption, shrink the LVM to a size that is lower than what you want.

While you’re at it, make sure you have a free space of 7G (since we are decreasing to 8G)

now you can reduce the size to what you want using the lvreduce command. Use “lvreduce –L 8G/dev/vg/disk-name” to reduce to 8g. or “lvreduce –L -8G/dev/vg/disk-name” to reduce by 8G.

after confirming that you set the size to 8G, enter y and enter.

Finally, run “resize2fs ldev /centos/var” to make use of the space that you create.

FOR NON-ROOT VOLUMEVOLUME

Unmount with “unmount ldev/centos/var”. But before doing this, make sure to close down apps that use data from the file.

Follow from step 3 to step 7 in reducing LVM partition size for root volume.