With virtual machines running modern server operating systems, VirtualBox supports CPU hot-plugging.[41] Whereas on a physical computer this would mean that a CPU can be added or removed while the machine is running, VirtualBox supports adding and removing virtual CPUs while a virtual machine is running.
CPU hot-plugging works only with guest operating systems that support it. So far this applies only to Linux and Windows Server 2008 x64 Data Center Edition. Windows supports only hot-add while Linux supports hot-add and hot-remove but to use this feature with more than 8 CPUs a 64bit Linux guest is required.
At this time, CPU hot-plugging requires using the VBoxManage command-line interface. First, hot-plugging needs to be enabled for a virtual machine:
VBoxManage modifyvm "VM name" --cpuhotplug on
After that, the --cpus
option specifies the maximum number of CPUs
that the virtual machine can have:
VBoxManage modifyvm "VM name" --cpus 8
When
the VM is off, you can then add and remove virtual CPUs with the
modifyvm --plugcpu
and
--unplugcpu
subcommands, which take the number of the
virtual CPU as a parameter, like this:
VBoxManage modifyvm "VM name" --plugcpu 3 VBoxManage modifyvm "VM name" --unplugcpu 3
Note that CPU 0 can never be removed.
While the VM is running, CPUs can be added and removed with the
controlvm plugcpu
and
unplugcpu
commands
instead:
VBoxManage controlvm "VM name" plugcpu 3 VBoxManage controlvm "VM name" unplugcpu 3
See Section 8.8, “VBoxManage modifyvm” and Section 8.13, “VBoxManage controlvm” for details.
With Linux guests, the following applies: To prevent ejection while the CPU is still used it has to be ejected from within the guest before. The Linux Guest Additions contain a service which receives hot-remove events and ejects the CPU. Also, after a CPU is added to the VM it is not automatically used by Linux. The Linux Guest Additions service will take care of that if installed. If not a CPU can be started with the following command:
echo 1 > /sys/devices/system/cpu/cpu<id>/online
[41] Support for CPU hot-plugging was introduced with VirtualBox 3.2.