VMware {code} Community
DArndt
Enthusiast
Enthusiast
Jump to solution

How do you create a VM with an existing disk?

I have been playing with the vmcreate.pl script, but it seems to only allow me to create a VM with a disk that is created during the process.

If I have an existing vmdk file and want to create a new VM using the existing disk, is there a way to do that?

Thanks,

Dave

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
njain
Expert
Expert
Jump to solution

Hi Dave,

You can indeed create a new VM with an existing vmdk file. This can be done by setting the "deviceChange" property of the VirtualMachineConfigSpec. Below is the code snippet to illustrate the same. While creating the disk backing info, you can provide the path to VMDK file and assign it to the "fileName" property.

my $disk_backing_info =

VirtualDiskFlatVer2BackingInfo->new(diskMode => 'persistent',

fileName => $vmdk_path);

my $disk = VirtualDisk->new(backing => $disk_backing_info,

controllerKey => 0,

key => 0,

unitNumber => 0,

capacityInKB => $disksize);

my $disk_vm_dev_conf_spec =

VirtualDeviceConfigSpec->new(device => $disk);

Hope the above information resolves your query.

Regards,

Neha

View solution in original post

0 Kudos
2 Replies
njain
Expert
Expert
Jump to solution

Hi Dave,

You can indeed create a new VM with an existing vmdk file. This can be done by setting the "deviceChange" property of the VirtualMachineConfigSpec. Below is the code snippet to illustrate the same. While creating the disk backing info, you can provide the path to VMDK file and assign it to the "fileName" property.

my $disk_backing_info =

VirtualDiskFlatVer2BackingInfo->new(diskMode => 'persistent',

fileName => $vmdk_path);

my $disk = VirtualDisk->new(backing => $disk_backing_info,

controllerKey => 0,

key => 0,

unitNumber => 0,

capacityInKB => $disksize);

my $disk_vm_dev_conf_spec =

VirtualDeviceConfigSpec->new(device => $disk);

Hope the above information resolves your query.

Regards,

Neha

0 Kudos
DArndt
Enthusiast
Enthusiast
Jump to solution

So,

Let me get this straight. In the vmcreate.pl script where it does:

my $disk_vm_dev_cnf_scpe = create_virtual_disk(ds_path => $ds_path, disksize => $args);

I can instead set it as you show and then when the VirtualmachineConfigSpec->new(----


) is called it will use the existing disk specified.

I think I understand, thanks for your help.

Dave

0 Kudos