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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

joolsSenior Systems AdministratorCommented:
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.
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?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

joolsSenior Systems AdministratorCommented:
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...

joolsSenior Systems AdministratorCommented:
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.
gsalcedoAuthor 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... :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.