Tag Archives: lvextend command

How to extend the file system online in LVM

Learn how to extend the file system or logical volume in LVM under HPUX and Linux without any downtime. Grow your mount point capacity without impacting users.

“Extend file system” is of the common task every Linux Unix sysadmin face in his life. Insufficient capacity planning during deploying systems, un-foreseen grown data, improper data rotation techniques can lead to mount points reaching their capacity limits. A quick solution is to grow those mount point’s total size to get some breathing space till you finalize on final solution about data management.

Extending file system is actually extending related logical volume and then growing FS over it. There are few pre-requisite you should consider before attempting for file system extension.

Pre-requisite :

  1. You have free PE available in the respective Volume group. (check using vgdisplay)
  2. If not, you must have free disk/LUN which can be added to that VG
  3. In case of old HPUX versions, online JFS must be installed (check using swlist)

How to do it :

Let’s start with the case: We have /data (/dev/vg01/lvol01) mount point of 1024MB in vg01 volume group which needs to be extended by 500MB.

Now, as per the pre-requisite, we should have free PE available in vg01. You can verify it by checking the “free PE” field in vgdisplay output. If it’s a non-zero number then you have some PE available to use. You need to calculate how much free space exists in VG. For that check “PE size” in vgdisplay output, multiply it with the number of PEs, the resulting number is MBs you have free in VG. You can extend your file system by this many MB sizes.

Suppose, you don’t have free PE in vg01 then you need to add a new disk or LUN to system. Once detected, you need to add it vg01 using vgextend command. Once your vg01 is extended with new disk/LUN, you will see free PE in vgdisplay output.

For quick reference –

# vgextend <vg_name> <pv_name>

Now you verified and confirmed, you have 500MB free in VG. Proceed to extend the logical volume of /data mount point i.e. /dev/vg01/lvol01 using lvextend command.

# lvextend -L 1524 /dev/vg01/lvol1
Logical volume "/dev/vg01/lvol1" has been successfully extended.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

Existing 1024+500Mb hence 1524 in command.

Now your logical volume is extended to the desired size. Still, you won’t be able to see this space growth in mount point size. You need to extend the file system as well for that.

In HPUX, you can use fsadm command (size to be specified in KB) like below :

# fsadm -b 1560576 /data

In RHEL6 you can use resize2fs command like :

root@kerneltalks # resize2fs /dev/vg01/lvol01
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/vg01/lvol01 is mounted on /data; on-line resizing required
old_desc_blocks = 320, new_desc_blocks = 384
The filesystem on /dev/vg01/lvol01 is now 1610612736 blocks long.

Here, it will grow with maximum size of lvol hence size is not specified.

In RHEL7, for XFS filesystem :

# xfs_growfs /data -D size

where size is in system block (depends on your config). If you don’t specify size (-D) then it grows to the maximum available size of lvol. So in our case, we don’t need to specify size. Check all xfs commands here.

Final check :

You are done! Check mount point new size in bdf (HPUX) or df -h (Linux) output. Note that we haven’t stopped access to apps/users to the mount point in question. This means the entire operation was done online without any downtime or impacting users.

LVM commands tutorial: Part 3: Logical Volume (lvextend, lvreduce, lvchange)

Series of the tutorial to learn LVM commands. In this part, learn how to extend, reduce and change the state of the logical volume (lvextend, lvreduce, lvchange)

In continuation of last part of a logical volume, we will be seeing more commands on lvol in this post. Previous posts of this LVM command tutorial can be found on below links :

Logical volumes like VG can be extended and shrank. We will be seeing lvextend, lvreduce, lvchangecommands in this post.

Command: lvextend

To extend logical volume, you should have enough free space within that VG. Command syntax is pretty much similar to lvcreate command for size. The only thing is you need to supply the final required size in command. For example, the current LV size is 1GB and you want to extend it with 2GB. Then you need to give the final 3GB size in the command argument.

# lvextend -L 3072 /dev/vg01/lvol1
Logical volume "/dev/vg01/lvol1" has been successfully extended.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

Another important option is of mirror copies. It plays a vital role in root disk mirroring. -m is the option with the number of mirror copies as an argument.

# lvextend -m 1 /dev/vg00/lvol1 /dev/disk/disk2_p2
The newly allocated mirrors are now being synchronized. This operation will
take some time. Please wait ....
Logical volume "/dev/vg00/lvol1" has been successfully extended.
Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf

Command: lvreduce

This command used for decreasing the number of mirror copies or decreasing the size of LV. This is the data destroying command. Hence make sure you have data of related file system backed up first. The size and mirror copy options are works the same for this command as well. -L for LE_reduce_size, -l number of LE to be reduced and -m is the number of copies to be reduced.

# lvreduce -L 500 /dev/vg01/lvol1
When a logical colume is reduced useful data might get lost;
do you really want the command to proceed (y/n) : y
Logical volume "/dev/vg01/lvol1" has been successfully reduced.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

While reducing mirror copies if one of the PV is failed or missing then command won’t run successfully. you need to supply -k option which will proceed to remove the mirror in case PV is missing.

Command: lvchange

This command is used for changing the characteristics of LV. There are numerous options that can be used.

  • -a y/n Activate or deactivate LV
  • -C y/n Change contiguous allocation policy
  • -D y/n Change distributed allocation policy
  • -p w/r Set permission
  • -t timeout Set timeout in seconds
  • -M y/n Change mirror write cache flag
  • -d p/s Change scheduling policy

This is the end of the second post on LV commands. In the next post, we will see lvsync and lvlnboot commands.