How do I expand a certain partition on a Linux VM?


How do I expand a partition (/var) on an already running ESX Linux VM  host without a third party software?
Who is Participating?
gsalcedoConnect With a Mentor Author Commented:
This is the path that I went through with a ReHat Linux VM under the VMWare ESX environment.  Please see below.

Login to the ESX server that the VM host reside in.  Navigate to the directory where the .vmdk files that is associated to the VM that you would like to work on.  You must know what DataStore your VM resides in.  "/vmfs/volumes/DataStore<number>/<VM hostname>" is the directory that I had to navigate to.  Normally, the / directory is associated to <VM hostname>-flat.vmdk virtual disk.  Once you know the virtual disk and how much you would like to increase your partition to, run the following command

vmkfstools -X <size>G <VM hostname>.vmdk

Do not use the <VM hostname>-flat.vmdk file.  Please see below of the command that I used.

vmkfstools -X 9G ireland.vmdk

If the ireland-flat.vmdk file is only 2G and you indicate vmkfstools -X 1G ireland.vmdk to assume that it will be increased to 3G, it will not work.  You have to indicate to what size do you want the file to grow to.  So in this incident, you have to indicate vmkfstools -X 3G ireland.vmdk.

Once you have completed the vmkfstools command, log into the VM and proceed with the following tasks.  

- Create a new primary partition on the new space
# fdisk /dev/sda

- Reboot the VM and then log back in.

- Create a new physical volume
# pvcreate /dev/sda3

- With the recently created physical volume add it to the group
# vgextend VolGroup00 /dev/sda3

- Then within the new space in the volume group, extend the logical volume.  Since the previous size of the partition that is associated with the / directory was 2G and I added 7G, you can not use the entire 7G.  If you do, you will receive an error message stating that you do not have sufficient space.  I used .4G less as a point of reference.  So, in this case, I used 6.6G rather than 7G.
# lvextend -L +6.6G /dev/VolGroup00/LogVol00

- The final step would be to expand the file system in the new space of the volume
# resize2fs /dev/VolGroup00/LogVol00  

There you go... :)
are you running lvm?

you need to post more information about your system; df -k, vgdisplay -v.

if you have free disk space in the volume group it's straight forward enough but your file system type will have a bearing on this.
gsalcedoAuthor Commented:
Additional note... The version of the VI Client that I am running is 2.0.2, ESX server is version 3.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

gsalcedoAuthor Commented:
The VMWare ESX environment is running as a SAN environment.  So, I can gather as much disk space as possible and add it to the VM.  From the sites that I have visited, it seems that they have been showing only the most recent version of VI Client and ESX server.  I know that I have to shutdown the VM, click the Edit Settings option, and then make the changes under the "Hardware" tab.  The sites that I have visited displayed the ability to expand the partition of the disk in the "Capacity" section that is under the "Hardware" tab of the particular hard drive.  My VI Client does not have that ability.  Is there another way?  Do I just add another hard disk that is associated with a certain Data Store, power up the VM and make the configuration changes in the Linux VM host?
ok but the df -k and vgdisplay -v listings will help at the moment
gsalcedoAuthor Commented:
Hi Jools,

I am running lvm2
gsalcedoAuthor Commented:

I have tried running the vmkfstools command.  In return, I received a "Failed to extend disk : The file specified is not a virtual disk. (15)" message.  I have indicated the just the .vmdk file and also the entire path.  None worked.

vmkfstools -X <requested disk expansion>G <file name>.vmdk
example... # vmkfstools -X 3G vm1.vmdk
example2... # vmkfstools -X 3G /vmfs/volumes/DataStore2/vm1.vmdk
example3... # vmkfstools -X 3G "/vmfs/volumes/DataStore2/vm1.vmdk"

None of the examples worked...

what about;
   df -k
   vgdisplay -v

like I asked earlier...
Since you said you want to increase /var of the ESX host, I believe that it is on the local disk. Normal ESX
installation do not use LVM but normal partitions. Most modern systems have large disks (usually at least 70GB) though and an ESX install normally does not use the whole 70GB, when there is a SAN connection for the VMs.
I would check if you have free space left, go single user, create a new partition vor /var and copy stuff over. Then edit fstab and reboot.
If /var was the last partition you created, you could even copy the files temporarily somewhere else, delete the partiton and create it again bigger. If  there is for  example /home after /var, you have to do this twice...

But, since it is a ESX and you probably have more than one or two of thos, why don't you move the VMs, shut it down, and reinstall them, this time the correct way (at least 25GB for / and some GB for /var)


Also run "fdisk -l" to display the non-LVM disks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.