#lvm

Expand disk with LVM

This article will guide to expand disk with LVM. My scenario is I install linux in virtual machine VMWare. And I use VMWare to expand disk (sdb) from 80G to 160G. So now, I need to setup linux machine to use expanded disk.

At the first, check disks with fdisk

You can see in the output that /dev/sdb is 160 Gb. However, we just create a partition sdb1 (80G).

So use fdisk to add a new partition sdb2  (type Linux LVM)

Step 2, create physical volume with pvcreate:

Step 3, extend volume group:

Extend logical volume

Finally, re-size file system:

 

LVM remove physical volume

This article will show you the way to remove physical volume from logical volume group. The scenario as below:

Your machine have volume group named sonnst-vg. This group contains two physical volumes: sda5 and sdb1. And now, you want to remove sdb1 from sonnst-vg. See the details with lvdisplay command:

You should pay attention to “Physical extents 0 to 20478”. To remove, you use command lvreduce as below:

(Before try this command, please backup everything in your disk :))

Please note that number 20479 is calculated by 20478 + 1

Test the result with lvdisplay:

Reboot for now.