Home > Computing > Resizing an LVM in a CENTOS VMWare Guest

Resizing an LVM in a CENTOS VMWare Guest

This is more or less just a mash up of How to resize a VMWARE virtual disk and Resize LVM -Centos.

First just check the partition table of the virtual disk in the guest

fdisk -l /dev/sda

Disk /dev/sda: 68.7 GB, 68719476736 bytes
255 heads, 63 sectors/track, 10443 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        8354    66999082+  8e  Linux LVM

Now, shutdown the guest in preparation to resize the virtual disk

shutdown

In VMWare Workstation, use vmware-vdiskmanager to resize the VMDK. Note that the disk size given in the “-x” parameter is the desired disk size.

vmware-vdiskmanager.exe -x 80GB "centos-disk-0.vmdk"
 Grow: 100% done.
Disk expansion completed successfully.

Boot the CENTOS guest back up, and add a new partition with the free space of the virtual disk. Make sure to use partition id 8e for Linux LVM.

fdisk /dev/sda
  n {new partition}
  p {primary partition}
  3 {partition number}

  t {change partition id}
  8e {Linux LVM partition}
  w

You might need to reboot if fdisk could not update the kernel tables, just do it.

reboot

You can check the parition table after the reboot if you like, make sure it looks like what you expect

fdisk -l /dev/sda

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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        8354    66999082+  8e  Linux LVM
/dev/sda3            8355       10443    16779892+  8e  Linux LVM

Now, create a new physical volume from the new partition

pvcreate /dev/sda3

Then extend the existing volume group, you may want to use vgdisplay to list and identify the volume groups you have.

vgextend VolGroup00 /dev/sda3

Now, extend the logical volume, again, use lgdisplay to list and identify the logical volumes you have.

lvextend /dev/VolGroup00/LogVol00 /dev/sda3

And finally, resize the filesystem in the logical volume

resize2fs /dev/VolGroup00/LogVol00

Done.

About these ads
Categories: Computing
  1. _ck_
    June 19, 2011 at 3:51 pm | #1

    Exactly what I was looking for, thanks for taking the time to post it.

    I guess it doesn’t matter my volumes are actually dev/hda1 /dev/hda2 and not sda ?

    • June 19, 2011 at 4:44 pm | #2

      I believe the hd* devices are just IDE disks while the sd* devices are SCSI. So no, it doesn’t matter.

  2. Allan
    April 13, 2012 at 8:49 pm | #3

    Thanks a lot, saved my day and my samba server. You rock!

    best regards

  3. May 18, 2012 at 8:58 am | #4

    Bless you for documenting this!

    If you’re running vcenter – as long as you don’t have any snapshots you can increase the disk through the gui (sacrilege I know!). If you’re running esxi, I *think* the command is vmkfstools -X.

  4. Tantor
    August 21, 2012 at 2:19 am | #5

    Thanks a lot, it’s exactly what I need!

  5. amrit
    October 31, 2012 at 5:07 am | #6

    its “lvdisplay” to view all the logical volumes.
    btw, thanks a lot for documenting this.

  1. No trackbacks yet.

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: