VMware Cloud Community
marc045
Contributor
Contributor
Jump to solution

How to create an IDE hard disk instead of SCSI?

Hi All,

$myVM | new-harddisk -capacityKB 1234

Creates a SCSI hard disk.

Is there a switch/hack/workaround to create an IDE hard disk?

Or to modify an existing SCSI hard disk to become an IDE one?

Regards

marc0

Tags (2)
0 Kudos
31 Replies
LucD
Leadership
Leadership
Jump to solution

The script looks if there is an existing IDE controller, if there is not it adds one.
Then it adds the harddisk to that controller.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

Are there other parameters in the script that need to be changed for adding an existing disk?  My issue is that when I point the $dev.Device.Backing.FileName entry to the existing disk, rather than trying to attach the existing disk the script tries to create a new disk with that name in the same location.

Tags (1)
0 Kudos
zpollock
Contributor
Contributor
Jump to solution

I'm still stuck on this issue if anyone has other suggestions.  

I have not found a way with this script to add an existing disk, instead it keeps trying to create a new disk of the name provided.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you left the Operation to be 'Add' instead of 'Edit', that is normal.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

LucD,

Thanks for your continued help, but I'm still missing something.

Here's my test script using Edit:

$vmName = "Test VM" 
$Datastore_Name = "Datastore03"
$hdSize = 8 * 1GB

$vm = Get-VM -Name $vmName
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
# Check if there is an IDE COntroller present 
$ideCtrl = $vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualIDEController"} | select -First 1 
echo $ideCtrl
if(!$ideCtrl){
    $ctrl = New-Object VMware.Vim.VirtualDeviceConfigSpec
    $ctrl.Operation = "Add"
    $ctrl.Device = New-Object VMware.Vim.VirtualIDEController
    $ideKey = -1
    $ctrl.Device.ControllerKey = $ideKey
    $spec.deviceChange += $ctrl
    echo 'added controller'
}
else{
    $ideKey = $ideCtrl.Key
    echo 'no controller added'
}

# Get next harddisk number 
$hdNr = 0 
$vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} | %{
    $nr = [int]$_.DeviceInfo.Label.Split(' ')[2]
    if($hdNr -lt $nr){
        $hdNr = $nr    }
}
if($hdNr -eq 0){$hdNrStr = ""}
else{$hdNrStr = "_" + $hdNr}

# Add IDE harddisk 
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec 
$dev.FileOperation = "create"
$dev.Operation = "Edit"
$dev.Device = New-Object VMware.Vim.VirtualDisk
$dev.Device.backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo
$dev.Device.backing.Datastore = (Get-Datastore -Name $Datastore_Name).Extensiondata.MoRef
$dev.Device.backing.DiskMode = "persistent"
#$dev.Device.Backing.FileName = "[" + $Datastore_Name + "] " + $vmName + "/" + $vmName + $hdNrStr + ".vmdk"
$dev.Device.Backing.FileName = "[$Datastore_Name] $vmName/$vmName.vmdk"
$dev.Device.backing.ThinProvisioned = $true
#$dev.Device.CapacityInKb = $hdSize / 1KB
$dev.Device.ControllerKey = $ideKey
$dev.Device.UnitNumber = -1
$spec.deviceChange += $dev

$vm.ExtensionData.ReconfigVM($spec)

 

This results in an "Invalid configuration for device '0'." error.  I've tried it with and without the $hdSize parameter included, although I would not expect that to be used for attaching an existing disk.

Echoing the $ideCtrl variable returns the following:

BusNumber : 0
Device : {3000}
Key : 200
DeviceInfo : VMware.Vim.Description
Backing :
Connectable :
SlotInfo :
ControllerKey :
UnitNumber :

Does that look correct for the controller?  IDE controllers don't show up in the GUI so I'm not sure how to verify this is a real/working controller in place.  The script is skipping the Add Controller operation.

Thanks!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, you will have to use the controller to which the current harddisk is connected


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

There is no current disk on the VM.

I'm trying to attach a previously created disk from elsewhere to a newly created VM that has no disk, the existing disk will be the only one on the VM.  The existing disk requires an IDE controller.  My goal is to create an IDE controller (if required), and the attach a previously existing disk to the VM.

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

I'm still struggling with this seemingly simple task.  To recap:

* I created a new VM
* I removed the existing disk
* There is an IDE0 controller present
* I'm trying to add an existing IDE disk (from elsewhere) to the IDE0 controller as the only disk

$ds = "Datastore03"
$vmName = "Test VM"
$vmdkName = "[" + $ds + "] " + $vmName + "/Test VM.vmdk"
$vm = Get-VM -Name $vmName

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = @()
$spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualDisk
$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo
$spec.deviceChange[0].device.backing.datastore = $ds.ExtensionData.MoRef
$spec.deviceChange[0].device.backing.fileName = $vmdkName
$spec.deviceChange[0].device.backing.diskMode = "independent_persistent"
$spec.deviceChange[0].device.unitnumber = -1
$spec.deviceChange[0].device.controllerKey = $ideCtrl.ExtensionData.Key
$spec.deviceChange[0].operation = "add"
$vm.ExtensionData.ReconfigVM($spec)

 

This produces the error Exception calling "ReconfigVM" with "1" argument(s): "Device requires a controller.".  Note that the controller is present in the GUI, and running...

$ideCtrl = $vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualIDEController"} | select -First 1
echo $ideCtrl

...produces:

BusNumber : 0
Device : {3000}
Key : 200
DeviceInfo : VMware.Vim.Description
Backing :
Connectable :
SlotInfo :
ControllerKey :
UnitNumber :

When checking the devices list this seems to correctly correspond to the IDE0 controller.

It seems this should be an "Add" operation since it's a new disk, but based on previous comments I tried it as an "Edit" too and receive the error Exception calling "ReconfigVM" with "1" argument(s): "Invalid configuration for device '0'."

I'd be grateful for any assistance as this is the last piece of the puzzle I'm stuck on.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since your $ideCtrl value is already a vSphere object, there is no point in using the ExtensionData from .NET objects.
Just $ideCtrl.Key should be sufficient.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

zpollock
Contributor
Contributor
Jump to solution

That was the missing piece!

Thank you, thank you!!!

0 Kudos
acik
Contributor
Contributor
Jump to solution

How to run your script ?

./script (as a bash script) gives me a lot of errors

 

I'm a newbye.. 😁

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This is a PowerShell script, you will need to have PowerShell installed.
The VMware Developer Documentation describes under the Get Started section what you need.
Once PowerShell and the PowerCLI modules are installed, you can run the script, which is normally stored in a .ps1 file.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos