Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Resize LVM volumes

Leer en espanol
Resize LVM volumes

Table of contents

LVM is an implementation of a logical volume manager for the Linux kernel. It was originally written in 1998 by Heinz Mauelshagen, which was based on the volume manager ===

What is LVM?

LVM is an implementation of a logical volume manager for the Linux kernel. It was originally written in 1998 by Heinz Mauelshagen, which was based on the Veritas volume manager used on HP-UX systems.

LVM includes many of the features expected from a volume manager, including:

  • Resizing logical groups
  • Resizing logical volumes
  • Read-only snapshots (LVM2 offers read and write)
  • RAID0 of logical volumes.

Once we have reviewed the concepts, let's start:

In this entry we are going to see how to extend a logical and physical volume to expand a file system

We check how much space the disk has

Bash
fdisk -l /dev/sdb

Disk /dev/sdb: 50 GB, 53687091200 bytes

We rescan the disk

Bash
echo 1 > /sys/block/sdb/device/rescan

echo ‘1’ > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan

We check the disk size again

Bash
fdisk -l /dev/sdb

Disk /dev/sdb: 60 GB, 64424509440 bytes

As we can see, the size of the disk increased, but when running pvs it does not show the same information because the volume has not been extended.

text
pvs | grep /dev/sdb

/dev/sdb vg_app lvm2 a– 50g 0

If we expand the volume using the pvresize command

text
pvresize /dev/sdb

Physical volume «/dev/sdb» changed

1 physical volume(s) resized / 0 physical volume(s) not resized

By consulting the volume space again we can see how it shows the correct size

text
pvs | grep /dev/sdb

/dev/sdb vg_app lvm2 a– 60g 0

Now we just need to expand the logical volume

text
lvextend -l+100%FREE /dev/mapper/vg_app-lv_web

resize2fs /dev/mapper/vg_app-lv_web

All the best.

Comments