Linux Administrator

How to Extend Volume Group and Logical Volume on LVM

In my previous article I show you how to resize lvm. In this article I will show you how to extend Volume Group and Logical Volume.

Recently on my database server mysql volume was filling up quickly so I decide to add a new disk of size 10GB and want to extend the mysql volume quickly before the MySQL server stalls.

New Disk Partitioning

First of all lets see the partition table using below command.

# fdisk -l

I have new disk /dev/sdb/ but it is not partitioned, now I am going to create a single partition spanning the whole disk.

You can do this using fdisk utility.

# fdisk /dev/sdb/

It will provide you an interactive console, using this console you can create the partition. Follow the below commands in sequence:

Command (m for help): n

Command action
   e   extended
   p   primary partition (1-4)
p

Partition number (1-4): 1

First cylinder (1-1305, default 1): 1

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 1305

Command (m for help): w
I have created n, p, 1, 1, 1305 and w in the above example.

Next run the below command to show that your changes have been made to the disk.

# fdisk -l /dev/sdb/

You will get some output like below:

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa5081455

Device      Boot      Start      End      Blocks    Id    System
/dev/sdb1               1        1305    10482381   83    Linux

Create Physical Volumes

Now we have a new partition, now lets create a PV using below command.

# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

Extend Volume Group

Follow the below command to extend the Logical Volume.

# vgextend vg1 /dev/sdb1
Volume group "system" successfully extended

My Volume Group name is “vg1” and used /dev/sdb1 PV to add in vg1.

Now verify the the Volume Group using below command.

# vgs
VG     #PV #LV #SN Attr   VSize  VFree
system   2   2   0 wz--n- 15.31g 11.31g

As you can see the volume group size has been extended to 15.31GB.

Extend the Logical Volume

Lets extend mysql volume so that we can store mote data on it. Before extended logical volume it is safe to unmount the filesystem.

# umount /var/lib/mysql/

Run the below command to extend the logical volume.

# lvextend -L 6g /dev/system/mysql
Extending logical volume mysql to 6.00 GiB
Logical volume mysql successfully resized

Now verify the extend logical volume using below command.

# lvs
LV    VG     Attr   LSize Origin Snap%  Move Log Copy%  Convert
logs  system -wi-ao 2.00g
mysql system -wi-a- 6.00g

As you can see the logical volume mysql has been extended to the required size of 6 GB.

Resize the Filesystem

Next we will need to notifying the file system about changes in size of the volume. After extended logical volume we have to resize the file system as well using below command.

# e2fsck -f /dev/system/mysql
# resize2fs /dev/system/mysql

After resizing the filesystem now mount the volume again.

# mount /dev/system/mysql /var/lib/mysql/

Next, see the filesystem details now again using df command.

# df -h

Filesystem                Size  Used Avail Use% Mounted on
/dev/sda1                 3.7G  696M  2.9G  20% /
none                      116M  224K  116M   1% /dev
none                      122M     0  122M   0% /dev/shm
none                      122M     0  122M   0% /var/lock
/dev/sda2                 473M   30M  419M   7% /boot
/dev/mapper/system-mysql  6.0G   68M  5.6G   2% /var/lib/mysql

As you can see that mysql volume has been mounted with correct size.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

7 Comments

Leave a Comment