business · Linux · Open Source · Work

How to extend your LVM disk


How to extend a LVM

This document is a continuation of LVM made easy, my previous blog

This document is on LVM2 and assuming your Linux distribution supports LVM2

This document also assumes you have LVM setup out of /dev/sdb

Volume group name is “mail-storage-group

Logical volume name is “mail-storage-lv”

And we shall attempt to extend “mail-storage-lv” by adding a new disk

  1. Initialize a new physical volume in the on the disk/partition as applicable
  2. Add the physical disk to the existing volume group “mail-storage-group”, you want to expand
  3. Expand the logical volume  “mail-storage-lv” receding  in the volume group “mail-storage-group
  4. Do online resizing of the partition

This document is for people with prior LVM experience, not an alternative to LVM-HOWTO and I strongly recommend to use each and every command with caution as they cause data loss beyond recovery

Initialize a new physical volume in the on the disk/partition as applicable

Lets add a new disk called /dev/sdc

First we need to mark this disk as a physical volume

[root@mail ~]#  pvcreate /dev/sdc

Physical volume “/dev/xvdc” successfully created

To show your physical volume information

[root@mail ~]# pvscan

and

[root@mail ~]# pvdisplay /dev/sdc

Add the physical disk to the existing volume group “mail-storage-group

[root@mail ~]# vgextend mail-storage-group /dev/sdc

Volume group “mail-storage-group” successfully extended

Use the following commands to see a added disk place

[root@mail ~]# vgscan

[root@mail ~]# vgdisplay mail-storage-group

You are looking for something like this

Total PE              5118
  Alloc PE / Size       2559 / 10.00 GB
  Free  PE / Size       2559 / 10.00 GB
 

Expand the logical volume “mail-storage-lv” receding in the volume group “mail-storage-group

[root@mail ~]# lvextend -l +100%FREE  /dev/mail-storage-group/mail-storage-lv

Extending logical volume mail-storage-lv to 19.99 GB

Logical volume mail-storage-lv successfully resized

This will use up 100% of the free space

You can verify your increase space now with running

[root@mail ~]# lvdisplay /dev/mail-storage-group/mail-storage-lv

— Logical volume —
  LV Name                /dev/mail-storage-group/mail-storage-lv
  .
.
  LV Size                19.99 GB
.
.
  Block device           253:2

So you can see the LVM side has been increase from 10GB to 20GB

Do online resizing of the partition

Fifrst chek the disk space

[root@ds1 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00                      9.7G  1.4G  7.8G  16% /
/dev/xvda1             99M   30M   65M  32% /boottmpfs                 2.0G  4.0K  2.0G   1% /dev/shm
/dev/mapper/mail–storage–group-mail–storage–lv                      9.9G  151M  9.2G   2% /mnt

“/dev/mail-storage-group/mail-storage-lv” is now having more disk space then formatted for and its time ro resize the disk

the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 only using

[root@ds1 ~]# resize2fs /dev/mail-storage-group/mail-storage-lv

resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mail-storage-group/mail-storage-lv is mounted on /mnt; on-line resizing required
Performing an on-line resize of /dev/mail-storage-group/mail-storage-lv to 5240832 (4k) blocks.
The filesystem on /dev/mail-storage-group/mail-storage-lv is now 5240832 blocks long.

[root@ds1 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00                      9.7G  1.4G  7.8G  16% /
/dev/xvda1             99M   30M   65M  32% /boot
tmpfs                 2.0G  4.0K  2.0G   1% /dev/shm
/dev/mapper/mail–storage–group-mail–storage–lv      20G  156M   19G   1% /mnt
 

You can see it has been increased from 10 GB to 19 GB

Your extended space is ready to be used by your application

Advertisements

One thought on “How to extend your LVM disk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s