Grow LVM (Ubuntu) KVM

Firstly, the VM should be shut down and we should increase the disk size. Then start the VM and go to the console.

# fdisk -u /dev/xvda
(-u shows sectors instead of cylinders. This is important)

(Make a note of the start sector of the LVM partition)
Command (m for help): p

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048      499711      248832   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2          501758    16775167     8136705    5  Extended
/dev/xvda5          501760    16775167     8136704   8e  Linux LVM

(delete the LVM and/or Extended partition)
Command (m for help): d
Partition number (1-5): 2

(Create a new partition)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)5
e (I choose extended but you may choose extended)
Partition number (1-4): 2 (choose one that's available)


(Create a new extended partition)
Command (m for help): n
Command action
 e extended
 p primary partition (1-4)
e (I choose extended but you may choose extended)
Partition number (5-8): 5 (choose one that's available)

(Fill in the start sector of the LVM partition we deleted above)
First sector (63-16777215, default 63): 501760
Last sector, +sectors or +size{K,M,G} (501760-16777215, default 16777215): (Enter)

(change created partition to Linux LVM)
Command (m for help): t 
Partition number (1-7): 5
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048      499711      248832   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2          501758    16775167     8137727    5  Extended
/dev/xvda5          501760    16777215     8137728   8e  Linux LVM

Command (m for help): w (write)

# reboot

(Resize physical volume)
# pvresize /dev/xvda5

(make a note of the VG "Free PE")
# vgdisplay

(make a note of the "LV Name" of the LV you want to resize)
# lvdisplay 

(Resize LV. Fill in the found "Free PE" and "LV Name" (without the brackets))
# lvresize -l +[Free PE] [LV Name]

(resize the file system)
# resize2fs [LV Name] 
# reboot

Leave a Reply