Saturday, 13 May 2017

LVM Resize – How to Increase an LVM Partition



In this tutorial we will work through extending logical volume /opt from 9.8 GB to appr.15 GB. We have added new hard disk of 10 GB.

Logical Volume Manager (LVM): Below are the basic concepts about physical volumes, volume groups, logical volumes, and the file system:

Physical Volume (PV): This can be created on a whole physical disk or a Linux partition.

Volume Group (VG): This is made up of at least one or more physical volumes.

Logical Volume (LV): This is sometimes referred to as the partition, it sits within a volume group and has a file system written to it.

File System: A file system such as ext4 will be on the logical volume.

Expand the Logical Volume

Step 1: Create Physical Volume of a hard disk of Linux Partition. Here we are using hard disk (/dev/sdc)

[root@linuxcnf ~]# fdisk -l |grep /dev/sdc*
Disk /dev/sdc: 10.7 GB, 10737418240 bytes
[root@linuxcnf ~]#

[root@linuxcnf ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
[root@linuxcnf ~]#

Step 2: Create Volume Group of earlier create physical volume. We are extending VG vol_grp1 to get more space to extend LV. Use vgextend command to increase the VG size.

[root@linuxcnf ~]# vgextend vol_grp1 /dev/sdc
Volume group "vol_grp1" successfully extended
[root@linuxcnf ~]#

Step 3: Now we are going to expand the LV vol_lv1 mounted on /opt. Use lvextend command to increase the size.

[root@linuxcnf ~]# lvextend -L +5G /dev/mapper/vol_grp1-vol_lv1
  Size of logical volume vol_grp1/vol_lv1 changed from 9.99 GiB (2558 extents) to 14.99 GiB (3838 extents).
  Logical volume vol_lv1 successfully resized
[root@linuxcnf ~]#

Step 4: Run the resize2fs for ext3/4 based file systems:

[root@linuxcnf ~]# resize2fs /dev/mapper/vol_grp1-vol_lv1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vol_grp1-vol_lv1 is mounted on /opt; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/vol_grp1-vol_lv1 to 3930112 (4k) blocks.
The filesystem on /dev/mapper/vol_grp1-vol_lv1 is now 3930112 blocks long.
[root@linuxcnf ~]#

Alternatively, use this for xfs based file systems

[root@linuxcnf ~]# xfs_growfs /dev/mapper/vol_grp1-vol_lv1

Step 5: To verify the same use df –h command

[root@linuxcnf ~]# df -h
Filesystem                                                  Size    Used   Avail   Use%   Mounted on
/dev/mapper/VolGroup-LogVol00    15G     923M    13G     7%        /
tmpfs                                                         238M       0       238M   0%        /dev/shm
/dev/sda2                                               380M     30M    330M   9%        /boot
/dev/mapper/vol_grp1-vol_lv1          15G      27M     14G     1%        /opt
[root@linuxcnf ~]#

No comments:

Post a comment