2.4. CPU Hot-Plugging

With virtual machines running modern server operating systems, Oracle VM VirtualBox supports CPU hot-plugging.

On a physical computer CPU hot-plugging would mean that a CPU can be added or removed while the machine is running. Oracle VM VirtualBox supports adding and removing of virtual CPUs while a virtual machine is running.

CPU hot-plugging works only with guest operating systems that support the feature. So far this applies only to Linux and Windows Server. Windows supports only hot-add, while Linux supports hot-add and hot-remove. To use this feature with more than 8 CPUs, a 64-bit Linux guest is required.

CPU hot-plugging is done using the VBoxManage command-line interface. First, hot-plugging needs to be enabled for a virtual machine:

$ VBoxManage modifyvm VM-name --cpuhotplug on

The --cpus option is used to specify 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 VBoxManage modifyvm --plugcpu and VBoxManage modifyvm --unplugcpu commands, which take the number of the virtual CPU as a parameter, as follows:

$ 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 VBoxManage controlvm plugcpu and VBoxManage controlvm unplugcpu commands instead, as follows:

$ VBoxManage controlvm VM-name plugcpu 3
$ VBoxManage controlvm VM-name unplugcpu 3

See VBoxManage modifyvm and 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