#!/bin/bash # www.doomedraven.com/2016/05/kvm.html # strs[0] = "KVMKVMKVM\0\0\0"; /* KVM */ # strs[1] = "Microsoft Hv"; /* Microsoft Hyper-V or Windows Virtual PC */ # strs[2] = "VMwareVMware"; /* VMware */ # strs[3] = "XenVMMXenVMM"; /* Xen */ # strs[4] = "prl hyperv "; /* Parallels */ # strs[5] = "VBoxVBoxVBox"; /* VirtualBox */ function usage() { echo 'Usage: $0 ' echo echo 'Func:' echo ' All' echo ' KVM' echo ' QEMU' echo ' SeaBios' exit } function install_kvm() { # already done? echo "" } function qemu_func() { #Download code echo '[+] Downloading QEMU source code' curl https://dl.fedoraproject.org/pub/epel/7/SRPMS/Packages/q/qemu-2.0.0-1.el7.6.src.rpm > qemu-2.0.0-1.el7.6.src.rpm fail=0 if [ $? -eq 0 ]; then rm -rf ~/rpmbuild/BUILD/* rpm -vhi ./qemu-2.0*.src.rpm >/dev/null rpmbuild -bp ~/rpmbuild/SPECS/qemu.spec echo '[+] Patching QEMU clues' sed -i 's/QEMU HARDDISK/WDC WD20EARS/g' ~/rpmbuild/BUILD/qemu*/hw/ide/core.c if [ $? -ne 0 ]; then echo 'QEMU HARDDISK was not replaced in core.c' fail=1 fi sed -i 's/QEMU HARDDISK/WDC WD20EARS/g' ~/rpmbuild/BUILD/qemu*/hw/scsi/scsi-disk.c if [ $? -ne 0 ]; then echo 'QEMU HARDDISK was not replaced in scsi-disk.c' fail=1 fi sed -i 's/QEMU DVD-ROM/ DVD-ROM/g' ~/rpmbuild/BUILD/qemu*/hw/ide/core.c if [ $? -ne 0 ]; then echo 'QEMU DVD-ROM was not replaced in core.c' fail=1 fi sed -i 's/QEMU DVD-ROM/ DVD-ROM/g' ~/rpmbuild/BUILD/qemu*/hw/ide/atapi.c if [ $? -ne 0 ]; then echo 'QEMU DVD-ROM was not replaced in atapi.c' fail=1 fi sed -i 's/s->vendor = g_strdup("QEMU");/s->vendor = g_strdup("");/g' ~/rpmbuild/BUILD/qemu*/hw/scsi/scsi-disk.c if [ $? -ne 0 ]; then echo 'Vendor string was not replaced in scsi-disk.c' fail=1 fi sed -i 's/QEMU CD-ROM/ CD-ROM/g' ~/rpmbuild/BUILD/qemu*/hw/scsi/scsi-disk.c if [ $? -ne 0 ]; then echo 'QEMU CD-ROM was not patched in scsi-disk.c' fail=1 fi sed -i 's/padstr8(buf + 8, 8, "QEMU");/padstr8(buf + 8, 8, "");/g' ~/rpmbuild/BUILD/qemu*/hw/ide/atapi.c if [ $? -ne 0 ]; then echo 'padstr was not replaced in atapi.c' fail=1 fi sed -i 's/QEMU MICRODRIVE/ MICRODRIVE/g' ~/rpmbuild/BUILD/qemu*/hw/ide/core.c if [ $? -ne 0 ]; then echo 'QEMU MICRODRIVE was not replaced in core.c' fail=1 fi sed -i 's/KVMKVMKVM\\0\\0\\0/GenuineIntel/g' ~/rpmbuild/BUILD/qemu*/target-i386/kvm.c if [ $? -ne 0 ]; then echo 'KVMKVMKVM was not replaced in kvm.c' fail=1 fi sed -i 's/Microsoft Hv/GenuineIntel/g' ~/rpmbuild/BUILD/qemu*/target-i386/kvm.c if [ $? -ne 0 ]; then echo 'Microsoft Hv was not replaced in kvm.c' fail=1 fi sed -i 's/BOCHS /HAWKM /g' ~/rpmbuild/BUILD/qemu*/hw/i386/acpi-build.c if [ $? -ne 0 ]; then echo 'BOCHS was not replaced in acpi-build.c' fail=1 fi sed -i 's/bochs dispi interface/hawkm dispi interface/g' ~/rpmbuild/BUILD/qemu*/hw/display/vga-pci.c if [ $? -ne 0 ]; then echo 'bochs dispi interface was not replaced in hw/display/vga-pci.c' fail=1 fi sed -i 's/BOCHSCPU/HAWKMCPU/g' ~/rpmbuild/BUILD/qemu*/roms/seabios/src/config.h if [ $? -ne 0 ]; then echo 'BOCHSCPU was not replaced in seabio/config.h' fail=1 fi sed -i 's/BOCHS /HAWKM /g' ~/rpmbuild/BUILD/qemu*/roms/seabios/src/config.h if [ $? -ne 0 ]; then echo 'BOCHS was not replaced in seabio/config.h' fail=1 fi if [ $fail -eq 0 ]; then echo '[+] Starting compile it' # not make sense compile if was not patched rpmbuild --short-circuit -bc ~/rpmbuild/SPECS/qemu.spec rpmbuild --short-circuit -bi ~/rpmbuild/SPECS/qemu.spec rpmbuild --short-circuit -bb ~/rpmbuild/SPECS/qemu.spec if [ $? -eq 0 ]; then rpm -vhU --nodeps --force ~/rpmbuild/RPMS/x86_64/qemu*.rpm if [ $? -eq 0 ]; then echo '[+] Patched, compiled and installed' else echo '[-] Install failed' fi else echo '[-] Compilling failed' fi else echo '[-] Check previous output' exit fi else echo '[-] Download QEMU source was not possible' fi } function seabios_func { echo '[+] Installign SeaBios dependencies' yum -y install git iasl git clone git://git.seabios.org/seabios.git if [ $? -eq 0 ]; then cd seabios sed -i 's/Bochs//g' src/config.h sed -i 's/BOCHSCPU/CPU/g' src/config.h sed -i 's/BOCHS//g' src/config.h sed -i 's/BXPC/S/g' src/config.h make if [ $? -eq 0 ]; then echo '[+] Compiled SeaBios, bios file located in -> out/bios.bin' echo '[+] Replacing old bios.bin to new one, with backup' bios=0 echo '[+] Original bios.bin file backuped and replaced' if [ -f /usr/share/seabios/bios.bin ]; then cp /usr/share/seabios/bios.bin /usr/share/seabios/bios.bin_back cp out/bios.bin /usr/share/seabios/bios.bin bios=1 fi if [ -f /usr/share/qemu/bios.bin ]; then cp /usr/share/qemu/bios.bin /usr/share/qemu/bios.bin_back cp out/bios.bin /usr/share/qemu/bios.bin bios=1 fi if [ $bios -eq 1 ]; then echo '[+] Patched bios.bin placed correctly' else echo '[-] Bios patching failed' fi else echo '[-] Bios compilation failed' fi else echo '[-] Check if git installed or network connection is OK' fi } #check if start with root if [ $EUID -ne 0 ]; then echo 'This script must be run as root' exit 1 fi if [ $# -eq 0 ]; then usage fi if [ "$1" = '-h' ]; then usage fi if [ "$1" = 'All' ]; then install_kvm qemu_func seabios_func fi if [ "$1" = 'QEMU' ]; then qemu_func fi if [ "$1" = 'SeaBios' ]; then seabios_func fi if [ "$1" = 'KVM' ]; then install_kvm fi