LVM (Logical Volume Manager) is a tool in Linux which can help you manage disk drives and partition. Usually it being used in server/computer whereby you can easily re-size the partition, creating snapshots backup, combined all hard disk to be run under one partition and many more.

In this case, I already have logical volume “/dev/mapper/VolGroup00-LogVol00″ mounted as “/” partition in the server but the disk space is too small which is 50GB. I want to expand it to 170GB with another 120GB hard disk combine together. The new hard disk already plugged in the server and detected by the system. So we are going to do this online without downtime. Variables as below:

OS: CentOS 5.6 64bit
LV name: /dev/mapper/VolGroup00-LogVol00
New HD: /dev/sdb (120GB)

1. Make sure that you have logical volume mapped to your “/” partition. If you are using default CentOS partitioning during installation, you should see something like below:

[root@centos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       47G  3.2G   43.8G   8% /
/dev/sda1              99M   13M   81M  14% /boot
tmpfs                 249M     0  249M   0% /dev/shm

2. Check whether new hard disk has been detected on the system or not. It should be /dev/sdb:

[root@centos ~]# fdisk -l
 
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        6527    52323705   8e  Linux LVM
 
Disk /dev/sdb: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Disk /dev/sdb doesn't contain a valid partition table

3. This new hard disk does not have partition table yet. So we need to create one using fdisk:

[root@centos ~]# fdisk /dev/sdb
......
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-15665, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-15665, default 15665):
Using default value 15665
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.

The sequence I press on the keyboard is: n > p > 1 > Enter > Enter > w > Enter

4. Lets check the partition for all hard disk again. Make sure /dev/sdb1 exist and you got something like below:

[root@centos ~]# fdisk -l
 
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        6527    52323705   8e  Linux LVM
 
Disk /dev/sdb: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       15665   125829081   83  Linux

5. Lets create Physical Volume from the Linux partition we have in /dev/sdb1:

[root@centos ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

6. If you notice above that we want to extend “/” partition which hold by volume group “VolGroup00“. Lets extend the volume group to the newly created Physical Volume:

[root@centos ~]# vgextend VolGroup00 /dev/sdb1
  Volume group "VolGroup00" successfully extended

7. Then, we need to extend the Logical Volume for VolGroup00 which is LogVol00:

[root@centos ~]# lvextend /dev/VolGroup00/LogVol00 /dev/sdb1
  Extending logical volume LogVol00 to 167.88 GB
  Logical volume LogVol00 successfully resized

8. We have expand the partition but not the file system. So we need to tell the ext3 file system to use all newly added space in the partition /dev/VolGroup00/LogVol00:

[root@centos ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 44007424 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 44007424 blocks long.

9. Done. Lets check our new “/” partition disk space. It has combined with new 120GB hard disk with total space of 163GB:

[root@centos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      163G  2.9G  152G   2% /
/dev/sda1              99M   13M   81M  14% /boot
tmpfs                 501M     0  501M   0% /dev/shm

Thanks LVM for this great tool!

2 Responses to Increasing Disk Space in CentOS using LVM

  1. DigitalinuxNo Gravatar says:

    I appreciate your idea here. Definitely it has a good content. Thank you for imparting more of your own thoughts. Good job
    You can get more information from the below link,

    http://www.digitalinux.com/2010/11/lvm-logical-volume-manager.html

  2. AleksandarNo Gravatar says:

    Best tut for this kind of job!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>