xorl %eax, %eax

How-to: Extend LVM Logical Volume on Linux

with 8 comments

So, first of all attach the new hard disk to the machine and if it supports hot swap-able disks you’ll not even have to shutdown the system first. If this the case, you can use the SysFS filesystem to trigger a SCSI bus re-scan using a command similar to the one below.

root ~:# echo "- - -" > /sys/class/scsi_host/host0/scan
SCSI device sda: 41943040 512-byte hdwr sectors (21475 MB)
sda: Write Protect is off
SCSI device sda: drive cache: write back
root ~:#

Now, let’s assume that the current system’s storage space is this:

root ~:# df -h
Filesystem            Size  Used Avail Use% Mounted on
                       18G  4.0G   13G  24% /
/dev/sda1              99M   40M   55M  42% /boot
tmpfs                 502M     0  502M   0% /dev/shm
root ~:# 

Next, we use the classic fdisk to create a partition on the newly added device (in this case /dev/sdb).

root ~:# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in the memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-261, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261

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

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

Calling ioctl() to re-read partition table.
SCSI device sdb: 4194303 512-byte hdwr sectors (2147 MB)
sdb: Write Protect is off
SCSI device sdb: drive cache: write back
SCSI device sdb: 4194303 512-byte hdwr sectors (2147 MB)
sdb: Write Protect is off
SCSI device sdb: drive cache: write back
Syncing disks.
root ~:# 

We then use the next utility to notify the operating system of the partition table changes on the new device…

root ~:# partprobe /dev/sdb
root ~:# 

And we finally create the physical volume for the new hard disk…

root ~:# pvcreate /dev/sdb1
   Physical volume "/dev/sdb1" successfully created
root ~:# 

And you can now extend the (logical) volume group that you want to have more space.

root ~:# vgentend VolGroup00 /dev/sdb1
   Volume group "VolGroup00" successfully extended
root ~:# 

Remember, when extending the logical volume always leaving some space for LVM meta-data. So, we have…

root ~:# lvextend -L +1.8G /dev/VolGroup00/LogVol00
   Rounding up size to full physical extend 1.81 GB
   Extending logical volume LogVol00 to 19.72 GB
   Logical volume LogVol00 successfully resized
root ~:# 

At last, we have to resize the extended logical volume to allocate the additional disk space.

root ~:# 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 5169152 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 5169152 blocks long.

root ~:# 

And obviously, the size was increased…

root ~:# df -h
Filesystem            Size  Used Avail Use% Mounted on
                       20G  4.0G   15G  22% /
/dev/sda1              99M   40M   55M  42% /boot
tmpfs                 502M     0  502M   0% /dev/shm
root ~:# 

Written by xorl

June 9, 2011 at 13:03

Posted in administration, linux

8 Responses

Subscribe to comments with RSS.

  1. wow, rocket science ;-)


    June 12, 2011 at 05:23

  2. Thanks man. Came in handy.


    December 10, 2011 at 20:39

  3. This is really very nice posting in this blog. I had really liked the stuff very much.
    The information was very cordial. Thanks!
    Check out the below url,



    March 23, 2012 at 08:02

  4. So i don’t understand why so many people on web use partition with lvm, why not use the whole disk?
    what’s the difference?


    May 26, 2013 at 16:23

  5. @paparapa: LVM provides a lot of flexibility that it’s impossible when using the devices directly. You can extend, shrink, create snapshots and in general do things that are impossible without a volume manager layer.


    May 28, 2013 at 00:59

  6. @xorl i think you don’t understand what i mean, you can use lvm without partition and the result is the same, if you don’t believe try for your self, lvm with partition on a pc make sense, try to use lvm on server with 500 LUNS

    Have good day


    May 28, 2013 at 11:08

  7. @paparapa: You’re right about this and it’s a much more common practice using the unpartitioned drive as a PV for LVM. Sorry for not mentioning and sorry for the misunderstanding.

    P.S.: I have been working for quite some time on large infrastructures and I have rarely come across to any server with more than 10 LUNs.



    May 28, 2013 at 20:10

  8. use the extend2fs -p flag to see a percentage, or you will be blind during the process (which can take a long time).

    Tony K

    October 21, 2013 at 05:32

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s