Created
March 12, 2020 07:50
-
-
Save nguyenvanhaivn/b895c5a3eedb1a009d69cd58ad714943 to your computer and use it in GitHub Desktop.
Change the CPU brand on virtualbox and vmware, generating commands for Virtualbox and configuration for VMWare.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment