A little while back Frank posted a blog about increasing the size of a logical volume in Linux (
http://blog.gulfsoft.com/2008/11/adding-disk-space-to-linux-vm-in-vmware.html). I tried this out and it worked great.
I also had to do something similar in Windows, which turns out to be much simpler by using the VMWare Converter. Unfortunately this is not supported for Linux. The one thing that got me thinking though is that Windows can increase from a single drive and not have to use a separate drive. So why could I not do this in Linux?
The reason I needed to do this was for the new version of TPM (7.1). I originally had my VM set up with 20GB allocated, but the new version now requires approximately 50Gb to install, so the steps below are what I used to increase the LVM for my TPM install.
Here is my setup:
VM Ware: VMWare Server 2.0.0
Host OS: Windows 2003 SE SP2 x64
Guest OS: Red Hat ES4 U5
Increase VM Disk SizeUse the VMWare tool vmware-vdiskmanager.exe to increase the size
C:\Program Files (x86)\VMware\VMware Server>vmware-vdiskmanager.exe -x 50GB "f:\VM_Images\VM TPM7.1 RH\rhes4srv01\Red Hat Enterprise Linux 4.vmdk"Disk expansion completed successfully.Use fdisk to create new partitionEven though the previous step reports that more disk was added, it still is not recognized by the OS.
Current file system:
dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/VolGroup00-LogVol00 19448516 1964128 16496436 11% //dev/sda1 101086 13232 82635 14% /boot
none 257208 0 257208 0% /dev/shm1. Enter the FDISK utility
fdisk /dev/sda2. Print the existing partition table
Command (m for help): pDisk /dev/sda: 53.6 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 2610 20860402+ 8e Linux LVM3. Create new partition. This will be a Primary partition and is the 3rd partition. For the cylimder values, press enter to accept the defaults
Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 3First cylinder (2611-6527, default 2611):Using default value 2611Last cylinder or +size or +sizeM or +sizeK (2611-6527, default 6527):Using default value 65274. Set the Partition type to Linux LVM (hex 8e)
Command (m for help): tPartition number (1-4): 3Hex code (type L to list codes): 8eChanged system type of partition 3 to 8e (Linux LVM)5. Print the Partition table again to see the new partition
Command (m for help): pDisk /dev/sda: 53.6 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 2610 20860402+ 8e Linux LVM/dev/sda3 2611 6527 31463302+ 8e Linux LVM6. Write the new partition information
Command (m for help): wThe 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.7. Reboot
Create the Logical VolumeNow that the partition is created, the physical and logical volume needs to be created
1. Create the Physical Volume - use the new partition information from the df command. In this case the new partition is /dev/sda3
pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created2. Add the new Physical Volume to the Logical Volume
vgextend VolGroup00 /dev/sda3 Volume group "VolGroup00" successfully extended3. Extend the Logical Volume.
vgdisplay --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 49.88 GB PE Size 32.00 MB Total PE 1596 Alloc PE / Size 635 / 19.84 GB Free PE / Size 961 / 30.03 GB VG UUID bzOq45-o5yO-ruYY-Ffx1-DxCx-2e2j-ardXtulvextend -L +30.03G /dev/VolGroup00/LogVol00 Rounding up size to full physical extent 30.03 GB Extending logical volume LogVol00 to 48.88 GB Logical volume LogVol00 successfully resizedNote: The lvextend can either use the value of the Free PE from the vgdisplay command or the command
lvextend -l +100%FREE /dev/VolGroup00/LogVol00. I found out about the %FREE after, so I did not test this.
4. Extend the filesystem
The resize2fs does not work for this situation. The command ext2online will allow for the disk to be resized while disk is still mounted.
ext2online /dev/VolGroup00/LogVol005. View the new file system
dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/VolGroup00-LogVol00 50444996 1972848 45911716 5% //dev/sda1 101086 13232 82635 14% /bootnone 1825828 0 1825828 0% /dev/shmAnd there is a system with a nice large drive. Hope this helps you.