Last active
September 7, 2017 21:35
-
-
Save patrickmslatteryvt/11196973 to your computer and use it in GitHub Desktop.
PowerShell script to create a vSphere VM with 8 HDDs and 2 SSDs suitable for testing ZFS on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stops the client whining about certs | |
Set-PowerCLIConfiguration -InvalidCertificateAction ignore | |
# Edit these values to suit your environment | |
Connect-VIServer -server vcenter.dev.acme.com -User root -Password ******************* | |
# VM host we will create the VM on | |
$VS5_Host = "10.10.10.2" | |
# Name of VM we want to create | |
$vmName1 = "ZOL_CentOS" | |
# How many vCPUs in the VM | |
$vm_cpu = 2 | |
# How much RAM in the VM (in MB) | |
$vmRAM = 4096 | |
# The public network the VM will talk on | |
$public_network_name = "VMs" | |
# The datastore that the boot drive (EXT4) will reside on | |
$osstore = "RAID0" | |
# Size of the boot drive (in GB) | |
$osstore_size_GB = 8 | |
# The datastore that the 8 HDDS will be created in | |
$hddstore = "RAID0" | |
# Size of the HDDs (in GB) | |
$hddstore_size_GB = 10 | |
# The datastore that the 2 SSDs (for ZIL and L2ARC) will be created in | |
$ssdstore = "SSD" | |
# Size of the SSDs (in GB) | |
$ssdstore_size_GB = 8 | |
# NEEDS A CD AND AN ATTACHED ISO | |
# Don't edit below the line | |
#=============================================================================== | |
# Create the basic VM | |
$VM1 = new-vm ` | |
-Host "$VS5_Host" ` | |
-Name $vmName1 ` | |
-Datastore (get-datastore "$osstore") ` | |
-Location "ZOL" ` | |
-GuestID rhel6_64Guest ` | |
-MemoryMB $vmRAM ` | |
-DiskMB $osstore_size_MB ` | |
-NetworkName "$public_network_name" ` | |
-DiskStorageFormat "Thin" ` | |
-Version "v8" ` | |
-NumCpu $vm_cpu ` | |
-Confirm:$false | |
# Create first HDD on HBA #2 | |
$New_Disk1 = New-HardDisk -vm($VM1) -CapacityGB $hddstore_size_GB -StorageFormat Thin -datastore "$hddstore" | |
$New_SCSI_1_1 = $New_Disk1 | New-ScsiController -Type VirtualLsiLogicSAS -Confirm:$false | |
# Add 7 more HDDs on HBA #2 | |
foreach ($id in 1,2,3,4,5,6,8) { | |
$New_Disk1 = New-HardDisk -vm($VM1) -CapacityGB $hddstore_size_GB -StorageFormat Thin -datastore "$hddstore" | |
set-harddisk -Confirm:$false -harddisk $New_Disk1 -controller $New_SCSI_1_1 | |
} | |
# Create first SSD on HBA #3 | |
$New_Disk1 = New-HardDisk -vm($VM1) -CapacityGB $ssdstore_size_GB -StorageFormat Thin -datastore "$ssdstore" | |
$New_SCSI_1_1 = $New_Disk1 | New-ScsiController -Type VirtualLsiLogicSAS -Confirm:$false | |
# Add one more SSD on HBA #3 | |
$New_Disk1 = New-HardDisk -vm($VM1) -CapacityGB $ssdstore_size_GB -StorageFormat Thin -datastore "$ssdstore" | |
set-harddisk -Confirm:$false -harddisk $New_Disk1 -controller $New_SCSI_1_1 | |
# http://blogs.microsoft.co.il/scriptfanatic/2009/08/27/force-a-vm-to-enter-bios-setup-screen-on-next-reboot/ | |
filter Set-VMBIOSSetup | |
{ | |
param( | |
[switch]$Disable, | |
[switch]$PassThru | |
) | |
if($_ -is [VMware.VimAutomation.Types.VirtualMachine]) | |
{ | |
trap { throw $_ } | |
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions | |
$vmbo.EnterBIOSSetup = $true | |
if($Disable) | |
{ | |
$vmbo.EnterBIOSSetup = $false | |
} | |
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec | |
$vmcs.BootOptions = $vmbo | |
($_ | Get-View).ReconfigVM($vmcs) | |
if($PassThru) | |
{ | |
Get-VM $_ | |
} | |
} | |
else | |
{ | |
Write-Error "Wrong object type. Only virtual machine objects are allowed." | |
} | |
} | |
# Set VM to boot from BIOS on first boot so that we can disable the floppy/serial/parallel ports etc. | |
Get-VM $vmName1 | Set-VMBIOSSetup -PassThru | |
# Set any additional VM params that are useful | |
# Based on: https://github.com/rabbitofdeath/vm-powershell/blob/master/vsphere5_hardening.ps1 | |
$ExtraOptions = @{ | |
# Creates /dev/disk/by-id in Linux | |
"disk.EnableUUID"="true"; | |
# Disable virtual disk shrinking | |
"isolation.tools.diskShrink.disable"="true"; | |
"isolation.tools.diskWiper.disable"="true"; | |
# 5.0 Prevent device removal-connection-modification of devices | |
"isolation.tools.setOption.disable"="true"; | |
"isolation.device.connectable.disable"="true"; | |
"isolation.device.edit.disable"="true"; | |
# Disable copy/paste operations to/from VM | |
"isolation.tools.copy.disable"="true"; | |
"isolation.tools.paste.disable"="true"; | |
"isolation.tools.dnd.disable"="false"; | |
"isolation.tools.setGUIOptions.enable"="false"; | |
# Disable VMCI | |
"vmci0.unrestricted"="false"; | |
# Log Management | |
"tools.setInfo.sizeLimit"="1048576"; | |
"log.keepOld"="10"; | |
"log.rotateSize"="100000"; | |
# Limit console connections - choose how many consoles are allowed | |
#"RemoteDisplay.maxConnections"="1"; | |
"RemoteDisplay.maxConnections"="2"; | |
# 5.0 Disable serial port | |
"serial0.present"="false"; | |
# 5.0 Disable parallel port | |
"parallel0.present"="false"; | |
# 5.0 Disable USB | |
"usb.present"="false"; | |
# Disable VIX Messaging from VM | |
"isolation.tools.vixMessage.disable"="true"; # ESXi 5.x+ | |
"guest.command.enabled"="false"; # ESXi 4.x | |
# Disable logging | |
#"logging"="false"; | |
# 5.0 Disable HGFS file transfers [automated VMTools Upgrade] | |
"isolation.tools.hgfsServerSet.disable"="false"; | |
# Disable tools auto-install; must be manually initiated. | |
"isolation.tools.autoInstall.disable"="false"; | |
# 5.0 Disable VM Monitor Control - VM not aware of hypervisor | |
#"isolation.monitor.control.disable"="true"; | |
# 5.0 Do not send host information to guests | |
"tools.guestlib.enableHostInfo"="false"; | |
} | |
# build our configspec using the hashtable from above. | |
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec | |
# note we have to call the GetEnumerator before we can iterate through | |
Foreach ($Option in $ExtraOptions.GetEnumerator()) { | |
$OptionValue = New-Object VMware.Vim.optionvalue | |
$OptionValue.Key = $Option.Key | |
$OptionValue.Value = $Option.Value | |
$vmConfigSpec.extraconfig += $OptionValue | |
} | |
# Change our VM settings | |
$vmview=get-vm $vmName1 | get-view | |
$vmview.ReconfigVM_Task($vmConfigSpec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment