PowerCLI

 View Only
Expand all | Collapse all

Multiwriter Disk

  • 1.  Multiwriter Disk

    Posted Dec 02, 2017 06:50 AM

    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.



  • 2.  RE: Multiwriter Disk

    Posted Dec 02, 2017 08:12 AM

    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?



  • 3.  RE: Multiwriter Disk

    Posted Dec 02, 2017 09:58 AM

    Thanks for your reply.

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



  • 4.  RE: Multiwriter Disk

    Posted Dec 03, 2017 01:34 AM

    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)



  • 5.  RE: Multiwriter Disk

    Posted Dec 03, 2017 04:36 AM

    Thanks a lot.

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



  • 6.  RE: Multiwriter Disk

    Posted Dec 03, 2017 09:18 AM

    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)



  • 7.  RE: Multiwriter Disk

    Posted Dec 04, 2017 11:21 AM

    Thanks a lot.

    It is working perfectly.

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



  • 8.  RE: Multiwriter Disk
    Best Answer

    Posted Dec 04, 2017 03:30 PM

    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)



  • 9.  RE: Multiwriter Disk

    Posted Dec 05, 2017 07:17 AM

    Thanks Lucd for all your help. Much appreciated.



  • 10.  RE: Multiwriter Disk

    Posted Apr 12, 2018 02:13 PM

    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. 



  • 11.  RE: Multiwriter Disk

    Posted Apr 12, 2018 02:26 PM

    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?



  • 12.  RE: Multiwriter Disk

    Posted May 02, 2018 05:12 AM

    Thanks Luc,

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

    Love your work.

    :)



  • 13.  RE: Multiwriter Disk

    Posted Oct 30, 2019 04:55 PM

    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?



  • 14.  RE: Multiwriter Disk

    Posted Oct 30, 2019 05:15 PM

    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)