vSphere 4.1 Update 1 Coming Real Soon!

With a lot of bug fixes and updates I can not wait.  Should be released hopefully sometime next week.

Quick Guide To Transferring Hosts & VM From One vCenter To Another

 

These are some quick instructions we put together for moving machines between Virtual Centers.  There is an assumption that you have multiple vmkernels (ESXi) and that you are using dvs switching and all dvs switches are setup beforehand.

1.     Turn off HA/DRS

2.     Record VMotion IP of host

3.     Migrate VM to host you will work on

a.     Ensure all VM are on the same VLAN

4.     Record which portgroup the vmotion enable vmkernel is on.

5.     Disconnect host

6.     Add host to new vCenter

7.     Add Offnetwork dVS to host

 a. Import vMotion vmKernel into the correct port group on the new DVS switch.

8.     Add VM dVS to host

 a.     Assign the VM on this host to the appropriate port group at same time

9.     Run script to relocate VM to appropriate folder

10.    Run script to add VM annotations

11.    Run script to add Host annotations

12.    Manually add VMotion to host

Once you have 2 hosts, you then need to put 1st host into MM so you can apply host profiles to other hosts.

TImesync Script Version 1

This was written for prior to 4.1.

#################################################################################################
# Title:	vmTools TimeSyc Script
# Filename:	vmtoolstimesync.ps1
# Created by:	Douglas Smith
# Date:		4/6/2010
# Version:    	0.1
# Description:	This script will list all VMs that do not have timesync enabled, You have the 
#		option of viewing on the screen or emailing the report, doing all servers or a 
#		specific one, and the ability to enable timesync on the client.
#################################################################################################
#### Pass through paramaeters
param(
[String]$vcserver
)
#### Detail Settings
#### Other Variables $EmailTo = "doug@local.com"
$EmailReportFrom = "vSphere-PowerShell@local.com"
$EmailServer = "mail.local.com"
#### Functions
function GUIprompt {
[hashtable]$answers = @{}
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
# defining $cancel, otherwise the program just exits.
$cancel = $False
# creates a form for input via a window
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "vSphere Information Prompt"
$objForm.Size = New-Object System.Drawing.Size(290,365) # overall size
$objForm.StartPosition = "CenterScreen"
# Textbox for server name
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,20)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
# Textbox for username
$objTextBoxUserName = New-Object System.Windows.Forms.TextBox
$objTextBoxUserName.Location = New-Object System.Drawing.Size(10,60)
$objTextBoxUserName.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBoxUserName)
# Textbox for password
$objTextBoxUserPassword = New-Object System.Windows.Forms.TextBox
$objTextBoxUserPassword.Location = New-Object System.Drawing.Size(10,100)
$objTextBoxUserPassword.Size = New-Object System.Drawing.Size(260,20)
$objTextBoxUserPassword.PasswordChar = 'ï'
$objForm.Controls.Add($objTextBoxUserPassword)
# Checkbox for Report or Fix
$objCheckBox1 = New-Object System.Windows.Forms.CheckBox
$objCheckBox1.Location = New-Object System.Drawing.Size(10,140)
$objCheckBox1.Size = New-Object System.Drawing.Size(110,20)
$objCheckBox1.Text = "Enable Timesync"
$objForm.Controls.Add($objCheckBox1)
# Textbox for email
$objTextBoxEmail = New-Object System.Windows.Forms.TextBox
$objTextBoxEmail.Location = New-Object System.Drawing.Size(10,260)
$objTextBoxEmail.Size = New-Object System.Drawing.Size(260,20)
$objTextBoxEmail.Visible = $False
$objForm.Controls.Add($objTextBoxEmail)
# Checkbox for email report
$objCheckBox3 = New-Object System.Windows.Forms.CheckBox
$objCheckBox3.Location = New-Object System.Drawing.Size(10,220)
$objCheckBox3.Size = New-Object System.Drawing.Size(110,20)
$objCheckBox3.Text = "Email Report"
$objCheckBox3.Add_checkedChanged({if ($objCheckBox3.checked) {$objTextBoxEmail.Visible = $True; $objLabelEmail.Visible = $True} Else {$objTextBoxEmail.Visible = $False; $objLabelEmail.Visible = $False}})
$objForm.Controls.Add($objCheckBox3)
# Textbox for virtual servername
$objTextBoxvm = New-Object System.Windows.Forms.TextBox
$objTextBoxvm.Location = New-Object System.Drawing.Size(10,180)
$objTextBoxvm.Size = New-Object System.Drawing.Size(260,20)
$objTextBoxvm.Visible = $False
$objForm.Controls.Add($objTextBoxvm)
# Textbox for Single Server or All
$objCheckBox2 = New-Object System.Windows.Forms.CheckBox
$objCheckBox2.Location = New-Object System.Drawing.Size(130,140)
$objCheckBox2.Text = "Single Server"
$objCheckBox2.Add_checkedChanged({if ($objCheckBox2.checked) {$objTextBoxvm.Visible = $True; $objLabelvm.Visible = $True} Else {$objTextBoxvm.Visible = $False; $objLabelvm.Visible = $False}})
$objForm.Controls.Add($objCheckBox2)
# add keystroke options. Pressing "Enter" is the same as clicking "OK, "Esc" is the same as "Cancel"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$Server=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$cancel = $True;$objForm.Close()}})
# Draw 'OK' button and sets button action.
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(60,300)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({
$answers.server=$objTextBox.Text
$answers.user=$objTextBoxUserName.Text
$answers.password=$objTextBoxUserPassword.Text
$answers.Enablets=$objCheckBox1.checked
$answers.EnableSingle=$objCheckBox2.checked
$answers.SingleServer=$objTextBoxvm.Text
$answers.EmailReport=$objCheckBox3.checked
$answers.EmailAddress=$objTextBoxEmail.Text
$objForm.Close()})
$objForm.Controls.Add($OKButton)
# Draw 'Cancel' button and sets button action.
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(135,300)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$cancel = $True;$objForm.Close()})
$objForm.Controls.Add($CancelButton)
# Adding labels for text boxes.
# Label for server name prompt
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,5)
$objLabel.Size = New-Object System.Drawing.Size(240,40)
$objLabel.Text = "Enter Server name of vSphere:"
$objForm.Controls.Add($objLabel)
# Label for username prompt
$objLabelUserName = New-Object System.Windows.Forms.Label
$objLabelUserName.Location = New-Object System.Drawing.Size(10,45)
$objLabelUserName.Size = New-Object System.Drawing.Size(240,40)
$objLabelUserName.Text = "Enter the vSphere Username:"
$objForm.Controls.Add($objLabelUserName)
# Label for password prompt
$objLabelPassword = New-Object System.Windows.Forms.Label
$objLabelPassword.Location = New-Object System.Drawing.Size(10,85)
$objLabelPassword.Size = New-Object System.Drawing.Size(240,40)
$objLabelPassword.Text = "Enter the vSphere Password:"
$objForm.Controls.Add($objLabelPassword)
# Label for email prompt
$objLabelEmail = New-Object System.Windows.Forms.Label
$objLabelEmail.Location = New-Object System.Drawing.Size(10,245)
$objLabelEmail.Size = New-Object System.Drawing.Size(240,40)
$objLabelEmail.Text = "Enter your Email Address:"
$objLabelEmail.Visible = $False
$objForm.Controls.Add($objLabelEmail)
# Label for Virtual Machine
$objLabelvm = New-Object System.Windows.Forms.Label
$objLabelvm.Location = New-Object System.Drawing.Size(10,165)
$objLabelvm.Size = New-Object System.Drawing.Size(240,40)
$objLabelvm.Text = "Enter the virtual server name:"
$objLabelvm.Visible = $False
$objForm.Controls.Add($objLabelvm)
# Puts the form on top of all other windows.
$objForm.Topmost = $True
# Activates/draws the form.
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
return $answers
}
Function Enable-VMTimeSync {
Begin {
$spec = new-object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.syncTimeWithHost = $true
}
Process {
$_.ReconfigVM_Task($spec)
}
}
#### Begin Script
#### Validate Input Variables
If ($vcserver -eq "") {
[hashtable]$info = @{}
$info = GUIprompt
$vcserver = $info.server
}
If ($info.server -eq "") {
$wscript = new-object -comobject wscript.shell
$msgbox = $wscript.popup("You MUST enter the name or IP of your vSphere server",0,"Access Denied",1)
exit
}
If ($info.EnableTS) {
If (!$info.user.ToLower().EndsWith("ad")) {
$wscript = new-object -comobject wscript.shell
$msgbox = $wscript.popup("You need admin privledges to complete this function",0,"Access Denied",1)
exit
}
}
If ($info.EmailReport) {
If (!$info.EmailAddress.ToLower().Contains("@local.com")) {
$wscript = new-object -comobject wscript.shell
$msgbox = $wscript.popup("You MUST enter a valid SMTP address",0,"Access Denied",1)
exit
}
}
#### Check if Snapin loaded, if not load
if ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
{Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue}
#### Connect to vCenter
If ($info.user -eq "") {
$VIServer = connect-VIServer $vcserver
}
Else {
$VIServer = connect-VIServer $vcserver -user $info.user -Password $info.password
}
#### Get A list of Objects that meet the criteria
$VMs = get-vm | where-object {$_.powerstate -eq "PoweredOn"}
If ($info.EnableSingle) {$VMs = $VMs | where-object {$_.Name -eq $info.SingleServer}}
$VMs = $VMs | get-view | where-object {$_.config.tools.SyncTimeWithHost -eq $False}
$VMs = $VMs | sort-object Name
If ($info.EnableTS) {
$VMs = $VMs | where-object {$_.name -notlike "*vpopnet*"}
$VMs | Enable-VMTimeSync
}
If ($info.EmailReport) {
$SendEmail = $mailer = new-object Net.Mail.SMTPclient($EmailServer)
$message = new-object Net.Mail.MailMessage
$message.From = $EmailReportFrom
$message.To.add($info.EmailAddress)
$message.Subject = 'Virtual Machine TimeSync Report for ' + (Get-Date)
$message.body = $VMs | Select Name | ConvertTo-Html
$message.IsBodyHTML = $true
$mailer.send($message)
} Else {$VMs | Select Name}
#Disconnect from vCenter Server
$VIServer | Disconnect-VIServer -Confirm:$false

 

Manually Removing A Host From Inventory

I recently had an issue where a machine had died and  could not remove if from inventory, after the typcial troubleshooting and reboots.  I finally decided to work with support I got this piece of information.

WARNING: Only do this as an absolute last resort and backup your database before starting.  This procedure should only be used as a last resort where all other attempts to remove an ESX host from the vCenter Inventory fail.

1. Stop the VMware VirtualCenter service on the vCenter Server.

2. Identify the ESX host ID in the vCenter database with the command:

select ID from VPX_ENTITY where name ='esx01.local.com';

Note: As an example in this article, the ESX host being removed is esx01.local.com. This host returns a host ID of 24699 when the select statement above is executed.

3. Execute the following SQL statements to remove the ESX host from the vCenter database.

Remove all the datastore assignments for virtual machines which exist on this ESX host with the statement:

delete from vpx_ds_assignment where entity_id in (select id from vpx_vm where host_id = 24699);

Remove all the network assignments virtual machines which exist on this ESX host with the statement:

delete from vpx_nw_assignment where entity_id in (select id from vpx_vm where host_id = 24699);

List the virtual machines in the virtual machine table which exist on this ESX host with the statement:

select id from vpx_vm where host_id = 24699

Note: Make a note of any virtual machine IDs returned. In this example, the values returned are 26149, 26215, 26217, 26219, 95343.

Delete virtual machines which exist on this ESX from the virtual machine table with the statement:

delete from vpx_vm where host_id = 24699;

Delete virtual machines which exist on this ESX host from the entity table with the statement:

delete from vpx_entity where id in (26149,26215,26217,26219,95343);

Delete the ESX host from the host table with the statement:

delete from vpx_host where id = 24699;

Delete the ESX host from the entity table with the statement:

delete from vpx_entity where id = 24699;

Remove all relations to this ESX host from the entity table with the statement:

delete from vpx_entity where parent_id = 24699;
delete from vpx_entity where id = 24699;

4. Start the VMware VirtualCenter Server service on the vCenter server to pick up the database changes.

VMware vSphere 4.1 Scripted Installation Procedure

Prerequisites

Prior to the installation the following environment is required to successfully create and configure the boot disk.

  • A standard Linux distribution like Red Hat and Linux.
  • The most current ESXi 4.1 media
  • A functional ESXi 4.1 operating system.  This is required to obtain a file necessary for extracting the compressed files within the ESXi ISO image.

Kickstart Script Creation

Each ESXi host server will contain an individual configuration file containing the very basic and minimal server settings required for network connectivity.  The remainder of the configuration settings will take place with the Host Profiles feature within vCenter.

infoimage

Copy Kickstart Files to Media

This procedure contains the required steps to create a custom ESXi boot disk.

1. Mount the ESXi ISO to Linux

2. Within the bash shell perform the following:

# cd /home/<user>
# mkdir iso-mount kickstart iso-new

3. Copy all files from ESXi CD to /home/<user>/iso and /home/<user>/iso-new

4. Obtain vmtar from the running ESXi 4.1 operating system.  The file resides in /usr/sbin folder

5. Place vmtar in /usr/sbin within the Linux operating system.

6. Move ienviron.vgz from /home/<user>/iso-new to /home/<user>/kickstart

# mv /home/<user>/iso/ienviron.vgz /home/<user>/kickstart/ienviron.vgz

7. Navigate to /home/<user>/kickstart and extract ienviron.vgz

# cd /home/<user>/kickstart
# vmtar –x ienviron.vgz –o ienviron.tgz

8. Extract the ienviron.tgz in its current location and remove it.

# tar xvzf ienviron.tgz
# rm ienviron*

9. Copy the modified kickstart files within the weasel folder

# cp /<location of kickstart files>/* /home/<user>/kickstart/etc/vmware/weasel/

10. Create a new tarball with the additional kickstart files.

# tar zvcf ienviron.tgz etc/ lib/ sbin/ usr/

11. Copy the new file to the iso-new location.

# cp /home/<user>/kickstart/ienviron.tgz /home/<user>/iso-new/

Modify the Boot Menu

The following procedures will add the servernames to the boot menu during the installation.  Follow the procedures below to modify the default boot menu.

1. Navigate to /home/<user>/iso
2. Edit ISOLINUX.CFG
3. Add the following lines per server (4 lines each) after the first entry (ESXi Installer):

label <servername>

menu label ^<servername>

kernel mboot.c32

append vmkboot.gz ks=file://etc/vmware/weasel/<servername>.cfg — vmkernel.gz — sys.vgz — cim.vgz — ienviron.tgz — install.vgz

 

Create the New ISO

1. Create a new ISO from the iso-new/ folder

# cd /home/<user>/iso-new
# mkisofs –o ../My_VMvisor_xxx.iso –b isolinux.bin –c boot.cat –no-emul-boot –boot-load-size 4 –boot-info-table .

2. Copy the ISO to the host system.
3. Mount the ISO to a physical server or burn the disk image.
4. Boot the ISO

Test the new ISO

1. Mount the ISO (or burn) to the target ESXi host
2. When the boot menu is loaded, press the tab key.
3. On the command line add the following syntax after the vmkboot.gz entry.

ks=file://etc/vmware/weasel/<filename>.cfg

4. On the same command line, modify the following string:

ienviron.vgz   >>to>>  ienviron.tgz

The entire command syntax should look similar to the following:

vmkboot.gz — vmkernel.gz ks=file://etc/vmware/weasel/det01xxbpvesx301.cfg — sys.vgz — cim.vgz — ienviron.tgz — install.vgz

 

5. Press enter and wait until operating system loads.  Any errors from the kickstart file will be displayed with the line number to be fixed.