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

Posted on 2008-11-12
Medium Priority
Last Modified: 2013-12-06

How do I expand a partition (/var) on an already running ESX Linux VM  host without a third party software?
Question by:gsalcedo
LVL 19

Expert Comment

ID: 22943566
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.

Author Comment

ID: 22943653
Additional note... The version of the VI Client that I am running is 2.0.2, ESX server is version 3.

Author Comment

ID: 22943739
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?
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

LVL 19

Expert Comment

ID: 22943766
ok but the df -k and vgdisplay -v listings will help at the moment

Author Comment

ID: 22944012
Hi Jools,

I am running lvm2

Author Comment

ID: 22944364

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...

LVL 19

Expert Comment

ID: 22944539
what about;
   df -k
   vgdisplay -v

like I asked earlier...

Expert Comment

ID: 22950092
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)



Expert Comment

ID: 22953860
Also run "fdisk -l" to display the non-LVM disks.

Accepted Solution

gsalcedo earned 0 total points
ID: 22960771
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... :)

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
Teach the user how to rename, unmount, delete and upgrade VMFS datastores. Open vSphere Web Client: Rename VMFS and NFS datastores: Upgrade VMFS-3 volume to VMFS-5: Unmount VMFS datastore: Delete a VMFS datastore:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question