Howto::Resize LVM

From Computer Science Wiki
Revision as of 10:11, 19 August 2021 by Carnold (talk | contribs)
Jump to navigation Jump to search

Introduction

This how to will explain how to resize your LVM volume to use to full size available on your Virtual Machine.

Resize the LVM partition

First you must resize the partition that LVM is using. Make sure that you use your correct VM disk device and partition! Run these as root:

  • parted /dev/sda - In this case the VM disk is /dev/sda
  • resizepart 2 100% - In this case the LVM partition is extended partition 2 and 5
  • resizepart 5 100%
  • quit

Resize the LVM physical volume

Determine your LVM physical volume:

  • pvs
  PV         VG       Fmt  Attr PSize   PFree 
  /dev/sda5  vgubuntu lvm2 a--  <49.50g 48.00m

Resize the PV:

  • pvresize /dev/sda5 - In this case the LVM PV is /dev/sda5

Your LVM group should now have the full amount available. You can create a new logical volume or resize an existing volume.

Resize an existing LVM logical volume

Determine the LVM LV that you want to resize

  • lvdisplay
  --- Logical volume ---
  LV Path                /dev/vgubuntu/root
  LV Name                root
  VG Name                vgubuntu
  LV UUID                cgSheV-OV17-d5Zy-oeJ2-evqi-O1Pz-qmLTaR
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2021-08-18 13:47:23 -0400
  LV Status              available
  # open                 1
  LV Size                <48.50 GiB
  Current LE             12415
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vgubuntu/swap_1
  LV Name                swap_1
  VG Name                vgubuntu
  LV UUID                i9VuXs-U6v9-UTvP-dL1P-ItpK-WRed-wc5Axq
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2021-08-18 13:47:23 -0400
  LV Status              available
  # open                 2
  LV Size                976.00 MiB
  Current LE             244
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

Resize the LV:

  • lvresize --extents +100%FREE --resizefs /dev/vgubuntu/root - In this case the LV path is /dev/vgubuntu/root

Note: This command also automatically resizes your filesystem for you