Contributor
Contributor

Change SCSI adapater to paravirtual with PowerCLI

Jump to solution

Hi All,

I have people at my site who canot follow documentation, so I'm trying to make things a little easier, but not having much luck. After I upgrade my ESX servers to Update 1, I would like to automate updating guest tools and changing the disk adapters to paravirtual. Upgrading the tools is easy as I see the cmdlet to do that, but does anyone know how to determine the the type of scsi adapter a VM is using and change it to VMware paravirtual on Windows 2003 / Windows 2008 guests using powershell.

Thanks

Mike

0 Kudos
1 Solution

Accepted Solutions
Leadership
Leadership
0 Kudos
12 Replies
Immortal
Immortal

We don't have cmdlets for anything SCSI adapter related. You might have a look at Project Onyx. Others out there are solving similar problems this way.

=====

Carter Shanklin

Read the PowerCLI Blog
[Follow me on Twitter|http://twitter.com/cshanklin]

Leadership
Leadership
0 Kudos
Contributor
Contributor

LucD,

Thanks very much for the script. This is going to be a hugh help and it works perfectly. For those that would like to try out this script, take note that if you do not have a SCSI adapter (i.e. SCSI controller 1) in the guest that is already set to paravirtual, then will will receive a blue screen because the OS cannot find the boot drive. What I'll need to do is modify this script so that it powers down the VM, adds a PV scsi adapter, boots up the VM so that the OS can auto load the driver, then power down and convert SCSI 0 to PV.

LucD,

Do you know of a method to add a PV adapter without attaching a drive to it? The only method I know to create another SCSI adapter is by adding an additional drive on a separate SCSI adapter. Then when all is configured, I'd need to delete the 2nd drive and adapter.

Thanks

Mike

0 Kudos
Leadership
Leadership

Yes, when you change the SCSI controller that is connected to your boot disk, it will BSOD.

On the other hand you can change the controllers for all non-boot disks without any problem.

I'll have a look at adding a 2nd controller without a disk.

Vaguely remember writing such a script in the past.


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

0 Kudos
Contributor
Contributor

LucD,

I was doing a google search and ran across this code that you wrote May 2009 in this forum. Correct me if I'm wrong, but this looks like it'd add a controller to the VM, but it is LSI and I'm not sure how to edit it for my purposes. Thoughts? Thanks

filter set-SCSILsiLogicController {

$vm = Get-View $_.ID

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = @()

$spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualLsiLogicController

$spec.deviceChange[0].device.busNumber = 0

$spec.deviceChange[0].device.ControllerKey = 100

$spec.deviceChange[0].device.DeviceInfo = New-Object VMware.Vim.Description

$spec.deviceChange[0].device.DeviceInfo.label = "SCSI Controller 0"

$spec.deviceChange[0].device.DeviceInfo.summary = "Lsi Logic"

$spec.deviceChange[0].device.hotAddRemove = $true

$spec.deviceChange[0].device.key = 1000

$spec.deviceChange[0].device.scsiCtlrUnitNumber = 7

$spec.deviceChange[0].device.sharedBus = "noSharing"

$spec.deviceChange[0].operation = "edit"

$vm.ReconfigVM_Task($spec)

0 Kudos
Leadership
Leadership

It should be easy to adapt that script for a PV controller.

Let me get back to you.


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

0 Kudos
Leadership
Leadership

This is the adapted script to add a Paravirtual SCSI controller.

Note that the script does not check if a controller with the number you specify, in $ctrlNumber, already exists on the guest !

$vmName = <vm-name>

$ctrlNumber = 1

$vm = Get-VM $vmName | Get-View

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = @()

$newPV = New-Object VMware.Vim.VirtualDeviceConfigSpec

$newPV.device = New-Object VMware.Vim.ParaVirtualSCSIController

$newPV.device.busNumber = $ctrlNumber

$newPV.device.DeviceInfo = New-Object VMware.Vim.Description

$newPV.device.DeviceInfo.label =( "SCSI Controller " + $ctrlNumber)

$newPV.device.DeviceInfo.summary = "VMware paravirtual SCSI"

$newPV.device.key = -100

$newPV.device.scsiCtlrUnitNumber = 7

$newPV.operation = "add"

$spec.deviceChange += $newPV

$vm.ReconfigVM_Task($spec)


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

0 Kudos
Contributor
Contributor

Works perfectly of course! I ran the add controller script, powered up the VM for approximately 15 seconds, powered off guest without logging in, then ran the script to convert controler 0 to PV, powered OS back up, and no BSOD. Now, how would I modify your script which adds controller 1 to take it away? I tried changing out new and add with words such as remove and detele, but that's not it. With this final part, once I tie it all together with appropiate checks, etc ... it'll be an awesome script that I hope even my admins who cannot follow directions cannot muck up Smiley Happy

Thanks in advance.

0 Kudos
Leadership
Leadership

Here you go.

This should do the trick.

Same note for the controller number as my previous reply. No testing done in the script, know what you are doing !

$vmName = <vm-name>
$ctrlNumber = 1

$vm = Get-VM $vmName | Get-View
$vm.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq ("SCSI controller " + $ctrlNumber)} | %{
	$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
	$spec.deviceChange = @()
	$oldPV = New-Object VMware.Vim.VirtualDeviceConfigSpec
	$oldPV.device = $_
	$oldPV.operation = "remove"

	$spec.deviceChange += $oldPV

	$vm.ReconfigVM_Task($spec)
}


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

0 Kudos
Contributor
Contributor

Just tested. Works perfect. It might take me a few days, but I'll tie together these scripts along with some other portions I already have and I think it'll do very nicely. For those that might be interested, I'll post my stab at it when I'm done.

Thanks very much LucD. You have saved me a lot of time.

0 Kudos
Contributor
Contributor

Use this script at your own risk! I have done numerous testing and feel it'll work pretty well, but it is still a work in progress. I wanted to share what I had as perhaps it'll help others and if you have suggestions or bug fixes, I'd love to see them.

Currently this script is designed to only work on Windows servers with one SCSI Controller and will perform the following:

!. Upgrade tools to latest

2. Convert hardware to version 7

3. Convert SCSI Ctrl 0 to Paravirtual

Steps 1 and 2 are performed on XP and higher. Step 3 is only performed on Windows 2003 or Windows 2008

Limitations:

Script is not able to check if CRTL0 is already paravirtual, convert SCSI Ctrl 1 or higher, or even detect if there is a CTRL1. The script will fail if a VM has two controllers. I’m sure that I’ll be able to overcome these problems, but have not identified the code I need to use yet.

If the VM is Windows and only has 1 controller which is not PV yet, it works very smoothly. I think I’m going to look at adding convert Network adapter to VMXNET3. I’m also going to create a wrapper script that ‘ll read from a csv file for a list of VMs in order to spawn multiple instances of this script so that multiple servers can be worked on at the same time.

I don't claim to be a great scripter, so please feel free to suggest improvements. Many thanks go out to LucD for suppling the code which converts SCSI Controller 0 to Paravirtual.

Mike

0 Kudos
Contributor
Contributor

Can this be modified for vmx-8 too?

0 Kudos