Important lvextend command in Linux

Linux LVM

In this post, I will discuss the lvextend command in Linux. I will show you practical example of how to extend the LVM partition using lvextend command. Increasing the size of the file system in Linux without any data loss is one of the important tasks for any system admin. lvextend is a tool in  LVM(Logical Volume Manager) provides that provides support to increase and reduce the file system size without data loss. Now the first question comes to mind when we use the lvextend command? To understand this question, let’s create a simple Scenario.

Suppose you are getting alert for file system. Alert said that any specific mount point say /usr filled with 100%. Now it our task to add some space to stop getting alerts.

Below are the steps to add space on any mount point.

prerequisites -:

Physical volume (PV)

volume groups in Linux (VG)

if you have space in vgs then only you can increase space to that mount point. why I am saying this , I will show you.

Step 1:  run df -hT

lvextend command in LINUX

see above out carefully,

/dev/mapper/os_vg-usr xfs 8.5G 3.9G 4.7G 46% /usr

Let’s break this to understand better the relation between VG and LV.

/dev/mapper – The device-mapper is a framework provided by the Linux kernel for mapping physical block devices onto higher-level virtual block devices [Google]

os_vg – volume group

usr- logical volume

/usr – folder ( above path mounting to usr folder)

lvextend command in LINUX

Let take some more output to clear everything.

Step 2 : run vgs :

lvextend command in LINUX

There are 2 volume group exist in this server. for better understand run vgdisplay command.

lvextend command in LINUX

Basically our lv depends in vg ,  in above example our /usr mount point is mounted on os_vg volume group and usr logical volume.

Step 3: run lvs

lvextend command in LINUX

Now you can see more clearly relation between VG and LV.

In this case , we don’t have any mount point which have 100% full , so i am performing my task on /usr mount point.

Let see output of df -hT before increase space to /usr mount point.

lvextend command in LINUX

Now I am adding 500MB to make it 9.0 Gb

Step 4 : use lvextend

syntax  :       lvextend -L +X G/M /dev/mapper/vg- lv 

X – the number of amounts you want to add space. G/M – GB / MB

MOST  IMPORTANT: ALWAYS PUT + SIGN BEFORE AMOUNT OF SPACE OTHERWISE YOU CAN LOSE DATA.

lvextend command in LINUX

See above output. why space is not added after running lvextend?

lvextend command only takes space from VG and add in LV. After add space in LV we have to run a command to resize that mount point. There are different types of file systems, the most commonly used are EXT4 and XFS.

for resizing EXT4 , we use resize2fs command.

for resizing XFS , we use xfs_growfs command.

So that is all about lvextend utility. If you are a beginner then take help from experienced before running those all commands, because once you add space in any mount point then it is the most difficult task to retrieve back. Memory is in disk format and distributed in sectors so, you don’t know in which sector the data has been written.

In the previous article, I show you basic commands using Linux. If you were not visited yet, please Click here.

Hope you like our Blog. If you want to have any issues then please do comment. We are always ready to help and always ready to update ourselves. If you have not subscribed to infohubblog then please do subscribe for the upcoming Blog.

Reference :

https://www.linuxtechi.com/extend-lvm-partitions/

2 Comments on "Important lvextend command in Linux"

  1. Suresh Iyyanar | August 21, 2021 at 11:00 am | Reply

    excellent blog !!!!!!! simply super………….

Leave a comment

Your email address will not be published.


*