尝试使用以下代码 (C#) 创建克隆的 VM,但失败:
VirtualBox.VirtualBox box = new VirtualBox.VirtualBox();
//create a new machine
IMachine machine = box.CreateMachine(null, "MyClone", null, null, "forceOverwrite=1");
box.RegisterMachine(machine);
//Lock machine for editing
machine.LockMachine(session, LockType.LockType_Write);
IMachine machsettings = session.Machine;
//clone the disk image from an existing vdi (source VDI is not being locked/used)
IMedium hddorig = box.OpenMedium("c:\\tmp\\VDI\\dsl-4.4.10-x86.vdi", DeviceType.DeviceType_HardDisk, AccessMode.AccessMode_ReadOnly, 0);
IMedium hddclone = box.CreateHardDisk("VDI", "c:\\tmp\\VDI\\clone.vdi");
IProgress hddprogress = hddorig.CloneTo(hddclone, 0, hddorig);
hddprogress.WaitForCompletion(-1);
//attach disk image to machine
machsettings.AddStorageController("IDE", StorageBus.StorageBus_IDE);
machsettings.AttachDevice("IDE", 0, 0, DeviceType.DeviceType_HardDisk, hddclone); //fails - Storage for the medium 'c:\tmp\VDI\clone.vdi' is not created
machsettings.SaveSettings();
AttachDevice 总是失败说“未创建媒体存储”。我在这里缺少什么步骤?
以下代码工作正常,因此看起来创建 hddclone 存在一些问题。machsettings.AttachDevice("IDE", 0, 0, DeviceType.DeviceType_HardDisk, hddorig); //好的
谢谢史蒂夫