Creating Virtual Disks
This section discusses the types of local VMDK files and how to create virtual disk for a remote ESXi host.
Creating Local Disk
The sample program presented in Virtual Disk API Sample Code creates virtual disk of type MONOLITHIC_SPARSE, in other words one big file, not pre-allocated. This is the default because modern file systems, in particular NTFS, support files larger than 2GB, and can hold more than 2GB of total data. This is not true of legacy file systems, such as FAT16 on MS-DOS and early Windows, or the ISO9660 file system for writing files on CD, or NFS version 2, or Linux kernel 2.4. All are limited to 2GB per volume. FAT and FAT32 were extended to 4GB in NT 3.51.
However, a SPLIT virtual disk might be safer than the MONOLITHIC variety, because if something goes wrong with the underlying host file system, some data might be recoverable from uncorrupted 2GB extents. VMware products do their best to repair a damaged VMDK, but having a split VMDK increases the chance of salvaging files during repair. On the downside, SPLIT virtual disk involves higher overhead (more file descriptors) and increases administrative complexity.
When required for a FAT16 or early Linux file system, you can create SPLIT_SPARSE virtual disk. The change is simple: the line highlighted in boldface. The sample program could be extended to have an option for this.
static void DoCreate(void)
{
VixDiskLibAdapterType adapter = strcmp(appGlobals.adapterType, "scsi") == 0 ?
VIXDISKLIB_ADAPTER_SCSI_BUSLOGIC : VIXDISKLIB_ADAPTER_IDE;
VixDiskLibCreateParams createParams;
VixError vixError;
createParams.adapterType = adapter;
createParams.capacity = appGlobals.mbSize * 2048;
createParams.diskType = VIXDISKLIB_DISK_SPLIT_SPARSE;
vixError = VixDiskLib_Create(appGlobals.connection, appGlobals.diskPath, &createParams, NULL, NULL);
CHECK_AND_THROW(vixError);
}
This one-line change to DoCreate() causes creation of 200MB split VMDK files (200MB being the capacity set on the previous line) unless the -cap command-line argument specifies otherwise.
Creating Remote Disk
As stated in Support for Managed Disk, VixDiskLib_Create() does not support managed disk. To create a managed disk on the remote ESXi host, first create a hosted disk on the local Workstation, then convert the hosted disk into managed disk with VixDiskLib_Clone() over the network.
To create remote managed disk using the sample program, type the following commands:
./vix-disklib-sample -create -cap 1000000 virtdisk.vmdk
./vix-disklib-sample -clone virtdisk.vmdk -host esx3i -user root -password secret vmfsdisk.vmdk
You could write a virtual-machine provisioning application to perform the following steps:
1
2
3
vixError = VixDiskLib_Clone(appGlobals.connection, appGlobals.diskPath,
srcConnection, appGlobals.srcPath,
&createParams, CloneProgressFunc, NULL, TRUE);
In this call, appGlobals.connection and appGolbals.diskPath represent the remote VMDK on the ESXi host, while srcConnection and appGlobals.srcPath represent the local hosted VMDK.
4
On Workstation, the VixVMPowerOn() function in the VIX API does this. For ESXi hosts, you must use the PowerOnVM_Task method. As easy way to use this method is in the VMware vSphere Perl Toolkit, which has the PowerOnVM_Task() call (non-blocking), and the PowerOnVM() call (synchronous).
5
Special Consideration for ESXi Hosts
No matter what virtual file type you create in Step 1, it becomes type VIXDISKLIB_DISK_VMFS_FLAT in Step 3.