Tag Archives: ESXi

vCenter VM reboot script

Once in a while I run into problems that are really fun resolving. A colleague  of mine said that he was early today to fix the XenApp servers that did not reboot successfully. He said that since the storage of the Citrix Provisioning server was moved from flash to SAS the XenApp servers sometimes cannot boot. A shortage in IOPS is supposed to be the cause of this trouble. However all Provisioning servers combined consume over a TeraByte of storage. During the day this fast storage does not is nearly idle. Only during boot of the XenApp machines it is used in an appropriate manner. So that is quite costly.

VMWare created CMDlet’s the right way. You can basically do anything you can in GUI via Powershell using the PowerCLI.  The PowerCLI is an incredible tool in automatising stuff. We have RES Automation Manager. So I put the bits together and created A Powershell script in RES Automation Manager that runs every night. This script uses a few parameters which you can see in the code in the top section of the script. The script heavily relies on PowerCLI 6.0 This version works for any vCenter server.

The script connects to a VIserver (in this case the vCenter server). Next it gathers a list of all servers. Then it filters server based on the condition if it is PoweredOn and it matches on Name. Next it gets the VMware Tools status. If the status is NotRunning it will be applicable for a restart. The servers will be rebooted in a staggered way. So every two minutes a server will reboot. There’ll be a second attempt if the first attempt fails. At last it sends an e-mail with all server that fit the condition the first time, the second time and server that did not rebooted well.

I hope you can use it.

# Adds the base cmdlets
Add-PSSnapin VMware.VimAutomation.Core
$Recipients = $[Recipients]
$VIServer = "$[VIServer]"
$NotCondition = "$[NotCondition]"
$Condition = "$[Condition]"
$Username = [Environment]::UserName
$Hostname = $env:COMPUTERNAME
$Mailserver = "$[MailServer]"
$Level = "0"
Connect-VIServer $VIServer

#List bouwen van VM's die voldoen aan de voorwaarden
$List =@(Get-VM | ? {$_.Name -match $Condition -and $_.PowerState -match "PoweredOn" -and $_.Name -notmatch $NotCondition} | Get-VMGuest | ? {$_.State -match "NotRunning"})

#Check of de PowerCLi wel geinstalleerd is
If (((Get-PSSnapin).name -match "VMware.VimAutomation") -eq $Null){$Body = "De computer $Hostname heeft geen PowerCLI geinstalleerd staan. Installeer PowerCLI en probeer het opnieuw "; $Level = "1"}

#Check of er een verbinding is met de VI server
If ($global:DefaultVIServer -eq $null -and $Level -ne "1"){$Body = "Kon geen verbinding krijgen met de VCenter Server: $VIServer. Verander de waarde in het script als de servernaam veranderd is. Controleer of de user $UserName rechten heeft op de VCenter server. Controleer eventueel of de PowerCLI tools op de server wel compatible zijn met de Vcenter Server versie." ; $Level = "2"}

#Geen servers gevonden
If ($list.count -eq "0" -and $Level -eq "0"){$Body = "Er zijn geen server(s) gevonden welke voldoen aan de voorwaarden."}

#Actie bij wel servers gevonden
If ($list.count -gt "0" -and $Level -eq "0"){
$Body = "Er waren "+ $list.count +" server(s) die voldeden aan de voorwaarden. Het gaat om de server(s):`n`n"
$Body = "Er worden "+ $list.count +"servers herstart. De servers zijn:`n`n"
Foreach ($item in $list){$Body = $Body + $Item.vm + "`r"}

#Herstarten van servers
Foreach ($item in $list){Restart-VM -VM $Item.VM -Confirm:$False ; Start-Sleep -s 120}

#Check of er nu geen servers meer zijn die voldoen aan de voorwaarden
$List2 =@(Get-VM | ? {$_.Name -match $Condition -and $_.PowerState -match "PoweredOn" -and $_.Name -notmatch $NotCondition} | Get-VMGuest | ? {$_.State -match "NotRunning"})

#Actie bij wel servers gevonden die nog niet goed herstart zijn
If ($List2.Count -ne "0"){
$Body = $Body + "`n`n Er waren server die nog steeds niet goed herstart waren. De naam van deze server(s) waren:`n`n"
Foreach ($item2 in $list2){$Body = $Body + $Item2.vm + "`r"}
$Body = $Body + "`n`n Er worden geprobeerd de server opnieuw te herstarten."
Foreach ($item2 in $list2){Restart-VM -VM $Item2.VM -Confirm:$False ; Start-Sleep -s 120}
#Laatste check
$List3 =@(Get-VM | ? {$_.Name -match $Condition -and $_.PowerState -match "PoweredOn" -and $_.Name -notmatch $NotCondition} | Get-VMGuest | ? {$_.State -match "NotRunning"})
If ($List3.Count -ne "0"){
$Body = "Er zijn fouten gevonden bij het herstarten van servers. Zie onderaan de e-mail!!" + $Body
$Body = $Body + "`n`n De server die niet herstart zijn na twee pogingen zijn:`n`n"
Foreach ($item3 in $list3){$Body = $Body + $Item3.vm + "`r"}
}}}

#Mail versturen
Send-MailMessage -From "Rebootscript@domain.tld" -Subject "VMs rebooten" -To $Recipients -Body $Body -SmtpServer $MailServer

#Output naar Console in het geval dat er geen mail verstuurd is.
Write-host `n`n Mail Body`n
$Body

Set time om ESXi host in Command Line

As you will probably know, ESXi does not support Time Zones for whatever reasons. Sometimes however Windows takes over the system time of de ESXi host. If you configured NTP services well enough this shouldn’t cause any problems. If you didn’t you need to configure the time manually. You can of course also need this for just checking of the time is right.

Check the time:

esxcli system time get

Set the time:

esxcli system time set -d 28 -M 4 -y 2014 -H 10 -m 0 -s 0

Please bare in mind that ESXi does not support timezones so you should configure the time for the timezone for UTC. Also keep in mind that if you configured ESXi to check the NTP from now and then that the time will be off again. The best thing to do is to configure the NTP infrastructure in Windows.

Recently i extended my RAID 5 array by replacing one-by-one hdd’s with bigger ones and waiting for each to rebuild.

All the instructions are executed on a HP DL360 G6 with an SmartArray P410i controller with only one logicaldisk.

It is highly recommended that you backup all your VM’s before executing a single command – everything worked fine for me but one error in a command could leas to a complete data loss of everything!

To see the rebuilding status, HP has a tool called hpacucli which allows you to control the array and see the status of it out of the ESXi console.

First you have to install HP’s ESXi5 Offline Utilities right from here

Upload it to your datastore, login to your ESXi5 server and execute

esxcli software vib install -d/path/to/hp-HPUtil-esxi5.0-bundle-1.1-38.zip

Now you can see the array rebuild with

/opt/hp/hpacucli/bin/hpacucli controller slot=0 show config

** Warning: Add a new hard disk ONLY if ALL harddisks show “OK” **
After adding all the disks without destroying the array you can now see unused space here:

/opt/hp/hpacucli/bin/hpacucli controller slot=0 array all show detail

Now let’s extend the array to use up the new space:

/opt/hp/hpacucli/bin/hpacucli controller slot=0 logicaldrive 1 modify size=max

A second call to show detail of the array should show you that the unused space is again zero, now your logicaldrive is successfully extended!

/opt/hp/hpacucli/bin/hpacucli controller slot=0 array all show detail

Now on to the datastore part. Unfortunatly it is not possible to extend or expand the datastore from within the GUI because the “VMWare extend” is for adding several sources of Partitions, NFS mounts etc. to one “big” datastore and not expanding the partition to fill up the new space we won.

First we need to find what disk we are using, as i’m have only one logical disk, this is easy for me, be sure to select the correct disk from: /vmfs/devices/disks/

let have a look at the partitioning table:

partedUtil getptbl /vmfs/devices/disks/vml.0200010000600508b1001c504c1f73b6b6947016164c4f47494341

gpt
109406 255 63 1757614684
1 64 8191 C12A7328F81F11D2BA4B00A0C93EC93B systemPartition 128
5 8224 520191 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0
6 520224 1032191 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0
7 1032224 1257471 9D27538040AD11DBBF97000C2911D1B8 vmkDiagnostic 0
8 1257504 1843199 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0
2 1843200 10229759 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0
3 10229760 860050190 AA31E02A400F11DB9590000C2911D1B8 vmfs 0

The last line is the one we are intrested in, the VMFS partition. For me it is the Partition number 3 with start-sector at 10229760 and end-sector at 860050190.

We now need to know the last sector of the Harddisk we could use up, give that a shot:

partedUtil getUsableSectors /vmfs/devices/disks/vm.0200010000600508b1001c504c1f73b6b6947016164c4f47494341

This is what i get back: 1757614650

Now i can go and extend the partition where my datastore lives in:

partedUtil resize “/vmfs/devices/disks/vml.0200010000600508b1001c504c1f73b6b6947016164c4f47494341″ 3 10229760 1757614650

Note the last 3 arguments: Partition 3, start-sector and new last-sector

After that has been done without output we will stright go and expand the Filesystem of our VMFS partition to fill it up:

vmkfstools –growfs /vmfs/devices/disks/vml.0200010000600508b1001c504c1f73b6b6947016164c4f47494341:3 /vmfs/devices/disks/vml.0200010000600508b1001c504c1f73b6b6947016164c4f47494341:3

Again, note the :3 at the end..

http://devbios.wordpress.com/2012/04/21/esxi-5-expanding-datastore-by-extending-local-array/

VM network aanmaken

VM Network aanmaken op een vCenter kan erg tijdbesparend zijn. Met 1 simpel commando is het mogelijk een port group aan te maken op alle host in het vCenter:

get-vmhost | Get-VirtualSwitch -Name vSwitch0 | New-VirtualPortGroup -Name Solis-Heartbeat -VLANID 788

Let op hiervoor is PowerClI nodig van VMware

Update VMware ESXi 4.1 manually

Het handmatig updaten van VMware ESXi 4.1 gaat anders dan het handmatig bijwerken van VMware ESX 3.5. Servers die bijvoorbeeld stand-alone inricht zijn moeten handmatig bijgewerkt worden.

Zet via de VIC de server in Maintenance mode. Ga naar de site van patch site van VMware. Download het ZIP bestand en pak deze uit voordat je de update kopieert naar de ESXi 4.0 server.

De .vib bestanden worden als bundel gezien. Deze bundels kunnen worden geupload door een programme die het SCP (Secure Copy) protocol ondersteund. Een voorbeeld is WinSCP. Verbind met de ESXi server en load de bestanden up.

Verbind met de ESXi 4.1 server met Putty. Ga naar de directory waar je net de vib bestanden heb geupload door het

cd

commando. Voorbeeld

cd /vmfs/volumes/Datastore1/Updates

Voer het commando

esxupdate -b vmware-esx-firmware-4.1.0-1.6.381591.i386.vib update

Hierbij is het schuin gedrukte gedeelte variable aan de naam van de vib.

Exit Maintenance mode en herstart de server. Hierna kan in de VIC het build niveau gezien worden of door in SSH het commando

vmware -v

uit te voeren.

Update VMware ESXi 5.0 manually

Voor VMware ESXi 5.0 komen regelmatig updates uit. Deze zijn te vinden op de website: www.vmware.com/patch/download. De installatie van VMware updates voor ESXi 5.0 stand-alone gaat anders dan die van ESXi 4.1. VMware wil eigenlijk dat een ESXi server verbonden wordt met een vCenter Server. Middels vCenter kan een ESXi server geupdate worden. Helaas wordt er regelmatig gebruik gemaakt van Stand-alone server. Hierdoor kan er geen gebruik gemaakt worden van de update feature van vCenter server. In dit document kort uitgelegd wat er moet gebeuren om een ESXi 5.0 server te voorzien van updates.  Continue reading “Update VMware ESXi 5.0 manually” »