Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change the CPU brand on virtualbox and vmware, generating commands for Virtualbox and configuration for VMWare.
#!/bin/bash
#
# change variable vm (only virtualbox) and brand for your use
#
vm='VM' # UUID works as well, only for virtualbox
# The brand string needs to have 47 characters!
# The null terminator is added automatically
brand=' Intel(R) Pentium(R) 4 CPU 1500MHz'
if [ ${#brand} -ne 47 ]; then
exit 1
fi
ascii2hex() { echo -n 0x; od -A n --endian little -t x4 | sed 's/ //g'; }
ascii2bin() {
HEX=$(od -A n --endian little -t x4 | sed 's/ //g' | tr 'a-f' 'A-F')
echo "obase=2; ibase=16; $HEX" | BC_LINE_LENGTH=9999 bc | awk '{
s="00000000000000000000000000000000"$0;
t = substr( s, length(s) - 31, length(s));
gsub(/..../,"&:",t);
printf("%s",substr(t, 1, length(t)-1));
}'
}
echo "For Virtualbox exec the command:"
echo
eax_values=(80000002 80000003 80000004)
registers=(eax ebx ecx edx)
for (( i=0; i<${#brand}; i+=4 )); do
eax=${eax_values[$((${i} / 4 / 4))]}
register=${registers[$((${i} / 4 % 4 ))]}
key=VBoxInternal/CPUM/HostCPUID/${eax}/${register}
value=`echo -n "${brand:$i:4}" | ascii2hex`
# set value to an empty string to reset the CPUID, i.e.
# value=""
echo vboxmanage setextradata "$vm" $key $value
# vboxmanage setextradata "$vm" $key $value
done
echo "============================================="
echo "For VMWare to add vmx file:"
echo
echo "monitor_control.enable_fullcpuid = \"TRUE\""
eax_values=(80000002 80000003 80000004)
registers=(eax ebx ecx edx)
for (( i=0; i<${#brand}; i+=4 )); do
eax=${eax_values[$((${i} / 4 / 4))]}
register=${registers[$((${i} / 4 % 4 ))]}
key="cpuid.${eax}.0.${register} ="
value=`echo -n "${brand:$i:4}" | ascii2bin`
# set value to an empty string to reset the CPUID, i.e.
# value=""
echo $key "\""$value"\""
done
@etmatrix

This comment has been minimized.

Copy link
Owner Author

@etmatrix etmatrix commented Dec 22, 2018

The source of this script is here https://superuser.com/questions/625648/virtualbox-how-to-force-a-specific-cpu-to-the-guest, I correct a little bug and developed the generation for vmware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment