VMware Cloud Community
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Multiwriter Disk

Guys,

I need help to add multiwriter disk shared between 2 oracle VM's in my environment (vSphere 6, U2) using powercli.

They are so many posts on the internet on this but I am not able get success my requirement as mentioned below:

if the VM's are hosting one database then 9 multiwriter disk need to be added and shared between to these 2 VM's on the below SCSIID:

Hard Disk 2: SCSI0:1

Hard Disk 3: SCSI0:2

Hard Disk 4: SCSI0:3

Hard Disk 5: SCSI0:4

Hard Disk 6: SCSI0:5

Hard Disk 7: SCSI0:6

Hard Disk 8: SCSI0:7

Hard Disk 9: SCSI0:8

Hard Disk 10: SCSI0:9

if the VM's are hosting two database then another set of 9 multiwriter disk need to be added to new scso controller and shared between to these 2 VM's on the below SCSIID:

Hard Disk 11: SCSI1:1

Hard Disk 12: SCSI1:2

Hard Disk 13: SCSI1:3

Hard Disk 14: SCSI1:4

Hard Disk 15: SCSI1:5

Hard Disk 16: SCSI1:6

Hard Disk 17: SCSI1:7

Hard Disk 18: SCSI1:8

Hard Disk 19: SCSI1:9

The VM's wiil be offline.

Any help will be much appreciated.

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

$vmNames = 'VM1','VM2'

$nrDB = 2

$nrDisk= 1

$diskSizeGB = 1

$dsName = 'OtherDS'

$diskUnitNr = 1..15 | where{$_ -ne 7}

$vm = Get-VM -Name $vmNames[0]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = "[$($dsName)]"

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $back.EagerlyScrub = $true

        $back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.CapacityInKB = $diskSizeGB*1GB/1KB

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create

        $dev.Device = $disk

        $spec.DeviceChange += $dev

    }

}

$vm.ExtensionData.ReconfigVM($spec)

$hdNames = Get-VM -Name $vmNames[0] | Get-HardDisk | where{$_.Name -ne 'Hard disk 1'} | Select -ExpandProperty FileName

$vm = Get-VM -Name $vmNames[1]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = $hdNames[($db - 1) * $nrDisk + ($hd - 1)]

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $back.EagerlyScrub = $true

        $back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.Device = $disk

        $spec.DeviceChange += $dev

    }

}

$vm.ExtensionData.ReconfigVM($spec)


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

View solution in original post

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Note that scsi0:7 and scsi1:7 are not possible.
The device number 7 is reserved for the SCSI controller itself.

How would you tackle that in your numbering scheme?
Just skip x:7 and continue with x:8?


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

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Thanks for your reply.

yes in that case will skip x:7 and continue with x:8

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vmNames = 'VM1','VM2'

$nrDB = 2

$nrDisk= 9

$diskSizeGB = 1

$diskUnitNr = 1..15 | where{$_ -ne 7}

$vm = Get-VM -Name $vmNames[0]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = ''

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.CapacityInKB = $diskSizeGB*1GB/1KB

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create

        $dev.Device = $disk

        $spec.DeviceChange += $dev

        $extra = New-Object VMware.Vim.OptionValue

        $extra.key = "scsi$($scsiBus):$($diskUnitNr[$hd - 1]).sharing"

        $extra.Value = "multi-writer"

        $spec.ExtraConfig += $extra

    }

}

$vm.ExtensionData.ReconfigVM($spec)

$hdNames = Get-VM -Name $vmNames[0] | Get-HardDisk | where{$_.Name -ne 'Hard disk 1'} | Select -ExpandProperty FileName

$vm = Get-VM -Name $vmNames[1]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = $hdNames[($db - 1) * $nrDisk + ($hd - 1)]

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.Device = $disk

        $spec.DeviceChange += $dev

        $extra = New-Object VMware.Vim.OptionValue

        $extra.key = "scsi$($scsiBus):$($diskUnitNr[$hd - 1]).sharing"

        $extra.Value = "multi-writer"

        $spec.ExtraConfig += $extra

    }

}

$vm.ExtensionData.ReconfigVM($spec)


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

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Thanks a lot.

Just one query and forgot to mention that the format  of multi-writer vmdks will be eager zeroed thick.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try the following.

Note that I also used the Sharing (introduced in vSphere 6) property instead of the ExtraConfig for setting multi-writer.

$vmNames = 'VM1','VM2'

$nrDB = 2

$nrDisk= 9

$diskSizeGB = 1

$diskUnitNr = 1..15 | where{$_ -ne 7}

$vm = Get-VM -Name $vmNames[0]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = ''

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $back.EagerlyScrub = $true

        $back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.CapacityInKB = $diskSizeGB*1GB/1KB

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create

        $dev.Device = $disk

        $spec.DeviceChange += $dev

    }

}

$vm.ExtensionData.ReconfigVM($spec)

$hdNames = Get-VM -Name $vmNames[0] | Get-HardDisk | where{$_.Name -ne 'Hard disk 1'} | Select -ExpandProperty FileName

$vm = Get-VM -Name $vmNames[1]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = $hdNames[($db - 1) * $nrDisk + ($hd - 1)]

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $back.EagerlyScrub = $true

        $back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.Device = $disk

        $spec.DeviceChange += $dev

    }

}

$vm.ExtensionData.ReconfigVM($spec)


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

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Thanks a lot.

It is working perfectly.

One last thing. I would like to store each of these multiwriter vmdk on a dedicated datastore.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$vmNames = 'VM1','VM2'

$nrDB = 2

$nrDisk= 1

$diskSizeGB = 1

$dsName = 'OtherDS'

$diskUnitNr = 1..15 | where{$_ -ne 7}

$vm = Get-VM -Name $vmNames[0]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = "[$($dsName)]"

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $back.EagerlyScrub = $true

        $back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.CapacityInKB = $diskSizeGB*1GB/1KB

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create

        $dev.Device = $disk

        $spec.DeviceChange += $dev

    }

}

$vm.ExtensionData.ReconfigVM($spec)

$hdNames = Get-VM -Name $vmNames[0] | Get-HardDisk | where{$_.Name -ne 'Hard disk 1'} | Select -ExpandProperty FileName

$vm = Get-VM -Name $vmNames[1]

$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'

$scsiBus = $scsi.ExtensionData.BusNumber

$scsiKey = $scsi.Key

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

for($db = 1; $db -le $nrDB; $db++){

    if($db -gt 1){

        $scsiBus = $scsiBus + 1

        $scsiKey = -(200 + $db)

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $controller = New-Object VMware.Vim.ParaVirtualSCSIController

        $controller.Key = $scsiKey

        $controller.BusNumber = 1

        $dev.Device = $controller

        $spec.DeviceChange += $dev

    }

    for($hd = 1;$hd -le $nrDisk; $hd++){

        $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $disk = New-Object VMware.Vim.VirtualDisk

        $back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

        $back.FileName = $hdNames[($db - 1) * $nrDisk + ($hd - 1)]

        $back.ThinProvisioned = $true

        $back.DiskMode = 'independent_persistent'

        $back.EagerlyScrub = $true

        $back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter

        $disk.Key = -($db * 100 + $hd)

        $disk.ControllerKey = $scsiKey

        $disk.UnitNumber = $diskUnitNr[$hd - 1]

        $disk.Backing = $back

        $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add

        $dev.Device = $disk

        $spec.DeviceChange += $dev

    }

}

$vm.ExtensionData.ReconfigVM($spec)


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

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Thanks Lucd for all your help. Much appreciated.

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

I have noticed that I can add multiwriter disk in shared mode but the once I restart the VM, sharing option is setting back to unspecified when checking from web client. Please advise. 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You did set the multi-writer flag while the VM was powered off I assume?

So after power on everything looks ok?

But after another restart the setting is gone?


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

Reply
0 Kudos
theFrog
Contributor
Contributor
Jump to solution

Thanks Luc,

You just saved me a bunch of time writing this myself.

Love your work.

🙂

Reply
0 Kudos
IKirill
Enthusiast
Enthusiast
Jump to solution

Hi LucD!

I started testing this script and have questions!

1. Why the default controller is 0? After all, this controller, which is installed with the VM and is usually used under the OS. Besides, it is not shared.

2. I have an error at the second node- " Invalid Datastore Path [". I suspect the problem here is:
$back.FileName = $hdNames[($db - 1) * $nrDisk + ($hd - 1)]

3. Is the $nrDB Variable the number of repeats?

How do I modify the script to use a controller other than 0 (in this case start by 1) and what i do whith second node?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Why are you looking at this thread, this is not the one I pointed to in Add and set Hard Disk MultiWriter flag on Powered On VM

  1. You can start with another controller by just changing the name. Not sure what a shared controller is?

  2. This an array holding the filenames of the VMDK created on the 1st VM. Does it contain perhaps VMDK paths that are not accessible from the 2nd VM?
  3. No, if you read the original question in this thread, the user required additional harddisk when the VM hosted 2 databases (hence $nrDB)


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

Reply
0 Kudos