March 24, 2015 Hatem

Resize LVM partition on the fly

I used to limit my Ubuntu partition size for many reasons, for example if my HD is 1TB, my Ubuntu partition is about 100G only. But this partition might get full quickly as you can see below I have used 94% of my storage :

$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-root   84G   75G  5.5G  94% /

To resize this on the fly, let’s add 50G :

$ sudo lvextend -L+50G /dev/ubuntu-vg/root
 Extending logical volume root to 135.00 GiB
  Logical volume root successfully resized

That’s it, we just need to tell our filesystem that the volume size changed :

$ sudo resize2fs /dev/ubuntu-vg/root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/ubuntu-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 6, new_desc_blocks = 9
The filesystem on /dev/ubuntu-vg/root is now 35389440 blocks long.

Now if we run df again we can see that I have now 53G available but not 55.5G, since before I had 5.5G available. The reason is that I was working in the same time on that partition and used 2.5G in the meantime.

$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-root  133G   75G   53G  59% /

The end.

Leave a Reply

Your email address will not be published. Required fields are marked *

(HBY) Consultancy