Live Resizing LVM on Linux

Robert AndresenTutorials Leave a Comment

Expanding disk on Linux can always be a pain. Most guides I found requires a restart, which is not always that popular on an production server. This guide was written as we had to expand a disk on our internal webserver at work, running Ubuntu server 16.04.

A special thanks to SirLagz for his guide on this topic:

Expand disk in VMware vCenter and run scsi rescan for the system to catch the disk-changes.

Find devices:

ls /sys/class/scsi_device/

Init scan:

echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

Check changes:

fdisk -l
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x306b05de

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   6293503   6291456   3G 83 Linux
/dev/sda2       6293504 167772159 161478656  77G  5 Extended
/dev/sda5       6295552 167772159 161476608  77G 8e Linux LVM

Expand partition
In the example above you’ll see that the LVM partition is inside an extended partition. Both of these must be expanded in this case. Expand the Extended partition first:

parted /dev/sda
resizepart 2 100%
resizepart 5 100%
print free

Expand Physical Volume (PV)

pvresize /dev/sda5

Expand Logical Volume (LV)

lvresize -l +100%FREE /dev/s1000-2wm-0030-vg/root

Expand filesystem

df -h
resize2fs /dev/mapper/s1000--2wm--0030--vg-root