Extending linux LVM partition

Published on December 5, 2019 at 9:53:21 PM GMT+8 by Administrator

This article explain briefly on how you can extend the linux LVM partition


Extending linux LVM partition

There are three steps to make:

  1. alter your partition table so sda2 ends at end of disk
  2. reread the partition table (will require a reboot)
  3. resize your LVM pv using pvresize


Step 1 - Partition table

Run lsblk to confirm the layout OR partitioning scheme to get a better understanding about our disk partition.

Run fdisk /dev/sda. Issue p to print your current partition table and copy that output to some safe place. Now issue d followed by 2 to remove the second partition. Issue n to create a new second partition. Make sure the start equals the start of the partition table you printed earlier. Make sure the end is at the end of the disk (usually the default).

Issue t followed by 2 followed by 8e to toggle the partition type of your new second partition to 8e (Linux LVM).

Issue p to review your new partition layout and make sure the start of the new second partition is exactly where the old second partition was.

If everything looks right, issue w to write the partition table to disk. You will get an error message from partprobe that the partition table couldn't be reread (because the disk is in use).

Reboot your system

This step is neccessary so the partition table gets re-read.

Resize the LVM PV

After your system rebooted invoke pvresize /dev/sda2. Your Physical LVM volume will now span the rest of the drive and you can create or extend logical volumes into that space.

Example below is how to extend the available space at /dev/sda2 to root partition

lvextend -l +100%FREE --resizefs /dev/centos/root