Extending Logical Volume

Extending Logical Volume

Previously article we have seen how to create and removing a logical volume group, refer below link. Here, we are going to see how to extend logical volume group.

Managing Logical Volumes in Linux

Let’s take a Example, We have two LVs (logical Volume) one is itcare-lv1 and other is itcare-lv2.
And Both the logical volume group belongs from itcare-vg volume group.

[root@server1 ~]# df -hT /itcaredir/ /storage/
Filesystem                         Type  Size  Used Avail Use% Mounted on
/dev/mapper/itcare--vg-itcare--lv1 xfs   2.0G  2.0G   26M  99% /itcaredir
/dev/mapper/itcare--vg-itcare--lv2 ext4  2.8G  2.6G   21M 100% /storage
[root@server1 ~]#vgs itcare-vg
  VG        #PV #LV #SN Attr   VSize VFree  
  itcare-vg   1   2   0 wz--n- 5.00g 168.00m
[root@server1 ~]#

As shown above, The size of itcare-vg volume group is 5GB and remaining size is 168MB. Similar the Available size of /itcaredir and /storage mount point is 26MB  and 21MB respectively.

To increase the size of a logical volume first we have to extend the volume group. because the new physical extend provided by the additional physical volume can be assigned to logical volume.

Note: Both mount points (i.e /itcaredir, /storage) consist of different file systems.

Extending a Volume Group

Extending a volume group is actually adding a new PV (Physical Volume) to the Volume group.

There are few steps needed to extend a volume group.

1.) Prepare the Physical device.

To extend a volume group we need to create a new partition using fdisk.

#fdisk /dev/sdf

Add a new partition of “+2GB“.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-8388607, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607): +2G
Partition 1 of type Linux and of size 2 GiB is set

Change the partition type to Linux LVM – “8e”.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdf: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc6a78165

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf1            2048     4196351     2097152   8e  Linux LVM

Write the change to the partition table.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@server1 ~]#

Use partprobe to register the new partition with the kernel.

[root@server1 ~]# partprobe /dev/sdf
[root@server1 ~]#

2.) Create the physical volume.

Use pvcreate to add the new partition as a PV.

# pvcreate <Physical Partition>

[root@server1 ~]# pvcreate /dev/sdf1
  Physical volume "/dev/sdf1" successfully created
[root@server1 ~]#

3.) Extend the volume group.

Use vgextend command to extend the VG named itcare-vg, using the name /dev/sdf1 PV.

#vgextend <Volume Name> <Physical Partition>

[root@server1 ~]# vgextend itcare-vg /dev/sdf1
  Volume group "itcare-vg" successfully extended
[root@server1 ~]#vgs itcare-vg
  VG        #PV #LV #SN Attr   VSize VFree
  itcare-vg   2   2   0 wz--n- 6.99g 2.16g
[root@server1 ~]#

Now, We have “2.16GB” available size on itcare-vg volume group.

Increase the size of logical Volume

The size of LVs can be in increased online, no downltime is required.

4.) Extend the logical Volume.

Use lvextend command to extend the existing LVs.

#lvextend -L <Size of LV> <Logical Device>

[root@server1 ~]# lvextend -L +900M /dev/itcare-vg/itcare-lv1
  Size of logical volume itcare-vg/itcare-lv1 changed from 2.00 GiB (512 extents) to 2.88 GiB (737 extents).
  Logical volume itcare-lv1 successfully resized.
[root@server1 ~]# lvextend -L +900M /dev/itcare-vg/itcare-lv2
  Size of logical volume itcare-vg/itcare-lv2 changed from 2.83 GiB (725 extents) to 3.71 GiB (950 extents).
  Logical volume itcare-lv2 successfully resized.
[root@server1 ~]#

6.) Extend the file system.

Use xfs_growfs command to extend the XFS file system.

# xfs_growfs <Mount Point>

[root@server1 ~]# df -hT /itcaredir/ 
Filesystem                         Type  Size  Used Avail Use% Mounted on
/dev/mapper/itcare--vg-itcare--lv1 xfs   2.0G  2.0G   26M  99% /itcaredir
[root@server1 ~]# xfs_growfs /itcaredir/
meta-data=/dev/mapper/itcare--vg-itcare--lv1 isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 524288 to 754688
[root@server1 ~]# df -hT /itcaredir/ 
Filesystem                         Type  Size  Used Avail Use% Mounted on
/dev/mapper/itcare--vg-itcare--lv1 xfs   2.9G  2.0G  926M  69% /itcaredir
[root@server1 ~]#

For EXT4 file system use resize2fs command.

#resize2fs <logical Device>

[root@server1 ~]# df -hT /storage/
Filesystem                         Type  Size  Used Avail Use% Mounted on
/dev/mapper/itcare--vg-itcare--lv2 ext4  2.8G  2.6G   21M 100% /storage
[root@server1 ~]# resize2fs /dev/mapper/itcare--vg-itcare--lv2
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/itcare--vg-itcare--lv2 is mounted on /storage; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/itcare--vg-itcare--lv2 is now 972800 blocks long.

[root@server1 ~]# df -hT /storage/
Filesystem                         Type  Size  Used Avail Use% Mounted on
/dev/mapper/itcare--vg-itcare--lv2 ext4  3.6G  2.6G  870M  76% /storage
[root@server1 ~]#

Note: The Primary difference between xfs_growfs and resizefs is the argument passed to identify the file system. xfs_growfs takes the mount point and resize2fs takes the logical volume name.

Read Also:

Reducing Logical Volume
Creating Striped Volumes
Migrating the Logical Volume Data

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz