Hot extending LVM volumes

How to extend a LVM volume when increasing the size of the underlying LUN (eg with VMware).

eg:

Create a LVM volume:

# pvcreate /dev/sdc
 Physical volume "/dev/sdc" successfully created
# vgcreate myvg /dev/sdc
 Volume group "myvg" successfully created
# lvcreate --extents 100%VG myvg
 Logical volume "lvol0" created
# mke2fs -j -L data /dev/myvg/lvol0
mke2fs 1.39 (29-May-2006)
Filesystem label=data
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261120 blocks
13056 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
 32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# mount -L data /data

Now, assume we have extended the physical disk, in VMware, say:

rescan scsi bus:

# echo 1 > "/sys/bus/scsi/devices/0:0:2:0/rescan"

Now try to extend the volume group:

# pvresize /dev/sdc
Physical volume "/dev/sdc" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

# lvextend -l 100%VG /dev/myvg/lvol0
Extending logical volume lvol0 to 2.00 GB
Logical volume lvol0 successfully resized

# resize2fs /dev/myvg/lvol0
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/myvg/lvol0 is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/myvg/lvol0 to 523264 (4k) blocks.
The filesystem on /dev/myvg/lvol0 is now 523264 blocks long.
Advertisements