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
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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)


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

View solution in original post

0 Kudos
31 Replies
LucD
Leadership
Leadership
Jump to solution

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.


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

0 Kudos
marc045
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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)


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

0 Kudos
marc045
Contributor
Contributor
Jump to solution

Thanks Luc, great stuff.

0 Kudos
Rumple
Virtuoso
Virtuoso
Jump to solution

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

0 Kudos
AndySimmons
Hot Shot
Hot Shot
Jump to solution

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.

-Andy VCAP5-DCA, VCP-DV 4/5, MCSE, space camp graduate.
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks, I updated the post.


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

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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.

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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? 


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

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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.

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

0 Kudos
zpollock
Contributor
Contributor
Jump to solution

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?

0 Kudos