PowerCLI

 View Only
Expand all | Collapse all

How to create an IDE hard disk instead of SCSI?

marc045

marc045May 08, 2011 12:28 AM

LucD

LucDNov 12, 2012 10:18 PM

  • 1.  How to create an IDE hard disk instead of SCSI?

    Posted May 02, 2011 01:35 PM

    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



  • 2.  RE: How to create an IDE hard disk instead of SCSI?

    Posted May 02, 2011 01:48 PM

    Afaik, the cmdlets in the current PowerCLI build don't allow this.

    To add an IDE disk you will first need to create an IDE controller.

    See the New-VM   -> how to define ControllerType thread.

    That thread has pointers to some functions that can accomplish what you want to do.



  • 3.  RE: How to create an IDE hard disk instead of SCSI?

    Posted May 02, 2011 09:58 PM

    Hi Luc,

    Is there such a thing as an "IDE controller"?

    If you edit settings of a VM with IDE hard disk(s) there is no IDE controller listed.

    Is there a way of changing the hard disk itself from a SCSI to an IDE?

    Even if you add a hard disk via New-HardDisk to a VM with existing IDE drives, it still gets added as SCSI.

    Regards

    marc0



  • 4.  RE: How to create an IDE hard disk instead of SCSI?
    Best Answer

    Posted May 03, 2011 09:26 AM

    There is, but you don't see it in the Edit Settings form.

    Also note that it is a very limited controller, you can for example only add 2 devices.

    So if you have 2 CD/DVD defined as IDE you will not be able to add an IDE disk on the same controller.

    The following script will add an IDE harddisk.

    $vmName = "MyVM" 
    $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
    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
    } else{     $ideKey = $ideCtrl.Key } # 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} # Get datastore
    $dsName
    = $vm.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[') # Add IDE harddisk
    $dev
    = New-Object VMware.Vim.VirtualDeviceConfigSpec
    $dev
    .FileOperation = "create"
    $dev
    .Operation = "add"
    $dev.Device = New-Object VMware.Vim.VirtualDisk
    $dev
    .Device.backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo
    $dev.Device.backing.Datastore = (Get-Datastore -Name $dsName).Extensiondata.MoRef $dev.Device.backing.DiskMode = "persistent"
    $dev
    .Device.Backing.FileName = "[" + $dsName + "] " + $vmName + "/" + $vmName + $hdNrStr + ".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)


  • 5.  RE: How to create an IDE hard disk instead of SCSI?

    Posted May 08, 2011 12:28 AM

    Thanks Luc, great stuff.



  • 6.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Nov 12, 2012 08:58 PM

    Thanks for the script Luc! Works like a champ; just needed to add a linebreak after the "0" on line 21:

    $hdNr = 0

    $vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} | %{

    It's worth mentioning that the VM needs to be powered off with this approach. One alternative is to edit VMX and VMDK stub file(s) by hand, and just vMotion to re-read the config without downtime, but your mileage may vary there. IDE HDDs are already an unsupported configuration, so expect surprises if you don't test it first.

    I'm not sure why the OP had a requirement for IDE HDDs, but in my case it's due to an emergency P2V of an old SCO box. Testing SCSI drives with dd consistently produced a bunch of non-recoverable errors that we didn't experience with IDE. Again, this is a totally unsupported configuration, but it was the fastest way to ressurect a legacy system sitting on rickety old hardware.



  • 7.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Nov 12, 2012 10:18 PM

    Thanks, I updated the post.



  • 8.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 11, 2021 11:01 PM

    Would you happen to have an example of the code for attaching an existing IDE disk to the VM rather than creating a new one?

    Thanks!



  • 9.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 04:58 AM

    In that case, you could use the New-Harddisk cmdlet with the DiskPath parameter.



  • 10.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 01:55 PM

    Doesn't New-HardDisk still try and attach it with a SCSI controller?  I tried that method initially but always receive the "Incompatible device backing specified for device '1'" error.  Here's what I'm using:

    $VM_Name = "Windows 10"
    $Location = (Get-Folder "MySubFolder" | where {$_.Parent -like "MyFolder"})
    $Datastore_Name = "Datastore01"

    $New_VM_Name = Get-VM -Name $VM_Name -Location $Location -Datastore $Datastore_Name
    New-HardDisk -VM $New_VM_Name -DiskPath "[$Datastore_Name] $VM_Name/$VM_Name.vmdk"

    The VMDX is a converted Hyper-V VHDX that is configured to use an IDE controller, and works fine if importing manually as an existing disk with IDE.

     



  • 11.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 02:11 PM

    You will have to fetch the Controller first with Get-ScsiController, and then pass that via the Controller parameter on the New-Harddisk cmdlet



  • 12.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 03:51 PM

    LucD - Thanks for the help.  I just want to be certain we're on the same page, you're saying that the Get-ScsiController cmdlet should work when I'm trying to add a disk to the IDE controller?

    Running that command against my VM returns a NULL object, which is what I would expect since there is no SCSI Controller present.  I'm attempting to add an existing IDE disk to the IDE controller of a newly created VM.  Am I missing something?

    Thanks!



  • 13.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 04:11 PM

    Come to think of it, you could use the script.
    You would just need to point the 

    $dev.Device.Backing.FileName

    property to the existing VMDK file.
    Did you try that? 



  • 14.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 05:07 PM

    Yes, but no luck with that so far.  If I use the script as is (just pointed to the existing disk) it still tries to create a new disk and the dies because there's already a disk with that name.  I've tried tweaking the various parameters to prevent it from creating a new disk, but haven't found a combination that works.



  • 15.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 05:10 PM

    Ok, I didn't realise you wanted to use an existing Harddisk and attach an existing VMDK to it.
    I'll have a look.



  • 16.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 05:44 PM

    Just to clarify, this is a newly created VM, and I'm attaching an existing (but unused) VMDK to it as the only disk.

    I'm taking a virtual disk exported from Hyper-V, converting to VMDK, then use scripting to build a new VM and attempting to make that existing disk the master/only disk on the new VM.  Just migrating everything over to VMware.



  • 17.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 05:45 PM

    My comment in our previous discussion about "existing disk" should have said "existing VMDK".  



  • 18.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 05:46 PM

    Instead of me producing a new script, you could also remove the existing disk (on the VM), and then use the script to add a new harddisk pointing to the existing VMDK.



  • 19.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 05:54 PM

    That's what I'm attempting to do, but have not found a programmatic way to add the new disk.

    My steps thus far are:

    Convert VHDX to VMDK
    Use Cmdlet to create new VM
    Delete existing disk from new VM
    Use Cmdlet to upload newly converted VMDK to Datastore
    Add converted VMDK to New VM as the only disk

    Everything works except the last step.  The virtual hardware in the converted disk expects an IDE controller, so it needs to be added to VMware as IDE.  It works great through the GUI, but I have not been able to add the disk to the IDE bus via CLI.

    Does that help clarify?



  • 20.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 12, 2021 08:04 PM

    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.



  • 21.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 13, 2021 12:30 AM

    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.



  • 22.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 26, 2021 03:55 PM

    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.



  • 23.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 26, 2021 04:31 PM

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



  • 24.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 27, 2021 05:29 PM

    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!



  • 25.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 27, 2021 05:48 PM

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



  • 26.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 27, 2021 06:17 PM

    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.



  • 27.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Sep 08, 2021 05:30 PM

    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.



  • 28.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Sep 08, 2021 05:45 PM

    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.



  • 29.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Sep 08, 2021 06:30 PM

    That was the missing piece!

    Thank you, thank you!!!



  • 30.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 29, 2023 08:50 AM

    How to run your script ?

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

     

    I'm a newbye..

     



  • 31.  RE: How to create an IDE hard disk instead of SCSI?

    Posted Aug 29, 2023 09:15 AM

    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.



  • 32.  RE: How to create an IDE hard disk instead of SCSI?

    Posted May 08, 2011 07:48 PM

    Out of curiousity, is there a reason you are trying to create an unsupported configuration using IDE disks instead of SCSI disks?