VMware {code} Community
dmhaynes
Enthusiast
Enthusiast

Growing a Hard Disk

I am trying to increase the size of an existing hard disk using the SDK and Java.

I set up the file backing (VirtualDiskFlatVer2BackingInfo) and the virtual disk (VirtualDisk) with the same values as I used to create the hard disk initially.

I then set the device and operation in the VirtualDeviceConfigSpec. The operation is set as "edit".

The task completes successfully but the disk is not set to the size I requested.

Setting the file operation causes an 'invalid operation' error from the VC.

I have tried setting the DiskMode in the backing to both 'persistent' and 'append' but this does not seem to make a difference.

Can anyone supply some guidance on this?

(I am already signed up for the reconfigure webinar on Thursday)

0 Kudos
15 Replies
hrobinson
VMware Employee
VMware Employee

At present there is no way to grown a VMDK using the SDK.

The "edit" method is to replace it.

You can use VMKFSTOOLS on COS to modify the VMDK size, if I remember.

It's on the list of futures to enable that via the SDK.

Programmatically, your choice is to create a new VMDK with the required size. Copy the old contents to the new and then replace the drive.

0 Kudos
dmhaynes
Enthusiast
Enthusiast

Thanks

I thought that might be the case since the option was not offered in Virtual Center but it never hurts to ask.

0 Kudos
GlenMarquis2
Enthusiast
Enthusiast

What type of soil are you using?

0 Kudos
dmhaynes
Enthusiast
Enthusiast

One with a high iron and silicate component of course!

0 Kudos
GlenMarquis2
Enthusiast
Enthusiast

Making more space is a two step process -

1 - vmkfstools -X 10G file-location.vmdk

(its a capital X and will allow a smaller than 10Gb vmdk to become 10Gb)

2 - Once you've done this and powered on the VM you will then need to use diskpart or some other partition sizing tool, as although the vmdk will be bigger windows will not use it automatically.

0 Kudos
dmhaynes
Enthusiast
Enthusiast

Thanks

This was the way we ended up doing it for 2.54. My question was really around whether it could be accomplished via the SDK (the answer to which is 'not yet').

We are constantly reviewing our product to try to minimize the number of places where we are going to an ESX agent to do something that can be accomplished via the Virtual Center (via the SDK) since that removes complexity from our application (or, at least, pushes some of the complexity onto the SDK).

0 Kudos
GlenMarquis2
Enthusiast
Enthusiast

I see, yeah I would have thought this type of functionality will be in a future release and then even better functionality soon after that.

0 Kudos
esloof
Expert
Expert

What about this ?

Download Patch ESX-6921838 for VMware ESX Server 3.0.1

Resolved Issues

This patch adds support to the SDK for the removal and resizing of virtual disks while attached virtual machines are running.

Regards,

Eric Sloof http://www.ntpro.nl

0 Kudos
dmhaynes
Enthusiast
Enthusiast

I'll check it again, but I was under the impression that this was for the ESX agent not the SDK via the virtual center.

0 Kudos
BraindG
Contributor
Contributor

Hiya,

I understand this patch allows the functionality for SDK's to now make these changes, however someone still needs to actually write the app - does anyone know of something?

Thanks

Barry

0 Kudos
IanGibbs
Enthusiast
Enthusiast

You can get a VirtualDisk object for the disk in question, change its capacityInKb, put it into a VirtualDeviceConfigSpec, and then put that in a VirtualMachineConfigSpec, and then call ReconfigVM_Task. All of this completes successfully, but the disk never gets any bigger.

Growing it with vmkfstools, or modifying its size from the VI client both work. So if VC can do it remotely, it must be doable. God knows how.

0 Kudos
admin
Immortal
Immortal

Hi,

I tried to increase the hard disk size of an existing VM, in vSphere, and it works well. I was able to increase the disk size using vSphere APIs and via vSphere Client as well.

Couple of points to note are as follows:

1. Once the size gets increased, we dont see the size of the disk partition inside the guest OS to be increased, instead a new unallocated partition gets created with the (new disk size- old size). Hence, one has to manually allocate the partition and get the changes in the disk in place.

2. The size of the disk would not increase if VM is in the powered ON state. For reconfiguring the VM for a new disk size, VM must be powered off.

3. The size of the disk would not increase if VM contains snapshot(s). In such a case, disk file gets locked and it is not possible to increase the size in such a scenario.

It would be great if you can share your sample code/code snippet so that we can verify how you are expanding the disk size.

Thanks,

Angela

0 Kudos
IanGibbs
Enthusiast
Enthusiast

Thanks for posting, Angela. I'm glad it is possible somehow.

In response to your points, I am only having trouble with growing the disk; my mechanisms for growing the partition and the filesystem work fine. As you'll see in the code attached, I already check for snapshots and shut the machine down before attempting the grow.

I am using ESX/vSphere 4.0 update 1.

Here's what I did:

1. Take a screenshot of the disk in the DS browser before (attached)

2. Check the size of the disk using ls on the ESX server before:

[root@gbldcvdi03 ThinApp-Ian]# pwd
/vmfs/volumes/VDI-TEST/ThinApp-Ian
[root@gbldcvdi03 ThinApp-Ian]# ls -lk | grep flat
-rw------- 1 root root 10558990 Mar 30 12:30 ThinApp-Ian-flat.vmdk

3. Run the attached script which completes without errors:

root@gbldcvut01:/usr/local/bin# ./no-grow-disk.pl
Growing disk 'Hard Disk 1' on VM ThinApp-Ian
Connecting to VC at https://fqdn.mycorp.com/sdk with user username and password ********...done
Locating datacentre London VDI Datacentre...done
Locating VM ThinApp-Ian...done
Looking for hard disks attached to this VM...
        1: Hard disk 1 ([VDI-TEST] ThinApp-Ian/ThinApp-Ian.vmdk) attached to controller 1000 as device 0
Sending shut down request to VM...
        Sending graceful shut down to VM...done
Waiting for VM to power down...
        VM is still powered on...
        VM is still powered on...
done gracefully
Expanding VMDK for Hard Disk 1...       Starting Reconfigure...
        Starting Reconfigure...
        Reconfigure: 100%
Grow complete. Your VM's disk has been grown. It will now reboot and be useable shortly.

4. Run the ls again and refresh the DS browser. They show exactly the same sizes.

5. I conclude the disk has not grown.

6. I run vmkfstools and then ls again. The disk has grown:

[root@gbldcvdi03 ThinApp-Ian]# vmkfstools -X 10569490k ThinApp-Ian.vmdk
[root@gbldcvdi03 ThinApp-Ian]# ls -lk | grep flat
-rw------- 1 root root 10569490 Mar 30 12:35 ThinApp-Ian-flat.vmdk

Here's the relevant snippet. $name here would be "Hard disk 1". As I said above, the premise is to get the VirtualDisk object, modify its size, and then run Edit on it. I am assuming it is this that is wrong.

161 my $devspec = resize_disk_spec($vm_view, $disks->{$disk_num}->{'label'}, $disk_size);
162 if($devspec)
163 {
164   push (@device_change_specs, $devspec);
165 }
166 else
167 {
168   print STDERR "\nERROR: Could not create disk grow_spec\n";
169   exit INT_ERR_NO_DEVICE_SPEC_4;
170 }
171
172 $vmspec = VirtualMachineConfigSpec->new( deviceChange => \@device_change_specs );
173 $task_moref = $vm_view->ReconfigVM_Task(spec => $vmspec);

188 sub resize_disk_spec {
189    my ($vm_view, $name, $sizeInKb) = @_;
190    my ($config_spec_operation, $config_file_operation);
191    my $disk;
192    $config_spec_operation = VirtualDeviceConfigSpecOperation->new('edit');
193
194    $disk = VMUtils::find_device(vm => $vm_view,
195                                 controller => $name);
196         $disk->{capacityInKb} = $sizeInKb;
197         if($disk)
198         {
199       my $devspec =
200          VirtualDeviceConfigSpec->new(operation => $config_spec_operation,
201                                       device => $disk);
202           return $devspec;
203         }
204
205    return undef;
206 }

0 Kudos
admin
Immortal
Immortal

Hi,

There is a typo mistake in the script provided by you. "capacityInKB " property is mistakenly set as "capacityInKb", in the following line in resize_disk_spec sub routine:

$disk-> = $sizeInKb;

Making this correction successfully increases the size of the hard disk. Smiley Happy

- Angela -

0 Kudos
IanGibbs
Enthusiast
Enthusiast

I concur Angela - thank you so much for pointing that out. A little lesson for us all there, in that properties aren't validated. Disappointing.

I hope the posted code is of use to someone once corrected.

0 Kudos