All virtualization
news articles ask an expert
home / Articles / Expanding The Virtual Disk Size In 4 Steps

Article

Expanding the Virtual Disk Size in 4 Steps

Expanding the Virtual Disk Size in 4 Steps

Author: Alexey Vasilyev
Applies to: GSX Server, VMware Server, VMware Workstation
Date: November 20, 2006

PDF Version Download PDF
Comment this article Comment on this article

In this article I will show you an effective way to expand the virtual disk size in 4 steps. It's easy and doesn't require installing any additional OS or third-party tools.

Running out of disk space is a common problem and a very annoying one as it always comes all of a sudden. When you run out of hardware space, the idea of going out to buy a new disk makes you sick. A benefit of using a virtual machine is that you don’t have to go out to expand the disk. You just need to know how to do it.

One day I faced the same problem. I got one the Windows insufficient disk space message on my virtual machine:

You are running out of disk space on Local Disk (C:).
To free space on this drive by deleting old or unnecessary files, click here…

I realized that I needed more space. I spent much time searching through the Internet and looking for the solution in VMware manuals. Finally, I found my own way to get rid of the problem.

To start with, I needed to make sure that the disk I had was in a consistent state for expanding. It was also necessary to make a backup so that I could always get back to what I had had before. Besides, the task was not only to expand the disk itself as this wouldn’t give me the desired result, but also increase the Windows partition to the full disk size. I worked out this approach testing it on VMware Workstation. However, it can definitely be applied to other VMware products: VMware Server, GSX Server, etc.   

I am using Windows XP professional SP2 with a 4 GB capacity pre-allocated disk (I have several snapshots taken - so the machine itself occupies 7.3GB). My XP installation uses one NTFS drive but most things in the approach can also be used by those who use FAT. For my needs I needed to expand the vmdk to 10 GB. Thus, I needed 17.3 GB of the host machine free disk space: 7.3 GB for backup + 10GB for the destination disk.

advertisement
 

Veeam FastSCP 2.0 released by Veeam Software

  • ESX to ESX direct copy
  • Multiple ESX Management.
  • Complete File Management & Windows Integration.

Learn more.

Veeam FastSCP
 
 

 

Step 1. Checking the disk consistency

Before the expansion I had to see if the virtual disk is consistent. This step is not vital, but as the upcoming steps will change the structure of my disk, I have to make sure everything works ok, before I start to improve it.    

  1. I shutdown my guest OS.

 

  1. I used vmware-mount utility to mount the virtual disk into host OS:

pressed Start->Run and typed “cmd”. In the command window I typed:

D:\Program Files\VMware\VMware Workstation>vmware-mount v: G:\vmimages\winxp_pro_sp2\diskc.vmdk

The operation took less that 1 minute.

  1. Then I used built-in Windows utility chkdsk to test the virtual disk for consistency.

 

To see the full list of available options, please run the ‘CHKDSK /?’ command.  

In my case, I ran the command as follows: ‘chkdsk V: /F /X’
which means that the utility will fix all the errors found (which is performed by /F) and, in case if you had some files opened on this disk, /X forces its unmount. 

As a result, I saw that my disk was ok:

D:\Program Files\VMware\VMware Workstation>chkdsk /F V:
The type of the file system is NTFS.

CHKDSK is verifying files (stage 1 of 3)...
File verification completed.
CHKDSK is verifying indexes (stage 2 of 3)...
Index verification completed.
CHKDSK is verifying security descriptors (stage 3 of 3)...
Security descriptor verification completed.

   4184900 KB total disk space.
   3004792 KB in 24880 files.
      7248 KB in 3054 indexes.
         0 KB in bad sectors.
     51512 KB in use by the system.
     22976 KB occupied by the log file.
   1121348 KB available on disk.

      4096 bytes in each allocation unit.
   1046225 total allocation units on disk.
    280337 allocation units available on disk.

 

The operation took me about 2 minutes.

  1. I used vmware-mount utility to unmount the virtual disk from host OS. In case you don’t have vmware-mount utility, you can download it here: http://www.vmware.com/download/eula/diskmount_ws_v55.html

 
In the command window I typed:

D:\Program Files\VMware\VMware Workstation>vmware-mount v: /d

           
Now everything was ready to start expanding the vmdk disk. However, before I had to backup my virtual machine to be sure that I could always restore the virtual machine if things went wrong.  

Step 2. Backup of the virtual machine

I backed up the virtual machine folder by copying the entire VM folder to the backup directory (C:\vm_backup\).  Please don’t forget to copy the snapshots folder as well.

The command looked as follows:

xcopy "C:\vmware_vms\winXPproSp2\*.*" "c:\vm_backup\winXPproSp2\*.*"

C:\vmware_vms\winXPproSp2\564d13ea-a63b-e915-a27f-7752c1d76fa1.vme
C:\vmware_vms\winXPproSp2\diskC-000001.vmdk
C:\vmware_vms\winXPproSp2\diskC-000002.vmdk
C:\vmware_vms\winXPproSp2\diskC-000003.vmdk
C:\vmware_vms\winXPproSp2\diskC-flat.vmdk
C:\vmware_vms\winXPproSp2\diskC.vmdk
C:\vmware_vms\winXPproSp2\vmware-0.log
C:\vmware_vms\winXPproSp2\vmware-1.log
C:\vmware_vms\winXPproSp2\vmware-2.log
C:\vmware_vms\winXPproSp2\vmware.log
C:\vmware_vms\winXPproSp2\Windows XP Professional-Snapshot1.vmem
C:\vmware_vms\winXPproSp2\Windows XP Professional-Snapshot1.vmsn
C:\vmware_vms\winXPproSp2\Windows XP Professional-Snapshot2.vmem
C:\vmware_vms\winXPproSp2\Windows XP Professional-Snapshot2.vmsn
C:\vmware_vms\winXPproSp2\Windows XP Professional-Snapshot3.vmem
C:\vmware_vms\winXPproSp2\Windows XP Professional-Snapshot3.vmsn
C:\vmware_vms\winXPproSp2\Windows XP Professional.nvram
C:\vmware_vms\winXPproSp2\Windows XP Professional.vmsd
C:\vmware_vms\winXPproSp2\Windows XP Professional.vmx
C:\vmware_vms\winXPproSp2\Windows XP Professional.vmx.lck
20 File(s) copied

 

It took me 7.26 GB (7,796,603,535 bytes) to backup my virtual machine together with 3 snapshots.

Step 3a. Solving snapshot problems

To my astonishment, this was the most time-consuming out of all the steps.  
To resolve this problem, I deleted all snapshots except the one selected for further extending.
I didn’t worry about deleting the snapshots as I had made a backup.

pic01

The result of this step was the following:
pic02

Alternatively, you can clone the selected snapshot into a standalone disk. 

I fulfilled the step in 10 minutes.

Step 3b. Virtual disk expansion

The essential step of the whole procedure is expanding the virtual disk capacity. Having prepared the backup, I started expanding my disk using the VMware utility called vmware-vdiskmanager.

  1. The command window utility vmware-vdiskmanager.

This utility uses the following syntax:

VMware Virtual Disk Manager - build 19175.
Usage: vmware-vdiskmanager.exe OPTIONS diskName | drive-letter:
Offline disk manipulation utility
  Options:
     -c                   : create disk; need to specify other create options
     -d                   : defragment the specified virtual disk
     -k                   : shrink the specified virtual disk
     -n <source-disk>     : rename the specified virtual disk; need to
                            specify destination disk-name
     -p                   : prepare the mounted virtual disk specified by
                            the drive-letter for shrinking
     -q                   : do not log messages
     -r <source-disk>     : convert the specified disk; need to specify
                            destination disk-type
     -x <new-capacity>    : expand the disk to the specified capacity

     Additional options for create and convert:
        -a <adapter>      : (for use with -c only) adapter type (ide, buslogic or lsilogic)
        -s <size>         : capacity of the virtual disk
        -t <disk-type>    : disk type id

     Disk types:
        0                 : single growable virtual disk
        1                 : growable virtual disk split in 2Gb files
        2                 : preallocated virtual disk
        3                 : preallocated virtual disk split in 2Gb files

     The capacity can be specified in sectors, Kb, Mb or Gb.
     The acceptable ranges:
                           ide adapter : [100.0Mb, 950.0Gb]
                           scsi adapter: [100.0Mb, 950.0Gb]
        ex 1: vmware-vdiskmanager.exe -c -s 850Mb -a ide -t 0 myIdeDisk.vmdk
        ex 2: vmware-vdiskmanager.exe -d myDisk.vmdk
        ex 3: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 0 destinationDisk.vmdk
        ex 4: vmware-vdiskmanager.exe -x 36Gb myDisk.vmdk
        ex 5: vmware-vdiskmanager.exe -n sourceName.vmdk destinationName.vmdk
        ex 6: vmware-vdiskmanager.exe -k myDisk.vmdk
        ex 7: vmware-vdiskmanager.exe -p m:
              (A virtual disk first needs to be mounted at m:
               using the VMware Diskmount Utility.)

Note that we need only –x option to expand our disk. This parameter gets the argument <new-capacity> that contains a number and Kb, Mb, Gb (the first letter must be uppercase and the second – lowercase – it’s case sensitive).

2. Using vmware-vdiskmanager for expanding virtual disk diskC.vmdk

  1. In your host OS click Start->Run  and type “cmd”
  2. In the command window:

 

C:\path to VMware Workstation\vmware-vdiskmanager –x 10Gb diskC.vmdk

Result:

D:\Program Files\VMware\VMware Workstation>vmware-vdiskmanager.exe -x 10GB G:\wmimages\winxp_pro_sp2\diskc.vmdk
Using log file D:\DOCUME~1\ALEX\LOCALS~1\Temp\vmware-alex\vdiskmanager.log
Grow: 100% done.
The old geometry C/H/S of the disk is: 8322/16/63
The new geometry C/H/S of the disk is: 16383/16/63
Disk expansion completed successfully.

 

 

At the end of this operation I got the following warning:

If the virtual disk is partitioned, you must use a third-party utility in the virtual machine to expand the
size of the partitions. For more information, see:
         http://www.vmware.com/support/kb/enduser/std_adp.php?p_faqid=1647

       However, I decided not to use any third-party tools at all as there is the one that is built-in to the Windows XP.

This step took me about 6 minutes. Now the vmdk disk was already extended. All I had to do was to extend the Windows partition to the size I needed.  

Step 4. Extending the Windows partition to the necessary size

1. First of all, I set “host only” networking of backup machine.
To avoid any changes of backup, I changed the network configuration to host-only (usually there might be mail synchronization or something like this in your case):
pic03

In less than 1 minute the operation was over.  

2. After that I added the expanded disk to the backed up machine.
To do so, I opened the backed up machine and edited its configuration, adding a new existent disk (diskC.vmdk that I had just extended).

pic04

3. Finally, I expanded the partition as follows.

I started the backup machine. Then I clicked Start->Run and typed “cmd”. In command line I typed diskpart to start Microsoft DiskPart built-in utility. Then I entered commands ‘list disk’, ‘list volume’ to explore the configuration of my disks subsystem:

 

C:\Documents and Settings\Administrator>diskpart
Microsoft DiskPart version 5.1.3565
Copyright (C) 1999-2003 Microsoft Corporation.
On computer: WebServ

DISKPART> list disk

  Disk ###  Status      Size     Free     Dyn  Gpt
  --------  ----------  -------  -------  ---  ---
  Disk 0    Online      4095 MB      0 B
  Disk 1    Online        10 GB  6150 MB

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D   WinLite      CDFS   CD-ROM       506 MB
  Volume 1     C                NTFS   Partition   4087 MB  Healthy    System
  Volume 2     E                NTFS   Partition   4087 MB  Healthy

I selected the disk that I had just extended and typed ‘extend’ to extend the volume for the newly allocated space:

DISKPART> select volume=2

Volume 2 is the selected volume.

DISKPART> extend

DiskPart successfully extended the volume.

After this operation I got what I wanted - the 10 GB disk:

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D   WinLite      CDFS   CD-ROM       506 MB
  Volume 1     C                NTFS   Partition   4087 MB  Healthy    System
* Volume 2     E                NTFS   Partition     10 GB  Healthy

 

pic05

The operation took me 5 minutes, the step – 7 minutes.

Then I removed the extended disk from the backup machine settings->Hardware. And that was it! Now my virtual machine had a 10GB disk!
 
Having fulfilled the 4-step procedure in 40 minutes, I’ve got the virtual machine with a 10 GB disk that runs without any problems. I am satisfied at the result and happy about the idea that I can apply this scenario at any time, if I ever happen to run out of the disk space.

18 CommentsPost your comment
Dan Richards (November 22, 2006)
Thanks, guys, I tried the method - it works ok! disk expansion is no more a problem
Chris Reynolds (November 23, 2006)
Indeed, step 3 eats pretty much time. On the whole, the procedure is rather fast, though.
Sean de Jager (November 26, 2006)
I am trying this on the C: drive (system drive) which step 4 replies, The selected drive can not be extended, please select a different drive. I realise that this is most likely because the system drive is in use, but I was wondering if there was still a way toextend this drive?
Vlada, VM Weekly Support Team (November 27, 2006)
2 Sean de Jager: Please, refer to the original text - I expanded not C: (which is the system disk of the backup machine), but disk E: - this expanded disk I added to the backup machine. To select disk E, please do the following: DISKPART> select volume=2 (disk E is number 2 in the list of volumes)
KIran Amin (December 19, 2006)
Wonderful !!!! I have Tried This and this works Great...Thankoy
Randall Comm (January 03, 2007)
Can you perform the "diskpart" step after you perform the VMware extend step? In other words while the VMDK is mounted to your local system, why not just diskpart it then? Admit: I have not tried this, just wondering.
Randall Comm (January 03, 2007)
Answering my own question, I tried it and it won't work. Seems Disk Part will only see local volumes, not "mounted" volumes.
Mark Carranza (May 27, 2007)
Step 4 (expanding partition) doesn't work with Windows 2003 Server (W2k3). See: http://support.microsoft.com/kb/841650. To fix this, mount the W2k3 drive as the second drive in an XP Professional virtual machine (I had to create one, and install XP). Then use DISKPART in XP, just like step 4. When restarting W2k3, W2k3 required an immediate reboot to change settings, and after that worked fine.
Max (June 08, 2007)
Mark, actually, you CAN extend the disk without using XP machine. Do just like Alexey recommends - connect it as a second drive to a backed up machine and then run diskpart. I just did it.
Sam Garnham (August 22, 2007)
Thanks, worked for me. See http://support.microsoft.com/kb/325590 for supported OSs for DiskPart. Its included with XP and 2003; for 2000 you can download it from a link on that page.
cori (September 24, 2007)
Thanks for the great information! I do have one question. After the last step, when you are booting your original VM with the newly expanded disk, I get a BIOS error (to be expected). VMware's Phoenix bios drive setting of AUTO doesn't seem to recognize the new size. I'm also unable to enter numbers (I'm on a dell laptop) so I have to hold the plus key for it to go from 8322 to 16383 - quite time consuming. Did you run into this at all?
Kwami (September 25, 2007)
Exellent tutorial! Thank you so much, this is much faster than using a linux live cd or other methods I've tried. One thing I have encountered at times is that if you add a disk through the method described in step 4, the new disk shows up as a system disk. You will not be able to extend it it in this case. My solution was to select the properties for the new disk > Advanced, and change change the virtual node to anything other than harddisk 1. I have also checked the independent mode, and selected the default "persistent" radio button. Then everything worked just as described here.
MikeBTexas (October 10, 2007)
One small note for the novice: on step 2 I could not get this command to work unless I put the diskname in quotes, even though there is no space in the diskname path. So the working command for me was: vmware-vdiskmanager –x 10Gb "D:\Virtmachines\machine1\diskC.vmdk"
Greg Saunders (October 18, 2007)
Strange... followed steps exactly except host is Win2003 SP1 and guest is Win2000SP4. It looked all correct until I booted the expanded guest and in computer management it shows 30GB in the bottom graphical window (new size), but in the upper textual window it still shows mine at the original 10GB. Looking in explorer shows 10GB. Looking at the virtual disk file still shows 10GB. This is very strange. Am I missing something?
Tim (November 20, 2007)
I am experiencing the same problem as Greg. Disk Manager reports the new size but Explorer still shows the old size.
David (April 24, 2008)
Just use Converter! You will be asked to reboot one more time when the new vm comes back up.
Nikolajus (June 08, 2008)
Experienced sam problem as Greg and Tim. David, what is Converter? How to use it?
Billy Low (June 12, 2008)
I have tried this on MS Vista 64 bit and cannot get the drive to Extend. I have enlarged the drive to 20 GB and can mount it. Disk Part however does not see it, meither does MMC. any ideas?
Your comments:
  Name
Email
URL
Password
   

advertisement
Veeam Reporter for VMware Infrastructure 3


Popular articles
 



contact us | disclaimer | privacy policy © Copyright 2008 VM Weekly