Skip to content

Extend a live volume with LVM

Sizing storage up-front is hard — workloads grow. The simple Resize a volume flow requires the volume to be detached. This page shows how to expand storage live, without unmounting, by managing a Logical Volume Manager (LVM) group that spans multiple OpenStack volumes — each new volume is attached and added to the group, and the logical volume grows underneath the running filesystem.

Prerequisites

  • A running Ubuntu (or similar Linux) instance with at least one attached secondary volume.
  • Root access on the instance.
  • A recent snapshot of the volume before starting (LVM operations on live volumes can fail in ways that leave the filesystem in an inconsistent state).

Steps

1. Build the initial LVM volume group

Start with a running instance and an attached secondary volume. See Launch an instance, Create a volume, and Attach a volume to an instance if you don't have those yet.

Create a volume group in LVM on the newly attached volume:

vgcreate /dev/Volume_Group_1 /dev/vdb

Expected Output:

  Physical volume "/dev/vdb" successfully created.
  Volume group "Volume_Group_1" successfully created

Create a logical volume within the new volume group:

lvcreate -L +9G --name app_data Volume_Group_1

Expected Output:

  Logical volume "app_data" created.

Verify that the volume group was created:

vgdisplay

Expected Output:

--- Volume group ---
  VG Name               Volume_Group_1
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <10.00 GiB
  PE Size               4.00 MiB
  Total PE              2559
  Alloc PE / Size       2304 / 9.00 GiB
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               bjqp3k-i8l5-7vmR-eO0o-8TaQ-Z7BX-a2aCtI

2. Create a filesystem and mount it

Create an ext4 filesystem on the new Logical Volume:

mkfs -t ext4 /dev/Volume_Group_1/app_data

Expected Output:

mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 2359296 4k blocks and 589824 inodes
Filesystem UUID: 4705017d-6a81-4a4c-b8df-04dea461d32f
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

Mount the newly created partition:

mkdir -p /mnt/app_data
mount -rw /dev/Volume_Group_1/app_data /mnt/app_data

3. Extend the volume group with a second disk

Create an additional volume, attach it to the instance, and then extend the volume group:

vgextend /dev/Volume_Group_1 /dev/vdc

Expected Output:

  Physical volume "/dev/vdc" successfully created.
  Volume group "Volume_Group_1" successfully extended

4. Extend the logical volume

lvextend -L 24GB /dev/Volume_Group_1/app_data

Expected Output:

  Size of logical volume Volume_Group_1/app_data changed from 9.00 GiB (2304 extents) to 24.00 GiB (6144 extents).
  Logical volume Volume_Group_1/app_data successfully resized.

5. Resize the filesystem

Resize the partition to the new maximum size:

resize2fs /dev/Volume_Group_1/app_data

Expected Output:

resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/Volume_Group_1/app_data is mounted on /mnt/app_data; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/Volume_Group_1/app_data is now 6291456 (4k) blocks long.

Verification

Confirm the new size:

df | grep -i app_data

Expected Output:

/dev/mapper/Volume_Group_1-app_data  24660348      24  23542956   1% /mnt/app_data

Next steps

  • Take a snapshot of the extended volume — the LVM layout change is a sensible point to capture a fresh restore point.
  • Manage snapshots — list and clean up snapshots as you accumulate them.
  • Resize a volume — when you only have one volume and can afford the detach window, the Portal-side extend is simpler than the LVM dance.