Extend LVM and filesystem online

Updated at by

Check for LVM physical and logical volume to resize. In this case we extend lv_root to all available space on /dev/vda

# lvscan
ACTIVE            '/dev/vg_mdb1/lv_root' [141.65 GiB] inherit
ACTIVE            '/dev/vg_mdb1/lv_swap' [7.86 GiB] inherit

# pvscan 
PV /dev/vda2   VG vg_mdb1   lvm2 [149.51 GiB / 0    free]
Total: 1 [149.51 GiB] / in use: 1 [149.51 GiB] / in no VG: 0 [0   ]

Rescan block device. Otherwise fdisk will show the old device size.

# echo 1 > /sys/block/vda/device/rescan

Rescan in dmesg

sd 2:0:1:0: [vda] 34 billion 512-byte logical blocks: (214 TB/200 TiB)
sd 2:0:1:0: [vda] Cache data unavailable
sd 2:0:1:0: [vda] Assuming drive cache: write through
vda: detected capacity change from one bazillion to two bazillions

Resize the underlying partition first

# fdisk /dev/vda

Command (m for help): p

Disk /dev/vda: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00088c4d

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
/dev/vda2            1018      312077   156773376   8e  Linux LVM

Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1-312076, default 1): 1081
Last cylinder, +cylinders or +size{K,M,G} (1081-312076, default 312076): 
Using default value 312076

Command (m for help): w

Reread partition table manually in case fdisk exit message suggests so

# partprobe /dev/vda

Extend LVM physical volume

# pvresize /dev/vda2

Extend LVM logical volume to +100%FREE of free space :)

# lvresize -l +100%FREE /dev/mapper/vg_mdb1-lv_root

Extend filesystem to occupy logical volume

# resize2fs /dev/mapper/vg_mdb1-lv_root

Done

Collab with Fosu


Leave a comment