Enable CPU-Hot Plug and RAM-Hot Add at Virtual machines on VMware vCenter 5
Update 12.02.2013 / Gabrie post in the comments a important extra info about Hot-Add and post the link to the blog from Duncan Eppinghttp://www.yellow-bricks.com/2012/01/16/enabling-hot-add-by-default-cc-gabvirtualworld/ it’s important to read this!!!
vSphere Virtual Machine Administration, Chapter 8 “Configuring Virtual Machines”, Section “Change CPU Hot Plug Settings in the … Client”, page 94.
cpu-and-ram-hot-add
Some conditions and requirements for CPU Hot Plug

To enable new CPU after adding a new CPU. You can use this script:
Hot add cpu to supported Linux guestOS

#!/bin/bash
# William Lam
# http://engineering.ucsb.edu/~duonglt/vmware/
# hot-add cpu to LINUX system using vSphere ESX(i) 4.0
# 08/09/2009
for CPU in $(ls /sys/devices/system/cpu/ | grep cpu | grep -v idle)
do
CPU_DIR="/sys/devices/system/cpu/${CPU}"
echo "Found cpu: "${CPU_DIR}" ..."
CPU_STATE_FILE="${CPU_DIR}/online"
if [ -f "${CPU_STATE_FILE}" ]; then
STATE=$(cat "${CPU_STATE_FILE}" | grep 1)
if [ "${STATE}" == "1" ]; then
echo -e "t${CPU} already online"
else
echo -e "t${CPU} is new cpu, onlining cpu ..."
echo 1 > "${CPU_STATE_FILE}"
fi
else
echo -e "t${CPU} already configured prior to hot-add"
fi
done

Hot adding memory in Linux

ONLY for Suse Linux Enterprise Linux 11
Note: These instructions work for SLES OS. Other distributions may be different.
To enable acpi_memhotplug, run this command within the SLES virtual machine:

modprobe acpi_memhotplug

Using vSphere Client, edit the virtual machine settings to increase the memory assigned to the virtual machine. For more information, see Increasing the amount of memory assigned to a virtual machine (1004059).
Bring the memory online in /sys/devices/system/memory with the command:

echo online > /sys/devices/system/memory/memory[number]/state

Run this command to check the state of the memory, looking for memory that appears offline:

grep line /sys/devices/system/memory/*/state

If memory appears as offline, set it to online with the command:

echo online > /sys/devices/system/memory/memory[number]/state

Verify that you can see the extra memory with the command:

free -m

Expert Mode: PowerCLI

This Works when System is online, but need one “cold” start to enable this function.
Enable-MemHotAdd and Enable-vCpuHotAdd

Function Enable-MemHotAdd($vm){
$vmview = Get-vm $vm | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="mem.hotadd"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vmview.ReconfigVM($vmConfigSpec)
}
Function Enable-vCpuHotAdd($vm){
$vmview = Get-vm $vm | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="vcpu.hotadd"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vmview.ReconfigVM($vmConfigSpec)
}

 

Good information about hot-add cpu and memory can found here

 

2 Responses