I would recommend trying hot-plug instead of powering off, changing CPU and starting it again.
First, you need to mark it as cpu-hot-plug:
VBoxManage modifyvm "VM name" --cpuhotplug on
Second, set a maximum CPU count
VBoxManage modifyvm "VM name" --cpus 2
Third and last, add or remove the "extra" cpu:
VBoxManage modifyvm "VM name" --plugcpu 1
# DO STUFF with extra core
VBoxManage modifyvm "VM name" --unplugcpu 1
Make sure you have installed the Linux Guest Additions
or the Ubuntu box would not see the new CPU and could have some issues when unpluggin.
Alternatively, if you experience issues with hot-plugging, disable the feature, stop the VM, perform the CPU operation and start it again:
# Disable hot-plug if it does not work for you (only once)
VBoxManage modifyvm "VM name" --cpuhotplug off
VBoxManage controlvm "VM name" acpipowerbutton
VBoxManage modifyvm "VM name" --cpus 2
VBoxManage startvm "VM name"
# DO STUFF with extra core
VBoxManage controlvm "VM name" acpipowerbutton
VBoxManage modifyvm "VM name" --cpus 1
VBoxManage startvm "VM name"