canada flag  linkedinfacebook   Call Us Today: (613) 494-5010

Resize LVM disk partition

Let's say you've gotten a bigger disk (or just resized a VM partition) and now would like to use the extra space. Since for this example we are using LVM, the resizing has to be done using the following steps:

Assuming you want to use all of the free space, let's see what we got: 50Gb before resize

lvdisplay /dev/mapper/vg_smtp-lv_root
  --- Logical volume ---
  LV Path                /dev/vg_smtp/lv_root
  LV Name                lv_root
  VG Name                vg_smtp
  LV UUID                7wN75k-elLc-Dw9n-iWdY-25RV-syNl-HP7Z7U
  LV Write Access        read/write
  LV Creation host, time smtp, 2016-03-26 13:42:02 -0400
  LV Status              available
  # open                 1
  LV Size                47.54 GiB
  Current LE             12170
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Let's run the resize command. It is important to put +100%, otherwise you'll get an error:
New size given (XXX extents) not larger than existing size (XXX extents)

lvextend -l +100%FREE /dev/vg_smtp/lv_root
Size of logical volume vg_smtp/lv_root changed from 47.54 GiB (12170 extents)
to 75.66 GiB (19370 extents).

Let's see if it extended (yes, we now have 80Gb):

lvdisplay /dev/mapper/vg_smtp-lv_root
  --- Logical volume ---
  LV Path                /dev/vg_smtp/lv_root
  LV Name                lv_root
  VG Name                vg_smtp
  LV UUID                7wN75k-elLc-Dw9n-iWdY-25RV-syNl-HP7Z7U
  LV Write Access        read/write
  LV Creation host, time smtp, 2016-03-26 13:42:02 -0400
  LV Status              available
  # open                 1
  LV Size                75.66 GiB
  Current LE             19370
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

But if we do a df, the size is the same (reboot won't help).

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_smtp-lv_root
                       47G   35G  9.3G  80% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   70M  382M  16% /boot

You have to reboot the system into something like System Rescue CD and then run these commands to resize the file system:

resize2fs /dev/vg_smtp/lv_root

Let's check after our reboot back into the OS (file-system resized to 80Gb ):

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_smtp-lv_root
                       75G   35G   36G  50% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   70M  382M  16% /boot

 ALT IT Consulting is a full service IT support firm, assisting clients across US and Canada. Original article has been posted on ALT IT Consulting Miami.

Last updated Mar 17, 2019