Situation:
I’ve come across a situation where I needed to LIVE-raise the number of CPUs for a VMWAre Linux VM without having to reboot.
Solution:
– In VMAre ris the number of CPUs
– In the Linux VM do the following:
– Save the following script into /root/bin/ directory
(It was take from this article: https://communities.vmware.com/docs/DOC-10493)
OR
mkdir -p /root/bin
cd /root/bin
wget https://communities.vmware.com/servlet/JiveServlet/download/10493-2-26560/online_hotplug_cpu.sh
Content of script:
#!/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
– Make the script runnable
chmod 755 online_hotplug_cpu.sh
– Run the script
/root/bin/online_hotplug_cpu.sh
Check the number of CPUs:
cat /proc/cpuinfo | grep ‘processor’
eg.
processor : 0
processor : 1
processor : 2
processor : 3