LVM — Extending Logical Volume in Linux
Mahinsha Nazeer

Mahinsha Nazeer @mahinshanazeer

About: Certified engineer—just one loose nut away from a total breakdown

Location:
Hyderabad, India
Joined:
Apr 14, 2025

LVM — Extending Logical Volume in Linux

Publish Date: Apr 20
0 0

LVM — Extending Logical Volume in Linux

Extending LVM volume on linux system

What is LVM?

(From official Redhat documentation)

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes.

With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes. LVM physical volumes can be placed on other block devices which might span two or more disks.

The physical volumes are combined into logical volumes, with the exception of the /boot partition. The /boot partition cannot be on a logical volume group because the boot loader cannot read it. If the root (/) partition is on a logical volume, create a separate /boot partition which is not a part of a volume group.

Since a physical volume cannot span over multiple drives, to span over more than one drive, create one or more physical volumes per drive.

  1. Physical Disk : This is the actual hardware component, such as a hard drive or SSD, where data is stored. It’s the physical medium that holds the data.

Disk1, Disk2, Disk3

  1. Physical Volume (PV): A physical volume is a storage device that has been initialized for use by the Logical Volume Manager (LVM). It can be a whole disk or a partition on a disk. PVs are the building blocks for creating volume groups.

Physical Volume 1 — /dev/nvme0n1

Physical Volume 2 — /dev/nvme0n2

Physical Volume 3 — /dev/nvme0n3

Physical Volume 4 — /dev/nvme0n4

  1. Volume Group (VG): A volume group is a collection of physical volumes. When you create a VG, you combine multiple PVs into a single storage pool. This allows for more flexible and efficient use of storage space.

vghome — /dev/vghome

  1. Logical Volume (LV): A logical volume is a virtual partition created from the space in a volume group. LVs can be resized, moved, and managed independently of the underlying physical storage. They provide a flexible way to allocate storage for different purposes.

Logical Volume 1 — /dev/vg-home/lv-1

Logical Volume 2 — /dev/vg-home/lv-2

Logical Volume 3 — /dev/vg-home/lv-3

Logical Volume 4 — /dev/vg-home/lv-4

Physical Volumes:

The underlying physical storage unit of an LVM logical volume is a block device such as a partition or whole disk. To use the device for an LVM logical volume, the device must be initialized as a physical volume (PV). Initializing a block device as a physical volume places a label near the start of the device.

By default, the LVM label is placed in the second 512-byte sector. You can overwrite this default by placing the label on any of the first 4 sectors when you create the physical volume. This allows LVM volumes to co-exist with other users of these sectors, if necessary.

An LVM label provides correct identification and device ordering for a physical device, since devices can come up in any order when the system is booted. An LVM label remains persistent across reboots and throughout a cluster.

The LVM label identifies the device as an LVM physical volume. It contains a random unique identifier (the UUID) for the physical volume. It also stores the size of the block device in bytes, and it records where the LVM metadata will be stored on the device.

The LVM metadata contains the configuration details of the LVM volume groups on your system. By default, an identical copy of the metadata is maintained in every metadata area in every physical volume within the volume group. LVM metadata is small and stored as ASCII.

Currently LVM allows you to store 0, 1 or 2 identical copies of its metadata on each physical volume. The default is 1 copy. Once you configure the number of metadata copies on the physical volume, you cannot change that number at a later time. The first copy is stored at the start of the device, shortly after the label. If there is a second copy, it is placed at the end of the device. If you accidentally overwrite the area at the beginning of your disk by writing to a different disk than you intend, a second copy of the metadata at the end of the device will allow you to recover the metadata.

Volume Groups:

Physical volumes are combined into volume groups (VGs). This creates a pool of disk space out of which logical volumes can be allocated.

Within a volume group, the disk space available for allocation is divided into units of a fixed-size called extents. An extent is the smallest unit of space that can be allocated. Within a physical volume, extents are referred to as physical extents.

A logical volume is allocated into logical extents of the same size as the physical extents. The extent size is thus the same for all logical volumes in the volume group. The volume group maps the logical extents to physical extents.

Logical Volumes:

The volume groups can be divided into logical volumes, which are assigned mount points, such as /home and / and file system types, such as ext2 or ext3. When “partitions” reach their full capacity, free space from the volume group can be added to the logical volume to increase the size of the partition. When a new hard drive is added to the system, it can be added to the volume group, and partitions that are logical volumes can be increased in size.

On the other hand, if a system is partitioned with the ext3 file system, the hard drive is divided into partitions of defined sizes. If a partition becomes full, it is not easy to expand the size of the partition. Even if the partition is moved to another hard drive, the original hard drive space must be reallocated as a different partition or not used.

In this case, I am extending the volume of my EC2 instance running on AWS Environment. I get a new EBS volume and attach the volume to the EC2 machine. For easy configuration, we can keep the block ID of the volume. There will a block ID associated with all the EBS volume in AWS. This block ID is also similar in bare metal nodes.

So now to set up a new Logical Volume, follow these steps:

  1. Create Physical Volumes : Initialize one or more existing hard drives as physical volumes.
  2. Create a Volume Group : Combine the physical volumes into a volume group.
  3. Create a Logical Volume : Allocate space from the volume group to create a logical volume.
  4. Format the Logical Volume : Format the logical volume with the desired filesystem, such as EXT3, EXT4, XFS etc.

1. Creating Physical Volume(PV):

Use the following command to list the existing physical volumes:

sudo pvs
sudo pvdisplay
Enter fullscreen mode Exit fullscreen mode

Use the following command to list the attached drives with corresponding block ID:

lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,SERIAL | grep -i -e vol0783341 *******e53 -e vol4558415********** -e vol0556421 **********
Enter fullscreen mode Exit fullscreen mode

Output will be similar to the following:

[root@ip-10–0–1–22 ~]# lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,SERIAL | grep vol0783341 ******* e53
nvme0n1 10T vol0783341 ******* e53
nvme0n2 10T vol4558415 **********
nvme0n3 10T vol0556421 **********
Enter fullscreen mode Exit fullscreen mode

Now run the following command to create the volume ID:

pvcreate /dev/nvme5n1
Enter fullscreen mode Exit fullscreen mode

Then run ‘lsblk’ command and watch the output, the attached drive will be now showing as a disk

[root@ip-10–0–1–22 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 10T 0 disk
nvme0n2 259:0 0 10T 0 disk
nvme0n3 259:0 0 10T 0 disk
Enter fullscreen mode Exit fullscreen mode

2. Create a new Volume Group/Adding a new physical volume to existing group:

If you are trying to create a new volume group (VG), use the following commands.

Create a volume group named vg-home: Use the following commands to create a volume group named vg-home with 3 physical volumes. This will result in a volume group size of 30T:

sudo vgcreate vg-home /dev/nvme0n1 /dev/nvme0n2 /dev/nvme0n3
Enter fullscreen mode Exit fullscreen mode

To display the volume groups, use either of the following commands:

sudo vgs
sudo vgdisplay
Enter fullscreen mode Exit fullscreen mode

If you plan to extend the existing volume group without creating a new one, use the same commands to view the current volume group details.

To extend the volume group, run the following command. In this example, vg-home is the volume group name, and /dev/nvme0n1 is the physical volume to be added to vg-home:

vgextend vg-home /dev/nvme0n1
Enter fullscreen mode Exit fullscreen mode

Run the volume group display command again to verify the updated volume group size:

3. Create or Extend Logical Volume:

If we want to create a new logical volume from the volume group, first identify the volume-group and get the details:

vgdisplay
Enter fullscreen mode Exit fullscreen mode

To create a logical volume named vol1 in the vg-home volume group, use the following command, Replace [size] with the desired size of the logical volume, for example, 10G for 10 gigabytes:

lvcreate -L 10G -n vol1 vg-home
Enter fullscreen mode Exit fullscreen mode

To identify all the logical volumes in the vg-home volume group, use the following command:

lvdisplay vg-home
Enter fullscreen mode Exit fullscreen mode

The following command will list all the logical volumes

lvdisplay
Enter fullscreen mode Exit fullscreen mode

Now use the following command to extend the volume, here ‘+1T’ shows the size of memory we want to extend for the the logical volume ‘vol1’:

sudo lvextend -L +1T /dev/vg-home/vol1
Enter fullscreen mode Exit fullscreen mode

If you want to use all there remaining freespace to vol1, use the following command:

sudo lvextend -l +100% /dev/vg-home/vol1
Enter fullscreen mode Exit fullscreen mode

Formatting Logical Volume:

Once the volume is created, we can use the following command to format the volume,

mkfs.ext4 /dev/vg-home/vol1 #to ext4
mkfs.ext3 /dev/vg-home/vol1 #to ext3
mkfs.ext2 /dev/vg-home/vol1 #to ext2
mkfs.xfs /dev/vg-home/vol1 #to xfs
mkfs.vfat /dev/vg-home/vol1#to btrfs
mkfs.ntfs /dev/vg-home/vol1 #to ntfs
Enter fullscreen mode Exit fullscreen mode

Once this is done, we can use the following commands to verify the details:

lsblk -f
fdisk -l
Enter fullscreen mode Exit fullscreen mode

Please note that this blog does not cover the steps for mounting the volume to any location. It specifically focuses on creating or extending LVM volumes only.

Thank you for reading! If there’s anything I missed, please let me know.

Comments 0 total

    Add comment