Expanding LVM drives in VMWare

When I created this most recent batch of webservers, I got a little stingy with the drive space. I skimped on the “/” partition, and as you can see, I’m paying for it now:

[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2.5G 2.3G 80M 97% /
/dev/mapper/VolGroup00-LogVol04
29G 9.1G 19G 33% /apps
/dev/sda1 99M 13M 82M 14% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/mapper/VolGroup00-LogVol03
2.9G 37M 2.8G 2% /opt
/dev/mapper/VolGroup00-LogVol02
1008M 933M 25M 98% /var

Here’s how I was able to solve my problem.

1) Turn off the VM and expand the drive. (I’m adding 5 Gigs to “/” for a total of 7.5). I’m doing this thru the vmware VirtualCenter management software, but the documentation recommends the following command:

vmware-vdiskmanager -x 10GB /path/machineName.vmdk

2) After powering the VM back on, I now have to create a partition that will incorporate the new space:

[root@server ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 5874.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

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

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

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Command (m for help): p

Disk /dev/sda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 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 5221 41833260 8e Linux LVM
/dev/sda3 5222 5874 5245222+ 8e Linux LVM

Command (m for help): q

I now have 3 partitions, including my most recent, partition 3 that has been formatted to use LVM. Now I must reboot my VM so that it will include this partition in the table at reboot.

3) Now I must create a physical volume so that I can access my partition with LVM.

[root@server ~]# pvcreate /dev/sda3
Physical volume “/dev/sda3″ successfully created

4) Following that, I need to extend my VolGroup into my new physical Volume:

[root@server ~]# vgextend VolGroup00 /dev/sda3
Volume group “VolGroup00″ successfully extended

5) With that complete, I need to extend the logical volume into the newly created space. I know that I planned to give myself 5 gigs, but I want to see how the system is really going to give me, so I’m going to run:

[root@server ~]# vgdisplay | grep ‘Free’
Free PE / Size 165 / 5.16 GB

So now I can be sure that I have 5 GB to work with. I can run lvextend to grow my logical volume across the new partition:

[root@server ~]# lvextend -L+5G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 7.47 GB
Logical volume LogVol00 successfully resized

With that completed, I now have the Logical Volume sitting at 7.47 Gigs. I now need to expand the file system to take advantage of the space that was created. This step is normally taken care of with the resize2fs command, but since I’m running RHEL 4, I can take advantage of ext2online command and don’t have to take the filesystem down. I like this idea much better:

[root@server ~]# ext2online /dev/VolGroup00/LogVol00
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b

That’s it! Now when I run my df -h, I have all the space I was needing:

[root@oasslcwpa01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.4G 2.2G 4.9G 31% /
/dev/mapper/VolGroup00-LogVol04
29G 7.3G 21G 27% /apps
/dev/sda1 99M 13M 82M 14% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/mapper/VolGroup00-LogVol03
2.9G 192M 2.6G 7% /opt
/dev/mapper/VolGroup00-LogVol02
1008M 447M 511M 47% /var

Special thanks to swizzling.org, who’s tutorial I modified minimally for my own benefit here.




You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Expanding LVM drives in VMWare”

  1. TIMOTHY Says:


    Medicamentspot.com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. Low price pills. Order pills online

    Buy:Prednisolone.Zovirax.Human Growth Hormone.Actos.Zyban.Lumigan.Prevacid.Synthroid.Mega Hoodia.Retin-A.Petcam (Metacam) Oral Suspension.100% Pure Okinawan Coral Calcium.Valtrex.Accutane.Arimidex.Nexium….

Leave a Reply