From af278189da29f65a69327d8cac43e6fc0313a941 Mon Sep 17 00:00:00 2001 From: T-vK Date: Mon, 26 Jul 2021 00:49:31 +0200 Subject: [PATCH 01/40] Started implementing virt-install --- .gitignore | 1 + README.md | 11 +- autounattend-vfd-files/Autounattend.xml | 89 ++++++ default.conf | 4 +- mbpt.sh | 1 - output.log | 357 ++++++++++++++++++++++++ scripts/generate-autounattend-vfd.sh | 35 +++ scripts/start-vm.sh | 319 ++++++++++++++------- utils/Fedora/34/install-dependencies | 2 +- utils/make-windows-iso-auto-bootable | 136 +++++++++ 10 files changed, 853 insertions(+), 102 deletions(-) create mode 100644 autounattend-vfd-files/Autounattend.xml create mode 100644 output.log create mode 100755 scripts/generate-autounattend-vfd.sh create mode 100755 utils/make-windows-iso-auto-bootable diff --git a/.gitignore b/.gitignore index 1f6acd8..cdce5b1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /vm-files/*.fd /vm-files/*.iso /vm-files/*.img +/vm-files/*.vfd /vm-files/*.aml /vm-files/patched-ovmf-files /vm-files/MAC_ADDRESS.txt diff --git a/README.md b/README.md index f42a6af..72a2931 100644 --- a/README.md +++ b/README.md @@ -263,4 +263,13 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for - Find a way to circumvent Error 43 for AMD GPUs like the `Radeon RX Vega M GL` - Reduce the size of the ovmf-vbios-patch Docker image - Make the USB passthrough device selection easier (i.e. display a list of devices that can be selected) -- Look into hotplugging and check if the GPU can be hotplugged during VM runtime \ No newline at end of file +- Look into hotplugging and check if the GPU can be hotplugged during VM runtime +- Generate libvirt XML +- Check which kernel parameters are currently used to determine if a reboot is necessary +- Check if required dependencies are installed for each script +- Check if fake-battery has been built +- Check if patched ovmf exists +- Add a fully unattended mode that runs the setup, then reboots and continues running the compatibility check and creating/installing the VM and starting it. +- Use virt-install to fully automate the windows installation +- Add support for multiple VMs +- Add support for Linux guests \ No newline at end of file diff --git a/autounattend-vfd-files/Autounattend.xml b/autounattend-vfd-files/Autounattend.xml new file mode 100644 index 0000000..a94f529 --- /dev/null +++ b/autounattend-vfd-files/Autounattend.xml @@ -0,0 +1,89 @@ + + + + + + en-US + + 0c09:00000409 + en-US + en-US + en-US + en-US + + + + true + + + + + Never + + + + false + Never + + false + C:\Log + + + + + false + + + + + 1 + + + + + 0409:00000409 + en-US + en-US + en-US + en-US + + + true + + + GPU-PASSTHROUGH-VM + + + + + + + admin + true</PlainText> + </AdministratorPassword> + </UserAccounts> + <AutoLogon> + <Password> + <Value>admin</Value> + <PlainText>true</PlainText> + </Password> + <Username>Administrator</Username> + <LogonCount>99</LogonCount> + <Enabled>true</Enabled> + </AutoLogon> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <HideLocalAccountScreen>true</HideLocalAccountScreen> + <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> + <HideOnlineAccountScreens>true</HideOnlineAccountScreens> + <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> + <NetworkLocation>Work</NetworkLocation> + <ProtectYourPC>3</ProtectYourPC> + <SkipMachineOOBE>true</SkipMachineOOBE> + <SkipUserOOBE>true</SkipUserOOBE> + </OOBE> + <TimeZone>Central European Standard Time</TimeZone> + </component> + </settings> + <cpi:offlineImage cpi:source="" xmlns:cpi="urn:schemas-microsoft-com:cpi" /> +</unattend> diff --git a/default.conf b/default.conf index e319658..f7f1cfc 100644 --- a/default.conf +++ b/default.conf @@ -20,7 +20,9 @@ OVMF_VARS="/usr/share/OVMF/OVMF_VARS.fd" # Required OVMF_VARS_VM="${VM_FILES_DIR}/OVMF_VARS_VM.fd" # Required VIRTIO_WIN_IMG="/usr/share/virtio-win/virtio-win.iso" # Required for driver installation +VIRTIO_WIN_VFD="/usr/share/virtio-win/virtio-win_amd64.vfd" # Required for driver installation +AUTOUNATTEND_WIN_VFD="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated windows installation HELPER_ISO="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated driver installation, looking glass setup, IP setup, remote desktop setup etc inseide of the VM DGPU_PCI_ADDRESS=01:00.0 # Required; If you don't use Bumblebee, you have to set this to the correct PCI address of your dGPU (see output of lspci) @@ -61,7 +63,7 @@ USB_DEVICES="" # example2: USB_DEVICES="vendorid=0x0b95,productid=0x1790" # example3: USB_DEVICES="vendorid=0x0b12,productid=0x9348;vendorid=0x0b95,productid=0x1790;hostbus=3,hostaddr=9" -####### This part of the config get's burned into the helper iso that you can generate using generate-helper-iso.sh ###### +####### This part of the config get's burned into the helper iso that you can generate by running './mbpt.sh iso' ###### # Not implemented yet; Please change the helper-iso-files/start.bat file manually, if you need to change the IPs #V_NETWORK_GATEWAY_IP=192.168.99.1 # Recommended (Leave this as is unless you know what you're doing) #V_NETWORK_DNS_IP=192.168.99.1 # Recommended (Leave this as is unless you know what you're doing) diff --git a/mbpt.sh b/mbpt.sh index b71d966..8208e7b 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -17,7 +17,6 @@ function printHelp() { echo '' echo 'Options:' echo ' -h, --help Print usage' - echo ' -v, --version Print version information' echo '' echo 'Commands:' echo ' setup Install required dependencies and set required kernel parameters' diff --git a/output.log b/output.log new file mode 100644 index 0000000..3ccd6a2 --- /dev/null +++ b/output.log @@ -0,0 +1,357 @@ +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:204) Launched with command line: /usr/bin/virt-install --virt-type kvm --os-variant win10 --arch=x86_64 --cdrom /usr/share/virtio-win/virtio-win.iso --cdrom /home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso --disk /home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img --debug --qemu-commandline= -name 'WindowsVM' -machine type=q35,accel=kvm -global ICH9-LPC.disable_s3=1 -global ICH9-LPC.disable_s4=1 -enable-kvm -cpu host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum -smp '2' -m '8G' -mem-prealloc -rtc clock=host,base=localtime -nographic -serial none -parallel none -boot menu=on -boot order=d -k en-us -spice port=5900,addr=127.0.0.1,disable-ticketing -drive 'if=pflash,format=raw,readonly=on,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_CODE.fd' -drive 'if=pflash,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_VARS.fd' -drive 'file=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso,index=1,media=cdrom' -drive 'file=/usr/share/virtio-win/virtio-win.iso,index=2,media=cdrom' -drive 'file=/home/fedora/Projects/MobilePassThrough/vm-files/mobile-passthrough-helper.iso,index=3,media=cdrom' -fda '/usr/share/virtio-win/virtio-win_amd64.vfd' -fdb '/home/fedora/Projects/MobilePassThrough/vm-files/autounattend.vfd' -drive 'id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img' -netdev 'type=tap,id=net0,ifname=tap0,script=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifup,downscript=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifdown,vhost=on' -device ich9-intel-hda -device hda-output -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x080d,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=/home/fedora/Projects/MobilePassThrough/vm-files/vbios-roms/vbios_1002_694e_1.rom -device 'virtio-net-pci,netdev=net0,addr=19.0,mac=52:54:BE:EF:D3:5C' -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 -acpitable 'file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml' -usb -device usb-tablet -device usb-host,vendorid=0x0b95,productid=0x1790 -device ivshmem-plain,memdev=ivshmem,bus=pcie.0 -object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M -device qxl,bus=pcie.0,addr=1c.4,id=video.2 -vga qxl +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (virtinstall:212) Distilled --network options: ['default'] +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (virtinstall:144) Distilled --disk options: ['/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img'] +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:216) Requesting libvirt URI default +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:219) Received libvirt URI qemu:///system +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (guest:320) Setting Guest osinfo name <_OsVariant name=generic> +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (guest:320) Setting Guest osinfo name <_OsVariant name=win10> +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (installer:544) installer.detect_distro returned=win10 +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:265) Using default --name win10 +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (osdict:344) No recommended value found for key='storage', using minimum=21474836480 * 2 +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (osdict:344) No recommended value found for key='ram', using minimum=2147483648 * 2 +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (osdict:344) No recommended value found for key='n-cpus', using minimum=1 * 2 +[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:265) Using win10 default --memory 4096 +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (graphics:165) Using default_graphics=spice +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (graphics:176) Local connection, disabling spice image compression. +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (disk:242) DeviceDisk.check_path_search path=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (disk:242) DeviceDisk.check_path_search path=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (disk:242) DeviceDisk.check_path_search path=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:265) +Starting install... +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (installer:599) Generated install XML: +<domain type="kvm"> + <name>win10</name> + <uuid>2c4503a5-11ba-4a5d-b850-8e65a31c187a</uuid> + <metadata> + <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0"> + <libosinfo:os id="http://microsoft.com/win/10"/> + </libosinfo:libosinfo> + </metadata> + <memory>4194304</memory> + <currentMemory>4194304</currentMemory> + <vcpu>2</vcpu> + <os> + <type arch="x86_64" machine="q35">hvm</type> + <boot dev="cdrom"/> + <boot dev="hd"/> + </os> + <features> + <acpi/> + <apic/> + <hyperv> + <relaxed state="on"/> + <vapic state="on"/> + <spinlocks state="on" retries="8191"/> + </hyperv> + <vmport state="off"/> + </features> + <cpu mode="host-model"/> + <clock offset="localtime"> + <timer name="rtc" tickpolicy="catchup"/> + <timer name="pit" tickpolicy="delay"/> + <timer name="hpet" present="no"/> + <timer name="hypervclock" present="yes"/> + </clock> + <on_reboot>destroy</on_reboot> + <pm> + <suspend-to-mem enabled="no"/> + <suspend-to-disk enabled="no"/> + </pm> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type="file" device="disk"> + <driver name="qemu" type="raw"/> + <source file="/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> + <target dev="sda" bus="sata"/> + </disk> + <disk type="file" device="cdrom"> + <driver name="qemu" type="raw"/> + <source file="/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso"/> + <target dev="sdb" bus="sata"/> + <readonly/> + </disk> + <controller type="usb" model="qemu-xhci" ports="15"/> + <interface type="network"> + <source network="default"/> + <mac address="52:54:00:b1:94:e6"/> + <model type="e1000e"/> + </interface> + <console type="pty"/> + <channel type="spicevmc"> + <target type="virtio" name="com.redhat.spice.0"/> + </channel> + <input type="tablet" bus="usb"/> + <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> + <image compression="off"/> + </graphics> + <sound model="ich9"/> + <video> + <model type="qxl"/> + </video> + <redirdev bus="usb" type="spicevmc"/> + <redirdev bus="usb" type="spicevmc"/> + </devices> + <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> + <qemu:arg value="-name"/> + <qemu:arg value="WindowsVM"/> + <qemu:arg value="-machine"/> + <qemu:arg value="type=q35,accel=kvm"/> + <qemu:arg value="-global"/> + <qemu:arg value="ICH9-LPC.disable_s3=1"/> + <qemu:arg value="-global"/> + <qemu:arg value="ICH9-LPC.disable_s4=1"/> + <qemu:arg value="-enable-kvm"/> + <qemu:arg value="-cpu"/> + <qemu:arg value="host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum"/> + <qemu:arg value="-smp"/> + <qemu:arg value="2"/> + <qemu:arg value="-m"/> + <qemu:arg value="8G"/> + <qemu:arg value="-mem-prealloc"/> + <qemu:arg value="-rtc"/> + <qemu:arg value="clock=host,base=localtime"/> + <qemu:arg value="-nographic"/> + <qemu:arg value="-serial"/> + <qemu:arg value="none"/> + <qemu:arg value="-parallel"/> + <qemu:arg value="none"/> + <qemu:arg value="-boot"/> + <qemu:arg value="menu=on"/> + <qemu:arg value="-boot"/> + <qemu:arg value="order=d"/> + <qemu:arg value="-k"/> + <qemu:arg value="en-us"/> + <qemu:arg value="-spice"/> + <qemu:arg value="port=5900,addr=127.0.0.1,disable-ticketing"/> + <qemu:arg value="-drive"/> + <qemu:arg value="if=pflash,format=raw,readonly=on,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_CODE.fd"/> + <qemu:arg value="-drive"/> + <qemu:arg value="if=pflash,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_VARS.fd"/> + <qemu:arg value="-drive"/> + <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso,index=1,media=cdrom"/> + <qemu:arg value="-drive"/> + <qemu:arg value="file=/usr/share/virtio-win/virtio-win.iso,index=2,media=cdrom"/> + <qemu:arg value="-drive"/> + <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/mobile-passthrough-helper.iso,index=3,media=cdrom"/> + <qemu:arg value="-fda"/> + <qemu:arg value="/usr/share/virtio-win/virtio-win_amd64.vfd"/> + <qemu:arg value="-fdb"/> + <qemu:arg value="/home/fedora/Projects/MobilePassThrough/vm-files/autounattend.vfd"/> + <qemu:arg value="-drive"/> + <qemu:arg value="id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> + <qemu:arg value="-netdev"/> + <qemu:arg value="type=tap,id=net0,ifname=tap0,script=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifup,downscript=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifdown,vhost=on"/> + <qemu:arg value="-device"/> + <qemu:arg value="ich9-intel-hda"/> + <qemu:arg value="-device"/> + <qemu:arg value="hda-output"/> + <qemu:arg value="-device"/> + <qemu:arg value="ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1"/> + <qemu:arg value="-device"/> + <qemu:arg value="vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x080d,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=/home/fedora/Projects/MobilePassThrough/vm-files/vbios-roms/vbios_1002_694e_1.rom"/> + <qemu:arg value="-device"/> + <qemu:arg value="virtio-net-pci,netdev=net0,addr=19.0,mac=52:54:BE:EF:D3:5C"/> + <qemu:arg value="-device"/> + <qemu:arg value="pci-bridge,addr=12.0,chassis_nr=2,id=head.2"/> + <qemu:arg value="-acpitable"/> + <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml"/> + <qemu:arg value="-usb"/> + <qemu:arg value="-device"/> + <qemu:arg value="usb-tablet"/> + <qemu:arg value="-device"/> + <qemu:arg value="usb-host,vendorid=0x0b95,productid=0x1790"/> + <qemu:arg value="-device"/> + <qemu:arg value="ivshmem-plain,memdev=ivshmem,bus=pcie.0"/> + <qemu:arg value="-object"/> + <qemu:arg value="memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M"/> + <qemu:arg value="-device"/> + <qemu:arg value="qxl,bus=pcie.0,addr=1c.4,id=video.2"/> + <qemu:arg value="-vga"/> + <qemu:arg value="qxl"/> + </qemu:commandline> +</domain> + +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (installer:601) Generated boot XML: +<domain type="kvm"> + <name>win10</name> + <uuid>2c4503a5-11ba-4a5d-b850-8e65a31c187a</uuid> + <metadata> + <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0"> + <libosinfo:os id="http://microsoft.com/win/10"/> + </libosinfo:libosinfo> + </metadata> + <memory>4194304</memory> + <currentMemory>4194304</currentMemory> + <vcpu>2</vcpu> + <os> + <type arch="x86_64" machine="q35">hvm</type> + <boot dev="hd"/> + </os> + <features> + <acpi/> + <apic/> + <hyperv> + <relaxed state="on"/> + <vapic state="on"/> + <spinlocks state="on" retries="8191"/> + </hyperv> + <vmport state="off"/> + </features> + <cpu mode="host-model"/> + <clock offset="localtime"> + <timer name="rtc" tickpolicy="catchup"/> + <timer name="pit" tickpolicy="delay"/> + <timer name="hpet" present="no"/> + <timer name="hypervclock" present="yes"/> + </clock> + <pm> + <suspend-to-mem enabled="no"/> + <suspend-to-disk enabled="no"/> + </pm> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type="file" device="disk"> + <driver name="qemu" type="raw"/> + <source file="/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> + <target dev="sda" bus="sata"/> + </disk> + <disk type="file" device="cdrom"> + <driver name="qemu" type="raw"/> + <source file="/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso"/> + <target dev="sdb" bus="sata"/> + <readonly/> + </disk> + <controller type="usb" model="qemu-xhci" ports="15"/> + <interface type="network"> + <source network="default"/> + <mac address="52:54:00:b1:94:e6"/> + <model type="e1000e"/> + </interface> + <console type="pty"/> + <channel type="spicevmc"> + <target type="virtio" name="com.redhat.spice.0"/> + </channel> + <input type="tablet" bus="usb"/> + <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> + <image compression="off"/> + </graphics> + <sound model="ich9"/> + <video> + <model type="qxl"/> + </video> + <redirdev bus="usb" type="spicevmc"/> + <redirdev bus="usb" type="spicevmc"/> + </devices> + <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> + <qemu:arg value="-name"/> + <qemu:arg value="WindowsVM"/> + <qemu:arg value="-machine"/> + <qemu:arg value="type=q35,accel=kvm"/> + <qemu:arg value="-global"/> + <qemu:arg value="ICH9-LPC.disable_s3=1"/> + <qemu:arg value="-global"/> + <qemu:arg value="ICH9-LPC.disable_s4=1"/> + <qemu:arg value="-enable-kvm"/> + <qemu:arg value="-cpu"/> + <qemu:arg value="host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum"/> + <qemu:arg value="-smp"/> + <qemu:arg value="2"/> + <qemu:arg value="-m"/> + <qemu:arg value="8G"/> + <qemu:arg value="-mem-prealloc"/> + <qemu:arg value="-rtc"/> + <qemu:arg value="clock=host,base=localtime"/> + <qemu:arg value="-nographic"/> + <qemu:arg value="-serial"/> + <qemu:arg value="none"/> + <qemu:arg value="-parallel"/> + <qemu:arg value="none"/> + <qemu:arg value="-boot"/> + <qemu:arg value="menu=on"/> + <qemu:arg value="-boot"/> + <qemu:arg value="order=d"/> + <qemu:arg value="-k"/> + <qemu:arg value="en-us"/> + <qemu:arg value="-spice"/> + <qemu:arg value="port=5900,addr=127.0.0.1,disable-ticketing"/> + <qemu:arg value="-drive"/> + <qemu:arg value="if=pflash,format=raw,readonly=on,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_CODE.fd"/> + <qemu:arg value="-drive"/> + <qemu:arg value="if=pflash,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_VARS.fd"/> + <qemu:arg value="-drive"/> + <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso,index=1,media=cdrom"/> + <qemu:arg value="-drive"/> + <qemu:arg value="file=/usr/share/virtio-win/virtio-win.iso,index=2,media=cdrom"/> + <qemu:arg value="-drive"/> + <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/mobile-passthrough-helper.iso,index=3,media=cdrom"/> + <qemu:arg value="-fda"/> + <qemu:arg value="/usr/share/virtio-win/virtio-win_amd64.vfd"/> + <qemu:arg value="-fdb"/> + <qemu:arg value="/home/fedora/Projects/MobilePassThrough/vm-files/autounattend.vfd"/> + <qemu:arg value="-drive"/> + <qemu:arg value="id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> + <qemu:arg value="-netdev"/> + <qemu:arg value="type=tap,id=net0,ifname=tap0,script=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifup,downscript=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifdown,vhost=on"/> + <qemu:arg value="-device"/> + <qemu:arg value="ich9-intel-hda"/> + <qemu:arg value="-device"/> + <qemu:arg value="hda-output"/> + <qemu:arg value="-device"/> + <qemu:arg value="ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1"/> + <qemu:arg value="-device"/> + <qemu:arg value="vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x080d,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=/home/fedora/Projects/MobilePassThrough/vm-files/vbios-roms/vbios_1002_694e_1.rom"/> + <qemu:arg value="-device"/> + <qemu:arg value="virtio-net-pci,netdev=net0,addr=19.0,mac=52:54:BE:EF:D3:5C"/> + <qemu:arg value="-device"/> + <qemu:arg value="pci-bridge,addr=12.0,chassis_nr=2,id=head.2"/> + <qemu:arg value="-acpitable"/> + <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml"/> + <qemu:arg value="-usb"/> + <qemu:arg value="-device"/> + <qemu:arg value="usb-tablet"/> + <qemu:arg value="-device"/> + <qemu:arg value="usb-host,vendorid=0x0b95,productid=0x1790"/> + <qemu:arg value="-device"/> + <qemu:arg value="ivshmem-plain,memdev=ivshmem,bus=pcie.0"/> + <qemu:arg value="-object"/> + <qemu:arg value="memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M"/> + <qemu:arg value="-device"/> + <qemu:arg value="qxl,bus=pcie.0,addr=1c.4,id=video.2"/> + <qemu:arg value="-vga"/> + <qemu:arg value="qxl"/> + </qemu:commandline> +</domain> + +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:255) File "/usr/bin/virt-install", line 8, in <module> + virtinstall.runcli() + File "/usr/share/virt-manager/virtinst/virtinstall.py", line 1158, in runcli + sys.exit(main()) + File "/usr/share/virt-manager/virtinst/virtinstall.py", line 1151, in main + start_install(guest, installer, options) + File "/usr/share/virt-manager/virtinst/virtinstall.py", line 901, in start_install + fail(e, do_exit=False) + File "/usr/share/virt-manager/virtinst/cli.py", line 255, in fail + log.debug("".join(traceback.format_stack())) + +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] ERROR (cli:256) internal error: process exited while connecting to monitor: qemu-system-x86_64: -acpitable file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: can't open file /home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: Permission denied +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:258) +Traceback (most recent call last): + File "/usr/share/virt-manager/virtinst/virtinstall.py", line 881, in start_install + domain = installer.start_install( + File "/usr/share/virt-manager/virtinst/install/installer.py", line 701, in start_install + domain = self._create_guest( + File "/usr/share/virt-manager/virtinst/install/installer.py", line 649, in _create_guest + domain = self.conn.createXML(install_xml or final_xml, 0) + File "/usr/lib64/python3.9/site-packages/libvirt.py", line 4366, in createXML + raise libvirtError('virDomainCreateXML() failed') +libvirt.libvirtError: internal error: process exited while connecting to monitor: qemu-system-x86_64: -acpitable file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: can't open file /home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: Permission denied +[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:271) Domain installation does not appear to have been successful. +If it was, you can restart your domain by running: + virsh --connect qemu:///system start win10 +otherwise, please restart your installation. +Domain installation does not appear to have been successful. +If it was, you can restart your domain by running: + virsh --connect qemu:///system start win10 +otherwise, please restart your installation. +Using default --name win10 +Using win10 default --memory 4096 \ No newline at end of file diff --git a/scripts/generate-autounattend-vfd.sh b/scripts/generate-autounattend-vfd.sh new file mode 100755 index 0000000..f676d6c --- /dev/null +++ b/scripts/generate-autounattend-vfd.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) +PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" +UTILS_DIR="${PROJECT_DIR}/utils" +DISTRO=$("${UTILS_DIR}/distro-info") +DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" + +if [ -f "${PROJECT_DIR}/user.conf" ]; then + echo "> Loading config from ${PROJECT_DIR}/user.conf" + source "${PROJECT_DIR}/user.conf" +elif [ -f "${PROJECT_DIR}/default.conf" ]; then + echo "> Warning: No user.conf found, falling back to default.conf" + echo "> Loading config from ${PROJECT_DIR}/default.conf" + source "${PROJECT_DIR}/default.conf" +else + echo "> Error: No user.conf or user.conf found!" + exit +fi + +TMP_DIR="${PROJECT_DIR}/tmp" +VFD_MP="${TMP_DIR}/autounattend-vfd-mountpoint" +VFD_FILE="${VM_FILES_DIR}/autounattend.vfd" + +echo "> Creating empty floppy image..." +rm -f "${VFD_FILE}" +fallocate -l 1474560 "${VFD_FILE}" +mkfs.vfat "${VFD_FILE}" + +echo "> Copy files onto the floppy image..." +mkdir -p "${VFD_MP}" +sudo mount -o loop "${VFD_FILE}" "${VFD_MP}" +sudo cp -r "${PROJECT_DIR}/autounattend-vfd-files/." "${VFD_MP}/" +sudo umount "${VFD_MP}" +rm -rf "${TMP_DIR}" \ No newline at end of file diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index 22d749d..e44332d 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -6,6 +6,8 @@ UTILS_DIR="${PROJECT_DIR}/utils" DISTRO=$("${UTILS_DIR}/distro-info") DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +VM_START_MODE="virt-install" # qemu or virt-install + # If user.conf doesn't exist use the default.conf if [ -f "${PROJECT_DIR}/user.conf" ]; then echo "> Loading config from ${PROJECT_DIR}/user.conf" @@ -24,19 +26,131 @@ shopt -s expand_aliases alias driver="sudo $UTILS_DIR/driver-util" alias vgpu="sudo $UTILS_DIR/vgpu-util" +VIRT_INSTALL_PARAMS=() +QEMU_PARAMS=() + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-name" "${VM_NAME}") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--name" "WindowsVM") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-machine" "type=q35,accel=kvm") # for virt-install that's the default WHEN "--os-variant win10" is specified +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-global" "ICH9-LPC.disable_s3=1") # for virt-install this enabled by default + QEMU_PARAMS+=("-global" "ICH9-LPC.disable_s4=1") # for virt-install this enabled by default +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-enable-kvm") # for virt-install this enabled by default +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + # Refer to https://github.com/saveriomiroddi/qemu-pinning for information on how to set your cpu affinity properly + QEMU_PARAMS+=("-cpu" "host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cpu" "host") + VIRT_INSTALL_PARAMS+=("--feature" "kvm.hidden.state=yes") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./features/hyperv/vendor_id/@state=on" "--xml" "xpath.set=./features/hyperv/vendor_id/@value='12alphanum'") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-smp" "${CPU_CORE_COUNT}") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--vcpu" "${CPU_CORE_COUNT}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-m" "${RAM_SIZE}") +elif [ "$VM_START_MODE" = "virt-install" ]; then + RAM_SIZE_GB="$(numfmt --from=si "${RAM_SIZE}" --to-unit=1M)" + VIRT_INSTALL_PARAMS+=("--memory" "${RAM_SIZE_GB}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-mem-prealloc") # for virt-install this enabled by default +fi + +QEMU_PARAMS+=("-rtc" "clock=host,base=localtime") +QEMU_PARAMS+=("-nographic") +QEMU_PARAMS+=("-serial" "none") +QEMU_PARAMS+=("-parallel" "none") +QEMU_PARAMS+=("-boot" "menu=on") +QEMU_PARAMS+=("-boot" "order=d") +QEMU_PARAMS+=("-k" "en-us") + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${VIRTIO_WIN_IMG},index=2,media=cdrom") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cdrom" "${VIRTIO_WIN_IMG}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=3,media=cdrom") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cdrom" "${HELPER_ISO}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-fda" "${VIRTIO_WIN_VFD}") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${VIRTIO_WIN_VFD}") +fi + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-fdb" "${AUTOUNATTEND_WIN_VFD}") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${AUTOUNATTEND_WIN_VFD}") +fi + +#TODO: Uncomment! +#QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") +#QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") +QEMU_PARAMS+=("-device" "ich9-intel-hda") +QEMU_PARAMS+=("-device" "hda-output") +QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") +# More parameters are added throughout the whole script -if [[ ${DRIVE_IMG} == /dev/* ]] ; then +VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") +VIRT_INSTALL_PARAMS+=("--os-variant" "win10") +VIRT_INSTALL_PARAMS+=("--arch=x86_64") + +if [[ ${DRIVE_IMG} == /dev/* ]]; then echo "> Using a physical OS drive..." - OS_DRIVE_PARAM="-drive file=${DRIVE_IMG},if=virtio -snapshot" - #OS_DRIVE_PARAM="-drive file=/dev/sda,if=virtio -drive file=/dev/sdb,if=virtio -drive file=/dev/sdc,if=virtio -drive file=/dev/sdd,if=virtio -snapshot" -elif [[ ${DRIVE_IMG} == *.img ]] ; then + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${DRIVE_IMG},if=virtio" "-snapshot") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") + fi + #QEMU_PARAMS+=("-drive" "file=/dev/sda,if=virtio" "-drive" "file=/dev/sdb,if=virtio" "-drive" "file=/dev/sdc,if=virtio" "-drive" "file=/dev/sdd,if=virtio" "-snapshot") +elif [[ ${DRIVE_IMG} == *.img ]]; then echo "> Using a virtual OS drive..." if [ ! -f "${DRIVE_IMG}" ]; then #sudo $DISTRO_UTILS_DIR/prepare-vm echo "> Creating a virtual disk for the VM..." qemu-img create -f raw "${DRIVE_IMG}" "${VM_DISK_SIZE}" + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${DRIVE_IMG}" + fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=${DRIVE_IMG}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") fi - OS_DRIVE_PARAM="-drive id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=${DRIVE_IMG}" else echo "> Error: It appears that no proper OS drive (image) has been provided. Check your 'DRIVE_IMG' var: '${DRIVE_IMG}'" exit @@ -45,6 +159,7 @@ fi if [ ! -f "${OVMF_VARS_VM}" ]; then echo "> Creating OVMF_VARS copy for this VM..." sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${OVMF_VARS_VM}" fi if sudo which optirun &> /dev/null && sudo optirun echo > /dev/null ; then @@ -83,7 +198,7 @@ fi echo "> Loading vfio-pci kernel module..." sudo modprobe vfio-pci -if [ "$USE_LOOKING_GLASS" = true ] ; then +if [ "$USE_LOOKING_GLASS" = true ]; then echo "> Using Looking Glass..." echo "> Calculating required buffer size for ${LOOKING_GLASS_MAX_SCREEN_WIDTH}x${LOOKING_GLASS_MAX_SCREEN_HEIGHT} for Looking Glass..." UNROUNDED_BUFFER_SIZE=$((($LOOKING_GLASS_MAX_SCREEN_WIDTH * $LOOKING_GLASS_MAX_SCREEN_HEIGHT * 4 * 2)/1024/1024+10)) @@ -93,12 +208,10 @@ if [ "$USE_LOOKING_GLASS" = true ] ; then done LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}M" echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}" - LOOKING_GLASS_DEVICE_PARAM="-device ivshmem-plain,memdev=ivshmem,bus=pcie.0" - LOOKING_GLASS_OBJECT_PARAM="-object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}" + QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") + QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}") else echo "> Not using Looking Glass..." - LOOKING_GLASS_DEVICE_PARAM="" - LOOKING_GLASS_OBJECT_PARAM="" fi if [ -z "$DGPU_ROM" ]; then @@ -119,13 +232,12 @@ fi if [ -z "$SMB_SHARE_FOLDER" ]; then echo "> Not using SMB share..." - SMB_SHARE_PARAM="" else echo "> Using SMB share..." - SMB_SHARE_PARAM="-net user,smb=${SMB_SHARE_FOLDER}" + QEMU_PARAMS+=("-net" "user,smb=${SMB_SHARE_FOLDER}") fi -if [ "$DGPU_PASSTHROUGH" = true ] ; then +if [ "$DGPU_PASSTHROUGH" = true ]; then echo "> Using dGPU passthrough..." echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." driver unbind "${DGPU_PCI_ADDRESS}" @@ -133,15 +245,13 @@ if [ "$DGPU_PASSTHROUGH" = true ] ; then driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) - DGPU_ROOT_PORT_PARAM="-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1" - DGPU_PARAM="-device vfio-pci,host=${DGPU_PCI_ADDRESS},bus=root.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}" + QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1") # DGPU root port + QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=root.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") else echo "> Not using dGPU passthrough..." - DGPU_ROOT_PORT_PARAM="" - DGPU_PARAM="" fi -if [ "$SHARE_IGPU" = true ] ; then +if [ "$SHARE_IGPU" = true ]; then echo "> Using mediated iGPU passthrough..." vgpu init # load required kernel modules @@ -158,64 +268,71 @@ if [ "$SHARE_IGPU" = true ] ; then fi fi - if [ "$USE_DMA_BUF" = true ] ; then + if [ "$USE_DMA_BUF" = true ]; then echo "> Using dma-buf..." - DMA_BUF_DISPLAY_PARAM="-display egl-headless" #"-display gtk,gl=on" + QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display GVTG_DISPLAY_STATE="on" else echo "> Not using dma-buf..." - DMA_BUF_DISPLAY_PARAM="" GVTG_DISPLAY_STATE="off" fi - - GVTG_PARAM="-device vfio-pci,bus=pcie.0,addr=02.0,sysfsdev=/sys/bus/pci/devices/0000:${IGPU_PCI_ADDRESS}/${VGPU_UUID},x-igd-opregion=on${IGPU_ROM_PARAM},display=${GVTG_DISPLAY_STATE}" + + QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=02.0,sysfsdev=/sys/bus/pci/devices/0000:${IGPU_PCI_ADDRESS}/${VGPU_UUID},x-igd-opregion=on${IGPU_ROM_PARAM},display=${GVTG_DISPLAY_STATE}") # GVT-G else echo "> Not using mediated iGPU passthrough..." - GVTG_PARAM="" - DMA_BUF_DISPLAY_PARAM="" fi -if [ "$USE_SPICE" = true ] ; then +if [ "$USE_SPICE" = true ]; then echo "> Using spice on port ${SPICE_PORT}..." - SPICE_PARAM="-spice port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing" + QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--channel" "spicevmc") + fi else echo "> Not using Spice..." - SPICE_PARAM="" fi -if [ "$USE_QXL" = true ] ; then +if [ "$USE_QXL" = true ]; then echo "> Using QXL..." - QXL_DEVICE_PARAM="-device qxl,bus=pcie.0,addr=1c.4,id=video.2" - QXL_VGA_PARAM="-vga qxl" + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "qxl,bus=pcie.0,addr=1c.4,id=video.2" "-vga" "qxl") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--video" "qxl") + fi else echo "> Not using QXL..." - QXL_DEVICE_PARAM="" - QXL_VGA_PARAM="" fi - -if [ "$USE_FAKE_BATTERY" = true ] ; then +-video qxl --channel spicevmc +if [ "$USE_FAKE_BATTERY" = true ]; then echo "> Using fake battery..." - if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ] ; then + if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ]; then mv "${PROJECT_DIR}/acpi-tables/fake-battery.aml" "${VM_FILES_DIR}/fake-battery.aml" fi FAKE_BATTERY_SSDT_TABLE="$(readlink -f "${VM_FILES_DIR}/fake-battery.aml")" - ACPI_TABLE_PARAM="-acpitable file=${FAKE_BATTERY_SSDT_TABLE}" + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-acpitable" "file=${FAKE_BATTERY_SSDT_TABLE}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./os/acpi/table/@type=slic" "--xml" "xpath.set=./os/acpi/table=${VM_FILES_DIR}/fake-battery.aml") + fi else echo "> Not using fake battery..." - ACPI_TABLE_PARAM="" fi -if [ "$PATCH_OVMF_WITH_VROM" = true ] ; then +if [ "$PATCH_OVMF_WITH_VROM" = true ]; then PATCHED_OVMF_FILES_DIR="${VM_FILES_DIR}/patched-ovmf-files" - if [ "$DGPU_ROM" != "" ] ; then + if [ "$DGPU_ROM" != "" ]; then echo "> Using patched OVMF..." DGPU_ROM_NAME="$(basename "${DGPU_ROM}")" - if [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" ] || [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" ] ; then + if [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" ] || [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" ]; then DGPU_ROM_DIR="$(dirname "${DGPU_ROM}")" mkdir -p "${PATCHED_OVMF_FILES_DIR}/tmp-build" + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${PATCHED_OVMF_FILES_DIR}" echo "> Patching OVMF with your vBIOS ROM. This may take a few minutes!" sleep 5 # Ensure the user can read this first sudo docker run --rm -ti -v "${PATCHED_OVMF_FILES_DIR}/tmp-build:/build:z" -v "${DGPU_ROM_DIR}:/roms:z" -e "VROM=${DGPU_ROM_NAME}" ovmf-vbios-patch + sudo chown "$(whoami):$(id -gn "$(whoami)")" -R "${PATCHED_OVMF_FILES_DIR}/tmp-build" sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_CODE.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_VARS.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" sudo rm -rf "${PATCHED_OVMF_FILES_DIR}/tmp-build" @@ -229,77 +346,83 @@ else echo "> Not using patched OVMF..." fi -if [ -z "$USB_DEVICES" ] ; then +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}") + QEMU_PARAMS+=("-drive" "if=pflash,format=raw,file=${OVMF_VARS_VM}") +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--boot" "loader=${OVMF_CODE},loader.readonly=yes,loader.type=pflash,nvram.template=${OVMF_VARS_VM},loader_secure=no") +fi + +if [ -z "$USB_DEVICES" ]; then echo "> Not using USB passthrough..." USB_DEVICE_PARAMS="" else echo "> Using USB passthrough..." + QEMU_PARAMS+=("-usb") IFS=';' read -a USB_DEVICES_ARRAY <<< "${USB_DEVICES}" - USB_DEVICE_PARAMS="" for USB_DEVICE in "${USB_DEVICES_ARRAY[@]}"; do - USB_DEVICE_PARAMS="${USB_DEVICE_PARAMS} -device usb-host,${USB_DEVICE}" + QEMU_PARAMS+=("-device" "usb-host,${USB_DEVICE}") + echo "> Passing USB device '${USB_DEVICE}' through..." done - echo "USB_DEVICE_PARAMS: $USB_DEVICE_PARAMS" fi -if [ "$VIRTUAL_INPUT_TYPE" = "virtio" ] ; then +if [ "$VIRTUAL_INPUT_TYPE" = "virtio" ]; then echo "> Using virtual input method 'virtio' for keyboard/mouse input..." - VIRTUAL_INPUT_PARAMS="-device virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2 -device virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2" -elif [ "$VIRTUAL_INPUT_TYPE" = "usb-tablet" ] ; then + QEMU_PARAMS+=("-device" "virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2") + QEMU_PARAMS+=("-device" "virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2") +elif [ "$VIRTUAL_INPUT_TYPE" = "usb-tablet" ]; then echo "> Using virtual input method 'usb-tablet' for keyboard/mouse input..." - VIRTUAL_KEYBOARD_PARAM="-device usb-tablet" + QEMU_PARAMS+=("-device" "usb-tablet") else echo "> Not using virtual input method for keyboard/mouse input..." - VIRTUAL_KEYBOARD_PARAM="" -fi - -echo "> Starting the Virtual Machine..." -# Refer to https://github.com/saveriomiroddi/qemu-pinning for information on how to set your cpu affinity properly -sudo qemu-system-x86_64 \ - -name "${VM_NAME}" \ - -machine type=q35,accel=kvm \ - -global ICH9-LPC.disable_s3=1 \ - -global ICH9-LPC.disable_s4=1 \ - -enable-kvm \ - -cpu host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum \ - -smp ${CPU_CORE_COUNT} \ - -m ${RAM_SIZE} \ - -mem-prealloc \ - -rtc clock=host,base=localtime \ - -nographic \ - -serial none \ - -parallel none \ - -boot menu=on \ - -boot order=c \ - -k en-us \ - ${SMB_SHARE_PARAM} \ - ${SPICE_PARAM} \ - -drive "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}" \ - -drive "if=pflash,format=raw,file=${OVMF_VARS_VM}" \ - -drive "file=${INSTALL_IMG},index=1,media=cdrom" \ - -drive "file=${VIRTIO_WIN_IMG},index=2,media=cdrom" \ - -drive "file=${HELPER_ISO},index=3,media=cdrom" \ - ${OS_DRIVE_PARAM} \ - -netdev "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on" \ - ${GVTG_PARAM} \ - -device ich9-intel-hda \ - -device hda-output \ - ${DGPU_ROOT_PORT_PARAM} \ - ${DGPU_PARAM} \ - -device virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS} \ - -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \ - ${ACPI_TABLE_PARAM} \ - -usb \ - ${VIRTUAL_KEYBOARD_PARAM} \ - ${USB_DEVICE_PARAMS} \ - ${LOOKING_GLASS_DEVICE_PARAM} \ - ${LOOKING_GLASS_OBJECT_PARAM} \ - ${QXL_DEVICE_PARAM} \ - ${QXL_VGA_PARAM} \ - ${DMA_BUF_DISPLAY_PARAM} +fi + +give_qemu_access() { + local skip_root=true + local -a paths + IFS=/ read -r -a paths <<<"$1" + local i + for (( i = 1; i < ${#paths[@]}; i++ )); do + paths[i]="${paths[i-1]}/${paths[i]}" + done + paths[0]=/ + for current_path in "${paths[@]}" ; do + if [ "$skip_root" = true ] && [ "${current_path}" = "/" ]; then + continue + fi + echo "> Granting qemu access to: '${current_path}'" + sudo setfacl --modify user:qemu:rx "${current_path}" + sudo chmod +x "${current_path}" + done + #sudo chmod 777 "$1" +} + +give_qemu_access "${INSTALL_IMG}" + +#sudo bash -c "echo 'user = root' >> /etc/libvirt/qemu.conf" +#sudo systemctl restart libvirtd + +# Delete VM +sudo virsh destroy --domain WindowsVM &> /dev/null +sudo virsh undefine --domain WindowsVM --nvram &> /dev/null + +if [ "$VM_START_MODE" = "qemu" ]; then + echo "> Starting the spice client..." + spicy -h localhost -p 5900 & + echo "> Starting the Virtual Machine using qemu..." + sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" +elif [ "$VM_START_MODE" = "virt-install" ]; then + echo "> Starting the Virtual Machine using virt-install..." + #VIRT_INSTALL_PARAMS+=("--debug") + for param in "${QEMU_PARAMS[@]}"; do + VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") + done + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" +fi + # This gets executed when the vm exits -if [ "$DGPU_PASSTHROUGH" = true ] ; then +if [ "$DGPU_PASSTHROUGH" = true ]; then echo "> Unbinding dGPU from vfio driver..." driver unbind "${DGPU_PCI_ADDRESS}" if [ "$HOST_DGPU_DRIVER" = "nvidea" ] || [ "$HOST_DGPU_DRIVER" = "nuveau" ]; then @@ -309,7 +432,7 @@ if [ "$DGPU_PASSTHROUGH" = true ] ; then echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" fi -if [ "$SHARE_IGPU" = true ] ; then +if [ "$SHARE_IGPU" = true ]; then # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. # So for now we can't create a new vGPU every time the VM starts. echo "> Keeping Intel vGPU for next VM start..." diff --git a/utils/Fedora/34/install-dependencies b/utils/Fedora/34/install-dependencies index 09b2d83..23e6a28 100755 --- a/utils/Fedora/34/install-dependencies +++ b/utils/Fedora/34/install-dependencies @@ -3,7 +3,7 @@ echo "Updating software..." sudo dnf update -y echo "Installing some useful tools..." -sudo dnf install -y wget curl vim screen git crudini lshw msr-tools sysfsutils tunctl remmina samba spice-gtk-tools genisoimage uuid acpica-tools docker +sudo dnf install -y wget curl vim screen git crudini lshw msr-tools sysfsutils tunctl remmina samba spice-gtk-tools genisoimage uuid acpica-tools docker dumpet echo "Installing virtualization software..." sudo dnf install -y qemu #@virtualization diff --git a/utils/make-windows-iso-auto-bootable b/utils/make-windows-iso-auto-bootable new file mode 100755 index 0000000..9537ee9 --- /dev/null +++ b/utils/make-windows-iso-auto-bootable @@ -0,0 +1,136 @@ +#!/usr/bin/env bash + +# WARNING: THIS SCRIPT DOES NOT WORK YET! +# WARNING: THIS SCRIPT DOES NOT WORK YET! +# WARNING: THIS SCRIPT DOES NOT WORK YET! + +# Variable containing the path to the windows.iso +WIN10_IMG="$1" + +TMP="./tmp" +ISO_FILES="${TMP}/iso-files" +ISO_MP="${TMP}/iso-mountpoint" + +#rm -rf "${TMP}" +#mkdir -p "${ISO_FILES}" +#mkdir -p "${ISO_MP}" +#sudo mount -t udf "${WIN10_IMG}" "${ISO_MP}" +#sudo cp -Rva ${ISO_MP}/* "${ISO_FILES}" +#sudo umount "${ISO_MP}" + +# Make modifications to the Windows ISO +#BOOT_DIR="${ISO_FILES}/efi/microsoft/boot" +#sudo mv "${BOOT_DIR}/cdboot.efi" "${BOOT_DIR}/tmp.efi" +#sudo mv "${BOOT_DIR}/cdboot_noprompt.efi" "${BOOT_DIR}/cdboot.efi" +#sudo mv "${BOOT_DIR}/tmp.efi" "${BOOT_DIR}/cdboot_noprompt.efi" + +# Extract the boot.img +#BOOT_SECTOR_LENGTH="$(isoinfo -d -i "${WIN10_IMG}" | grep "Nsect " | grep -o "[^ ]*$")" +#STARTING_SECTOR="$(isoinfo -d -i ./vm-files/windows10.iso | grep "Bootoff " | grep -o "[^ ]*$")" +#dd if="${WIN10_IMG}" of="${ISO_FILES}/boot.img" bs=2048 count="${BOOT_SECTOR_LENGTH}" skip="${STARTING_SECTOR}" + + +# Extract boot load segment address and size +BOOT_LOAD_SEG="$(dumpet -i "${WIN10_IMG}" | grep "Media load segment: " | cut -d ':' -f2 | cut -d ' ' -f2)" +BOOT_LOAD_SIZE="$(dumpet -i "${WIN10_IMG}" | grep "Load Sectors: " | grep -o "[^:]*$" | cut -d ' ' -f2 | head -1)" + +EFI_STARTING_SECTOR="$(dumpet -i "${WIN10_IMG}" | grep "Load LBA: " | grep -o "[^:]*$" | cut -d ' ' -f2 | tail -1)" + +echo "EFI_STARTING_SECTOR: $EFI_STARTING_SECTOR" + +dd if="${WIN10_IMG}" of="${ISO_FILES}/efi.dmp" bs=2048 count=1 skip="${EFI_STARTING_SECTOR}" +EFI_BOOT_LOAD_SIZE="$(file "${ISO_FILES}/efi.dmp" | grep -oP 'sectors (\d+)' | cut -d ' ' -f2)" +echo "EFI_BOOT_LOAD_SIZE: $EFI_BOOT_LOAD_SIZE" +rm -f "${ISO_FILES}/efi.dmp" +dd if="${WIN10_IMG}" of="${ISO_FILES}/boot_efi.img" bs=2048 count="${EFI_BOOT_LOAD_SIZE}" skip="${EFI_STARTING_SECTOR}" + +mkdir -p /tmp/bbb +sudo mount -o loop,ro "${ISO_FILES}/boot_efi.img" /tmp/bbb +sudo cp /tmp/bbb/EFI/BOOT/BOOTX64.EFI "${ISO_FILES}/boot.efi" +#sudo umount /tmp/bbb +#sudo rm -f "${ISO_FILES}/boot.efi.img" +exit + +# Extract meta data : +SYSTEM_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "System id: " | cut -d ' ' -f3-)" +VOLUME_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Volume id: " | cut -d ' ' -f3-)" +VOLUME_SET_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Volume set id: " | cut -d ' ' -f4-)" +#PUBLISHER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Publisher id: " | cut -d ' ' -f3-)" # Always uppercase +PUBLISHER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "ID '" | cut -d "'" -f2)" +DATA_PREPARER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Data preparer id: " | cut -d ' ' -f4-)" +APPLICATION_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Application id: " | cut -d ' ' -f3-)" +COPYRIGHT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Copyright file id: " | cut -d ' ' -f4-)" +ABSTRACT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Abstract file id: " | cut -d ' ' -f4-)" +BIBLIOGRAPHIC_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Bibliographic file id: " | cut -d ' ' -f4-)" + +rm ".mkisofsrc" +echo "APPI=${APPLICATION_ID}" >> ".mkisofsrc" +echo "COPY=${COPYRIGHT_FILE_ID}" >> ".mkisofsrc" +echo "ABST=${ABSTRACT_FILE_ID}" >> ".mkisofsrc" +echo "BIBL=${BIBLIOGRAPHIC_FILE_ID}" >> ".mkisofsrc" +echo "PREP=${DATA_PREPARER_ID}" >> ".mkisofsrc" +echo "PUBL=${PUBLISHER_ID}" >> ".mkisofsrc" +echo "SYSI=${SYSTEM_ID}" >> ".mkisofsrc" +echo "VOLI=${VOLUME_ID}" >> ".mkisofsrc" +echo "VOLS=${VOLUME_SET_ID}" >> ".mkisofsrc" +sudo rm "${WIN10_IMG}.tmp.iso" +sudo mkisofs \ + -no-emul-boot \ + -b boot/etfsboot.com \ + -boot-load-seg "${BOOT_LOAD_SEG}" \ + -boot-load-size "${BOOT_LOAD_SIZE}" \ + -eltorito-alt-boot \ + -e boot.efi.img \ + -no-emul-boot \ + -iso-level 2 \ + -boot-info-table \ + -udf \ + -D \ + -N \ + -relaxed-filenames \ + -allow-lowercase \ + -o "${WIN10_IMG}.tmp.iso" \ + "${ISO_FILES}" +rm ".mkisofsrc" + +echo "BOOT_LOAD_SEG: ${BOOT_LOAD_SEG}" +echo "BOOT_LOAD_SIZE: ${BOOT_LOAD_SIZE}" +echo "-------" +echo "SYSTEM_ID: ${SYSTEM_ID}" +echo "VOLUME_ID: ${VOLUME_ID}" +echo "VOLUME_SET_ID: ${VOLUME_SET_ID}" +echo "PUBLISHER_ID: ${PUBLISHER_ID}" +echo "DATA_PREPARER_ID: ${DATA_PREPARER_ID}" +echo "APPLICATION_ID: ${APPLICATION_ID}" +echo "COPYRIGHT_FILE_ID: ${COPYRIGHT_FILE_ID}" +echo "ABSTRACT_FILE_ID: ${ABSTRACT_FILE_ID}" +echo "BIBLIOGRAPHIC_FILE_ID: ${BIBLIOGRAPHIC_FILE_ID}" + + +# Show difference between new and old image as reported by isoinfo +echo +echo "-------------- isoinfo diff -----------------" +diff <(isoinfo -d -i "${WIN10_IMG}") <(isoinfo -d -i "${WIN10_IMG}.tmp.iso") + +# Show difference between new and old image as reported by dumpet +echo +echo " -------------- dumpet diff -----------------" +diff <(dumpet -i "${WIN10_IMG}") <(dumpet -i "${WIN10_IMG}.tmp.iso") + + + +# Method from: https://www.g-loaded.eu/2007/04/25/how-to-create-a-windows-bootable-cd-with-mkisofs/ +#sudo mkisofs -o "${WIN10_IMG}.tmp.iso" -b "boot.img" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 \ +# -iso-level 2 -udf \ +# -J -l -D -N -joliet-long -relaxed-filenames "${ISO_FILES}" + +#sudo mkisofs \ +# -b "boot.img" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 \ +# -iso-level 2 -J -l -D -N -joliet-long -relaxed-filenames \ +# -V "WINDOWS10_AUTOBOOT" \ +# -o "${WIN10_IMG}.tmp.iso" "${ISO_FILES}" + + +#sudo mkisofs -D -r -V "WINDOWS10_AUTOBOOT" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o "${WIN10_IMG}.tmp" "${ISO_FILES}" +#sudo rm "${WIN10_IMG}" +#sudo mv "${WIN10_IMG}.tmp.iso" "${WIN10_IMG}" From 7dd9371470a5eb2220d95b36e33f588d7f2937a2 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Mon, 26 Jul 2021 19:58:03 +0200 Subject: [PATCH 02/40] Add root port support for virt-install --- scripts/start-vm.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index e44332d..f8b1d10 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -117,7 +117,6 @@ if [ "$VM_START_MODE" = "qemu" ]; then elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${AUTOUNATTEND_WIN_VFD}") fi - #TODO: Uncomment! #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") @@ -245,8 +244,20 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) - QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1") # DGPU root port + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1") # DGPU root port + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port" "--xml xpath.set=./devices/controller/model/@name=ioh3420") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> + fi + + # TODO: when the VM boots, check what chassis and slot libvirt allocates. Then plug that into the vfio-pci line. QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=root.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") + + #if [ "$VM_START_MODE" = "qemu" ]; then + # QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=root.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") + #elif [ "$VM_START_MODE" = "virt-install" ]; then + # VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.type=pci,address.multifunction=on,address") # TODO: not complete; i.e. rom file param missing + #fi else echo "> Not using dGPU passthrough..." fi @@ -278,6 +289,13 @@ if [ "$SHARE_IGPU" = true ]; then fi QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=02.0,sysfsdev=/sys/bus/pci/devices/0000:${IGPU_PCI_ADDRESS}/${VGPU_UUID},x-igd-opregion=on${IGPU_ROM_PARAM},display=${GVTG_DISPLAY_STATE}") # GVT-G + + # TODO: same as for iGPU + #if [ "$VM_START_MODE" = "qemu" ]; then + # QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=02.0,sysfsdev=/sys/bus/pci/devices/0000:${IGPU_PCI_ADDRESS}/${VGPU_UUID},x-igd-opregion=on${IGPU_ROM_PARAM},display=${GVTG_DISPLAY_STATE}") # GVT-G + #elif [ "$VM_START_MODE" = "virt-install" ]; then + # VIRT_INSTALL_PARAMS+=("--hostdev" "") + #fi else echo "> Not using mediated iGPU passthrough..." fi @@ -304,7 +322,7 @@ if [ "$USE_QXL" = true ]; then else echo "> Not using QXL..." fi --video qxl --channel spicevmc +#-video qxl --channel spicevmc if [ "$USE_FAKE_BATTERY" = true ]; then echo "> Using fake battery..." if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ]; then From 9d65db0d3ae98a620ca1941c9c5cd38f3ec6f117 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 27 Jul 2021 02:04:59 +0200 Subject: [PATCH 03/40] Add Looking Glass compatibilityfor virt-install --- scripts/start-vm.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index f8b1d10..83370ce 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -207,8 +207,14 @@ if [ "$USE_LOOKING_GLASS" = true ]; then done LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}M" echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}" - QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") - QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}") + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") + QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--xml xpath.set=./devices/shmem/model/@type=ivshmem-plain") + VIRT_INSTALL_PARAMS+=("--xml xpath.set=./devices/shmem/size=32") + VIRT_INSTALL_PARAMS+=("--xml xpath.set=./devices/shmem/size/@unit=M") + fi else echo "> Not using Looking Glass..." fi @@ -456,4 +462,4 @@ if [ "$SHARE_IGPU" = true ]; then echo "> Keeping Intel vGPU for next VM start..." #echo "> Remove Intel vGPU..." #vgpu remove "${IGPU_PCI_ADDRESS}" "${VGPU_UUID}" -fi +fi \ No newline at end of file From 7beb9641a608af5b04dceaea442859e27f050e34 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 27 Jul 2021 17:34:15 +0200 Subject: [PATCH 04/40] Add Schily Tools --- README.md | 3 ++- default.conf | 2 +- scripts/setup.sh | 2 ++ scripts/start-vm.sh | 26 ++++++++++++++++++------- utils/Fedora/34/install-dependencies | 2 +- utils/Fedora/34/looking-glass-setup | 6 ++---- utils/Ubuntu/21.04/install-dependencies | 2 +- utils/Ubuntu/21.04/looking-glass-setup | 6 ++---- utils/schily-tools-setup | 21 ++++++++++++++++++++ 9 files changed, 51 insertions(+), 19 deletions(-) create mode 100755 utils/schily-tools-setup diff --git a/README.md b/README.md index 72a2931..4ef19a8 100644 --- a/README.md +++ b/README.md @@ -272,4 +272,5 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for - Add a fully unattended mode that runs the setup, then reboots and continues running the compatibility check and creating/installing the VM and starting it. - Use virt-install to fully automate the windows installation - Add support for multiple VMs -- Add support for Linux guests \ No newline at end of file +- Add support for Linux guests +- Sanity checks for setup scritps (i.e. check if binaries have actually been compiled / installed) \ No newline at end of file diff --git a/default.conf b/default.conf index f7f1cfc..4eeadaf 100644 --- a/default.conf +++ b/default.conf @@ -43,7 +43,7 @@ NETWORK_MODE=TAP # Currently only supports TAP (bridged, NAT and none don't work USE_LOOKING_GLASS=true # Optional LOOKING_GLASS_MAX_SCREEN_WIDTH=1920 # Recommended (bigger resolutions will result in a bigger buffer with worse performance) LOOKING_GLASS_MAX_SCREEN_HEIGHT=1080 # Recommended (bigger resolutions will result in a bigger buffer with worse performance) -LOOKING_GLASS_VERSION=B3 # Recommended +LOOKING_GLASS_VERSION=B4 # Recommended USE_SPICE=true # Required for Windows installation and recommended for Looking Glass SPICE_PORT=5900 # 5900 is recommended diff --git a/scripts/setup.sh b/scripts/setup.sh index f5cd48b..6fcba65 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -37,6 +37,8 @@ sudo $DISTRO_UTILS_DIR/vbios-finder-installer sudo $DISTRO_UTILS_DIR/looking-glass-setup +sudo $UTILS_DIR/schily-tools-setup + echo "Make sure you didn't get any critical errors above." echo "Then reboot!" echo "After the reboot you can check if your device is compatible by running: ./mbpt.sh check" diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index 83370ce..2be7087 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -128,6 +128,8 @@ QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") VIRT_INSTALL_PARAMS+=("--os-variant" "win10") VIRT_INSTALL_PARAMS+=("--arch=x86_64") +VIRT_INSTALL_PARAMS+=("--unattended") +VIRT_INSTALL_PARAMS+=("--initrd-inject=/home/fedora/Projects/MobilePassThrough/autounattend-vfd-files/Autounattend.xml") if [[ ${DRIVE_IMG} == /dev/* ]]; then echo "> Using a physical OS drive..." @@ -210,11 +212,17 @@ if [ "$USE_LOOKING_GLASS" = true ]; then if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}") + SHM_LOOKING_GLASS_OWNER="$(logname)" elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--xml xpath.set=./devices/shmem/model/@type=ivshmem-plain") - VIRT_INSTALL_PARAMS+=("--xml xpath.set=./devices/shmem/size=32") - VIRT_INSTALL_PARAMS+=("--xml xpath.set=./devices/shmem/size/@unit=M") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/@name=looking-glass") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/model/@type=ivshmem-plain") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=32") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size/@unit=M") + SHM_LOOKING_GLASS_OWNER="qemu" fi + sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" + sudo bash -c "echo 'f /dev/shm/looking-glass 0660 ${SHM_LOOKING_GLASS_OWNER} kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" + sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass else echo "> Not using Looking Glass..." fi @@ -308,11 +316,12 @@ fi if [ "$USE_SPICE" = true ]; then echo "> Using spice on port ${SPICE_PORT}..." - QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + #QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--channel" "spicevmc") + VIRT_INSTALL_PARAMS+=("--channel" "spicevmc,target.address=127.0.0.1:${SPICE_PORT}") + #VIRT_INSTALL_PARAMS+=("--graphics" "spice,port=${SPICE_PORT}") fi else echo "> Not using Spice..." @@ -431,8 +440,8 @@ sudo virsh destroy --domain WindowsVM &> /dev/null sudo virsh undefine --domain WindowsVM --nvram &> /dev/null if [ "$VM_START_MODE" = "qemu" ]; then - echo "> Starting the spice client..." - spicy -h localhost -p 5900 & + echo "> Starting the spice client @${SPICE_PORT}..." + spicy -h localhost -p "${SPICE_PORT}" & echo "> Starting the Virtual Machine using qemu..." sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -444,6 +453,9 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" fi +# Delete VM +sudo virsh destroy --domain WindowsVM &> /dev/null +sudo virsh undefine --domain WindowsVM --nvram &> /dev/null # This gets executed when the vm exits if [ "$DGPU_PASSTHROUGH" = true ]; then diff --git a/utils/Fedora/34/install-dependencies b/utils/Fedora/34/install-dependencies index 23e6a28..ce2c62b 100755 --- a/utils/Fedora/34/install-dependencies +++ b/utils/Fedora/34/install-dependencies @@ -3,7 +3,7 @@ echo "Updating software..." sudo dnf update -y echo "Installing some useful tools..." -sudo dnf install -y wget curl vim screen git crudini lshw msr-tools sysfsutils tunctl remmina samba spice-gtk-tools genisoimage uuid acpica-tools docker dumpet +sudo dnf install -y wget curl vim screen git crudini lshw msr-tools sysfsutils tunctl remmina samba spice-gtk-tools genisoimage uuid acpica-tools docker dumpet e2fsprogs-devel imake gcc-c++ echo "Installing virtualization software..." sudo dnf install -y qemu #@virtualization diff --git a/utils/Fedora/34/looking-glass-setup b/utils/Fedora/34/looking-glass-setup index 0e63fcd..d8f434f 100755 --- a/utils/Fedora/34/looking-glass-setup +++ b/utils/Fedora/34/looking-glass-setup @@ -12,7 +12,7 @@ cd "${PROJECT_DIR}/thirdparty" sudo dnf install -y binutils-devel cmake texlive-gnu-freefont fontconfig-devel SDL2-devel SDL2_ttf-devel spice-protocol libX11-devel nettle-devel wayland-protocols-devel gcc libXScrnSaver-devel libXfixes-devel libXi-devel wayland-devel mingw64-gcc-c++ mingw32-nsis -LOOKING_GLASS_VERSION="B3" +LOOKING_GLASS_VERSION="B4" # Build the (Linux) client application git clone --single-branch --branch "${LOOKING_GLASS_VERSION}" --depth 1 --recursive https://github.com/gnif/LookingGlass.git @@ -21,10 +21,8 @@ cd LookingGlass/client/build cmake ../ make -TMP_USER_NAME="$(logname)" -TMP_USER_ID="$(id -u "$TMP_USER_NAME")" sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" -sudo bash -c "echo 'f /dev/shm/looking-glass ${TMP_USER_ID} ${TMP_USER_NAME} kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" +sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" # Build the (Windows) host application cd "${PROJECT_DIR}/thirdparty" diff --git a/utils/Ubuntu/21.04/install-dependencies b/utils/Ubuntu/21.04/install-dependencies index f325f59..98eb2f5 100755 --- a/utils/Ubuntu/21.04/install-dependencies +++ b/utils/Ubuntu/21.04/install-dependencies @@ -3,7 +3,7 @@ echo "Updating software..." sudo apt upgrade -y echo "Installing some useful tools..." -sudo apt install -y wget curl vim screen git crudini lshw msr-tools sysfsutils uml-utilities remmina samba spice-client-gtk genisoimage uuid acpica-tools docker +sudo apt install -y wget curl vim screen git crudini lshw msr-tools sysfsutils uml-utilities remmina samba spice-client-gtk genisoimage uuid acpica-tools docker e2fsprogs imake g++ echo "Installing virtualization software..." sudo apt install qemu-kvm qemu-utils qemu-efi ovmf qemu -y diff --git a/utils/Ubuntu/21.04/looking-glass-setup b/utils/Ubuntu/21.04/looking-glass-setup index 7fe81e3..4552c0f 100755 --- a/utils/Ubuntu/21.04/looking-glass-setup +++ b/utils/Ubuntu/21.04/looking-glass-setup @@ -12,7 +12,7 @@ cd "${PROJECT_DIR}/thirdparty" sudo apt install binutils binutils-multiarch-dev cmake texlive-fonts-recommended fonts-freefont-ttf libfontconfig-dev libegl-dev libspice-protocol-dev libsdl2-dev nettle-dev libx11-dev libxi-dev libxinerama-dev libxss-dev libwayland-dev wayland-protocols -LOOKING_GLASS_VERSION="B3" +LOOKING_GLASS_VERSION="B4" # Build the (Linux) client application git clone --single-branch --branch "${LOOKING_GLASS_VERSION}" --depth 1 --recursive https://github.com/gnif/LookingGlass.git @@ -21,10 +21,8 @@ cd LookingGlass/client/build cmake ../ make -TMP_USER_NAME="$(logname)" -TMP_USER_ID="$(id -u "$TMP_USER_NAME")" sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" -sudo bash -c "echo 'f /dev/shm/looking-glass ${TMP_USER_ID} ${TMP_USER_NAME} kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" +sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" # Build the (Windows) host application cd "${PROJECT_DIR}/thirdparty" diff --git a/utils/schily-tools-setup b/utils/schily-tools-setup new file mode 100755 index 0000000..f2a338e --- /dev/null +++ b/utils/schily-tools-setup @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) +PROJECT_DIR="${SCRIPT_DIR}/.." +UTILS_DIR="${PROJECT_DIR}/utils" +DISTRO=$("${UTILS_DIR}/distro-info") +DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" + +mkdir -p "${PROJECT_DIR}/thirdparty" +cd "${PROJECT_DIR}/thirdparty" + +SCHILY_VERSION="2021-06-07" +SCHILY_ARCHIVE="schily-${SCHILY_VERSION}.tar.bz2" +SCHILY_DIR="${PROJECT_DIR}/thirdparty/schily-tools" +sudo rm -rf "${SCHILY_DIR}" +wget "https://altushost-swe.dl.sourceforge.net/project/schilytools/${SCHILY_ARCHIVE}" -O "${SCHILY_ARCHIVE}" +tar -xf "${SCHILY_ARCHIVE}" +rm "${SCHILY_ARCHIVE}" +mv "schily-${SCHILY_VERSION}" "${SCHILY_DIR}" +cd "${SCHILY_DIR}" +./Gmake.linux \ No newline at end of file From 72eff8b5457555f9479d64bc2b8305b1a6cdabcc Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Tue, 27 Jul 2021 18:41:08 +0200 Subject: [PATCH 05/40] First steps to switching to schily tools --- utils/make-windows-iso-auto-bootable | 52 +++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/utils/make-windows-iso-auto-bootable b/utils/make-windows-iso-auto-bootable index 9537ee9..1a51f28 100755 --- a/utils/make-windows-iso-auto-bootable +++ b/utils/make-windows-iso-auto-bootable @@ -11,12 +11,12 @@ TMP="./tmp" ISO_FILES="${TMP}/iso-files" ISO_MP="${TMP}/iso-mountpoint" -#rm -rf "${TMP}" -#mkdir -p "${ISO_FILES}" -#mkdir -p "${ISO_MP}" -#sudo mount -t udf "${WIN10_IMG}" "${ISO_MP}" -#sudo cp -Rva ${ISO_MP}/* "${ISO_FILES}" -#sudo umount "${ISO_MP}" +rm -rf "${TMP}" +mkdir -p "${ISO_FILES}" +mkdir -p "${ISO_MP}" +sudo mount -t udf "${WIN10_IMG}" "${ISO_MP}" +sudo cp -Rva ${ISO_MP}/* "${ISO_FILES}" +sudo umount "${ISO_MP}" # Make modifications to the Windows ISO #BOOT_DIR="${ISO_FILES}/efi/microsoft/boot" @@ -63,34 +63,38 @@ COPYRIGHT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Copyright file id: " | ABSTRACT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Abstract file id: " | cut -d ' ' -f4-)" BIBLIOGRAPHIC_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Bibliographic file id: " | cut -d ' ' -f4-)" -rm ".mkisofsrc" -echo "APPI=${APPLICATION_ID}" >> ".mkisofsrc" -echo "COPY=${COPYRIGHT_FILE_ID}" >> ".mkisofsrc" -echo "ABST=${ABSTRACT_FILE_ID}" >> ".mkisofsrc" -echo "BIBL=${BIBLIOGRAPHIC_FILE_ID}" >> ".mkisofsrc" -echo "PREP=${DATA_PREPARER_ID}" >> ".mkisofsrc" -echo "PUBL=${PUBLISHER_ID}" >> ".mkisofsrc" -echo "SYSI=${SYSTEM_ID}" >> ".mkisofsrc" -echo "VOLI=${VOLUME_ID}" >> ".mkisofsrc" -echo "VOLS=${VOLUME_SET_ID}" >> ".mkisofsrc" sudo rm "${WIN10_IMG}.tmp.iso" sudo mkisofs \ + -appid "${APPLICATION_ID}" \ + -copyright "${COPYRIGHT_FILE_ID}" \ + -abstract "${ABSTRACT_FILE_ID}" \ + -biblio "${BIBLIOGRAPHIC_FILE_ID}" \ + -preparer "${DATA_PREPARER_ID}" \ + -publisher "${PUBLISHER_ID}" \ + -sysid "${SYSTEM_ID}" \ + -volid "${VOLUME_ID}" \ + -volset "${VOLUME_SET_ID}" \ -no-emul-boot \ -b boot/etfsboot.com \ -boot-load-seg "${BOOT_LOAD_SEG}" \ -boot-load-size "${BOOT_LOAD_SIZE}" \ -eltorito-alt-boot \ - -e boot.efi.img \ -no-emul-boot \ - -iso-level 2 \ - -boot-info-table \ - -udf \ - -D \ - -N \ - -relaxed-filenames \ - -allow-lowercase \ + -b efi/win_efi_boot.img \ + -boot-load-size 1 \ + -iso-level 4 \ + -UDF \ -o "${WIN10_IMG}.tmp.iso" \ "${ISO_FILES}" + + #-e boot.efi.img \ + #-boot-info-table \ + #-D \ + #-N \ + #-relaxed-filenames \ + #-allow-lowercase \ + #-o "${WIN10_IMG}.tmp.iso" \ + #"${ISO_FILES}" rm ".mkisofsrc" echo "BOOT_LOAD_SEG: ${BOOT_LOAD_SEG}" From db834ef6abd94108482ea64e91465882736c77a7 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Wed, 28 Jul 2021 09:41:04 +0200 Subject: [PATCH 06/40] Fix make-windows-iso-auto-bootable --- .gitignore | 1 + .../make-windows-iso-auto-bootable | 47 ++++++++++++------- scripts/start-vm.sh | 1 - utils/Ubuntu/21.04/vbios-finder-installer | 3 -- 4 files changed, 32 insertions(+), 20 deletions(-) rename {utils => scripts}/make-windows-iso-auto-bootable (75%) diff --git a/.gitignore b/.gitignore index cdce5b1..524de09 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /helper-iso-files/bin /utils/nvflash_linux /helper-iso-files/drivers +/tmp .*.swp .*.swo *.asc diff --git a/utils/make-windows-iso-auto-bootable b/scripts/make-windows-iso-auto-bootable similarity index 75% rename from utils/make-windows-iso-auto-bootable rename to scripts/make-windows-iso-auto-bootable index 1a51f28..ec6e3e0 100755 --- a/utils/make-windows-iso-auto-bootable +++ b/scripts/make-windows-iso-auto-bootable @@ -1,5 +1,11 @@ #!/usr/bin/env bash +SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) +PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" +UTILS_DIR="${PROJECT_DIR}/utils" +DISTRO=$("${UTILS_DIR}/distro-info") +DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" + # WARNING: THIS SCRIPT DOES NOT WORK YET! # WARNING: THIS SCRIPT DOES NOT WORK YET! # WARNING: THIS SCRIPT DOES NOT WORK YET! @@ -11,7 +17,7 @@ TMP="./tmp" ISO_FILES="${TMP}/iso-files" ISO_MP="${TMP}/iso-mountpoint" -rm -rf "${TMP}" +sudo rm -rf "${TMP}" mkdir -p "${ISO_FILES}" mkdir -p "${ISO_MP}" sudo mount -t udf "${WIN10_IMG}" "${ISO_MP}" @@ -38,33 +44,41 @@ EFI_STARTING_SECTOR="$(dumpet -i "${WIN10_IMG}" | grep "Load LBA: " | grep -o "[ echo "EFI_STARTING_SECTOR: $EFI_STARTING_SECTOR" -dd if="${WIN10_IMG}" of="${ISO_FILES}/efi.dmp" bs=2048 count=1 skip="${EFI_STARTING_SECTOR}" +sudo dd if="${WIN10_IMG}" of="${ISO_FILES}/efi.dmp" bs=2048 count=1 skip="${EFI_STARTING_SECTOR}" EFI_BOOT_LOAD_SIZE="$(file "${ISO_FILES}/efi.dmp" | grep -oP 'sectors (\d+)' | cut -d ' ' -f2)" echo "EFI_BOOT_LOAD_SIZE: $EFI_BOOT_LOAD_SIZE" -rm -f "${ISO_FILES}/efi.dmp" -dd if="${WIN10_IMG}" of="${ISO_FILES}/boot_efi.img" bs=2048 count="${EFI_BOOT_LOAD_SIZE}" skip="${EFI_STARTING_SECTOR}" +sudo rm -f "${ISO_FILES}/efi.dmp" +sudo rm -f "${ISO_FILES}/efi/win_efi_boot.img" +sudo dd if="${WIN10_IMG}" of="${ISO_FILES}/efi/win_efi_boot.img" bs=2048 count="${EFI_BOOT_LOAD_SIZE}" skip="${EFI_STARTING_SECTOR}" + +sudo rm -rf "${ISO_FILES}/efi/microsoft/boot/cdboot.efi" +sudo mv "${ISO_FILES}/efi/microsoft/boot/cdboot_noprompt.efi" "${ISO_FILES}/efi/microsoft/boot/cdboot.efi" +sudo rm -rf "${ISO_FILES}/efi/microsoft/boot/efisys.bin" +sudo mv "${ISO_FILES}/efi/microsoft/boot/efisys_noprompt.bin" "${ISO_FILES}/efi/microsoft/boot/efisys.bin" + +#mkdir -p /tmp/bbb +#sudo mount -o loop,ro "${ISO_FILES}/boot_efi.img" /tmp/bbb +#sudo cp /tmp/bbb/EFI/BOOT/BOOTX64.EFI "${ISO_FILES}/boot.efi" -mkdir -p /tmp/bbb -sudo mount -o loop,ro "${ISO_FILES}/boot_efi.img" /tmp/bbb -sudo cp /tmp/bbb/EFI/BOOT/BOOTX64.EFI "${ISO_FILES}/boot.efi" #sudo umount /tmp/bbb #sudo rm -f "${ISO_FILES}/boot.efi.img" -exit + # Extract meta data : SYSTEM_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "System id: " | cut -d ' ' -f3-)" VOLUME_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Volume id: " | cut -d ' ' -f3-)" VOLUME_SET_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Volume set id: " | cut -d ' ' -f4-)" -#PUBLISHER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Publisher id: " | cut -d ' ' -f3-)" # Always uppercase -PUBLISHER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "ID '" | cut -d "'" -f2)" +PUBLISHER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Publisher id: " | cut -d ' ' -f3-)" # Always uppercase +ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "ID '" | cut -d "'" -f2)" DATA_PREPARER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Data preparer id: " | cut -d ' ' -f4-)" APPLICATION_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Application id: " | cut -d ' ' -f3-)" COPYRIGHT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Copyright file id: " | cut -d ' ' -f4-)" ABSTRACT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Abstract file id: " | cut -d ' ' -f4-)" BIBLIOGRAPHIC_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Bibliographic file id: " | cut -d ' ' -f4-)" -sudo rm "${WIN10_IMG}.tmp.iso" -sudo mkisofs \ + +sudo rm -f "${WIN10_IMG}.tmp.iso" +sudo "${PROJECT_DIR}/thirdparty/schily-tools/mkisofs/OBJ/x86_64-linux-gcc/mkisofs" \ -appid "${APPLICATION_ID}" \ -copyright "${COPYRIGHT_FILE_ID}" \ -abstract "${ABSTRACT_FILE_ID}" \ @@ -80,7 +94,7 @@ sudo mkisofs \ -boot-load-size "${BOOT_LOAD_SIZE}" \ -eltorito-alt-boot \ -no-emul-boot \ - -b efi/win_efi_boot.img \ + -eltorito-boot "efi/win_efi_boot.img" \ -boot-load-size 1 \ -iso-level 4 \ -UDF \ @@ -95,7 +109,7 @@ sudo mkisofs \ #-allow-lowercase \ #-o "${WIN10_IMG}.tmp.iso" \ #"${ISO_FILES}" -rm ".mkisofsrc" + echo "BOOT_LOAD_SEG: ${BOOT_LOAD_SEG}" echo "BOOT_LOAD_SIZE: ${BOOT_LOAD_SIZE}" @@ -104,6 +118,7 @@ echo "SYSTEM_ID: ${SYSTEM_ID}" echo "VOLUME_ID: ${VOLUME_ID}" echo "VOLUME_SET_ID: ${VOLUME_SET_ID}" echo "PUBLISHER_ID: ${PUBLISHER_ID}" +echo "ID: ${ID}" echo "DATA_PREPARER_ID: ${DATA_PREPARER_ID}" echo "APPLICATION_ID: ${APPLICATION_ID}" echo "COPYRIGHT_FILE_ID: ${COPYRIGHT_FILE_ID}" @@ -114,12 +129,12 @@ echo "BIBLIOGRAPHIC_FILE_ID: ${BIBLIOGRAPHIC_FILE_ID}" # Show difference between new and old image as reported by isoinfo echo echo "-------------- isoinfo diff -----------------" -diff <(isoinfo -d -i "${WIN10_IMG}") <(isoinfo -d -i "${WIN10_IMG}.tmp.iso") +colordiff <(isoinfo -d -i "${WIN10_IMG}") <(isoinfo -d -i "${WIN10_IMG}.tmp.iso") # Show difference between new and old image as reported by dumpet echo echo " -------------- dumpet diff -----------------" -diff <(dumpet -i "${WIN10_IMG}") <(dumpet -i "${WIN10_IMG}.tmp.iso") +colordiff <(dumpet -i "${WIN10_IMG}") <(dumpet -i "${WIN10_IMG}.tmp.iso") diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index 2be7087..08cd92f 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -129,7 +129,6 @@ VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") VIRT_INSTALL_PARAMS+=("--os-variant" "win10") VIRT_INSTALL_PARAMS+=("--arch=x86_64") VIRT_INSTALL_PARAMS+=("--unattended") -VIRT_INSTALL_PARAMS+=("--initrd-inject=/home/fedora/Projects/MobilePassThrough/autounattend-vfd-files/Autounattend.xml") if [[ ${DRIVE_IMG} == /dev/* ]]; then echo "> Using a physical OS drive..." diff --git a/utils/Ubuntu/21.04/vbios-finder-installer b/utils/Ubuntu/21.04/vbios-finder-installer index 7c25227..b148e42 100755 --- a/utils/Ubuntu/21.04/vbios-finder-installer +++ b/utils/Ubuntu/21.04/vbios-finder-installer @@ -6,8 +6,6 @@ UTILS_DIR="${PROJECT_DIR}/utils" DISTRO=$("${UTILS_DIR}/distro-info") DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" VM_FILES_DIR="${PROJECT_DIR}/vm-files" -="${PROJECT_DIR}/vm-files" -_DIR="${PROJECT_DIR}/vm-files" mkdir -p "${PROJECT_DIR}/thirdparty" cd "${PROJECT_DIR}/thirdparty" @@ -18,7 +16,6 @@ cd VBiosFinder sudo apt install ruby ruby-rubygems ruby-bundler ruby-dev p7zip innoextract upx -y - wget https://github.com/LongSoft/UEFITool/releases/download/A58/UEFIExtract_NE_A58_linux_x86_64.zip -O ./UEFIExtract.zip unzip ./UEFIExtract.zip -d ./3rdparty/ rm -f ./UEFIExtract.zip From e958d2ed327dbe3b2c389b0e3194b42bdf0f0819 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Fri, 30 Jul 2021 02:25:35 +0200 Subject: [PATCH 07/40] Improve Windows unattended install --- autounattend-vfd-files/Autounattend.xml | 176 +++++++++++++++++++--- scripts/start-vm.sh | 185 ++++++++++++++++-------- 2 files changed, 284 insertions(+), 77 deletions(-) diff --git a/autounattend-vfd-files/Autounattend.xml b/autounattend-vfd-files/Autounattend.xml index a94f529..5df6a70 100644 --- a/autounattend-vfd-files/Autounattend.xml +++ b/autounattend-vfd-files/Autounattend.xml @@ -1,17 +1,124 @@ <?xml version="1.0" encoding="utf-8"?> <unattend xmlns="urn:schemas-microsoft-com:unattend"> <settings pass="windowsPE"> + <component name="Microsoft-Windows-PnpCustomizationsWinPE" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" processorArchitecture="amd64" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"> + <!-- + This makes the VirtIO drivers available to Windows, assuming that + the VirtIO driver disk at https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso + (see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html#virtio-win-direct-downloads) + is available as drive E: + --> + <DriverPaths> + <PathAndCredentials wcm:action="add" wcm:keyValue="2"> + <Path>D:\viostor\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="3"> + <Path>D:\NetKVM\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="4"> + <Path>D:\Balloon\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="5"> + <Path>D:\pvpanic\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="6"> + <Path>D:\qemupciserial\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="7"> + <Path>D:\qxldod\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="8"> + <Path>D:\vioinput\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="9"> + <Path>D:\viorng\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="10"> + <Path>D:\vioscsi\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="11"> + <Path>D:\vioserial\w10\amd64</Path> + </PathAndCredentials> + + <PathAndCredentials wcm:action="add" wcm:keyValue="12"> + <Path>D:\vioserial\w10\amd64</Path> + </PathAndCredentials> + </DriverPaths> + </component> <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <SetupUILanguage> - <UILanguage>en-US</UILanguage> - </SetupUILanguage> - <InputLocale>0c09:00000409</InputLocale> - <SystemLocale>en-US</SystemLocale> - <UILanguage>en-US</UILanguage> - <UILanguageFallback>en-US</UILanguageFallback> - <UserLocale>en-US</UserLocale> + <SetupUILanguage> + <UILanguage>en-GB</UILanguage> + </SetupUILanguage> + <InputLocale>en-GB</InputLocale> + <SystemLocale>en-GB</SystemLocale> + <UILanguage>en-GB</UILanguage> + <UILanguageFallback>en-GB</UILanguageFallback> + <UserLocale>en-GB</UserLocale> </component> <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <DiskConfiguration> + <Disk wcm:action="add"> + <DiskID>0</DiskID> + <WillWipeDisk>true</WillWipeDisk> + <CreatePartitions> + <CreatePartition wcm:action="add"> + <Order>1</Order> + <Type>EFI</Type> + <Size>100</Size> + </CreatePartition> + <CreatePartition wcm:action="add"> + <Order>2</Order> + <Type>MSR</Type> + <Size>4096</Size> + </CreatePartition> + <CreatePartition wcm:action="add"> + <Order>3</Order> + <Type>Primary</Type> + <Extend>true</Extend> + </CreatePartition> + </CreatePartitions> + <ModifyPartitions> + <ModifyPartition wcm:action="add"> + <Order>1</Order> + <PartitionID>1</PartitionID> + <Label>System</Label> + <Format>FAT32</Format> + </ModifyPartition> + <ModifyPartition wcm:action="add"> + <Order>2</Order> + <PartitionID>3</PartitionID> + <Label>Windows</Label> + <Letter>C</Letter> + <Format>NTFS</Format> + </ModifyPartition> + </ModifyPartitions> + </Disk> + <WillShowUI>OnError</WillShowUI> + </DiskConfiguration> + <ImageInstall> + <OSImage> + <WillShowUI>OnError</WillShowUI> + <InstallFrom> + <MetaData wcm:action="add"> + <Key>/IMAGE/NAME</Key> + <Value>Windows 10 Pro</Value> + </MetaData> + </InstallFrom> + <InstallTo> + <DiskID>0</DiskID> + <PartitionID>3</PartitionID> + </InstallTo> + </OSImage> + </ImageInstall> <UserData> <AcceptEula>true</AcceptEula> <FullName></FullName> @@ -40,18 +147,22 @@ </component> </settings> <settings pass="specialize"> - <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <InputLocale>0409:00000409</InputLocale> - <SystemLocale>en-US</SystemLocale> - <UILanguage>en-US</UILanguage> - <UILanguageFallback>en-US</UILanguageFallback> - <UserLocale>en-US</UserLocale> - </component> <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SkipAutoActivation>true</SkipAutoActivation> </component> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <ComputerName>GPU-PASSTHROUGH-VM</ComputerName> + <ComputerName>MBPT</ComputerName> + </component> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon> + </component> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <!-- Disable IE ESC. --> + <IEHardenAdmin>false</IEHardenAdmin> + <IEHardenUser>false</IEHardenUser> + </component> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon> </component> </settings> <settings pass="oobeSystem"> @@ -82,7 +193,38 @@ <SkipMachineOOBE>true</SkipMachineOOBE> <SkipUserOOBE>true</SkipUserOOBE> </OOBE> - <TimeZone>Central European Standard Time</TimeZone> + <TimeZone>UTC</TimeZone> + <FirstLogonCommands> + <!--<SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> + <Description>Set Execution Policy 64 Bit</Description> + <Order>1</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> + <Description>Set Execution Policy 32 Bit</Description> + <Order>2</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>powershell -NoLogo -ExecutionPolicy RemoteSigned -File a:\base_setup.ps1</CommandLine> + <Description>Configure WinRM so packer can connect to run Chef</Description> + <Order>3</Order> + <RequiresUserInput>false</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c wmic useraccount where "name='vagrant'" set PasswordExpires=FALSE</CommandLine> + <Order>4</Order> + <Description>Disable password expiration for vagrant user</Description> + </SynchronousCommand>--> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe E:\start.bat"</CommandLine> + <Description>Set Execution Policy 64 Bit</Description> + <Order>1</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + </FirstLogonCommands> </component> </settings> <cpi:offlineImage cpi:source="" xmlns:cpi="urn:schemas-microsoft-com:cpi" /> diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index 08cd92f..e6151a8 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -82,12 +82,6 @@ QEMU_PARAMS+=("-boot" "menu=on") QEMU_PARAMS+=("-boot" "order=d") QEMU_PARAMS+=("-k" "en-us") -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") -fi - if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-drive" "file=${VIRTIO_WIN_IMG},index=2,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -106,11 +100,11 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") fi -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-fda" "${VIRTIO_WIN_VFD}") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${VIRTIO_WIN_VFD}") -fi +#if [ "$VM_START_MODE" = "qemu" ]; then +# QEMU_PARAMS+=("-fda" "${VIRTIO_WIN_VFD}") +#elif [ "$VM_START_MODE" = "virt-install" ]; then +# VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${VIRTIO_WIN_VFD}") +#fi if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-fdb" "${AUTOUNATTEND_WIN_VFD}") @@ -128,7 +122,7 @@ QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") VIRT_INSTALL_PARAMS+=("--os-variant" "win10") VIRT_INSTALL_PARAMS+=("--arch=x86_64") -VIRT_INSTALL_PARAMS+=("--unattended") +#VIRT_INSTALL_PARAMS+=("--unattended") if [[ ${DRIVE_IMG} == /dev/* ]]; then echo "> Using a physical OS drive..." @@ -156,6 +150,15 @@ else exit fi +echo "Generating vFloppy for auto Widnows Installation..." +sudo ${SCRIPT_DIR}/generate-auto-unattended-vfd.sh +# TODO: add check if files have changed and vfd needs to be regenerated + +echo "Generating helper-iso for auto Windows Configuration / Driver installation..." +sudo ${SCRIPT_DIR}/generate-helper-iso.sh +# TODO: add check if files have changed and helper iso needs to be regenerated + + if [ ! -f "${OVMF_VARS_VM}" ]; then echo "> Creating OVMF_VARS copy for this VM..." sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" @@ -222,26 +225,11 @@ if [ "$USE_LOOKING_GLASS" = true ]; then sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" sudo bash -c "echo 'f /dev/shm/looking-glass 0660 ${SHM_LOOKING_GLASS_OWNER} kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass + sudo setfacl --modify user:$(logname):rw "/dev/shm/looking-glass" else echo "> Not using Looking Glass..." fi -if [ -z "$DGPU_ROM" ]; then - echo "> Not using DGPU vBIOS override..." - DGPU_ROM_PARAM=",rombar=0" -else - echo "> Using DGPU vBIOS override..." - DGPU_ROM_PARAM=",romfile=${DGPU_ROM}" -fi - -if [ -z "$IGPU_ROM" ]; then - echo "> Not using DGPU vBIOS override..." - IGPU_ROM_PARAM=",rombar=0" -else - echo "> Using DGPU vBIOS override..." - IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" -fi - if [ -z "$SMB_SHARE_FOLDER" ]; then echo "> Not using SMB share..." else @@ -258,19 +246,35 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1") # DGPU root port + QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=pci.1") # DGPU root port elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port" "--xml xpath.set=./devices/controller/model/@name=ioh3420") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> + VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port,address.type=pci,address.bus=0x0,address.slot=0x1c,address.function=0x0,address.multifunction=on,index=1,alias.name=pci.1") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/model/@name=ioh3420") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/target/@chassis=1") fi - # TODO: when the VM boots, check what chassis and slot libvirt allocates. Then plug that into the vfio-pci line. - QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=root.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") - - #if [ "$VM_START_MODE" = "qemu" ]; then - # QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=root.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") - #elif [ "$VM_START_MODE" = "virt-install" ]; then - # VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.type=pci,address.multifunction=on,address") # TODO: not complete; i.e. rom file param missing - #fi + if [ "$VM_START_MODE" = "qemu" ]; then + if [ -z "$DGPU_ROM" ]; then + echo "> Not using DGPU vBIOS override..." + DGPU_ROM_PARAM=",rombar=0" + else + echo "> Using DGPU vBIOS override..." + DGPU_ROM_PARAM=",romfile=${DGPU_ROM}" + fi + QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=pci.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ -z "$DGPU_ROM" ]; then + echo "> Not using DGPU vBIOS override..." + DGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.bus=1,address.type=pci,address.multifunction=on${DGPU_ROM_PARAM}") + if [ ! -z "$DGPU_ROM" ]; then + echo "> Using DGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev/rom/@file=${DGPU_ROM}") + QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-device-id=$((16#${DGPU_SS_DEVICE_ID}))") + QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-vendor-id=$((16#${DGPU_SS_VENDOR_ID}))") + fi + fi else echo "> Not using dGPU passthrough..." fi @@ -291,24 +295,52 @@ if [ "$SHARE_IGPU" = true ]; then exit 1 fi fi - - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - GVTG_DISPLAY_STATE="on" - else - echo "> Not using dma-buf..." - GVTG_DISPLAY_STATE="off" - fi - - QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=02.0,sysfsdev=/sys/bus/pci/devices/0000:${IGPU_PCI_ADDRESS}/${VGPU_UUID},x-igd-opregion=on${IGPU_ROM_PARAM},display=${GVTG_DISPLAY_STATE}") # GVT-G # TODO: same as for iGPU - #if [ "$VM_START_MODE" = "qemu" ]; then - # QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=02.0,sysfsdev=/sys/bus/pci/devices/0000:${IGPU_PCI_ADDRESS}/${VGPU_UUID},x-igd-opregion=on${IGPU_ROM_PARAM},display=${GVTG_DISPLAY_STATE}") # GVT-G - #elif [ "$VM_START_MODE" = "virt-install" ]; then - # VIRT_INSTALL_PARAMS+=("--hostdev" "") - #fi + if [ "$VM_START_MODE" = "qemu" ]; then + + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + DMA_BUF_PARAM=",display=on,x-igd-opregion=on" + else + echo "> Not using dma-buf..." + DMA_BUF_PARAM="" + fi + + if [ -z "$IGPU_ROM" ]; then + echo "> Not using IGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + else + echo "> Using IGPU vBIOS override..." + IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" + fi + + QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") + GVTG_DISPLAY_STATE="on" + else + echo "> Not using dma-buf..." + GVTG_DISPLAY_STATE="off" + fi + + if [ -z "$IGPU_ROM" ]; then + echo "> Not using IGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") + + if [ ! -z "$IGPU_ROM" ]; then + echo "> Using IGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + fi + fi else echo "> Not using mediated iGPU passthrough..." fi @@ -434,29 +466,62 @@ give_qemu_access "${INSTALL_IMG}" #sudo bash -c "echo 'user = root' >> /etc/libvirt/qemu.conf" #sudo systemctl restart libvirtd -# Delete VM -sudo virsh destroy --domain WindowsVM &> /dev/null -sudo virsh undefine --domain WindowsVM --nvram &> /dev/null if [ "$VM_START_MODE" = "qemu" ]; then echo "> Starting the spice client @${SPICE_PORT}..." spicy -h localhost -p "${SPICE_PORT}" & echo "> Starting the Virtual Machine using qemu..." + echo "" + + printf "sudo qemu-system-x86_64" + for param in "${QEMU_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" elif [ "$VM_START_MODE" = "virt-install" ]; then + # Delete VM + sudo virsh destroy --domain WindowsVM &> /dev/null + sudo virsh undefine --domain WindowsVM --nvram &> /dev/null echo "> Starting the Virtual Machine using virt-install..." + #VIRT_INSTALL_PARAMS+=("--debug") for param in "${QEMU_PARAMS[@]}"; do VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") done + + echo "" + + printf "sudo virt-install" + for param in "${VIRT_INSTALL_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + + # Delete VM + sudo virsh destroy --domain WindowsVM &> /dev/null + sudo virsh undefine --domain WindowsVM --nvram &> /dev/null fi -# Delete VM -sudo virsh destroy --domain WindowsVM &> /dev/null -sudo virsh undefine --domain WindowsVM --nvram &> /dev/null # This gets executed when the vm exits + if [ "$DGPU_PASSTHROUGH" = true ]; then echo "> Unbinding dGPU from vfio driver..." driver unbind "${DGPU_PCI_ADDRESS}" From 3e35715cd06ae8f6f6c51f3ed58da892e67ec193 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Mon, 2 Aug 2021 13:01:01 +0200 Subject: [PATCH 08/40] Improve Windows unattended install --- .../Autounattend.xml | 69 +- helper-iso-files/RedHat.cer | Bin 0 -> 1290 bytes .../{start.bat => mbpt-helper.bat} | 16 +- .../scripts/chcolatey-install.ps1 | 698 ++++++++++++++++++ helper-iso-files/scripts/gpu-check.ps1 | 48 ++ helper-iso-files/scripts/network-check.ps1 | 55 ++ mbpt.sh | 12 +- ...erate-autounattend-vfd.sh => delete-vm.sh} | 19 +- scripts/generate-helper-iso.sh | 13 +- scripts/iommu-check.sh | 38 + scripts/make-windows-iso-auto-bootable | 8 +- scripts/setup.sh | 123 ++- scripts/start-vm.sh | 179 ++--- utils/Fedora/34/amd-setup | 0 utils/Fedora/34/intel-setup | 8 +- utils/Fedora/34/kernel-param-utils | 5 + utils/Ubuntu/21.04/kernel-param-utils | 5 + utils/lsiommu | 7 +- 18 files changed, 1135 insertions(+), 168 deletions(-) rename {autounattend-vfd-files => helper-iso-files}/Autounattend.xml (78%) create mode 100644 helper-iso-files/RedHat.cer rename helper-iso-files/{start.bat => mbpt-helper.bat} (71%) create mode 100644 helper-iso-files/scripts/chcolatey-install.ps1 create mode 100644 helper-iso-files/scripts/gpu-check.ps1 create mode 100644 helper-iso-files/scripts/network-check.ps1 rename scripts/{generate-autounattend-vfd.sh => delete-vm.sh} (58%) mode change 100755 => 100644 create mode 100755 scripts/iommu-check.sh mode change 100644 => 100755 utils/Fedora/34/amd-setup diff --git a/autounattend-vfd-files/Autounattend.xml b/helper-iso-files/Autounattend.xml similarity index 78% rename from autounattend-vfd-files/Autounattend.xml rename to helper-iso-files/Autounattend.xml index 5df6a70..29a5ef2 100644 --- a/autounattend-vfd-files/Autounattend.xml +++ b/helper-iso-files/Autounattend.xml @@ -10,47 +10,47 @@ --> <DriverPaths> <PathAndCredentials wcm:action="add" wcm:keyValue="2"> - <Path>D:\viostor\w10\amd64</Path> + <Path>E:\viostor\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="3"> - <Path>D:\NetKVM\w10\amd64</Path> + <Path>E:\NetKVM\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="4"> - <Path>D:\Balloon\w10\amd64</Path> + <Path>E:\Balloon\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="5"> - <Path>D:\pvpanic\w10\amd64</Path> + <Path>E:\pvpanic\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="6"> - <Path>D:\qemupciserial\w10\amd64</Path> + <Path>E:\qemupciserial\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="7"> - <Path>D:\qxldod\w10\amd64</Path> + <Path>E:\qxldod\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="8"> - <Path>D:\vioinput\w10\amd64</Path> + <Path>E:\vioinput\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="9"> - <Path>D:\viorng\w10\amd64</Path> + <Path>E:\viorng\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="10"> - <Path>D:\vioscsi\w10\amd64</Path> + <Path>E:\vioscsi\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="11"> - <Path>D:\vioserial\w10\amd64</Path> + <Path>E:\vioserial\w10\amd64</Path> </PathAndCredentials> <PathAndCredentials wcm:action="add" wcm:keyValue="12"> - <Path>D:\vioserial\w10\amd64</Path> + <Path>E:\vioserial\w10\amd64</Path> </PathAndCredentials> </DriverPaths> </component> @@ -146,25 +146,32 @@ <SkipRearm>1</SkipRearm> </component> </settings> - <settings pass="specialize"> + <!--<settings pass="specialize"> + <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <InputLocale>en-GB</InputLocale> + <SystemLocale>en-GB</SystemLocale> + <UILanguage>en-GB</UILanguage> + <UILanguageFallback>en-GB</UILanguageFallback> + <UserLocale>en-GB</UserLocale> + </component> <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SkipAutoActivation>true</SkipAutoActivation> </component> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <ComputerName>MBPT</ComputerName> + <ComputerName>GPU-PASSTHROUGH-VM</ComputerName> </component> <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon> </component> <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> - <!-- Disable IE ESC. --> + <IEHardenAdmin>false</IEHardenAdmin> <IEHardenUser>false</IEHardenUser> </component> <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon> </component> - </settings> + </settings>--> <settings pass="oobeSystem"> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <UserAccounts> @@ -195,34 +202,34 @@ </OOBE> <TimeZone>UTC</TimeZone> <FirstLogonCommands> - <!--<SynchronousCommand wcm:action="add"> - <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> - <Description>Set Execution Policy 64 Bit</Description> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE</CommandLine> <Order>1</Order> - <RequiresUserInput>true</RequiresUserInput> + <Description>Disable password expiration for Administrator user</Description> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> - <Description>Set Execution Policy 32 Bit</Description> + <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\mbpt-helper.bat cmd /c %i:\mbpt-helper.bat"</CommandLine> + <Description>Install drivers, change some settings and install Looking Glass</Description> <Order>2</Order> - <RequiresUserInput>true</RequiresUserInput> + <RequiresUserInput>false</RequiresUserInput> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>powershell -NoLogo -ExecutionPolicy RemoteSigned -File a:\base_setup.ps1</CommandLine> - <Description>Configure WinRM so packer can connect to run Chef</Description> <Order>3</Order> + <Description>Set-ExecutionPolicy Unrestricted</Description> <RequiresUserInput>false</RequiresUserInput> + <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy Unrestricted"</CommandLine> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>cmd.exe /c wmic useraccount where "name='vagrant'" set PasswordExpires=FALSE</CommandLine> <Order>4</Order> - <Description>Disable password expiration for vagrant user</Description> - </SynchronousCommand>--> + <RequiresUserInput>false</RequiresUserInput> + <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\network-check.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\network-check.ps1"</CommandLine> + <Description>Wait for a Network connection and install Chocolatey if possible</Description> + </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>cmd.exe E:\start.bat"</CommandLine> - <Description>Set Execution Policy 64 Bit</Description> - <Order>1</Order> - <RequiresUserInput>true</RequiresUserInput> + <Order>5</Order> + <RequiresUserInput>false</RequiresUserInput> + <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\gpu-check.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\gpu-check.ps1"</CommandLine> + <Description>Check for GPU Errors and install drivers if possible and necessary</Description> </SynchronousCommand> </FirstLogonCommands> </component> diff --git a/helper-iso-files/RedHat.cer b/helper-iso-files/RedHat.cer new file mode 100644 index 0000000000000000000000000000000000000000..91c8be6b271419233f8b59f5a1a56462a67e33a6 GIT binary patch literal 1290 zcmXqLVr4UEVt%)PnTe5!Ng(XlrS!EA>WkiONwD7Ea&D;sFB_*;n@8JsUPeY%RtAH{ zEr#3%oNUaYENsF|p}~gY2BIJimoQ&gYEfozW_q5Ef@fZ`o}s*fEJ%V|SPUki5K>fH zT%zEYT2h{0lx=8jU<pxR6p~t$Tda_urchd(s*qTskWo@nP;8~IUtV6WR|Yh-7-*_q za(=FUQ9+`DMzW@%fuWv(4oEYzuqxbi=bXgiVg+Lb=lqmZ1&~8B^U@WJ3=9nvoE;71 z#CZ+P42%se48R}?$h9yuGO{!>HnlXhj55f;>MIUmKEM2;k_-js#G?G1%)CTH0Ruje zz3js5L5Vr3ndupZVg@205iSwlpwtuvkHiwF|Doc{XyOJ<j7rF1%E-#V+{DPw02Jq9 zYGPz$IAHGC<xy~n<=m=GS3W1rvM$dJGu3*ex5t2Svb>_E<F0k_VZ8Gm<sRKtU(VIE zH(KL?oYi3=zITiM#2kF1E&J{Lt-qZN9!wmE`?bC){Lo$*t@XX`_VP|n*CL&AvFWBM zD;imgKCIrmYF6+!)%b7Aw`|=cllIo?%3Slp_~cpnd(EyL{m-u=+GbsO^^2<a6=SaZ zEX(h1@y&BNz3sY3V0%Jm{i=@~w~fCRN!vYVzN#<rR$VmZrt2*w%_M6XUa{F*9!D2W zI?nK5LD)CeY0NxVme!kSre#0Zx=~-tbC#cbS&NPJ)`&T~zu5?H@NUU56mjdnES4*9 z<>mah@fU6UkIgxK+n9-&k%4h>6JsneL?Xc{O;(tN$$$YI@Ur}jjQ?3!n3>oc477p4 zE-TNXVxVN8ut08sOq&!a-2jtKahhInWo~j3ILQDx$wfH^i6F%aEKvp#24QS$>5V*$ zEQ|&|2Fh$4+HAmd&CbLqCJsw>DM;Fr3yKX?;fk0HBzdqZ113xZVUQK7EIbBWF!jvL z2H`L^BO{Bqfv15yjBmi$CXDLd6p(uj)Zhx3@OY>MXb{jgWflnou?CUzGgrQ<R{P?8 zvakR82UfNBk1s8s3(kGAd@N!tBKyC8i7PTOb?)4I@UEx1^3juCd!mq&ATV14lOQ9* zwXI9H@UHrE>#jqo+EN?WH|-kg`{b=%kMFW8Hv7Ngf0vaR-x}E|6MTD`r#$ir7Mrgu zv|ht_%H7AOO71@B-Qc_Z*tXPXE0!JO?x?An*CEzj$+<Cg^<|mQKCjn3bxb}`YdBqI z+ILrzADgrciV_zdXDT;I{?c%%$)<G6ciBTFhn*C}Zyff!Q@o<~XXLh|lY5P%mWN4S zw6br=l3uv?%U^A0&hjD|p&8fHxAnyD7u|mU{Te0__k*0z+t?bpS^wlalv`WX9Y1n- za`xmSCCi>qG$;u+)Oz9jR+RDW@_kQ5UTyWb@3rTr#|3Wb{e8OiY87kET#YRLG(BE( O`j`9hM9rt=M@<2BI=p@W literal 0 HcmV?d00001 diff --git a/helper-iso-files/start.bat b/helper-iso-files/mbpt-helper.bat similarity index 71% rename from helper-iso-files/start.bat rename to helper-iso-files/mbpt-helper.bat index f37f2c8..d60e21f 100644 --- a/helper-iso-files/start.bat +++ b/helper-iso-files/mbpt-helper.bat @@ -12,20 +12,22 @@ echo "MobilePassThrough Helper, Register Looking Glass as a startup application. reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "LookingGlass" /t REG_SZ /f /d "%ProgramFiles%\Looking Glass (host)\looking-glass-host.exe -f" echo "Install vfio drivers..." +certutil -addstore "TrustedPublisher" .\RedHat.cer %WINDIR%\system32\pnputil.exe /add-driver .\bin\virtio-drivers\Win10\amd64\*.inf /subdirs /install -echo "Set static IP for vfio network device..." +::echo "Set static IP for vfio network device..." :: TODO: Find the correct network adapter name -netsh int ip set address "Ethernet" static 192.168.99.2 255.255.255.0 192.168.99.1 1 -netsh int ip set dns "Ethernet" static 192.168.99.1 primary +::netsh int ip set address "Ethernet" static 192.168.99.2 255.255.255.0 192.168.99.1 1 +::netsh int ip set dns "Ethernet" static 192.168.99.1 primary :: netsh int ip set address "Local Area Connection" static 192.168.99.2 255.255.255.0 192.168.99.1 1 :: netsh int ip set dns "Local Area Connection" static 192.168.99.1 primary -:: echo "Change the virtual Ethernet adapter to a private one to allow RDP access..." -:: powershell -command Set-NetConnectionProfile -Name "Network" -NetworkCategory Private +::echo "Waiting for 5 seconds..." +::timeout /t 5 /nobreak > nul + +echo "Change the virtual Ethernet adapter to a private one to allow RDP access..." +powershell -command Set-NetConnectionProfile -Name "Network" -NetworkCategory Private echo "Enable remote desktop..." reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f netsh advfirewall firewall set rule group="remote desktop" new enable=Yes - -pause diff --git a/helper-iso-files/scripts/chcolatey-install.ps1 b/helper-iso-files/scripts/chcolatey-install.ps1 new file mode 100644 index 0000000..34c9908 --- /dev/null +++ b/helper-iso-files/scripts/chcolatey-install.ps1 @@ -0,0 +1,698 @@ +<# + .SYNOPSIS + Downloads and installs Chocolatey on the local machine. + + .DESCRIPTION + Retrieves the Chocolatey nupkg for the latest or a specified version, and + downloads and installs the application to the local machine. + + .NOTES + ===================================================================== + Copyright 2017 - 2020 Chocolatey Software, Inc, and the + original authors/contributors from ChocolateyGallery + Copyright 2011 - 2017 RealDimensions Software, LLC, and the + original authors/contributors from ChocolateyGallery + at https://github.com/chocolatey/chocolatey.org + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ===================================================================== + + Environment Variables, specified as $env:NAME in PowerShell.exe and %NAME% in cmd.exe. + For explicit proxy, please set $env:chocolateyProxyLocation and optionally $env:chocolateyProxyUser and $env:chocolateyProxyPassword + For an explicit version of Chocolatey, please set $env:chocolateyVersion = 'versionnumber' + To target a different url for chocolatey.nupkg, please set $env:chocolateyDownloadUrl = 'full url to nupkg file' + NOTE: $env:chocolateyDownloadUrl does not work with $env:chocolateyVersion. + To use built-in compression instead of 7zip (requires additional download), please set $env:chocolateyUseWindowsCompression = 'true' + To bypass the use of any proxy, please set $env:chocolateyIgnoreProxy = 'true' + + .LINK + For organizational deployments of Chocolatey, please see https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide + +#> +[CmdletBinding(DefaultParameterSetName = 'Default')] +param( + # The URL to download Chocolatey from. This defaults to the value of + # $env:chocolateyDownloadUrl, if it is set, and otherwise falls back to the + # official Chocolatey community repository to download the Chocolatey package. + [Parameter(Mandatory = $false)] + [string] + $ChocolateyDownloadUrl = $env:chocolateyDownloadUrl, + + # Specifies a target version of Chocolatey to install. By default, the latest + # stable version is installed. This will use the value in + # $env:chocolateyVersion by default, if that environment variable is present. + # This parameter is ignored if -ChocolateyDownloadUrl is set. + [Parameter(Mandatory = $false)] + [string] + $ChocolateyVersion = $env:chocolateyVersion, + + # If set, uses built-in Windows decompression tools instead of 7zip when + # unpacking the downloaded nupkg. This will be set by default if + # $env:chocolateyUseWindowsCompression is set to a value other than 'false' or '0'. + # + # This parameter will be ignored in PS 5+ in favour of using the + # Expand-Archive built in PowerShell cmdlet directly. + [Parameter(Mandatory = $false)] + [switch] + $UseNativeUnzip = $( + $envVar = "$env:chocolateyUseWindowsCompression".Trim() + $value = $null + if ([bool]::TryParse($envVar, [ref] $value)) { + $value + } elseif ([int]::TryParse($envVar, [ref] $value)) { + [bool]$value + } else { + [bool]$envVar + } + ), + + # If set, ignores any configured proxy. This will override any proxy + # environment variables or parameters. This will be set by default if + # $env:chocolateyIgnoreProxy is set to a value other than 'false' or '0'. + [Parameter(Mandatory = $false)] + [switch] + $IgnoreProxy = $( + $envVar = "$env:chocolateyIgnoreProxy".Trim() + $value = $null + if ([bool]::TryParse($envVar, [ref] $value)) { + $value + } + elseif ([int]::TryParse($envVar, [ref] $value)) { + [bool]$value + } + else { + [bool]$envVar + } + ), + + # Specifies the proxy URL to use during the download. This will default to + # the value of $env:chocolateyProxyLocation, if any is set. + [Parameter(ParameterSetName = 'Proxy', Mandatory = $false)] + [string] + $ProxyUrl = $env:chocolateyProxyLocation, + + # Specifies the credential to use for an authenticated proxy. By default, a + # proxy credential will be constructed from the $env:chocolateyProxyUser and + # $env:chocolateyProxyPassword environment variables, if both are set. + [Parameter(ParameterSetName = 'Proxy', Mandatory = $false)] + [System.Management.Automation.PSCredential] + $ProxyCredential +) + +#region Functions + +function Get-Downloader { + <# + .SYNOPSIS + Gets a System.Net.WebClient that respects relevant proxies to be used for + downloading data. + + .DESCRIPTION + Retrieves a WebClient object that is pre-configured according to specified + environment variables for any proxy and authentication for the proxy. + Proxy information may be omitted if the target URL is considered to be + bypassed by the proxy (originates from the local network.) + + .PARAMETER Url + Target URL that the WebClient will be querying. This URL is not queried by + the function, it is only a reference to determine if a proxy is needed. + + .EXAMPLE + Get-Downloader -Url $fileUrl + + Verifies whether any proxy configuration is needed, and/or whether $fileUrl + is a URL that would need to bypass the proxy, and then outputs the + already-configured WebClient object. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory = $false)] + [string] + $Url, + + [Parameter(Mandatory = $false)] + [string] + $ProxyUrl, + + [Parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $ProxyCredential + ) + + $downloader = New-Object System.Net.WebClient + + $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials + if ($defaultCreds) { + $downloader.Credentials = $defaultCreds + } + + if ($ProxyUrl) { + # Use explicitly set proxy. + Write-Host "Using explicit proxy server '$ProxyUrl'." + $proxy = New-Object System.Net.WebProxy -ArgumentList $ProxyUrl, <# bypassOnLocal: #> $true + + $proxy.Credentials = if ($ProxyCredential) { + $ProxyCredential.GetNetworkCredential() + } elseif ($defaultCreds) { + $defaultCreds + } else { + Write-Warning "Default credentials were null, and no explicitly set proxy credentials were found. Attempting backup method." + (Get-Credential).GetNetworkCredential() + } + + if (-not $proxy.IsBypassed($Url)) { + $downloader.Proxy = $proxy + } + } else { + Write-Host "Not using proxy." + } + + $downloader +} + +function Request-String { + <# + .SYNOPSIS + Downloads content from a remote server as a string. + + .DESCRIPTION + Downloads target string content from a URL and outputs the resulting string. + Any existing proxy that may be in use will be utilised. + + .PARAMETER Url + URL to download string data from. + + .PARAMETER ProxyConfiguration + A hashtable containing proxy parameters (ProxyUrl and ProxyCredential) + + .EXAMPLE + Request-String https://community.chocolatey.org/install.ps1 + + Retrieves the contents of the string data at the targeted URL and outputs + it to the pipeline. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string] + $Url, + + [Parameter(Mandatory = $false)] + [hashtable] + $ProxyConfiguration + ) + + (Get-Downloader $url @ProxyConfiguration).DownloadString($url) +} + +function Request-File { + <# + .SYNOPSIS + Downloads a file from a given URL. + + .DESCRIPTION + Downloads a target file from a URL to the specified local path. + Any existing proxy that may be in use will be utilised. + + .PARAMETER Url + URL of the file to download from the remote host. + + .PARAMETER File + Local path for the file to be downloaded to. + + .PARAMETER ProxyConfiguration + A hashtable containing proxy parameters (ProxyUrl and ProxyCredential) + + .EXAMPLE + Request-File -Url https://community.chocolatey.org/install.ps1 -File $targetFile + + Downloads the install.ps1 script to the path specified in $targetFile. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory = $false)] + [string] + $Url, + + [Parameter(Mandatory = $false)] + [string] + $File, + + [Parameter(Mandatory = $false)] + [hashtable] + $ProxyConfiguration + ) + + Write-Host "Downloading $url to $file" + (Get-Downloader $url @ProxyConfiguration).DownloadFile($url, $file) +} + +function Set-PSConsoleWriter { + <# + .SYNOPSIS + Workaround for a bug in output stream handling PS v2 or v3. + + .DESCRIPTION + PowerShell v2/3 caches the output stream. Then it throws errors due to the + FileStream not being what is expected. Fixes "The OS handle's position is + not what FileStream expected. Do not use a handle simultaneously in one + FileStream and in Win32 code or another FileStream." error. + + .EXAMPLE + Set-PSConsoleWriter + + .NOTES + General notes + #> + + [CmdletBinding()] + param() + if ($PSVersionTable.PSVersion.Major -gt 3) { + return + } + + try { + # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) + + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" + $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) + [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) + + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) + $field.SetValue($consoleHost, [Console]::Out) + + [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) + $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) + $field2.SetValue($consoleHost, [Console]::Error) + } catch { + Write-Warning "Unable to apply redirection fix." + } +} + +function Test-ChocolateyInstalled { + [CmdletBinding()] + param() + + $checkPath = if ($env:ChocolateyInstall) { $env:ChocolateyInstall } else { "$env:PROGRAMDATA\chocolatey" } + + if ($Command = Get-Command choco -CommandType Application -ErrorAction Ignore) { + # choco is on the PATH, assume it's installed + Write-Warning "'choco' was found at '$($Command.Path)'." + $true + } + elseif (-not (Test-Path $checkPath)) { + # Install folder doesn't exist + $false + } + elseif (-not (Get-ChildItem -Path $checkPath)) { + # Install folder exists but is empty + $false + } + else { + # Install folder exists and is not empty + Write-Warning "Files from a previous installation of Chocolatey were found at '$($CheckPath)'." + $true + } +} + +function Install-7zip { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string] + $Path, + + [Parameter(Mandatory = $false)] + [hashtable] + $ProxyConfiguration + ) + + if (-not (Test-Path ($Path))) { + Write-Host "Downloading 7-Zip commandline tool prior to extraction." + Request-File -Url 'https://community.chocolatey.org/7za.exe' -File $Path -ProxyConfiguration $ProxyConfiguration + + } + else { + Write-Host "7zip already present, skipping installation." + } +} + +#endregion Functions + +#region Pre-check + +# Ensure we have all our streams setup correctly, needed for older PSVersions. +Set-PSConsoleWriter + +if (Test-ChocolateyInstalled) { + $message = @( + "An existing Chocolatey installation was detected. Installation will not continue." + "For security reasons, this script will not overwrite existing installations." + "" + "Please use `choco upgrade chocolatey` to handle upgrades of Chocolatey itself." + ) -join [Environment]::NewLine + + Write-Warning $message + + return +} + +#endregion Pre-check + +#region Setup + +$proxyConfig = if ($IgnoreProxy -or -not $ProxyUrl) { + @{} +} else { + $config = @{ + ProxyUrl = $ProxyUrl + } + + if ($ProxyCredential) { + $config['ProxyCredential'] = $ProxyCredential + } elseif ($env:chocolateyProxyUser -and $env:chocolateyProxyPassword) { + $securePass = ConvertTo-SecureString $env:chocolateyProxyPassword -AsPlainText -Force + $config['ProxyCredential'] = [System.Management.Automation.PSCredential]::new($env:chocolateyProxyUser, $securePass) + } + + $config +} + +# Attempt to set highest encryption available for SecurityProtocol. +# PowerShell will not set this by default (until maybe .NET 4.6.x). This +# will typically produce a message for PowerShell v2 (just an info +# message though) +try { + # Set TLS 1.2 (3072) as that is the minimum required by Chocolatey.org. + # Use integers because the enumeration value for TLS 1.2 won't exist + # in .NET 4.0, even though they are addressable if .NET 4.5+ is + # installed (.NET 4.5 is an in-place upgrade). + Write-Host "Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)" + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 +} +catch { + $errorMessage = @( + 'Unable to set PowerShell to use TLS 1.2. This is required for contacting Chocolatey as of 03 FEB 2020.' + 'https://blog.chocolatey.org/2020/01/remove-support-for-old-tls-versions/.' + 'If you see underlying connection closed or trust errors, you may need to do one or more of the following:' + '(1) upgrade to .NET Framework 4.5+ and PowerShell v3+,' + '(2) Call [System.Net.ServicePointManager]::SecurityProtocol = 3072; in PowerShell prior to attempting installation,' + '(3) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally),' + '(4) use the Download + PowerShell method of install.' + 'See https://docs.chocolatey.org/en-us/choco/setup for all install options.' + ) -join [Environment]::NewLine + Write-Warning $errorMessage +} + +if ($ChocolateyDownloadUrl) { + if ($ChocolateyVersion) { + Write-Warning "Ignoring -ChocolateyVersion parameter ($ChocolateyVersion) because -ChocolateyDownloadUrl is set." + } + + Write-Host "Downloading Chocolatey from: $ChocolateyDownloadUrl" +} elseif ($ChocolateyVersion) { + Write-Host "Downloading specific version of Chocolatey: $ChocolateyVersion" + $ChocolateyDownloadUrl = "https://community.chocolatey.org/api/v2/package/chocolatey/$ChocolateyVersion" +} else { + Write-Host "Getting latest version of the Chocolatey package for download." + $queryString = [uri]::EscapeUriString("((Id eq 'chocolatey') and (not IsPrerelease)) and IsLatestVersion") + $queryUrl = 'https://community.chocolatey.org/api/v2/Packages()?$filter={0}' -f $queryString + + [xml]$result = Request-String -Url $queryUrl -ProxyConfiguration $proxyConfig + $ChocolateyDownloadUrl = $result.feed.entry.content.src +} + +if (-not $env:TEMP) { + $env:TEMP = Join-Path $env:SystemDrive -ChildPath 'temp' +} + +$chocoTempDir = Join-Path $env:TEMP -ChildPath "chocolatey" +$tempDir = Join-Path $chocoTempDir -ChildPath "chocoInstall" + +if (-not (Test-Path $tempDir -PathType Container)) { + $null = New-Item -Path $tempDir -ItemType Directory +} + +$file = Join-Path $tempDir "chocolatey.zip" + +#endregion Setup + +#region Download & Extract Chocolatey + +Write-Host "Getting Chocolatey from $ChocolateyDownloadUrl." +Request-File -Url $ChocolateyDownloadUrl -File $file -ProxyConfiguration $proxyConfig + +Write-Host "Extracting $file to $tempDir" +if ($PSVersionTable.PSVersion.Major -lt 5) { + # Determine unzipping method + # 7zip is the most compatible pre-PSv5.1 so use it unless asked to use builtin + if ($UseNativeUnzip) { + Write-Host 'Using built-in compression to unzip' + + try { + $shellApplication = New-Object -ComObject Shell.Application + $zipPackage = $shellApplication.NameSpace($file) + $destinationFolder = $shellApplication.NameSpace($tempDir) + $destinationFolder.CopyHere($zipPackage.Items(), 0x10) + } catch { + Write-Warning "Unable to unzip package using built-in compression. Set `$env:chocolateyUseWindowsCompression = ''` or omit -UseNativeUnzip and retry to use 7zip to unzip." + throw $_ + } + } else { + $7zaExe = Join-Path $tempDir -ChildPath '7za.exe' + Install-7zip -Path $7zaExe -ProxyConfiguration $proxyConfig + + $params = 'x -o"{0}" -bd -y "{1}"' -f $tempDir, $file + + # use more robust Process as compared to Start-Process -Wait (which doesn't + # wait for the process to finish in PowerShell v3) + $process = New-Object System.Diagnostics.Process + + try { + $process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo -ArgumentList $7zaExe, $params + $process.StartInfo.RedirectStandardOutput = $true + $process.StartInfo.UseShellExecute = $false + $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + + $null = $process.Start() + $process.BeginOutputReadLine() + $process.WaitForExit() + + $exitCode = $process.ExitCode + } + finally { + $process.Dispose() + } + + $errorMessage = "Unable to unzip package using 7zip. Perhaps try setting `$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:" + if ($exitCode -ne 0) { + $errorDetails = switch ($exitCode) { + 1 { "Some files could not be extracted" } + 2 { "7-Zip encountered a fatal error while extracting the files" } + 7 { "7-Zip command line error" } + 8 { "7-Zip out of memory" } + 255 { "Extraction cancelled by the user" } + default { "7-Zip signalled an unknown error (code $exitCode)" } + } + + throw ($errorMessage, $errorDetails -join [Environment]::NewLine) + } + } +} else { + Microsoft.PowerShell.Archive\Expand-Archive -Path $file -DestinationPath $tempDir -Force +} + +#endregion Download & Extract Chocolatey + +#region Install Chocolatey + +Write-Host "Installing Chocolatey on the local machine" +$toolsFolder = Join-Path $tempDir -ChildPath "tools" +$chocoInstallPS1 = Join-Path $toolsFolder -ChildPath "chocolateyInstall.ps1" + +& $chocoInstallPS1 + +Write-Host 'Ensuring Chocolatey commands are on the path' +$chocoInstallVariableName = "ChocolateyInstall" +$chocoPath = [Environment]::GetEnvironmentVariable($chocoInstallVariableName) + +if (-not $chocoPath) { + $chocoPath = "$env:ALLUSERSPROFILE\Chocolatey" +} + +if (-not (Test-Path ($chocoPath))) { + $chocoPath = "$env:PROGRAMDATA\chocolatey" +} + +$chocoExePath = Join-Path $chocoPath -ChildPath 'bin' + +# Update current process PATH environment variable if it needs updating. +if ($env:Path -notlike "*$chocoExePath*") { + $env:Path = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine); +} + +Write-Host 'Ensuring chocolatey.nupkg is in the lib folder' +$chocoPkgDir = Join-Path $chocoPath -ChildPath 'lib\chocolatey' +$nupkg = Join-Path $chocoPkgDir -ChildPath 'chocolatey.nupkg' + +if (-not (Test-Path $chocoPkgDir -PathType Container)) { + $null = New-Item -ItemType Directory -Path $chocoPkgDir +} + +Copy-Item -Path $file -Destination $nupkg -Force -ErrorAction SilentlyContinue + +#endregion Install Chocolatey + +# SIG # Begin signature block +# MIIZvwYJKoZIhvcNAQcCoIIZsDCCGawCAQExDzANBglghkgBZQMEAgEFADB5Bgor +# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBiXTlbpVQOoJeX +# rGtqATyaDXeEHi6Q2pKb3p02Iq/tc6CCFKgwggT+MIID5qADAgECAhANQkrgvjqI +# /2BAIc4UAPDdMA0GCSqGSIb3DQEBCwUAMHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQK +# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xMTAvBgNV +# BAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJlZCBJRCBUaW1lc3RhbXBpbmcgQ0EwHhcN +# MjEwMTAxMDAwMDAwWhcNMzEwMTA2MDAwMDAwWjBIMQswCQYDVQQGEwJVUzEXMBUG +# A1UEChMORGlnaUNlcnQsIEluYy4xIDAeBgNVBAMTF0RpZ2lDZXJ0IFRpbWVzdGFt +# cCAyMDIxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwuZhhGfFivUN +# CKRFymNrUdc6EUK9CnV1TZS0DFC1JhD+HchvkWsMlucaXEjvROW/m2HNFZFiWrj/ +# ZwucY/02aoH6KfjdK3CF3gIY83htvH35x20JPb5qdofpir34hF0edsnkxnZ2OlPR +# 0dNaNo/Go+EvGzq3YdZz7E5tM4p8XUUtS7FQ5kE6N1aG3JMjjfdQJehk5t3Tjy9X +# tYcg6w6OLNUj2vRNeEbjA4MxKUpcDDGKSoyIxfcwWvkUrxVfbENJCf0mI1P2jWPo +# GqtbsR0wwptpgrTb/FZUvB+hh6u+elsKIC9LCcmVp42y+tZji06lchzun3oBc/gZ +# 1v4NSYS9AQIDAQABo4IBuDCCAbQwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQC +# MAAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwgwQQYDVR0gBDowODA2BglghkgBhv1s +# BwEwKTAnBggrBgEFBQcCARYbaHR0cDovL3d3dy5kaWdpY2VydC5jb20vQ1BTMB8G +# A1UdIwQYMBaAFPS24SAd/imu0uRhpbKiJbLIFzVuMB0GA1UdDgQWBBQ2RIaOpLqw +# Zr68KC0dRDbd42p6vDBxBgNVHR8EajBoMDKgMKAuhixodHRwOi8vY3JsMy5kaWdp +# Y2VydC5jb20vc2hhMi1hc3N1cmVkLXRzLmNybDAyoDCgLoYsaHR0cDovL2NybDQu +# ZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC10cy5jcmwwgYUGCCsGAQUFBwEBBHkw +# dzAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tME8GCCsGAQUF +# BzAChkNodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNlcnRTSEEyQXNz +# dXJlZElEVGltZXN0YW1waW5nQ0EuY3J0MA0GCSqGSIb3DQEBCwUAA4IBAQBIHNy1 +# 6ZojvOca5yAOjmdG/UJyUXQKI0ejq5LSJcRwWb4UoOUngaVNFBUZB3nw0QTDhtk7 +# vf5EAmZN7WmkD/a4cM9i6PVRSnh5Nnont/PnUp+Tp+1DnnvntN1BIon7h6JGA078 +# 9P63ZHdjXyNSaYOC+hpT7ZDMjaEXcw3082U5cEvznNZ6e9oMvD0y0BvL9WH8dQgA +# dryBDvjA4VzPxBFy5xtkSdgimnUVQvUtMjiB2vRgorq0Uvtc4GEkJU+y38kpqHND +# Udq9Y9YfW5v3LhtPEx33Sg1xfpe39D+E68Hjo0mh+s6nv1bPull2YYlffqe0jmd4 +# +TaY4cso2luHpoovMIIFMDCCBBigAwIBAgIQBAkYG1/Vu2Z1U0O1b5VQCDANBgkq +# hkiG9w0BAQsFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5j +# MRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBB +# c3N1cmVkIElEIFJvb3QgQ0EwHhcNMTMxMDIyMTIwMDAwWhcNMjgxMDIyMTIwMDAw +# WjByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQL +# ExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3Vy +# ZWQgSUQgQ29kZSBTaWduaW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB +# CgKCAQEA+NOzHH8OEa9ndwfTCzFJGc/Q+0WZsTrbRPV/5aid2zLXcep2nQUut4/6 +# kkPApfmJ1DcZ17aq8JyGpdglrA55KDp+6dFn08b7KSfH03sjlOSRI5aQd4L5oYQj +# ZhJUM1B0sSgmuyRpwsJS8hRniolF1C2ho+mILCCVrhxKhwjfDPXiTWAYvqrEsq5w +# MWYzcT6scKKrzn/pfMuSoeU7MRzP6vIK5Fe7SrXpdOYr/mzLfnQ5Ng2Q7+S1TqSp +# 6moKq4TzrGdOtcT3jNEgJSPrCGQ+UpbB8g8S9MWOD8Gi6CxR93O8vYWxYoNzQYIH +# 5DiLanMg0A9kczyen6Yzqf0Z3yWT0QIDAQABo4IBzTCCAckwEgYDVR0TAQH/BAgw +# BgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwEwYDVR0lBAwwCgYIKwYBBQUHAwMweQYI +# KwYBBQUHAQEEbTBrMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j +# b20wQwYIKwYBBQUHMAKGN2h0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdp +# Q2VydEFzc3VyZWRJRFJvb3RDQS5jcnQwgYEGA1UdHwR6MHgwOqA4oDaGNGh0dHA6 +# Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJRFJvb3RDQS5jcmww +# OqA4oDaGNGh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJ +# RFJvb3RDQS5jcmwwTwYDVR0gBEgwRjA4BgpghkgBhv1sAAIEMCowKAYIKwYBBQUH +# AgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCgYIYIZIAYb9bAMwHQYD +# VR0OBBYEFFrEuXsqCqOl6nEDwGD5LfZldQ5YMB8GA1UdIwQYMBaAFEXroq/0ksuC +# MS1Ri6enIZ3zbcgPMA0GCSqGSIb3DQEBCwUAA4IBAQA+7A1aJLPzItEVyCx8JSl2 +# qB1dHC06GsTvMGHXfgtg/cM9D8Svi/3vKt8gVTew4fbRknUPUbRupY5a4l4kgU4Q +# pO4/cY5jDhNLrddfRHnzNhQGivecRk5c/5CxGwcOkRX7uq+1UcKNJK4kxscnKqEp +# KBo6cSgCPC6Ro8AlEeKcFEehemhor5unXCBc2XGxDI+7qPjFEmifz0DLQESlE/Dm +# ZAwlCEIysjaKJAL+L3J+HNdJRZboWR3p+nRka7LrZkPas7CM1ekN3fYBIM6ZMWM9 +# CBoYs4GbT8aTEAb8B4H6i9r5gkn3Ym6hU/oSlBiFLpKR6mhsRDKyZqHnGKSaZFHv +# MIIFMTCCBBmgAwIBAgIQCqEl1tYyG35B5AXaNpfCFTANBgkqhkiG9w0BAQsFADBl +# MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +# d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv +# b3QgQ0EwHhcNMTYwMTA3MTIwMDAwWhcNMzEwMTA3MTIwMDAwWjByMQswCQYDVQQG +# EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl +# cnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3VyZWQgSUQgVGltZXN0 +# YW1waW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvdAy7kvN +# j3/dqbqCmcU5VChXtiNKxA4HRTNREH3Q+X1NaH7ntqD0jbOI5Je/YyGQmL8TvFfT +# w+F+CNZqFAA49y4eO+7MpvYyWf5fZT/gm+vjRkcGGlV+Cyd+wKL1oODeIj8O/36V +# +/OjuiI+GKwR5PCZA207hXwJ0+5dyJoLVOOoCXFr4M8iEA91z3FyTgqt30A6XLdR +# 4aF5FMZNJCMwXbzsPGBqrC8HzP3w6kfZiFBe/WZuVmEnKYmEUeaC50ZQ/ZQqLKfk +# dT66mA+Ef58xFNat1fJky3seBdCEGXIX8RcG7z3N1k3vBkL9olMqT4UdxB08r8/a +# rBD13ays6Vb/kwIDAQABo4IBzjCCAcowHQYDVR0OBBYEFPS24SAd/imu0uRhpbKi +# JbLIFzVuMB8GA1UdIwQYMBaAFEXroq/0ksuCMS1Ri6enIZ3zbcgPMBIGA1UdEwEB +# /wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMBMGA1UdJQQMMAoGCCsGAQUFBwMI +# MHkGCCsGAQUFBwEBBG0wazAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNl +# cnQuY29tMEMGCCsGAQUFBzAChjdodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20v +# RGlnaUNlcnRBc3N1cmVkSURSb290Q0EuY3J0MIGBBgNVHR8EejB4MDqgOKA2hjRo +# dHRwOi8vY3JsNC5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1cmVkSURSb290Q0Eu +# Y3JsMDqgOKA2hjRodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1 +# cmVkSURSb290Q0EuY3JsMFAGA1UdIARJMEcwOAYKYIZIAYb9bAACBDAqMCgGCCsG +# AQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAsGCWCGSAGG/WwH +# ATANBgkqhkiG9w0BAQsFAAOCAQEAcZUS6VGHVmnN793afKpjerN4zwY3QITvS4S/ +# ys8DAv3Fp8MOIEIsr3fzKx8MIVoqtwU0HWqumfgnoma/Capg33akOpMP+LLR2HwZ +# YuhegiUexLoceywh4tZbLBQ1QwRostt1AuByx5jWPGTlH0gQGF+JOGFNYkYkh2OM +# kVIsrymJ5Xgf1gsUpYDXEkdws3XVk4WTfraSZ/tTYYmo9WuWwPRYaQ18yAGxuSh1 +# t5ljhSKMYcp5lH5Z/IwP42+1ASa2bKXuh1Eh5Fhgm7oMLSttosR+u8QlK0cCCHxJ +# rhO24XxCQijGGFbPQTS2Zl22dHv1VjMiLyI2skuiSpXY9aaOUjCCBTkwggQhoAMC +# AQICEAq50xD7ISvojIGz0sLozlEwDQYJKoZIhvcNAQELBQAwcjELMAkGA1UEBhMC +# VVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3LmRpZ2ljZXJ0 +# LmNvbTExMC8GA1UEAxMoRGlnaUNlcnQgU0hBMiBBc3N1cmVkIElEIENvZGUgU2ln +# bmluZyBDQTAeFw0yMTA0MjcwMDAwMDBaFw0yNDA0MzAyMzU5NTlaMHcxCzAJBgNV +# BAYTAlVTMQ8wDQYDVQQIEwZLYW5zYXMxDzANBgNVBAcTBlRvcGVrYTEiMCAGA1UE +# ChMZQ2hvY29sYXRleSBTb2Z0d2FyZSwgSW5jLjEiMCAGA1UEAxMZQ2hvY29sYXRl +# eSBTb2Z0d2FyZSwgSW5jLjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +# AKFxp42p47c7eHNsNhgxzG+/9A1I8Th+kj40YQJH4Vh0M7a61f39I/FELNYGuyCe +# 0+z/sg+T+4VmT/JMiI2hc75yokTjkv3Yt1+fqABzCMadr+PZ/9ttIVJ5db3P2Uzc +# Ml5wXBdCV5ZH/w4oKcP53VmYcHQEDm/RtAJ9TxlPtLS734oAqrKqBmsnJCI98FWp +# d6z1FK5rv7RJVeZoGsl/2eMcB/ko0Vj9MSCbWvXNjDF9yy4Tl5h2vb+y7K1Qmk3X +# yb0OYB1ibva9rQozGgogEa5DL0OdoMj6cyJ6Cx2GQv2wjKwiKfs9zCOTDH2VGa0i +# okDbsd+BvUxovQ6eSnBFj5UCAwEAAaOCAcQwggHAMB8GA1UdIwQYMBaAFFrEuXsq +# CqOl6nEDwGD5LfZldQ5YMB0GA1UdDgQWBBRO8wUYXZXrKVBqUW35p9FeNJoEgzAO +# BgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwdwYDVR0fBHAwbjA1 +# oDOgMYYvaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC1jcy1n +# MS5jcmwwNaAzoDGGL2h0dHA6Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9zaGEyLWFzc3Vy +# ZWQtY3MtZzEuY3JsMEsGA1UdIAREMEIwNgYJYIZIAYb9bAMBMCkwJwYIKwYBBQUH +# AgEWG2h0dHA6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAIBgZngQwBBAEwgYQGCCsG +# AQUFBwEBBHgwdjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29t +# ME4GCCsGAQUFBzAChkJodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNl +# cnRTSEEyQXNzdXJlZElEQ29kZVNpZ25pbmdDQS5jcnQwDAYDVR0TAQH/BAIwADAN +# BgkqhkiG9w0BAQsFAAOCAQEAoXGdwcDMMV6xQldozbWoxGTn6chlwO4hJ8aAlwOM +# wexEvDudrlifsiGI1j46wqc9WR8+Ev8w1dIcbqif4inGIHb8GvL22Goq+lB08F7y +# YU3Ry0kOCtJx7JELlID0SI7bYndg17TJUQoAb5iTYD9aEoHMIKlGyQyVGvsp4ubo +# O8CC8Owx+Qq148yXY+to4360U2lzZvUtMpPiiSJTm4BamNgC32xgGwpN5lvk0m3R +# lDdqQQQgBCzrf+ZIMBmXMw4kxY0r/K/g1TkKI9VyiEnRaNQlQisAyYBWVnaHw2EJ +# ck6/bxwdYSA+Sz/Op0N0iEl8MX4At3XQlMGvAI1xhAbrwDGCBG0wggRpAgEBMIGG +# MHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsT +# EHd3dy5kaWdpY2VydC5jb20xMTAvBgNVBAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJl +# ZCBJRCBDb2RlIFNpZ25pbmcgQ0ECEAq50xD7ISvojIGz0sLozlEwDQYJYIZIAWUD +# BAIBBQCggYQwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx +# DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAvBgkq +# hkiG9w0BCQQxIgQgey25OsHafMX1HWLKRJb0Sf/lMMX5vF0EAhjyQlfUDzgwDQYJ +# KoZIhvcNAQEBBQAEggEAC0wtyHWaoYbiMY8PXKaNf16zoeuj5jYAuvx0B/nzJ27A +# tP/Mo9SC1Z4M2iEps/LDScRoy3N8pCI8NQBDjWGGkjW5ScFvF7a042DcurR+LE30 +# aa4d7Y0MT8O+vhQDcVCmB7JB+9E6/7+qpD1vVfs1zYw1cprCZoOejttDCEvlvsAN +# VrPKixhxbLcLu/5KV9qUBUWW9vEz8/WL1IcNcsfwd61+JWa116CXeyoLKqWXJIPF +# uNnULZTs/E2BY1JYBKIfzvSi3QWg/uWvJucdGdbLib4d1gEXxLtHk+aDOLTXRG12 +# yjMdCF1FhyeC+hyWSgwyXZ0V9zRGpiS+IjarelHVDqGCAjAwggIsBgkqhkiG9w0B +# CQYxggIdMIICGQIBATCBhjByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNl +# cnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdp +# Q2VydCBTSEEyIEFzc3VyZWQgSUQgVGltZXN0YW1waW5nIENBAhANQkrgvjqI/2BA +# Ic4UAPDdMA0GCWCGSAFlAwQCAQUAoGkwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEH +# ATAcBgkqhkiG9w0BCQUxDxcNMjEwNjE3MDg0MjQzWjAvBgkqhkiG9w0BCQQxIgQg +# Osdf/2XOopSIGgniCq9vRS6UGDVJ7TingAmrcmwYcWowDQYJKoZIhvcNAQEBBQAE +# ggEAs50N1tQOpzvCCO9R4hCcaMY0jsOm7QOOk257yySmEFbtgmKUpNmyyfwK0Wl/ +# Ti1IOTOQ1oz7Wz6Q/kEgPoZAbuAhXKH+At6Vwa98Jp3GG6abokNohPI3cWGJbS3u +# rJEKZay3+1fGNaYOCpIqkhpnVqyTNoLlNBLcGOkq7FgBKsomtQSO9ejFluS1woKY +# wK7EiXjzDwFG18DmnUuRpO4xrdmcbh7m3MnC95DjYcFFzKr/xxideicJAGZSHOo1 +# nQorVQyPcXQe4Nl2JHAr3R6RTeaXgq6We4LSdMsO5BAyduh/w4nicahwAv5wgIsw +# cUvCYQiMMXCU2x9vsn8B5wKETQ== +# SIG # End signature block diff --git a/helper-iso-files/scripts/gpu-check.ps1 b/helper-iso-files/scripts/gpu-check.ps1 new file mode 100644 index 0000000..d8a25f2 --- /dev/null +++ b/helper-iso-files/scripts/gpu-check.ps1 @@ -0,0 +1,48 @@ +Add-Type -AssemblyName PresentationFramework + +try { + choco +} +catch { + Remove-Item C:\ProgramData\chocolatey -Recurse + [System.Windows.MessageBox]::Show('Chocolatey installation failed! Make sure the VM has Internet access.', "MobilePassThrough - Error") +} + +#For formatting: + $result = @{Expression = {$_.Name}; Label = "Device Name"}, + @{Expression = {$_.ConfigManagerErrorCode} ; Label = "Status Code" }, + @{Expression = {$_.DeviceID} ; Label = "ID" } + +$driverlessGpus = Get-WmiObject -Class Win32_PnpEntity -ComputerName localhost -Namespace Root\CIMV2 | Where-Object {$_.ConfigManagerErrorCode -gt 0 } | Format-Table $result -AutoSize | findstr -i "Video Controller" | findstr -i " 28 " + +if ($driverlessGpus -like '*VEN_1002*') { + Write-Host 'AMD GPU driver missing' + Write-Host 'Automatically installing AMD GPU drivers is not supported.' + [System.Windows.MessageBox]::Show("Please install the AMD GPU driver! AMD and Chocolatey unfortunately don't offer a way to do this automatically!", "MobilePassThrough - GPU Driver is missing") +} +if ($driverlessGpus -like '*VEN_10DE*') { + Write-Host 'Nvidia GPU driver missing' + try { + choco install nvidia-display-driver + } + catch { + [System.Windows.MessageBox]::Show('Failed to automatically install Nvidia Display driver using chocolatey!', "MobilePassThrough - Driver installation failed") + } +} +if ($driverlessGpus -like '*VEN_8086*') { + Write-Host 'Intel GPU driver missing' + try { + choco install intel-graphics-driver + } + catch { + [System.Windows.MessageBox]::Show('Failed to automatically install Intel Graphics driver using chocolatey!', "MobilePassThrough - Driver installation failed") + } +} + +$error43Devices = Get-WmiObject -Class Win32_PnpEntity -ComputerName localhost -Namespace Root\CIMV2 | Where-Object {$_.ConfigManagerErrorCode -gt 0 } | Format-Table $result -AutoSize | findstr -i "Video Controller" | findstr -i " 43 " + +if ($error43Devices) { + Write-Host 'Error 43 detected:' + Write-Host $error43Devices + [System.Windows.MessageBox]::Show($error43Devices, "MobilePassThrough - Detected Error 43") +} diff --git a/helper-iso-files/scripts/network-check.ps1 b/helper-iso-files/scripts/network-check.ps1 new file mode 100644 index 0000000..8242715 --- /dev/null +++ b/helper-iso-files/scripts/network-check.ps1 @@ -0,0 +1,55 @@ +Add-Type -AssemblyName PresentationFramework + +function wait-for-network ($tries) { + while (1) { + # Get a list of DHCP-enabled interfaces that have a + # non-$null DefaultIPGateway property. + $x = gwmi -class Win32_NetworkAdapterConfiguration ` + -filter DHCPEnabled=TRUE | + where { $_.DefaultIPGateway -ne $null } + + # If there is (at least) one available, exit the loop. + if ( ($x | measure).count -gt 0 ) { + #[System.Windows.MessageBox]::Show("Network connection established!", "MobilePassThrough") + Write-Host "Network connection established!" + break + } + + # If $tries > 0 and we have tried $tries times without + # success, throw an exception. + if ( $tries -gt 0 -and $try++ -ge $tries ) { + Write-Host "Network unavaiable after $try tries." + [System.Windows.MessageBox]::Show("Network unavaiable after $try tries.", "MobilePassThrough") + throw "Network unavaiable after $try tries." + } + + # Wait one second. + start-sleep -s 1 + } +} + +function wait-for-chocolatey ($tries) { + while (1) { + if ( $tries -gt 0 -and $try++ -ge $tries ) { + Write-Host "chocolatey.org unavaiable after $try tries." + [System.Windows.MessageBox]::Show("chocolatey.org unavaiable after $try tries.", "MobilePassThrough") + throw "chocolatey.org unavaiable after $try tries." + } + if ((Test-Connection -Quiet chocolatey.org)) { + Write-Host "chocolatey.org is reachable!" + break + } + start-sleep -s 1 + } +} + +Write-Host "Waiting for a network connection. Waiting up to 60 seconds..." +wait-for-network 60 + +Write-Host "Setting the Network to private..." +Set-NetConnectionProfile -Name "Network" -NetworkCategory Private + +Write-Host "Waiting for chocoltey.org to be reachable. Waiting up to 30 seconds..." +wait-for-chocolatey 30 + +cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\chcolatey-install.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\chcolatey-install.ps1" \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index 8208e7b..5e38bb6 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -60,15 +60,21 @@ elif [ "$COMMAND" = "configure" ]; then "${USER_SCRIPTS_DIR}/generate-vm-config.sh" elif [ "$COMMAND" = "iso" ]; then "${USER_SCRIPTS_DIR}/generate-helper-iso.sh" +elif [ "$COMMAND" = "install" ]; then + sudo "${USER_SCRIPTS_DIR}/start-vm.sh" install elif [ "$COMMAND" = "start" ]; then sudo "${USER_SCRIPTS_DIR}/start-vm.sh" +elif [ "$COMMAND" = "auto" ]; then + sudo "${USER_SCRIPTS_DIR}/setup.sh" + sudo "${USER_SCRIPTS_DIR}/iommu-check.sh" + sudo "${USER_SCRIPTS_DIR}/start-vm.sh" install elif [ "$COMMAND" = "vbios" ]; then - if [ "$2" == "extract" ] ; then + if [ "$2" == "extract" ]; then mkdir -p "$4/" cd "${PROJECT_DIR}/thirdparty/VBiosFinder" ./vbiosfinder extract "$(readlink -f "$3")" mv "${PROJECT_DIR}/thirdparty/VBiosFinder/output/*" "$4/" - elif [ "$2" == "dump" ] ; then + elif [ "$2" == "dump" ]; then sudo "${UTILS_DIR}/extract-vbios" "$3" "$4" fi -fi \ No newline at end of file +fi \ No newline at end of file diff --git a/scripts/generate-autounattend-vfd.sh b/scripts/delete-vm.sh old mode 100755 new mode 100644 similarity index 58% rename from scripts/generate-autounattend-vfd.sh rename to scripts/delete-vm.sh index f676d6c..1217326 --- a/scripts/generate-autounattend-vfd.sh +++ b/scripts/delete-vm.sh @@ -5,7 +5,9 @@ PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" UTILS_DIR="${PROJECT_DIR}/utils" DISTRO=$("${UTILS_DIR}/distro-info") DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +LOG_BASE_DIR="${PROJECT_DIR}/logs" +# If user.conf doesn't exist use the default.conf if [ -f "${PROJECT_DIR}/user.conf" ]; then echo "> Loading config from ${PROJECT_DIR}/user.conf" source "${PROJECT_DIR}/user.conf" @@ -18,18 +20,5 @@ else exit fi -TMP_DIR="${PROJECT_DIR}/tmp" -VFD_MP="${TMP_DIR}/autounattend-vfd-mountpoint" -VFD_FILE="${VM_FILES_DIR}/autounattend.vfd" - -echo "> Creating empty floppy image..." -rm -f "${VFD_FILE}" -fallocate -l 1474560 "${VFD_FILE}" -mkfs.vfat "${VFD_FILE}" - -echo "> Copy files onto the floppy image..." -mkdir -p "${VFD_MP}" -sudo mount -o loop "${VFD_FILE}" "${VFD_MP}" -sudo cp -r "${PROJECT_DIR}/autounattend-vfd-files/." "${VFD_MP}/" -sudo umount "${VFD_MP}" -rm -rf "${TMP_DIR}" \ No newline at end of file +sudo virsh destroy --domain "${VM_NAME}" +sudo virsh undefine --domain "${VM_NAME}" --nvram \ No newline at end of file diff --git a/scripts/generate-helper-iso.sh b/scripts/generate-helper-iso.sh index a51cce3..13d21e6 100755 --- a/scripts/generate-helper-iso.sh +++ b/scripts/generate-helper-iso.sh @@ -19,6 +19,7 @@ else fi mkdir -p "${PROJECT_DIR}/helper-iso-files/bin" +mkdir -p "${PROJECT_DIR}/helper-iso-files/scripts" #if [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/AutoHotkeyU64.exe" ]; then # echo "> Downloading AutoHotkey..." # rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" @@ -89,9 +90,15 @@ fi # echo "> devcon driver tool already exist in iso folder..." #fi +if [ ! -f "${PROJECT_DIR}/helper-iso-files/scripts/chcolatey-install.ps1" ]; then + echo "> Downloading Chocolatey install script..." + wget "https://chocolatey.org/install.ps1" -O "${PROJECT_DIR}/helper-iso-files/scripts/chcolatey-install.ps1" +else + echo "> Chocolatey install script already exist in iso folder..." +fi + rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -echo "> Generating new iso..." rm -f "${HELPER_ISO}" -echo "genisoimage -J -joliet-long -r -allow-lowercase -allow-multidot -o \"${HELPER_ISO}\" \"${PROJECT_DIR}/helper-iso-files\"" -genisoimage -J -joliet-long -r -allow-lowercase -allow-multidot -o "${HELPER_ISO}" "${PROJECT_DIR}/helper-iso-files" +#echo "genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o \"${HELPER_ISO}\" \"${PROJECT_DIR}/helper-iso-files\"" +genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o "${HELPER_ISO}" "${PROJECT_DIR}/helper-iso-files" diff --git a/scripts/iommu-check.sh b/scripts/iommu-check.sh new file mode 100755 index 0000000..ae6f23d --- /dev/null +++ b/scripts/iommu-check.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) +PROJECT_DIR="${SCRIPT_DIR}/.." +UTILS_DIR="${PROJECT_DIR}/utils" +DISTRO=$("${UTILS_DIR}/distro-info") +DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" + +if sudo which optirun &> /dev/null && sudo optirun echo>/dev/null ; then + OPTIRUN_PREFIX="optirun " +else + OPTIRUN_PREFIX="" +fi + +IOMMU_GROUPS=$(sudo ${OPTIRUN_PREFIX}${UTILS_DIR}/lsiommu) + +# Check if UEFI is configured correctly +if systool -m kvm_intel -v &> /dev/null || systool -m kvm_amd -v &> /dev/null ; then + UEFI_VIRTUALIZATION_ENABLED=true + echo "[OK] VT-X / AMD-V virtualization is enabled in the UEFI." +else + UEFI_VIRTUALIZATION_ENABLED=false + echo "[Error] VT-X / AMD-V virtualization is not enabled in the UEFI! This is required to run virtual machines!" +fi + +if [ "$IOMMU_GROUPS" != "" ] ; then + UEFI_IOMMU_ENABLED=true + echo "[OK] VT-D / IOMMU is enabled in the UEFI." +else + UEFI_IOMMU_ENABLED=false + echo "[Error] VT-D / IOMMU is not enabled in the UEFI! This is required to check which devices are in which IOMMU group and to use GPU passthrough!" +fi + +if [ $UEFI_VIRTUALIZATION_ENABLED = true ] && [ $UEFI_IOMMU_ENABLED = true ] ; then + exit 0 # success +else + exit 1 # error +fi \ No newline at end of file diff --git a/scripts/make-windows-iso-auto-bootable b/scripts/make-windows-iso-auto-bootable index ec6e3e0..54c3e86 100755 --- a/scripts/make-windows-iso-auto-bootable +++ b/scripts/make-windows-iso-auto-bootable @@ -1,15 +1,15 @@ #!/usr/bin/env bash +# WARNING: THIS SCRIPT DOES NOT WORK YET! +# WARNING: THIS SCRIPT DOES NOT WORK YET! +# WARNING: THIS SCRIPT DOES NOT WORK YET! + SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" UTILS_DIR="${PROJECT_DIR}/utils" DISTRO=$("${UTILS_DIR}/distro-info") DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -# WARNING: THIS SCRIPT DOES NOT WORK YET! -# WARNING: THIS SCRIPT DOES NOT WORK YET! -# WARNING: THIS SCRIPT DOES NOT WORK YET! - # Variable containing the path to the windows.iso WIN10_IMG="$1" diff --git a/scripts/setup.sh b/scripts/setup.sh index 6fcba65..2f8d0ba 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -8,37 +8,130 @@ DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" mkdir -p "${PROJECT_DIR}/thirdparty" +function commandsAvailable() { + commandsMissing=() + for currentCommand in $1; do + if ! command -v $currentCommand &> /dev/null; then + commandsMissing+=("$currentCommand") + fi + done + if ((${#commandsMissing[@]})); then + echo "Missing commands: ${commandsMissing[@]}" + return 1 # Some commands are missing + else + return 0 + fi +} + +# TODO: complete this list +if ! commandsAvailable "wget curl vim screen git crudini remmina spicy genisoimage uuid iasl docker dumpet imake g++ virt-install qemu-system-x86_64 systool"; then + sudo $DISTRO_UTILS_DIR/install-dependencies +else + echo "[Skipped] Required packages already installed." +fi + source "$DISTRO_UTILS_DIR/kernel-param-utils" -sudo $DISTRO_UTILS_DIR/install-dependencies -sudo $UTILS_DIR/set-kernel-params +if runtimeKernelHasParam "iommu=1" && \ + runtimeKernelHasParam "amd_iommu=on" && \ + runtimeKernelHasParam "intel_iommu=on" && \ + runtimeKernelHasParam "i915.enable_gvt=1" && \ + runtimeKernelHasParam "kvm.ignore_msrs=1" && \ + runtimeKernelHasParam "rd.driver.pre=vfio-pci"; then + REBOOT_REQUIRED=false + echo "[Skipped] Kernel parameters are already set." +else + sudo $UTILS_DIR/set-kernel-params + REBOOT_REQUIRED=true +fi +if [[ "$(docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then + sudo $UTILS_DIR/ovmf-vbios-patch-setup +else + echo "[Skipped] Image 'ovmf-vbios-patch' has already been built." +fi source "$UTILS_DIR/gpu-check" -sudo $UTILS_DIR/ovmf-vbios-patch-setup - -if [ $HAS_INTEL_GPU = true ]; then +if [ "$HAS_INTEL_GPU" = true ]; then sudo $DISTRO_UTILS_DIR/intel-setup fi -if [ $HAS_AMD_GPU = true ]; then +if [ "$HAS_AMD_GPU" = true ]; then sudo $DISTRO_UTILS_DIR/amd-setup fi -if [ $HAS_NVIDIA_GPU = true ]; then +if [ "$HAS_NVIDIA_GPU" = true ]; then sudo $DISTRO_UTILS_DIR/nvidia-setup fi -if [ $SUPPORTS_OPTIMUS = true ]; then +if [ "$SUPPORTS_OPTIMUS" = true ]; then sudo $DISTRO_UTILS_DIR/bumblebee-setup fi -sudo $UTILS_DIR/build-fake-battery-ssdt +if [ ! -f "${PROJECT_DIR}/acpi-tables/fake-battery.aml" ]; then + sudo $UTILS_DIR/build-fake-battery-ssdt +else + echo "[Skipped] Fake ACPI SSDT battery has already been built." +fi + +if [ ! -f "${PROJECT_DIR}/thirdparty/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then + sudo $DISTRO_UTILS_DIR/vbios-finder-installer/vbiosfinder +else + echo "[Skipped] VBiosFinder is already set up." +fi + +if [ ! -f "${PROJECT_DIR}/thirdparty/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${PROJECT_DIR}/thirdparty/LookingGlass/client/build/looking-glass-client" ]; then + sudo $DISTRO_UTILS_DIR/looking-glass-setup +else + echo "[Skipped] Looking Glass is already set up." +fi + +#if [ ! -f "${PROJECT_DIR}/thirdparty/schily-tools/mkisofs/OBJ/x86_64-linux-gcc/mkisofs" ]; then +# sudo $UTILS_DIR/schily-tools-setup +#else +# echo "[Skipped] Schily Tools is already set up." +#fi + +#echo "> Generating vFloppy for auto Widnows Installation..." +#sudo ${SCRIPT_DIR}/generate-autounattend-vfd.sh +# TODO: add check if files have changed and vfd needs to be regenerated + +echo "> Generating helper-iso for auto Windows Configuration / Driver installation..." +sudo ${SCRIPT_DIR}/generate-helper-iso.sh +# TODO: add check if files have changed and helper iso needs to be regenerated -sudo $DISTRO_UTILS_DIR/vbios-finder-installer -sudo $DISTRO_UTILS_DIR/looking-glass-setup +if [ "$1" = "auto" ]; then + if [ REBOOT_REQUIRED = true ]; then + echo "> Creating a temporary service that will run on next reboot and create the Windows VM" + echo "exit because this has not been tested yet" + exit + sudo echo "[Unit] +Description=MobilePassthroughInitSetup +After=multi-user.target network.target -sudo $UTILS_DIR/schily-tools-setup +[Service] +User=root +Group=root +Type=simple +Environment=DISPLAY=:0 +WorkingDirectory=${PROJECT_DIR} +ExecStart=$(sudo) -u $(loguser) $(which gnome-terminal) -- bash -c \"${PROJECT_DIR}/mbpt.sh auto\" +Restart=never -echo "Make sure you didn't get any critical errors above." -echo "Then reboot!" -echo "After the reboot you can check if your device is compatible by running: ./mbpt.sh check" +[Install] +WantedBy=multi-user.target" > /etc/systemd/system/MobilePassthroughInitSetup.service + sudo systemctl daemon-reload + sudo systemctl enable MobilePassthroughInitSetup.service + echo "> Rebooting in 15 seconds... Press Ctrl+C to reboot now." + sleep 15 + sudo systemctl --force reboot + else + sudo systemctl disable MobilePassthroughInitSetup.service &> /dev/null + echo "> No reboot required." + fi +else + if [ REBOOT_REQUIRED = true ]; then + echo "> Please reboot to load the new kernel parameters!" + else + echo "> No reboot required." + fi +fi \ No newline at end of file diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index e6151a8..e42526f 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -6,7 +6,12 @@ UTILS_DIR="${PROJECT_DIR}/utils" DISTRO=$("${UTILS_DIR}/distro-info") DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_START_MODE="virt-install" # qemu or virt-install +if [ "$1" = "install" ]; then + VM_INSTALL=true +else + VM_INSTALL=false +fi +VM_START_MODE="qemu" # qemu or virt-install # If user.conf doesn't exist use the default.conf if [ -f "${PROJECT_DIR}/user.conf" ]; then @@ -32,7 +37,7 @@ QEMU_PARAMS=() if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-name" "${VM_NAME}") elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--name" "WindowsVM") + VIRT_INSTALL_PARAMS+=("--name" "${VM_NAME}") fi if [ "$VM_START_MODE" = "qemu" ]; then @@ -79,38 +84,34 @@ QEMU_PARAMS+=("-nographic") QEMU_PARAMS+=("-serial" "none") QEMU_PARAMS+=("-parallel" "none") QEMU_PARAMS+=("-boot" "menu=on") -QEMU_PARAMS+=("-boot" "order=d") +QEMU_PARAMS+=("-boot" "once=d") QEMU_PARAMS+=("-k" "en-us") -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${VIRTIO_WIN_IMG},index=2,media=cdrom") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--cdrom" "${VIRTIO_WIN_IMG}") +if [ $VM_INSTALL = true ]; then + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") + fi fi if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=3,media=cdrom") + QEMU_PARAMS+=("-drive" "file=${VIRTIO_WIN_IMG},index=2,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--cdrom" "${HELPER_ISO}") + VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${VIRTIO_WIN_IMG}") fi if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") + QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=3,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") + VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") fi #if [ "$VM_START_MODE" = "qemu" ]; then -# QEMU_PARAMS+=("-fda" "${VIRTIO_WIN_VFD}") +# QEMU_PARAMS+=("-fdb" "${AUTOUNATTEND_WIN_VFD}") #elif [ "$VM_START_MODE" = "virt-install" ]; then -# VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${VIRTIO_WIN_VFD}") +# VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${AUTOUNATTEND_WIN_VFD}") #fi - -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-fdb" "${AUTOUNATTEND_WIN_VFD}") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${AUTOUNATTEND_WIN_VFD}") -fi #TODO: Uncomment! #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") @@ -150,17 +151,9 @@ else exit fi -echo "Generating vFloppy for auto Widnows Installation..." -sudo ${SCRIPT_DIR}/generate-auto-unattended-vfd.sh -# TODO: add check if files have changed and vfd needs to be regenerated - -echo "Generating helper-iso for auto Windows Configuration / Driver installation..." -sudo ${SCRIPT_DIR}/generate-helper-iso.sh -# TODO: add check if files have changed and helper iso needs to be regenerated - - -if [ ! -f "${OVMF_VARS_VM}" ]; then - echo "> Creating OVMF_VARS copy for this VM..." +if [ ! -f "${OVMF_VARS_VM}" ] || [ $VM_INSTALL = true ]; then + echo "> Creating fresh OVMF_VARS copy for this VM..." + sudo rm -f "${OVMF_VARS_VM}" sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" sudo chown "$(whoami):$(id -gn "$(whoami)")" "${OVMF_VARS_VM}" fi @@ -209,23 +202,20 @@ if [ "$USE_LOOKING_GLASS" = true ]; then while [[ $BUFFER_SIZE -le $UNROUNDED_BUFFER_SIZE ]]; do BUFFER_SIZE=$(($BUFFER_SIZE*2)) done - LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}M" + LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}" echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}" if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") - QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}") - SHM_LOOKING_GLASS_OWNER="$(logname)" + QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}M") elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/@name=looking-glass") VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/model/@type=ivshmem-plain") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=32") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=${LOOKING_GLASS_BUFFER_SIZE}") VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size/@unit=M") - SHM_LOOKING_GLASS_OWNER="qemu" fi - sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" - sudo bash -c "echo 'f /dev/shm/looking-glass 0660 ${SHM_LOOKING_GLASS_OWNER} kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" - sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass - sudo setfacl --modify user:$(logname):rw "/dev/shm/looking-glass" + #sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" + #sudo bash -c "echo 'f /dev/shm/looking-glass 0660 qemu kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" + #sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass else echo "> Not using Looking Glass..." fi @@ -402,7 +392,12 @@ if [ "$PATCH_OVMF_WITH_VROM" = true ]; then sudo rm -rf "${PATCHED_OVMF_FILES_DIR}/tmp-build" fi OVMF_CODE="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" - OVMF_VARS_VM="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" + if [ $VM_INSTALL = true ]; then + echo "> Creating fresh copy of patched OVMF VARS..." + rm -f "${OVMF_VARS_VM}" + sudo cp "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" "${OVMF_VARS_VM}" + fi + #OVMF_VARS_VM="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" else echo "> Not using patched OVMF..." fi @@ -441,35 +436,45 @@ else echo "> Not using virtual input method for keyboard/mouse input..." fi -give_qemu_access() { - local skip_root=true - local -a paths - IFS=/ read -r -a paths <<<"$1" - local i - for (( i = 1; i < ${#paths[@]}; i++ )); do - paths[i]="${paths[i-1]}/${paths[i]}" - done - paths[0]=/ - for current_path in "${paths[@]}" ; do - if [ "$skip_root" = true ] && [ "${current_path}" = "/" ]; then - continue - fi - echo "> Granting qemu access to: '${current_path}'" - sudo setfacl --modify user:qemu:rx "${current_path}" - sudo chmod +x "${current_path}" - done - #sudo chmod 777 "$1" -} - -give_qemu_access "${INSTALL_IMG}" +#give_qemu_access() { +# local skip_root=true +# local -a paths +# IFS=/ read -r -a paths <<<"$1" +# local i +# for (( i = 1; i < ${#paths[@]}; i++ )); do +# paths[i]="${paths[i-1]}/${paths[i]}" +# done +# paths[0]=/ +# for current_path in "${paths[@]}" ; do +# if [ "$skip_root" = true ] && [ "${current_path}" = "/" ]; then +# continue +# fi +# echo "> Granting qemu access to: '${current_path}'" +# sudo setfacl --modify user:qemu:rx "${current_path}" +# sudo chmod +x "${current_path}" +# done +# #sudo chmod 777 "$1" +#} + +#give_qemu_access "${INSTALL_IMG}" #sudo bash -c "echo 'user = root' >> /etc/libvirt/qemu.conf" #sudo systemctl restart libvirtd +if [ $VM_INSTALL = true ]; then + echo "> Deleting VM if it already exists..." + sudo virsh destroy --domain "${VM_NAME}" &> /dev/null + sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null +fi +echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") + bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & + echo "> Starting the spice client @${SPICE_PORT}..." - spicy -h localhost -p "${SPICE_PORT}" & + bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & + echo "> Starting the Virtual Machine using qemu..." echo "" @@ -487,9 +492,8 @@ if [ "$VM_START_MODE" = "qemu" ]; then echo "" sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" elif [ "$VM_START_MODE" = "virt-install" ]; then - # Delete VM - sudo virsh destroy --domain WindowsVM &> /dev/null - sudo virsh undefine --domain WindowsVM --nvram &> /dev/null + bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + echo "> Starting the Virtual Machine using virt-install..." #VIRT_INSTALL_PARAMS+=("--debug") @@ -497,32 +501,31 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") done - echo "" - - printf "sudo virt-install" - for param in "${VIRT_INSTALL_PARAMS[@]}"; do - if [[ "${param}" == -* ]]; then - printf " \\\\\n ${param}" - elif [[ $param = *" "* ]]; then - printf " \"${param}\"" - else - printf " ${param}" - fi - done - echo "" - echo "" - - sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + #if [ $VM_INSTALL = true ]; then + echo "" + printf "sudo virt-install" + for param in "${VIRT_INSTALL_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + #else + # virsh start "${VM_NAME}" + #fi - # Delete VM - sudo virsh destroy --domain WindowsVM &> /dev/null - sudo virsh undefine --domain WindowsVM --nvram &> /dev/null fi - # This gets executed when the vm exits if [ "$DGPU_PASSTHROUGH" = true ]; then + echo "> Unbinding dGPU from vfio driver..." driver unbind "${DGPU_PCI_ADDRESS}" if [ "$HOST_DGPU_DRIVER" = "nvidea" ] || [ "$HOST_DGPU_DRIVER" = "nuveau" ]; then @@ -531,11 +534,15 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then fi echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" + fi + if [ "$SHARE_IGPU" = true ]; then + echo "> Keeping Intel vGPU for next VM start..." + # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. # So for now we can't create a new vGPU every time the VM starts. - echo "> Keeping Intel vGPU for next VM start..." #echo "> Remove Intel vGPU..." #vgpu remove "${IGPU_PCI_ADDRESS}" "${VGPU_UUID}" + fi \ No newline at end of file diff --git a/utils/Fedora/34/amd-setup b/utils/Fedora/34/amd-setup old mode 100644 new mode 100755 diff --git a/utils/Fedora/34/intel-setup b/utils/Fedora/34/intel-setup index 090cf8c..710db43 100755 --- a/utils/Fedora/34/intel-setup +++ b/utils/Fedora/34/intel-setup @@ -10,7 +10,9 @@ VM_FILES_DIR="${PROJECT_DIR}/vm-files" source "$DISTRO_UTILS_DIR/kernel-param-utils" #TODO: verify if that actually works: -echo "Allow using external monitor for notebooks that have the port wired to the dGPU directly" -sudo dnf install -y intel-gpu-tools -sudo intel-virtual-output +#echo "Allow using external monitor for notebooks that have the port wired to the dGPU directly" +if ! command -v intel-virtual-output &> /dev/null; then + sudo dnf install -y intel-gpu-tools +fi +#sudo intel-virtual-output # TODO: Check if this should be added to the start-vm.sh #example usage: xrandr –output eDP1 –mode 1920×1080 –output HDMI1 –mode 1920×1080 –right-of eDP1 diff --git a/utils/Fedora/34/kernel-param-utils b/utils/Fedora/34/kernel-param-utils index 3ac278c..9f05969 100755 --- a/utils/Fedora/34/kernel-param-utils +++ b/utils/Fedora/34/kernel-param-utils @@ -44,4 +44,9 @@ function addInitramfsDriver() { function applyInitramfsChanges() { sudo dracut -f --kver `uname -r` #TODO: Find out if this needs to be executed again after every kernel update. +} + +function runtimeKernelHasParam() { + cmdline="$(cat /proc/cmdline)" + [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] } \ No newline at end of file diff --git a/utils/Ubuntu/21.04/kernel-param-utils b/utils/Ubuntu/21.04/kernel-param-utils index 3ac278c..9f05969 100755 --- a/utils/Ubuntu/21.04/kernel-param-utils +++ b/utils/Ubuntu/21.04/kernel-param-utils @@ -44,4 +44,9 @@ function addInitramfsDriver() { function applyInitramfsChanges() { sudo dracut -f --kver `uname -r` #TODO: Find out if this needs to be executed again after every kernel update. +} + +function runtimeKernelHasParam() { + cmdline="$(cat /proc/cmdline)" + [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] } \ No newline at end of file diff --git a/utils/lsiommu b/utils/lsiommu index 3da599e..8f540fd 100755 --- a/utils/lsiommu +++ b/utils/lsiommu @@ -4,5 +4,10 @@ shopt -s nullglob for d in /sys/kernel/iommu_groups/*/devices/*; do n=${d#*/iommu_groups/*}; n=${n%%/*} printf 'IOMMU Group %s ' "$n" - lspci -nns "${d##*/}" + if [[ $d =~ "." ]]; then + lspci -nns "${d##*/}" + else + printf "$(readlink -f "${d}" | cut -d'/' -f5- | cut -d':' -f2-) Virtual GPU of: " + lspci -nns "$(basename "$(dirname "$(readlink -f "${d}")")")" | cut -d' ' -f2- + fi done; From f822c5c55f4181a6d3529296b73dc86be11ee130 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Mon, 2 Aug 2021 17:30:16 +0200 Subject: [PATCH 09/40] tmp --- dependencies.json | 42 +++++++++++++++++++ mbpt.sh | 9 +--- scripts/compatibility-check.sh | 9 +--- scripts/delete-vm.sh | 23 ++-------- scripts/generate-helper-iso.sh | 8 +--- scripts/generate-vm-config.sh | 10 ++--- scripts/iommu-check.sh | 8 +--- scripts/make-windows-iso-auto-bootable | 7 +--- scripts/setup.sh | 10 ++--- scripts/start-vm.sh | 26 +++--------- utils/Fedora/34/amd-setup | 12 ------ utils/Ubuntu/21.04/amd-setup | 12 ------ utils/build-fake-battery-ssdt | 13 ------ utils/{ => common/libs}/gpu-check | 0 utils/common/libs/helpers | 31 ++++++++++++++ utils/common/setup/build-fake-battery-ssdt | 7 ++++ utils/{ => common/setup}/extract-vbios | 9 +--- .../{ => common/setup}/ovmf-vbios-patch-setup | 8 +--- utils/{ => common/setup}/schily-tools-setup | 11 ++--- utils/{ => common/setup}/set-kernel-params | 8 +--- utils/{ => common/tools}/distro-info | 0 utils/{ => common/tools}/download-windows-iso | 0 utils/{ => common/tools}/driver-util | 0 utils/{ => common/tools}/lsiommu | 0 utils/{ => common/tools}/vgpu-util | 0 utils/distro-specific/Fedora/34/amd-setup | 8 ++++ .../Fedora/34/bumblebee-setup | 10 ++--- .../Fedora/34/install-dependencies | 0 .../Fedora/34/intel-setup | 10 ++--- .../Fedora/34/kernel-param-utils | 0 .../Fedora/34/looking-glass-setup | 10 ++--- .../Fedora/34/nvidia-setup | 10 ++--- .../Fedora/34/vbios-finder-installer | 10 ++--- utils/distro-specific/Ubuntu/21.04/amd-setup | 8 ++++ .../Ubuntu/21.04/bumblebee-setup | 10 ++--- .../Ubuntu/21.04/install-dependencies | 3 +- .../Ubuntu/21.04/intel-setup | 10 ++--- .../Ubuntu/21.04/kernel-param-utils | 0 .../Ubuntu/21.04/looking-glass-setup | 10 ++--- .../Ubuntu/21.04/nvidia-setup | 10 ++--- .../Ubuntu/21.04/vbios-finder-installer | 10 ++--- 41 files changed, 161 insertions(+), 221 deletions(-) create mode 100644 dependencies.json delete mode 100755 utils/Fedora/34/amd-setup delete mode 100644 utils/Ubuntu/21.04/amd-setup delete mode 100755 utils/build-fake-battery-ssdt rename utils/{ => common/libs}/gpu-check (100%) create mode 100644 utils/common/libs/helpers create mode 100755 utils/common/setup/build-fake-battery-ssdt rename utils/{ => common/setup}/extract-vbios (88%) rename utils/{ => common/setup}/ovmf-vbios-patch-setup (68%) rename utils/{ => common/setup}/schily-tools-setup (62%) rename utils/{ => common/setup}/set-kernel-params (91%) rename utils/{ => common/tools}/distro-info (100%) rename utils/{ => common/tools}/download-windows-iso (100%) rename utils/{ => common/tools}/driver-util (100%) rename utils/{ => common/tools}/lsiommu (100%) rename utils/{ => common/tools}/vgpu-util (100%) create mode 100755 utils/distro-specific/Fedora/34/amd-setup rename utils/{ => distro-specific}/Fedora/34/bumblebee-setup (81%) rename utils/{ => distro-specific}/Fedora/34/install-dependencies (100%) rename utils/{ => distro-specific}/Fedora/34/intel-setup (68%) rename utils/{ => distro-specific}/Fedora/34/kernel-param-utils (100%) rename utils/{ => distro-specific}/Fedora/34/looking-glass-setup (87%) rename utils/{ => distro-specific}/Fedora/34/nvidia-setup (84%) rename utils/{ => distro-specific}/Fedora/34/vbios-finder-installer (74%) create mode 100644 utils/distro-specific/Ubuntu/21.04/amd-setup rename utils/{ => distro-specific}/Ubuntu/21.04/bumblebee-setup (79%) rename utils/{ => distro-specific}/Ubuntu/21.04/install-dependencies (72%) rename utils/{ => distro-specific}/Ubuntu/21.04/intel-setup (61%) rename utils/{ => distro-specific}/Ubuntu/21.04/kernel-param-utils (100%) rename utils/{ => distro-specific}/Ubuntu/21.04/looking-glass-setup (87%) rename utils/{ => distro-specific}/Ubuntu/21.04/nvidia-setup (82%) rename utils/{ => distro-specific}/Ubuntu/21.04/vbios-finder-installer (74%) diff --git a/dependencies.json b/dependencies.json new file mode 100644 index 0000000..77ba9cb --- /dev/null +++ b/dependencies.json @@ -0,0 +1,42 @@ +{ + "general": { + "executables": ["sudo", "bash", "mv", "cp", "sed", "awk", "git", "echo", "ls", "wget", "curl", "printf", "cd", "mkdir", "chmod", "chown", "grep", "cut", "which", "", "", "", "", "", "", ""], + "files": [] + }, + "fake-battery": { + "executables": ["iasl"], + "files": [] + }, + "ovmf-vbios-patch": { + "executables": ["docker"], + "files": [] + }, + "generate-vm-config": { + "executables": ["crudini"], + "files": [] + }, + "vbios-finder": { + "executables": ["wget", "curl", "unzip", "ruby", "gem", "bundle", "7za", "make", "innoextract", "upx"], + "files": ["include/ruby/ruby.h"] + }, + "virtualization": { + "executables": ["virt-install", "qemu-system-x86_x64", "virsh"], + "files": ["OVMF/OVMF_CODE.fd", "OVMF/OVMF_VARS.fd", "virtio-win/virtio-win.iso"] + }, + "remote-desktop": { + "executables": ["remmina"], + "files": [] + }, + "file-sharing": { + "executables": ["samba"], + "files": [] + }, + "iGPU-passthrough": { + "executables": ["uuid", "intel-virtual-output"], + "files": [] + }, + "schily-tools": { + "executables": ["g++", "imake"], + "files": ["include/ext2fs/ext2fs.h"] + } +} \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index 5e38bb6..350845d 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -1,11 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -USER_SCRIPTS_DIR="${PROJECT_DIR}/scripts" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" COMMAND="$1" diff --git a/scripts/compatibility-check.sh b/scripts/compatibility-check.sh index 63f6950..374f5e9 100755 --- a/scripts/compatibility-check.sh +++ b/scripts/compatibility-check.sh @@ -1,11 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -LOG_BASE_DIR="${PROJECT_DIR}/logs" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" # Enable these to mock the lshw output and iommu groups of other computers for testing purposes #MOCK_SET=1 diff --git a/scripts/delete-vm.sh b/scripts/delete-vm.sh index 1217326..f0cfdb9 100644 --- a/scripts/delete-vm.sh +++ b/scripts/delete-vm.sh @@ -1,24 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -LOG_BASE_DIR="${PROJECT_DIR}/logs" - -# If user.conf doesn't exist use the default.conf -if [ -f "${PROJECT_DIR}/user.conf" ]; then - echo "> Loading config from ${PROJECT_DIR}/user.conf" - source "${PROJECT_DIR}/user.conf" -elif [ -f "${PROJECT_DIR}/default.conf" ]; then - echo "> Warning: No user.conf found, falling back to default.conf" - echo "> Loading config from ${PROJECT_DIR}/default.conf" - source "${PROJECT_DIR}/default.conf" -else - echo "> Error: No user.conf or user.conf found!" - exit -fi +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig sudo virsh destroy --domain "${VM_NAME}" sudo virsh undefine --domain "${VM_NAME}" --nvram \ No newline at end of file diff --git a/scripts/generate-helper-iso.sh b/scripts/generate-helper-iso.sh index 13d21e6..2ee89a1 100755 --- a/scripts/generate-helper-iso.sh +++ b/scripts/generate-helper-iso.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" if [ -f "${PROJECT_DIR}/user.conf" ]; then echo "> Loading config from ${PROJECT_DIR}/user.conf" diff --git a/scripts/generate-vm-config.sh b/scripts/generate-vm-config.sh index a88877b..cc765e2 100755 --- a/scripts/generate-vm-config.sh +++ b/scripts/generate-vm-config.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" #source "$UTILS_DIR/gpu-check" @@ -82,7 +78,7 @@ interactiveCfg "Network mode to use? Only supports TAP at the moment." NETWORK_M interactiveCfg "Use Looking Glass to get super low latency video output." USE_LOOKING_GLASS interactiveCfg "Max screen width with Looking Glass." LOOKING_GLASS_MAX_SCREEN_WIDTH interactiveCfg "Max screen height with Looking Glass." LOOKING_GLASS_MAX_SCREEN_HEIGHT -interactiveCfg "Version of Looking Glass to use (B3 is highly recommended)" LOOKING_GLASS_VERSION +interactiveCfg "Version of Looking Glass to use (B4 is highly recommended)" LOOKING_GLASS_VERSION interactiveCfg "Enable spice. (Recommended for Looking Glass, required to install Windows)" USE_SPICE interactiveCfg "Port to use for spice." SPICE_PORT interactiveCfg "Enable dma-buf. (Yet another way to get display access to your VM)" USE_DMA_BUF diff --git a/scripts/iommu-check.sh b/scripts/iommu-check.sh index ae6f23d..edb2e66 100755 --- a/scripts/iommu-check.sh +++ b/scripts/iommu-check.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" if sudo which optirun &> /dev/null && sudo optirun echo>/dev/null ; then OPTIRUN_PREFIX="optirun " diff --git a/scripts/make-windows-iso-auto-bootable b/scripts/make-windows-iso-auto-bootable index 54c3e86..95717ba 100755 --- a/scripts/make-windows-iso-auto-bootable +++ b/scripts/make-windows-iso-auto-bootable @@ -4,11 +4,8 @@ # WARNING: THIS SCRIPT DOES NOT WORK YET! # WARNING: THIS SCRIPT DOES NOT WORK YET! -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" # Variable containing the path to the windows.iso WIN10_IMG="$1" diff --git a/scripts/setup.sh b/scripts/setup.sh index 2f8d0ba..117a0f9 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,12 +1,8 @@ #!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" - -mkdir -p "${PROJECT_DIR}/thirdparty" +mkdir -p "${THIRDPARTY_DIR}" function commandsAvailable() { commandsMissing=() diff --git a/scripts/start-vm.sh b/scripts/start-vm.sh index e42526f..9dfb935 100755 --- a/scripts/start-vm.sh +++ b/scripts/start-vm.sh @@ -1,10 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="$(readlink -f "${SCRIPT_DIR}/..")" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig if [ "$1" = "install" ]; then VM_INSTALL=true @@ -13,23 +10,10 @@ else fi VM_START_MODE="qemu" # qemu or virt-install -# If user.conf doesn't exist use the default.conf -if [ -f "${PROJECT_DIR}/user.conf" ]; then - echo "> Loading config from ${PROJECT_DIR}/user.conf" - source "${PROJECT_DIR}/user.conf" -elif [ -f "${PROJECT_DIR}/default.conf" ]; then - echo "> Warning: No user.conf found, falling back to default.conf" - echo "> Loading config from ${PROJECT_DIR}/default.conf" - source "${PROJECT_DIR}/default.conf" -else - echo "> Error: No user.conf or user.conf found!" - exit -fi - #source "$UTILS_DIR/gpu-check" shopt -s expand_aliases -alias driver="sudo $UTILS_DIR/driver-util" -alias vgpu="sudo $UTILS_DIR/vgpu-util" +alias driver="sudo '$UTILS_DIR/driver-util'" +alias vgpu="sudo '$UTILS_DIR/vgpu-util'" VIRT_INSTALL_PARAMS=() QEMU_PARAMS=() diff --git a/utils/Fedora/34/amd-setup b/utils/Fedora/34/amd-setup deleted file mode 100755 index 5abb1d8..0000000 --- a/utils/Fedora/34/amd-setup +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -# This script doesn't do anything yet. \ No newline at end of file diff --git a/utils/Ubuntu/21.04/amd-setup b/utils/Ubuntu/21.04/amd-setup deleted file mode 100644 index 5abb1d8..0000000 --- a/utils/Ubuntu/21.04/amd-setup +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -# This script doesn't do anything yet. \ No newline at end of file diff --git a/utils/build-fake-battery-ssdt b/utils/build-fake-battery-ssdt deleted file mode 100755 index ac780d9..0000000 --- a/utils/build-fake-battery-ssdt +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" - -ACPI_TABLES_DIR="$(readlink -f "${PROJECT_DIR}/acpi-tables")" - -# This script compiles the asm source code for the SSDT table that contains a fake battery for the VM. - -iasl "${ACPI_TABLES_DIR}/fake-battery.asl" # creates fake-battery.aml \ No newline at end of file diff --git a/utils/gpu-check b/utils/common/libs/gpu-check similarity index 100% rename from utils/gpu-check rename to utils/common/libs/gpu-check diff --git a/utils/common/libs/helpers b/utils/common/libs/helpers new file mode 100644 index 0000000..58ffb4b --- /dev/null +++ b/utils/common/libs/helpers @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# This script has to be sourced and is not meant to be executed directly! +# How to use: +# while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +# source "$PROJECT_DIR/utils/helpers" + +USER_SCRIPTS_DIR="${PROJECT_DIR}/scripts" +UTILS_DIR="${PROJECT_DIR}/utils" +DISTRO=$("${UTILS_DIR}/distro-info") +DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" +ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" +LOG_BASE_DIR="${PROJECT_DIR}/logs" + +shopt -s expand_aliases + +function loadConfig() { + # If user.conf doesn't exist use the default.conf + if [ -f "${PROJECT_DIR}/user.conf" ]; then + echo "> Loading config from ${PROJECT_DIR}/user.conf" + source "${PROJECT_DIR}/user.conf" + elif [ -f "${PROJECT_DIR}/default.conf" ]; then + echo "> Warning: No user.conf found, falling back to default.conf" + echo "> Loading config from ${PROJECT_DIR}/default.conf" + source "${PROJECT_DIR}/default.conf" + else + echo "> Error: No user.conf or user.conf found!" + exit + fi +} \ No newline at end of file diff --git a/utils/common/setup/build-fake-battery-ssdt b/utils/common/setup/build-fake-battery-ssdt new file mode 100755 index 0000000..7ab1b65 --- /dev/null +++ b/utils/common/setup/build-fake-battery-ssdt @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" + +# This script compiles the asm source code for the SSDT table that contains a fake battery for the VM. + +iasl "${ACPI_TABLES_DIR}/fake-battery.asl" # creates fake-battery.aml \ No newline at end of file diff --git a/utils/extract-vbios b/utils/common/setup/extract-vbios similarity index 88% rename from utils/extract-vbios rename to utils/common/setup/extract-vbios index 614a889..17a23fc 100755 --- a/utils/extract-vbios +++ b/utils/common/setup/extract-vbios @@ -1,11 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" - +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" function extractNvideaVbios() { if which optirun ; then diff --git a/utils/ovmf-vbios-patch-setup b/utils/common/setup/ovmf-vbios-patch-setup similarity index 68% rename from utils/ovmf-vbios-patch-setup rename to utils/common/setup/ovmf-vbios-patch-setup index 94dc9da..ee8cb8f 100755 --- a/utils/ovmf-vbios-patch-setup +++ b/utils/common/setup/ovmf-vbios-patch-setup @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" # This script builds a Docker image that allows us to patch OVMF_CODE.fd and OVMF_VARS.fd with your vBIOS ROM. # This helps circumvent Nvidia's Error 43 in some cases. diff --git a/utils/schily-tools-setup b/utils/common/setup/schily-tools-setup similarity index 62% rename from utils/schily-tools-setup rename to utils/common/setup/schily-tools-setup index f2a338e..a32ba52 100755 --- a/utils/schily-tools-setup +++ b/utils/common/setup/schily-tools-setup @@ -1,13 +1,8 @@ #!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" - -mkdir -p "${PROJECT_DIR}/thirdparty" -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" SCHILY_VERSION="2021-06-07" SCHILY_ARCHIVE="schily-${SCHILY_VERSION}.tar.bz2" diff --git a/utils/set-kernel-params b/utils/common/setup/set-kernel-params similarity index 91% rename from utils/set-kernel-params rename to utils/common/setup/set-kernel-params index fd4bb43..454b98e 100755 --- a/utils/set-kernel-params +++ b/utils/common/setup/set-kernel-params @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-info b/utils/common/tools/distro-info similarity index 100% rename from utils/distro-info rename to utils/common/tools/distro-info diff --git a/utils/download-windows-iso b/utils/common/tools/download-windows-iso similarity index 100% rename from utils/download-windows-iso rename to utils/common/tools/download-windows-iso diff --git a/utils/driver-util b/utils/common/tools/driver-util similarity index 100% rename from utils/driver-util rename to utils/common/tools/driver-util diff --git a/utils/lsiommu b/utils/common/tools/lsiommu similarity index 100% rename from utils/lsiommu rename to utils/common/tools/lsiommu diff --git a/utils/vgpu-util b/utils/common/tools/vgpu-util similarity index 100% rename from utils/vgpu-util rename to utils/common/tools/vgpu-util diff --git a/utils/distro-specific/Fedora/34/amd-setup b/utils/distro-specific/Fedora/34/amd-setup new file mode 100755 index 0000000..de46034 --- /dev/null +++ b/utils/distro-specific/Fedora/34/amd-setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig + +source "$DISTRO_UTILS_DIR/kernel-param-utils" + +# This script doesn't do anything yet. \ No newline at end of file diff --git a/utils/Fedora/34/bumblebee-setup b/utils/distro-specific/Fedora/34/bumblebee-setup similarity index 81% rename from utils/Fedora/34/bumblebee-setup rename to utils/distro-specific/Fedora/34/bumblebee-setup index cc1bca1..9eec454 100755 --- a/utils/Fedora/34/bumblebee-setup +++ b/utils/distro-specific/Fedora/34/bumblebee-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/Fedora/34/install-dependencies b/utils/distro-specific/Fedora/34/install-dependencies similarity index 100% rename from utils/Fedora/34/install-dependencies rename to utils/distro-specific/Fedora/34/install-dependencies diff --git a/utils/Fedora/34/intel-setup b/utils/distro-specific/Fedora/34/intel-setup similarity index 68% rename from utils/Fedora/34/intel-setup rename to utils/distro-specific/Fedora/34/intel-setup index 710db43..12505de 100755 --- a/utils/Fedora/34/intel-setup +++ b/utils/distro-specific/Fedora/34/intel-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/Fedora/34/kernel-param-utils b/utils/distro-specific/Fedora/34/kernel-param-utils similarity index 100% rename from utils/Fedora/34/kernel-param-utils rename to utils/distro-specific/Fedora/34/kernel-param-utils diff --git a/utils/Fedora/34/looking-glass-setup b/utils/distro-specific/Fedora/34/looking-glass-setup similarity index 87% rename from utils/Fedora/34/looking-glass-setup rename to utils/distro-specific/Fedora/34/looking-glass-setup index d8f434f..6726010 100755 --- a/utils/Fedora/34/looking-glass-setup +++ b/utils/distro-specific/Fedora/34/looking-glass-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig mkdir -p "${PROJECT_DIR}/thirdparty" cd "${PROJECT_DIR}/thirdparty" diff --git a/utils/Fedora/34/nvidia-setup b/utils/distro-specific/Fedora/34/nvidia-setup similarity index 84% rename from utils/Fedora/34/nvidia-setup rename to utils/distro-specific/Fedora/34/nvidia-setup index e7186e2..359f7ee 100755 --- a/utils/Fedora/34/nvidia-setup +++ b/utils/distro-specific/Fedora/34/nvidia-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/Fedora/34/vbios-finder-installer b/utils/distro-specific/Fedora/34/vbios-finder-installer similarity index 74% rename from utils/Fedora/34/vbios-finder-installer rename to utils/distro-specific/Fedora/34/vbios-finder-installer index 4438341..0bd34a7 100755 --- a/utils/Fedora/34/vbios-finder-installer +++ b/utils/distro-specific/Fedora/34/vbios-finder-installer @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig mkdir -p "${PROJECT_DIR}/thirdparty" cd "${PROJECT_DIR}/thirdparty" diff --git a/utils/distro-specific/Ubuntu/21.04/amd-setup b/utils/distro-specific/Ubuntu/21.04/amd-setup new file mode 100644 index 0000000..de46034 --- /dev/null +++ b/utils/distro-specific/Ubuntu/21.04/amd-setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig + +source "$DISTRO_UTILS_DIR/kernel-param-utils" + +# This script doesn't do anything yet. \ No newline at end of file diff --git a/utils/Ubuntu/21.04/bumblebee-setup b/utils/distro-specific/Ubuntu/21.04/bumblebee-setup similarity index 79% rename from utils/Ubuntu/21.04/bumblebee-setup rename to utils/distro-specific/Ubuntu/21.04/bumblebee-setup index d4d5e5e..02b4012 100755 --- a/utils/Ubuntu/21.04/bumblebee-setup +++ b/utils/distro-specific/Ubuntu/21.04/bumblebee-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/Ubuntu/21.04/install-dependencies b/utils/distro-specific/Ubuntu/21.04/install-dependencies similarity index 72% rename from utils/Ubuntu/21.04/install-dependencies rename to utils/distro-specific/Ubuntu/21.04/install-dependencies index 98eb2f5..e54fc87 100755 --- a/utils/Ubuntu/21.04/install-dependencies +++ b/utils/distro-specific/Ubuntu/21.04/install-dependencies @@ -3,7 +3,7 @@ echo "Updating software..." sudo apt upgrade -y echo "Installing some useful tools..." -sudo apt install -y wget curl vim screen git crudini lshw msr-tools sysfsutils uml-utilities remmina samba spice-client-gtk genisoimage uuid acpica-tools docker e2fsprogs imake g++ +sudo apt install -y wget curl git crudini lshw msr-tools sysfsutils uml-utilities remmina samba spice-client-gtk genisoimage uuid acpica-tools docker echo "Installing virtualization software..." sudo apt install qemu-kvm qemu-utils qemu-efi ovmf qemu -y @@ -11,6 +11,7 @@ sudo apt install qemu-kvm qemu-utils qemu-efi ovmf qemu -y #sudo wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo -O /etc/yum.repos.d/virtio-win.repo echo "Installing virtio-modules" sudo apt install virtio-modules -y +# TODO: consider: wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso #echo "Upgrading to latest virtio-win..." #sudo dnf --enablerepo=virtio-win-latest upgrade virtio-win -y echo "Installing virt-viewer so you can connect to the VM for the windows installation" diff --git a/utils/Ubuntu/21.04/intel-setup b/utils/distro-specific/Ubuntu/21.04/intel-setup similarity index 61% rename from utils/Ubuntu/21.04/intel-setup rename to utils/distro-specific/Ubuntu/21.04/intel-setup index 5c9ca09..698dc51 100755 --- a/utils/Ubuntu/21.04/intel-setup +++ b/utils/distro-specific/Ubuntu/21.04/intel-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/Ubuntu/21.04/kernel-param-utils b/utils/distro-specific/Ubuntu/21.04/kernel-param-utils similarity index 100% rename from utils/Ubuntu/21.04/kernel-param-utils rename to utils/distro-specific/Ubuntu/21.04/kernel-param-utils diff --git a/utils/Ubuntu/21.04/looking-glass-setup b/utils/distro-specific/Ubuntu/21.04/looking-glass-setup similarity index 87% rename from utils/Ubuntu/21.04/looking-glass-setup rename to utils/distro-specific/Ubuntu/21.04/looking-glass-setup index 4552c0f..82a32eb 100755 --- a/utils/Ubuntu/21.04/looking-glass-setup +++ b/utils/distro-specific/Ubuntu/21.04/looking-glass-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig mkdir -p "${PROJECT_DIR}/thirdparty" cd "${PROJECT_DIR}/thirdparty" diff --git a/utils/Ubuntu/21.04/nvidia-setup b/utils/distro-specific/Ubuntu/21.04/nvidia-setup similarity index 82% rename from utils/Ubuntu/21.04/nvidia-setup rename to utils/distro-specific/Ubuntu/21.04/nvidia-setup index 996724a..fb90119 100755 --- a/utils/Ubuntu/21.04/nvidia-setup +++ b/utils/distro-specific/Ubuntu/21.04/nvidia-setup @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/Ubuntu/21.04/vbios-finder-installer b/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer similarity index 74% rename from utils/Ubuntu/21.04/vbios-finder-installer rename to utils/distro-specific/Ubuntu/21.04/vbios-finder-installer index b148e42..5edbd39 100755 --- a/utils/Ubuntu/21.04/vbios-finder-installer +++ b/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer @@ -1,11 +1,7 @@ #!/usr/bin/env bash - -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) -PROJECT_DIR="${SCRIPT_DIR}/../../.." -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -VM_FILES_DIR="${PROJECT_DIR}/vm-files" +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/utils/helpers" +loadCfg mkdir -p "${PROJECT_DIR}/thirdparty" cd "${PROJECT_DIR}/thirdparty" From 91d970d8cba134de12fc67231d53386e438e0a8e Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 3 Aug 2021 03:29:34 +0200 Subject: [PATCH 10/40] Major folder structure refactor --- dependencies.json | 42 --- mbpt.sh | 35 +- output.log | 357 ------------------ requirements.json | 51 +++ scripts/README.md | 15 + scripts/delete-vm.sh | 7 - scripts/generate-helper-iso.sh | 100 ----- scripts/{ => main}/compatibility-check.sh | 14 +- scripts/main/generate-helper-iso.sh | 92 +++++ scripts/{ => main}/generate-vm-config.sh | 8 +- scripts/{ => main}/iommu-check.sh | 10 +- scripts/main/remove-vm.sh | 16 + scripts/{ => main}/setup.sh | 68 ++-- scripts/{start-vm.sh => main/vm.sh} | 16 +- scripts/make-windows-iso-auto-bootable | 152 -------- .../utils}/common/libs/gpu-check | 6 + scripts/utils/common/libs/helpers | 41 ++ .../common/setup/build-fake-battery-ssdt | 5 +- .../utils}/common/setup/extract-vbios | 19 +- .../common/setup/ovmf-vbios-patch-setup | 8 +- .../utils}/common/setup/set-kernel-params | 7 +- scripts/utils/common/tools/commands-available | 23 ++ .../utils}/common/tools/distro-info | 5 + .../utils}/common/tools/download-windows-iso | 5 + .../utils}/common/tools/driver-util | 5 + {utils => scripts/utils}/common/tools/lsiommu | 5 + .../utils}/common/tools/vgpu-util | 5 + .../distro-specific/Fedora/34}/amd-setup | 2 +- .../distro-specific/Fedora/34/bumblebee-setup | 2 +- .../Fedora/34/install-dependencies | 0 .../distro-specific/Fedora/34/intel-setup | 2 +- .../Fedora/34/kernel-param-utils | 0 .../Fedora/34/looking-glass-setup | 7 +- .../distro-specific/Fedora/34/nvidia-setup | 4 +- .../Fedora/34/vbios-finder-installer | 5 +- .../distro-specific/Ubuntu/21.04}/amd-setup | 2 +- .../Ubuntu/21.04/bumblebee-setup | 2 +- .../Ubuntu/21.04/install-dependencies | 0 .../distro-specific/Ubuntu/21.04/intel-setup | 2 +- .../Ubuntu/21.04/kernel-param-utils | 0 .../Ubuntu/21.04/looking-glass-setup | 7 +- .../distro-specific/Ubuntu/21.04/nvidia-setup | 2 +- .../Ubuntu/21.04/vbios-finder-installer | 5 +- utils/common/libs/helpers | 31 -- utils/common/setup/schily-tools-setup | 16 - 45 files changed, 396 insertions(+), 810 deletions(-) delete mode 100644 dependencies.json delete mode 100644 output.log create mode 100644 requirements.json create mode 100644 scripts/README.md delete mode 100644 scripts/delete-vm.sh delete mode 100755 scripts/generate-helper-iso.sh rename scripts/{ => main}/compatibility-check.sh (94%) create mode 100755 scripts/main/generate-helper-iso.sh rename scripts/{ => main}/generate-vm-config.sh (93%) rename scripts/{ => main}/iommu-check.sh (66%) create mode 100644 scripts/main/remove-vm.sh rename scripts/{ => main}/setup.sh (56%) rename scripts/{start-vm.sh => main/vm.sh} (97%) delete mode 100755 scripts/make-windows-iso-auto-bootable rename {utils => scripts/utils}/common/libs/gpu-check (60%) create mode 100644 scripts/utils/common/libs/helpers rename {utils => scripts/utils}/common/setup/build-fake-battery-ssdt (51%) rename {utils => scripts/utils}/common/setup/extract-vbios (59%) rename {utils => scripts/utils}/common/setup/ovmf-vbios-patch-setup (59%) rename {utils => scripts/utils}/common/setup/set-kernel-params (86%) create mode 100755 scripts/utils/common/tools/commands-available rename {utils => scripts/utils}/common/tools/distro-info (73%) rename {utils => scripts/utils}/common/tools/download-windows-iso (72%) rename {utils => scripts/utils}/common/tools/driver-util (95%) rename {utils => scripts/utils}/common/tools/lsiommu (58%) rename {utils => scripts/utils}/common/tools/vgpu-util (96%) rename {utils/distro-specific/Ubuntu/21.04 => scripts/utils/distro-specific/Fedora/34}/amd-setup (81%) mode change 100644 => 100755 rename {utils => scripts/utils}/distro-specific/Fedora/34/bumblebee-setup (95%) rename {utils => scripts/utils}/distro-specific/Fedora/34/install-dependencies (100%) rename {utils => scripts/utils}/distro-specific/Fedora/34/intel-setup (91%) rename {utils => scripts/utils}/distro-specific/Fedora/34/kernel-param-utils (100%) rename {utils => scripts/utils}/distro-specific/Fedora/34/looking-glass-setup (92%) rename {utils => scripts/utils}/distro-specific/Fedora/34/nvidia-setup (93%) rename {utils => scripts/utils}/distro-specific/Fedora/34/vbios-finder-installer (87%) rename {utils/distro-specific/Fedora/34 => scripts/utils/distro-specific/Ubuntu/21.04}/amd-setup (81%) mode change 100755 => 100644 rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/bumblebee-setup (94%) rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/install-dependencies (100%) rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/intel-setup (90%) rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/kernel-param-utils (100%) rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/looking-glass-setup (92%) rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/nvidia-setup (95%) rename {utils => scripts/utils}/distro-specific/Ubuntu/21.04/vbios-finder-installer (87%) delete mode 100644 utils/common/libs/helpers delete mode 100755 utils/common/setup/schily-tools-setup diff --git a/dependencies.json b/dependencies.json deleted file mode 100644 index 77ba9cb..0000000 --- a/dependencies.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "general": { - "executables": ["sudo", "bash", "mv", "cp", "sed", "awk", "git", "echo", "ls", "wget", "curl", "printf", "cd", "mkdir", "chmod", "chown", "grep", "cut", "which", "", "", "", "", "", "", ""], - "files": [] - }, - "fake-battery": { - "executables": ["iasl"], - "files": [] - }, - "ovmf-vbios-patch": { - "executables": ["docker"], - "files": [] - }, - "generate-vm-config": { - "executables": ["crudini"], - "files": [] - }, - "vbios-finder": { - "executables": ["wget", "curl", "unzip", "ruby", "gem", "bundle", "7za", "make", "innoextract", "upx"], - "files": ["include/ruby/ruby.h"] - }, - "virtualization": { - "executables": ["virt-install", "qemu-system-x86_x64", "virsh"], - "files": ["OVMF/OVMF_CODE.fd", "OVMF/OVMF_VARS.fd", "virtio-win/virtio-win.iso"] - }, - "remote-desktop": { - "executables": ["remmina"], - "files": [] - }, - "file-sharing": { - "executables": ["samba"], - "files": [] - }, - "iGPU-passthrough": { - "executables": ["uuid", "intel-virtual-output"], - "files": [] - }, - "schily-tools": { - "executables": ["g++", "imake"], - "files": ["include/ext2fs/ext2fs.h"] - } -} \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index 350845d..9598964 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This is the only script that you should really care about as a user of MobilePassThrough. +# Usage: `./mbpt.sh --help` +##################################################################################################### COMMAND="$1" @@ -48,28 +53,30 @@ function printHelp() { if [ "$COMMAND" = "help" ] || [ "$COMMAND" = "--help" ] || [ "$COMMAND" = "-h" ] || [ "$COMMAND" = "" ]; then printHelp elif [ "$COMMAND" = "setup" ]; then - sudo "${USER_SCRIPTS_DIR}/setup.sh" + sudo "${MAIN_SCRIPTS_DIR}/setup.sh" elif [ "$COMMAND" = "check" ]; then - sudo "${USER_SCRIPTS_DIR}/compatibility-check.sh" + sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" elif [ "$COMMAND" = "configure" ]; then - "${USER_SCRIPTS_DIR}/generate-vm-config.sh" + "${MAIN_SCRIPTS_DIR}/generate-vm-config.sh" elif [ "$COMMAND" = "iso" ]; then - "${USER_SCRIPTS_DIR}/generate-helper-iso.sh" -elif [ "$COMMAND" = "install" ]; then - sudo "${USER_SCRIPTS_DIR}/start-vm.sh" install + "${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh" +elif [ "$COMMAND" = "install" ] || [ "$COMMAND" = "create" ]; then + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install +elif [ "$COMMAND" = "remove" ]; then + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" remove # TODO: implement this elif [ "$COMMAND" = "start" ]; then - sudo "${USER_SCRIPTS_DIR}/start-vm.sh" + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" elif [ "$COMMAND" = "auto" ]; then - sudo "${USER_SCRIPTS_DIR}/setup.sh" - sudo "${USER_SCRIPTS_DIR}/iommu-check.sh" - sudo "${USER_SCRIPTS_DIR}/start-vm.sh" install + sudo "${MAIN_SCRIPTS_DIR}/setup.sh" + sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install elif [ "$COMMAND" = "vbios" ]; then if [ "$2" == "extract" ]; then mkdir -p "$4/" - cd "${PROJECT_DIR}/thirdparty/VBiosFinder" + cd "${THIRDPARTY_DIR}/VBiosFinder" ./vbiosfinder extract "$(readlink -f "$3")" - mv "${PROJECT_DIR}/thirdparty/VBiosFinder/output/*" "$4/" + mv "${THIRDPARTY_DIR}/VBiosFinder/output/*" "$4/" elif [ "$2" == "dump" ]; then - sudo "${UTILS_DIR}/extract-vbios" "$3" "$4" + sudo "${COMMON_UTILS_SETUP_DIR}/extract-vbios" "$3" "$4" fi fi \ No newline at end of file diff --git a/output.log b/output.log deleted file mode 100644 index 3ccd6a2..0000000 --- a/output.log +++ /dev/null @@ -1,357 +0,0 @@ -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:204) Launched with command line: /usr/bin/virt-install --virt-type kvm --os-variant win10 --arch=x86_64 --cdrom /usr/share/virtio-win/virtio-win.iso --cdrom /home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso --disk /home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img --debug --qemu-commandline= -name 'WindowsVM' -machine type=q35,accel=kvm -global ICH9-LPC.disable_s3=1 -global ICH9-LPC.disable_s4=1 -enable-kvm -cpu host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum -smp '2' -m '8G' -mem-prealloc -rtc clock=host,base=localtime -nographic -serial none -parallel none -boot menu=on -boot order=d -k en-us -spice port=5900,addr=127.0.0.1,disable-ticketing -drive 'if=pflash,format=raw,readonly=on,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_CODE.fd' -drive 'if=pflash,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_VARS.fd' -drive 'file=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso,index=1,media=cdrom' -drive 'file=/usr/share/virtio-win/virtio-win.iso,index=2,media=cdrom' -drive 'file=/home/fedora/Projects/MobilePassThrough/vm-files/mobile-passthrough-helper.iso,index=3,media=cdrom' -fda '/usr/share/virtio-win/virtio-win_amd64.vfd' -fdb '/home/fedora/Projects/MobilePassThrough/vm-files/autounattend.vfd' -drive 'id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img' -netdev 'type=tap,id=net0,ifname=tap0,script=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifup,downscript=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifdown,vhost=on' -device ich9-intel-hda -device hda-output -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x080d,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=/home/fedora/Projects/MobilePassThrough/vm-files/vbios-roms/vbios_1002_694e_1.rom -device 'virtio-net-pci,netdev=net0,addr=19.0,mac=52:54:BE:EF:D3:5C' -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 -acpitable 'file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml' -usb -device usb-tablet -device usb-host,vendorid=0x0b95,productid=0x1790 -device ivshmem-plain,memdev=ivshmem,bus=pcie.0 -object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M -device qxl,bus=pcie.0,addr=1c.4,id=video.2 -vga qxl -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (virtinstall:212) Distilled --network options: ['default'] -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (virtinstall:144) Distilled --disk options: ['/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img'] -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:216) Requesting libvirt URI default -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:219) Received libvirt URI qemu:///system -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (guest:320) Setting Guest osinfo name <_OsVariant name=generic> -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (guest:320) Setting Guest osinfo name <_OsVariant name=win10> -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (installer:544) installer.detect_distro returned=win10 -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:265) Using default --name win10 -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (osdict:344) No recommended value found for key='storage', using minimum=21474836480 * 2 -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (osdict:344) No recommended value found for key='ram', using minimum=2147483648 * 2 -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (osdict:344) No recommended value found for key='n-cpus', using minimum=1 * 2 -[Sun, 25 Jul 2021 16:19:34 virt-install 10897] DEBUG (cli:265) Using win10 default --memory 4096 -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (graphics:165) Using default_graphics=spice -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (graphics:176) Local connection, disabling spice image compression. -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (disk:242) DeviceDisk.check_path_search path=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (disk:242) DeviceDisk.check_path_search path=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (disk:242) DeviceDisk.check_path_search path=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:265) -Starting install... -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (installer:599) Generated install XML: -<domain type="kvm"> - <name>win10</name> - <uuid>2c4503a5-11ba-4a5d-b850-8e65a31c187a</uuid> - <metadata> - <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0"> - <libosinfo:os id="http://microsoft.com/win/10"/> - </libosinfo:libosinfo> - </metadata> - <memory>4194304</memory> - <currentMemory>4194304</currentMemory> - <vcpu>2</vcpu> - <os> - <type arch="x86_64" machine="q35">hvm</type> - <boot dev="cdrom"/> - <boot dev="hd"/> - </os> - <features> - <acpi/> - <apic/> - <hyperv> - <relaxed state="on"/> - <vapic state="on"/> - <spinlocks state="on" retries="8191"/> - </hyperv> - <vmport state="off"/> - </features> - <cpu mode="host-model"/> - <clock offset="localtime"> - <timer name="rtc" tickpolicy="catchup"/> - <timer name="pit" tickpolicy="delay"/> - <timer name="hpet" present="no"/> - <timer name="hypervclock" present="yes"/> - </clock> - <on_reboot>destroy</on_reboot> - <pm> - <suspend-to-mem enabled="no"/> - <suspend-to-disk enabled="no"/> - </pm> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <disk type="file" device="disk"> - <driver name="qemu" type="raw"/> - <source file="/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> - <target dev="sda" bus="sata"/> - </disk> - <disk type="file" device="cdrom"> - <driver name="qemu" type="raw"/> - <source file="/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso"/> - <target dev="sdb" bus="sata"/> - <readonly/> - </disk> - <controller type="usb" model="qemu-xhci" ports="15"/> - <interface type="network"> - <source network="default"/> - <mac address="52:54:00:b1:94:e6"/> - <model type="e1000e"/> - </interface> - <console type="pty"/> - <channel type="spicevmc"> - <target type="virtio" name="com.redhat.spice.0"/> - </channel> - <input type="tablet" bus="usb"/> - <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> - <image compression="off"/> - </graphics> - <sound model="ich9"/> - <video> - <model type="qxl"/> - </video> - <redirdev bus="usb" type="spicevmc"/> - <redirdev bus="usb" type="spicevmc"/> - </devices> - <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> - <qemu:arg value="-name"/> - <qemu:arg value="WindowsVM"/> - <qemu:arg value="-machine"/> - <qemu:arg value="type=q35,accel=kvm"/> - <qemu:arg value="-global"/> - <qemu:arg value="ICH9-LPC.disable_s3=1"/> - <qemu:arg value="-global"/> - <qemu:arg value="ICH9-LPC.disable_s4=1"/> - <qemu:arg value="-enable-kvm"/> - <qemu:arg value="-cpu"/> - <qemu:arg value="host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum"/> - <qemu:arg value="-smp"/> - <qemu:arg value="2"/> - <qemu:arg value="-m"/> - <qemu:arg value="8G"/> - <qemu:arg value="-mem-prealloc"/> - <qemu:arg value="-rtc"/> - <qemu:arg value="clock=host,base=localtime"/> - <qemu:arg value="-nographic"/> - <qemu:arg value="-serial"/> - <qemu:arg value="none"/> - <qemu:arg value="-parallel"/> - <qemu:arg value="none"/> - <qemu:arg value="-boot"/> - <qemu:arg value="menu=on"/> - <qemu:arg value="-boot"/> - <qemu:arg value="order=d"/> - <qemu:arg value="-k"/> - <qemu:arg value="en-us"/> - <qemu:arg value="-spice"/> - <qemu:arg value="port=5900,addr=127.0.0.1,disable-ticketing"/> - <qemu:arg value="-drive"/> - <qemu:arg value="if=pflash,format=raw,readonly=on,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_CODE.fd"/> - <qemu:arg value="-drive"/> - <qemu:arg value="if=pflash,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_VARS.fd"/> - <qemu:arg value="-drive"/> - <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso,index=1,media=cdrom"/> - <qemu:arg value="-drive"/> - <qemu:arg value="file=/usr/share/virtio-win/virtio-win.iso,index=2,media=cdrom"/> - <qemu:arg value="-drive"/> - <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/mobile-passthrough-helper.iso,index=3,media=cdrom"/> - <qemu:arg value="-fda"/> - <qemu:arg value="/usr/share/virtio-win/virtio-win_amd64.vfd"/> - <qemu:arg value="-fdb"/> - <qemu:arg value="/home/fedora/Projects/MobilePassThrough/vm-files/autounattend.vfd"/> - <qemu:arg value="-drive"/> - <qemu:arg value="id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> - <qemu:arg value="-netdev"/> - <qemu:arg value="type=tap,id=net0,ifname=tap0,script=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifup,downscript=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifdown,vhost=on"/> - <qemu:arg value="-device"/> - <qemu:arg value="ich9-intel-hda"/> - <qemu:arg value="-device"/> - <qemu:arg value="hda-output"/> - <qemu:arg value="-device"/> - <qemu:arg value="ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1"/> - <qemu:arg value="-device"/> - <qemu:arg value="vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x080d,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=/home/fedora/Projects/MobilePassThrough/vm-files/vbios-roms/vbios_1002_694e_1.rom"/> - <qemu:arg value="-device"/> - <qemu:arg value="virtio-net-pci,netdev=net0,addr=19.0,mac=52:54:BE:EF:D3:5C"/> - <qemu:arg value="-device"/> - <qemu:arg value="pci-bridge,addr=12.0,chassis_nr=2,id=head.2"/> - <qemu:arg value="-acpitable"/> - <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml"/> - <qemu:arg value="-usb"/> - <qemu:arg value="-device"/> - <qemu:arg value="usb-tablet"/> - <qemu:arg value="-device"/> - <qemu:arg value="usb-host,vendorid=0x0b95,productid=0x1790"/> - <qemu:arg value="-device"/> - <qemu:arg value="ivshmem-plain,memdev=ivshmem,bus=pcie.0"/> - <qemu:arg value="-object"/> - <qemu:arg value="memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M"/> - <qemu:arg value="-device"/> - <qemu:arg value="qxl,bus=pcie.0,addr=1c.4,id=video.2"/> - <qemu:arg value="-vga"/> - <qemu:arg value="qxl"/> - </qemu:commandline> -</domain> - -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (installer:601) Generated boot XML: -<domain type="kvm"> - <name>win10</name> - <uuid>2c4503a5-11ba-4a5d-b850-8e65a31c187a</uuid> - <metadata> - <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0"> - <libosinfo:os id="http://microsoft.com/win/10"/> - </libosinfo:libosinfo> - </metadata> - <memory>4194304</memory> - <currentMemory>4194304</currentMemory> - <vcpu>2</vcpu> - <os> - <type arch="x86_64" machine="q35">hvm</type> - <boot dev="hd"/> - </os> - <features> - <acpi/> - <apic/> - <hyperv> - <relaxed state="on"/> - <vapic state="on"/> - <spinlocks state="on" retries="8191"/> - </hyperv> - <vmport state="off"/> - </features> - <cpu mode="host-model"/> - <clock offset="localtime"> - <timer name="rtc" tickpolicy="catchup"/> - <timer name="pit" tickpolicy="delay"/> - <timer name="hpet" present="no"/> - <timer name="hypervclock" present="yes"/> - </clock> - <pm> - <suspend-to-mem enabled="no"/> - <suspend-to-disk enabled="no"/> - </pm> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <disk type="file" device="disk"> - <driver name="qemu" type="raw"/> - <source file="/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> - <target dev="sda" bus="sata"/> - </disk> - <disk type="file" device="cdrom"> - <driver name="qemu" type="raw"/> - <source file="/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso"/> - <target dev="sdb" bus="sata"/> - <readonly/> - </disk> - <controller type="usb" model="qemu-xhci" ports="15"/> - <interface type="network"> - <source network="default"/> - <mac address="52:54:00:b1:94:e6"/> - <model type="e1000e"/> - </interface> - <console type="pty"/> - <channel type="spicevmc"> - <target type="virtio" name="com.redhat.spice.0"/> - </channel> - <input type="tablet" bus="usb"/> - <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> - <image compression="off"/> - </graphics> - <sound model="ich9"/> - <video> - <model type="qxl"/> - </video> - <redirdev bus="usb" type="spicevmc"/> - <redirdev bus="usb" type="spicevmc"/> - </devices> - <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> - <qemu:arg value="-name"/> - <qemu:arg value="WindowsVM"/> - <qemu:arg value="-machine"/> - <qemu:arg value="type=q35,accel=kvm"/> - <qemu:arg value="-global"/> - <qemu:arg value="ICH9-LPC.disable_s3=1"/> - <qemu:arg value="-global"/> - <qemu:arg value="ICH9-LPC.disable_s4=1"/> - <qemu:arg value="-enable-kvm"/> - <qemu:arg value="-cpu"/> - <qemu:arg value="host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum"/> - <qemu:arg value="-smp"/> - <qemu:arg value="2"/> - <qemu:arg value="-m"/> - <qemu:arg value="8G"/> - <qemu:arg value="-mem-prealloc"/> - <qemu:arg value="-rtc"/> - <qemu:arg value="clock=host,base=localtime"/> - <qemu:arg value="-nographic"/> - <qemu:arg value="-serial"/> - <qemu:arg value="none"/> - <qemu:arg value="-parallel"/> - <qemu:arg value="none"/> - <qemu:arg value="-boot"/> - <qemu:arg value="menu=on"/> - <qemu:arg value="-boot"/> - <qemu:arg value="order=d"/> - <qemu:arg value="-k"/> - <qemu:arg value="en-us"/> - <qemu:arg value="-spice"/> - <qemu:arg value="port=5900,addr=127.0.0.1,disable-ticketing"/> - <qemu:arg value="-drive"/> - <qemu:arg value="if=pflash,format=raw,readonly=on,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_CODE.fd"/> - <qemu:arg value="-drive"/> - <qemu:arg value="if=pflash,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/patched-ovmf-files/vbios_1002_694e_1.rom_OVMF_VARS.fd"/> - <qemu:arg value="-drive"/> - <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/windows10.iso,index=1,media=cdrom"/> - <qemu:arg value="-drive"/> - <qemu:arg value="file=/usr/share/virtio-win/virtio-win.iso,index=2,media=cdrom"/> - <qemu:arg value="-drive"/> - <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/mobile-passthrough-helper.iso,index=3,media=cdrom"/> - <qemu:arg value="-fda"/> - <qemu:arg value="/usr/share/virtio-win/virtio-win_amd64.vfd"/> - <qemu:arg value="-fdb"/> - <qemu:arg value="/home/fedora/Projects/MobilePassThrough/vm-files/autounattend.vfd"/> - <qemu:arg value="-drive"/> - <qemu:arg value="id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/MobilePassThrough/vm-files/WindowsVM.img"/> - <qemu:arg value="-netdev"/> - <qemu:arg value="type=tap,id=net0,ifname=tap0,script=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifup,downscript=/home/fedora/Projects/MobilePassThrough/vm-files/network-scripts/tap_ifdown,vhost=on"/> - <qemu:arg value="-device"/> - <qemu:arg value="ich9-intel-hda"/> - <qemu:arg value="-device"/> - <qemu:arg value="hda-output"/> - <qemu:arg value="-device"/> - <qemu:arg value="ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1"/> - <qemu:arg value="-device"/> - <qemu:arg value="vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x080d,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=/home/fedora/Projects/MobilePassThrough/vm-files/vbios-roms/vbios_1002_694e_1.rom"/> - <qemu:arg value="-device"/> - <qemu:arg value="virtio-net-pci,netdev=net0,addr=19.0,mac=52:54:BE:EF:D3:5C"/> - <qemu:arg value="-device"/> - <qemu:arg value="pci-bridge,addr=12.0,chassis_nr=2,id=head.2"/> - <qemu:arg value="-acpitable"/> - <qemu:arg value="file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml"/> - <qemu:arg value="-usb"/> - <qemu:arg value="-device"/> - <qemu:arg value="usb-tablet"/> - <qemu:arg value="-device"/> - <qemu:arg value="usb-host,vendorid=0x0b95,productid=0x1790"/> - <qemu:arg value="-device"/> - <qemu:arg value="ivshmem-plain,memdev=ivshmem,bus=pcie.0"/> - <qemu:arg value="-object"/> - <qemu:arg value="memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M"/> - <qemu:arg value="-device"/> - <qemu:arg value="qxl,bus=pcie.0,addr=1c.4,id=video.2"/> - <qemu:arg value="-vga"/> - <qemu:arg value="qxl"/> - </qemu:commandline> -</domain> - -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:255) File "/usr/bin/virt-install", line 8, in <module> - virtinstall.runcli() - File "/usr/share/virt-manager/virtinst/virtinstall.py", line 1158, in runcli - sys.exit(main()) - File "/usr/share/virt-manager/virtinst/virtinstall.py", line 1151, in main - start_install(guest, installer, options) - File "/usr/share/virt-manager/virtinst/virtinstall.py", line 901, in start_install - fail(e, do_exit=False) - File "/usr/share/virt-manager/virtinst/cli.py", line 255, in fail - log.debug("".join(traceback.format_stack())) - -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] ERROR (cli:256) internal error: process exited while connecting to monitor: qemu-system-x86_64: -acpitable file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: can't open file /home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: Permission denied -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:258) -Traceback (most recent call last): - File "/usr/share/virt-manager/virtinst/virtinstall.py", line 881, in start_install - domain = installer.start_install( - File "/usr/share/virt-manager/virtinst/install/installer.py", line 701, in start_install - domain = self._create_guest( - File "/usr/share/virt-manager/virtinst/install/installer.py", line 649, in _create_guest - domain = self.conn.createXML(install_xml or final_xml, 0) - File "/usr/lib64/python3.9/site-packages/libvirt.py", line 4366, in createXML - raise libvirtError('virDomainCreateXML() failed') -libvirt.libvirtError: internal error: process exited while connecting to monitor: qemu-system-x86_64: -acpitable file=/home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: can't open file /home/fedora/Projects/MobilePassThrough/vm-files/fake-battery.aml: Permission denied -[Sun, 25 Jul 2021 16:19:35 virt-install 10897] DEBUG (cli:271) Domain installation does not appear to have been successful. -If it was, you can restart your domain by running: - virsh --connect qemu:///system start win10 -otherwise, please restart your installation. -Domain installation does not appear to have been successful. -If it was, you can restart your domain by running: - virsh --connect qemu:///system start win10 -otherwise, please restart your installation. -Using default --name win10 -Using win10 default --memory 4096 \ No newline at end of file diff --git a/requirements.json b/requirements.json new file mode 100644 index 0000000..734e2d2 --- /dev/null +++ b/requirements.json @@ -0,0 +1,51 @@ +{ + "kernel-parameters": { + "general": ["iommu=1", "kvm.ignore_msrs=1", "rd.driver.pre=vfio-pci"], + "intel-cpu": ["intel_iommu=on"], + "amd-cpu": ["amd_iommu=on"], + "intel-gpu": ["i915.enable_gvt=1"], + "amd-gpu": [], + "nvidia-gpu": [], + "nuveau-gpu": [], + "bumblebee-nvidia": ["nouveau.modeset=0"], + "bumblebee-nuveau": [] + }, + "dependencies": { + "general": { + "executables": ["sudo", "bash", "mv", "cp", "sed", "awk", "git", "echo", "ls", "wget", "curl", "printf", "cd", "mkdir", "chmod", "chown", "grep", "cut", "which", "", "", "", "", "", "", ""], + "files": [] + }, + "fake-battery": { + "executables": ["iasl"], + "files": [] + }, + "ovmf-vbios-patch": { + "executables": ["git", "docker"], + "files": [] + }, + "generate-vm-config": { + "executables": ["crudini"], + "files": [] + }, + "vbios-finder": { + "executables": ["git", "wget", "curl", "unzip", "ruby", "gem", "bundle", "7za", "make", "innoextract", "upx"], + "files": ["include/ruby/ruby.h"] + }, + "virtualization": { + "executables": ["virt-install", "qemu-system-x86_x64", "virsh"], + "files": ["OVMF/OVMF_CODE.fd", "OVMF/OVMF_VARS.fd", "virtio-win/virtio-win.iso"] // TODO: get the iso using wget, cuz only rhel distros have a package for that anyways + }, + "remote-desktop": { + "executables": ["remmina"], + "files": [] + }, + "file-sharing": { + "executables": ["samba"], // double check + "files": [] + }, + "iGPU-passthrough": { + "executables": ["uuid", "intel-virtual-output"], + "files": [] + } + } +} \ No newline at end of file diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..c906b83 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,15 @@ +``` +scripts # All bash scripts called directly or indirectly by `mbpt.sh`. (Some scripts may also be installed in the `thirdparty` directory or may straight up be system dependencies installed using your package manager.) +├── main # Scripts that can be called directly or by running `mbpt.sh`. They work on any Linux distribution, given that a corresponding `utils/distro-specific/{DISTRIBUTION}/{VERSION}` directory with its scripts exists. +└── utils # Scripts that are used by other scripts in this project. + ├── common # Scripts that work on any Linux distribution, given that a corresponding `utils/distro-specific/{DISTRIBUTION}/{VERSION}` directory with its scripts exists. + │ ├── libs # Scripts that are not executable and have to be `source`d. + │ ├── setup # Scripts that have dependencies on other scripts (or programs in the `thirdparty` directory) in this project. + │ └── tools # Scripts that don't have dependencies on other files in this project and could be moved into their own project at some point. + └── distro-specific # Scripts that are distribution-specific. For every distribution/version the exact same set of scripts have to exist (same names, but different content of course). + ├── Fedora # All `Fedora`-specific scripts. + │ ├── 34 # All `Fedora 34`-specific scripts. + │ └── 35 # All `Fedora 35`-specific scripts. + └── Ubuntu # All `Ubuntu`-specific scripts. + └── 21.04 # All `Ubuntu 21.04`-specific scripts. +``` \ No newline at end of file diff --git a/scripts/delete-vm.sh b/scripts/delete-vm.sh deleted file mode 100644 index f0cfdb9..0000000 --- a/scripts/delete-vm.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" -loadConfig - -sudo virsh destroy --domain "${VM_NAME}" -sudo virsh undefine --domain "${VM_NAME}" --nvram \ No newline at end of file diff --git a/scripts/generate-helper-iso.sh b/scripts/generate-helper-iso.sh deleted file mode 100755 index 2ee89a1..0000000 --- a/scripts/generate-helper-iso.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" - -if [ -f "${PROJECT_DIR}/user.conf" ]; then - echo "> Loading config from ${PROJECT_DIR}/user.conf" - source "${PROJECT_DIR}/user.conf" -elif [ -f "${PROJECT_DIR}/default.conf" ]; then - echo "> Warning: No user.conf found, falling back to default.conf" - echo "> Loading config from ${PROJECT_DIR}/default.conf" - source "${PROJECT_DIR}/default.conf" -else - echo "> Error: No user.conf or user.conf found!" - exit -fi - -mkdir -p "${PROJECT_DIR}/helper-iso-files/bin" -mkdir -p "${PROJECT_DIR}/helper-iso-files/scripts" -#if [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/AutoHotkeyU64.exe" ]; then -# echo "> Downloading AutoHotkey..." -# rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -# mkdir -p "${PROJECT_DIR}/helper-iso-files/tmp" -# wget "https://autohotkey.com/download/ahk.zip" -O "${PROJECT_DIR}/helper-iso-files/tmp/ahk.zip" -# unzip "${PROJECT_DIR}/helper-iso-files/tmp/ahk.zip" -d "${PROJECT_DIR}/helper-iso-files/tmp/" -# echo "> Adding AutoHotkey to iso folder..." -# cp "${PROJECT_DIR}/helper-iso-files/tmp/AutoHotkeyU64.exe" "${PROJECT_DIR}/helper-iso-files/bin/" -# rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -#else -# echo "> AutoHotkey already exist in iso folder..." -#fi - -if [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/VC_redist.x64.exe" ]; then - echo "> Downloading Visual C++ Redistributable Package 2017 x64 for the Looking Glass Host application..." - wget "https://download.microsoft.com/download/8/9/D/89D195E1-1901-4036-9A75-FBE46443FC5A/VC_redist.x64.exe" -O "${PROJECT_DIR}/helper-iso-files/bin/VC_redist.x64.exe" -else - echo "> Visual C++ Redistributable Package 2017 x64 already exist in iso folder..." -fi - -if [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/looking-glass-host-setup.exe" ]; then - #echo "> Downloading Looking Glass Host application..." - #wget "https://github.com/gnif/LookingGlass/releases/download/${LOOKING_GLASS_VERSION}/looking-glass-host.exe" -O "${PROJECT_DIR}/helper-iso-files/bin/looking-glass-host.exe" - echo "> Copy Looking Glass Host application setup to where we need it..." - cp "${PROJECT_DIR}/thirdparty/LookingGlass/platform/Windows/looking-glass-host-setup.exe" "${PROJECT_DIR}/helper-iso-files/bin/looking-glass-host-setup.exe" -else - echo "> Looking Glass Host application already exist in iso folder..." -fi - -#if [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver/ivshmem.cat" ] || [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver/ivshmem.inf" ] || [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver/ivshmem.pdb" ] || [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver/ivshmem.sys" ]; then -# echo "> Downloading IVSHMEM driver..." -# rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -# mkdir -p "${PROJECT_DIR}/helper-iso-files/tmp" -# wget "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/upstream-virtio/virtio-win10-prewhql-0.1-161.zip" -O "${PROJECT_DIR}/helper-iso-files/tmp/virtio-win10-prewhql.zip" -# unzip "${PROJECT_DIR}/helper-iso-files/tmp/virtio-win10-prewhql.zip" -d "${PROJECT_DIR}/helper-iso-files/tmp" -# rm -f "${PROJECT_DIR}/helper-iso-files/tmp/virtio-win10-prewhql.zip" -# rm -rf "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver" -# mkdir -p "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver" -# cp "${PROJECT_DIR}/helper-iso-files/tmp/Win10/amd64/ivshmem*" "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver/" -# #cp -r "${PROJECT_DIR}/helper-iso-files/tmp" "${PROJECT_DIR}/helper-iso-files/bin/ivshmem-driver" -# rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -#else -# echo "> IVSHMEM driver already exist in iso folder..." -#fi - -if [ ! -d "${PROJECT_DIR}/helper-iso-files/bin/virtio-drivers/Win10" ]; then - echo "> Downloading virtio drivers..." - rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" - mkdir -p "${PROJECT_DIR}/helper-iso-files/tmp" - wget "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/upstream-virtio/virtio-win10-prewhql-0.1-161.zip" -O "${PROJECT_DIR}/helper-iso-files/tmp/virtio-win10-prewhql.zip" - mkdir -p "${PROJECT_DIR}/helper-iso-files/bin/virtio-drivers" - unzip "${PROJECT_DIR}/helper-iso-files/tmp/virtio-win10-prewhql.zip" -d "${PROJECT_DIR}/helper-iso-files/bin/virtio-drivers" - rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -else - echo "> virtio drivers already exist in iso folder..." -fi - -#if [ ! -f "${PROJECT_DIR}/helper-iso-files/bin/devcon.exe" ]; then -# echo "> Downloading Microsoft's devcon driver tool..." -# rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -# mkdir -p "${PROJECT_DIR}/helper-iso-files/tmp" -# wget "https://download.microsoft.com/download/B/5/8/B58D625D-17D6-47A8-B3D3-668670B6D1EB/wdk/Installers/787bee96dbd26371076b37b13c405890.cab" -O "${PROJECT_DIR}/helper-iso-files/tmp/devcon.cab" -# cabextract -d "${PROJECT_DIR}/helper-iso-files/tmp" "${PROJECT_DIR}/helper-iso-files/tmp/devcon.cab" -# cp "${PROJECT_DIR}/helper-iso-files/tmp/devcon.cab" "${PROJECT_DIR}/helper-iso-files/bin/devcon.exe" -# #TODO: check if installing the cabextract is necessary or if it actually is devcon directly -# rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" -#else -# echo "> devcon driver tool already exist in iso folder..." -#fi - -if [ ! -f "${PROJECT_DIR}/helper-iso-files/scripts/chcolatey-install.ps1" ]; then - echo "> Downloading Chocolatey install script..." - wget "https://chocolatey.org/install.ps1" -O "${PROJECT_DIR}/helper-iso-files/scripts/chcolatey-install.ps1" -else - echo "> Chocolatey install script already exist in iso folder..." -fi - -rm -rf "${PROJECT_DIR}/helper-iso-files/tmp" - -rm -f "${HELPER_ISO}" -#echo "genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o \"${HELPER_ISO}\" \"${PROJECT_DIR}/helper-iso-files\"" -genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o "${HELPER_ISO}" "${PROJECT_DIR}/helper-iso-files" diff --git a/scripts/compatibility-check.sh b/scripts/main/compatibility-check.sh similarity index 94% rename from scripts/compatibility-check.sh rename to scripts/main/compatibility-check.sh index 374f5e9..add14ec 100755 --- a/scripts/compatibility-check.sh +++ b/scripts/main/compatibility-check.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This script checks the device it's executed on for GPU passthrough compatibility and prints a detailed report to the terminal. +##################################################################################################### # Enable these to mock the lshw output and iommu groups of other computers for testing purposes #MOCK_SET=1 -#LSHW_MOCK="${SCRIPT_DIR}/mock-data/$MOCK_SET-lshw" -#LSIOMMU_MOCK="${SCRIPT_DIR}/mock-data/$MOCK_SET-lsiommu" +#LSHW_MOCK="${PROJECT_DIR}/mock-data/$MOCK_SET-lshw" +#LSIOMMU_MOCK="${PROJECT_DIR}/mock-data/$MOCK_SET-lsiommu" if sudo which optirun &> /dev/null && sudo optirun echo>/dev/null ; then USE_BUMBLEBEE=true @@ -16,7 +20,7 @@ else fi if [ -z ${LSIOMMU_MOCK+x} ]; then - IOMMU_GROUPS=$(sudo ${OPTIRUN_PREFIX}${UTILS_DIR}/lsiommu) + IOMMU_GROUPS=$(sudo ${OPTIRUN_PREFIX}${COMMON_UTILS_TOOLS_DIR}/lsiommu) MOCK_MODE=false else IOMMU_GROUPS=$(cat "${LSIOMMU_MOCK}") @@ -221,7 +225,7 @@ fi #echo "Listing IOMMU Groups..." -#${SCRIPT_DIR}/utils/lsiommu +#${COMMON_UTILS_TOOLS_DIR}/lsiommu #echo "Listing GPU info with lshw..." #sudo lshw -class display diff --git a/scripts/main/generate-helper-iso.sh b/scripts/main/generate-helper-iso.sh new file mode 100755 index 0000000..bef1a12 --- /dev/null +++ b/scripts/main/generate-helper-iso.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This script creates a helper ISO file containing scripts and drivers to fully automate the Windows installation within the VM. +##################################################################################################### + +mkdir -p "${HELPER_ISO_FILES_DIR}/bin" +mkdir -p "${HELPER_ISO_FILES_DIR}/scripts" +#if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/AutoHotkeyU64.exe" ]; then +# echo "> Downloading AutoHotkey..." +# rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +# mkdir -p "${HELPER_ISO_FILES_DIR}/tmp" +# wget "https://autohotkey.com/download/ahk.zip" -O "${HELPER_ISO_FILES_DIR}/tmp/ahk.zip" +# unzip "${HELPER_ISO_FILES_DIR}/tmp/ahk.zip" -d "${HELPER_ISO_FILES_DIR}/tmp/" +# echo "> Adding AutoHotkey to iso folder..." +# cp "${HELPER_ISO_FILES_DIR}/tmp/AutoHotkeyU64.exe" "${HELPER_ISO_FILES_DIR}/bin/" +# rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +#else +# echo "> AutoHotkey already exist in iso folder..." +#fi + +if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/VC_redist.x64.exe" ]; then + echo "> Downloading Visual C++ Redistributable Package 2017 x64 for the Looking Glass Host application..." + wget "https://download.microsoft.com/download/8/9/D/89D195E1-1901-4036-9A75-FBE46443FC5A/VC_redist.x64.exe" -O "${HELPER_ISO_FILES_DIR}/bin/VC_redist.x64.exe" +else + echo "> Visual C++ Redistributable Package 2017 x64 already exist in iso folder..." +fi + +if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host-setup.exe" ]; then + #echo "> Downloading Looking Glass Host application..." + #wget "https://github.com/gnif/LookingGlass/releases/download/${LOOKING_GLASS_VERSION}/looking-glass-host.exe" -O "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host.exe" + echo "> Copy Looking Glass Host application setup to where we need it..." + cp "${PROJECT_DIR}/thirdparty/LookingGlass/platform/Windows/looking-glass-host-setup.exe" "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host-setup.exe" +else + echo "> Looking Glass Host application already exist in iso folder..." +fi + +#if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver/ivshmem.cat" ] || [ ! -f "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver/ivshmem.inf" ] || [ ! -f "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver/ivshmem.pdb" ] || [ ! -f "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver/ivshmem.sys" ]; then +# echo "> Downloading IVSHMEM driver..." +# rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +# mkdir -p "${HELPER_ISO_FILES_DIR}/tmp" +# wget "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/upstream-virtio/virtio-win10-prewhql-0.1-161.zip" -O "${HELPER_ISO_FILES_DIR}/tmp/virtio-win10-prewhql.zip" +# unzip "${HELPER_ISO_FILES_DIR}/tmp/virtio-win10-prewhql.zip" -d "${HELPER_ISO_FILES_DIR}/tmp" +# rm -f "${HELPER_ISO_FILES_DIR}/tmp/virtio-win10-prewhql.zip" +# rm -rf "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver" +# mkdir -p "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver" +# cp "${HELPER_ISO_FILES_DIR}/tmp/Win10/amd64/ivshmem*" "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver/" +# #cp -r "${HELPER_ISO_FILES_DIR}/tmp" "${HELPER_ISO_FILES_DIR}/bin/ivshmem-driver" +# rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +#else +# echo "> IVSHMEM driver already exist in iso folder..." +#fi + +if [ ! -d "${HELPER_ISO_FILES_DIR}/bin/virtio-drivers/Win10" ]; then + echo "> Downloading virtio drivers..." + rm -rf "${HELPER_ISO_FILES_DIR}/tmp" + mkdir -p "${HELPER_ISO_FILES_DIR}/tmp" + wget "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/upstream-virtio/virtio-win10-prewhql-0.1-161.zip" -O "${HELPER_ISO_FILES_DIR}/tmp/virtio-win10-prewhql.zip" + mkdir -p "${HELPER_ISO_FILES_DIR}/bin/virtio-drivers" + unzip "${HELPER_ISO_FILES_DIR}/tmp/virtio-win10-prewhql.zip" -d "${HELPER_ISO_FILES_DIR}/bin/virtio-drivers" + rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +else + echo "> virtio drivers already exist in iso folder..." +fi + +#if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/devcon.exe" ]; then +# echo "> Downloading Microsoft's devcon driver tool..." +# rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +# mkdir -p "${HELPER_ISO_FILES_DIR}/tmp" +# wget "https://download.microsoft.com/download/B/5/8/B58D625D-17D6-47A8-B3D3-668670B6D1EB/wdk/Installers/787bee96dbd26371076b37b13c405890.cab" -O "${HELPER_ISO_FILES_DIR}/tmp/devcon.cab" +# cabextract -d "${HELPER_ISO_FILES_DIR}/tmp" "${HELPER_ISO_FILES_DIR}/tmp/devcon.cab" +# cp "${HELPER_ISO_FILES_DIR}/tmp/devcon.cab" "${HELPER_ISO_FILES_DIR}/bin/devcon.exe" +# #TODO: check if installing the cabextract is necessary or if it actually is devcon directly +# rm -rf "${HELPER_ISO_FILES_DIR}/tmp" +#else +# echo "> devcon driver tool already exist in iso folder..." +#fi + +if [ ! -f "${HELPER_ISO_FILES_DIR}/scripts/chcolatey-install.ps1" ]; then + echo "> Downloading Chocolatey install script..." + wget "https://chocolatey.org/install.ps1" -O "${HELPER_ISO_FILES_DIR}/scripts/chcolatey-install.ps1" +else + echo "> Chocolatey install script already exist in iso folder..." +fi + +rm -rf "${HELPER_ISO_FILES_DIR}/tmp" + +rm -f "${HELPER_ISO}" +#echo "genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o \"${HELPER_ISO}\" \"${HELPER_ISO_FILES_DIR}\"" +genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o "${HELPER_ISO}" "${HELPER_ISO_FILES_DIR}" diff --git a/scripts/generate-vm-config.sh b/scripts/main/generate-vm-config.sh similarity index 93% rename from scripts/generate-vm-config.sh rename to scripts/main/generate-vm-config.sh index cc765e2..ac494c8 100755 --- a/scripts/generate-vm-config.sh +++ b/scripts/main/generate-vm-config.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This interactive script creates a custom config file (user.conf) to your liking. +##################################################################################################### #source "$UTILS_DIR/gpu-check" @@ -93,5 +97,5 @@ interactiveCfg "List of USB devices to pass through. (Semicolon separated, e.g. source "$USER_CONFIG_FILE" if [ ! -f "$INSTALL_IMG" ]; then echo "'$INSTALL_IMG' does not exist and will be downloaded automatically now. If you don't want that, press Ctrl+C to cancel it." - $UTILS_DIR/download-windows-iso "$INSTALL_IMG" + "$COMMON_UTILS_TOOLS_DIR/download-windows-iso" "$INSTALL_IMG" fi diff --git a/scripts/iommu-check.sh b/scripts/main/iommu-check.sh similarity index 66% rename from scripts/iommu-check.sh rename to scripts/main/iommu-check.sh index edb2e66..279ad34 100755 --- a/scripts/iommu-check.sh +++ b/scripts/main/iommu-check.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This script checks if virtualization and IOMMU are enabled in the UEFI and kernel. +# Exits with 0 in case of success; Exits with 1 if it's not fully enabled. +# Will print helpful output telling you what is working and what is not. +##################################################################################################### if sudo which optirun &> /dev/null && sudo optirun echo>/dev/null ; then OPTIRUN_PREFIX="optirun " @@ -8,7 +14,7 @@ else OPTIRUN_PREFIX="" fi -IOMMU_GROUPS=$(sudo ${OPTIRUN_PREFIX}${UTILS_DIR}/lsiommu) +IOMMU_GROUPS=$(sudo ${OPTIRUN_PREFIX}${COMMON_UTILS_TOOLS_DIR}/lsiommu) # Check if UEFI is configured correctly if systool -m kvm_intel -v &> /dev/null || systool -m kvm_amd -v &> /dev/null ; then diff --git a/scripts/main/remove-vm.sh b/scripts/main/remove-vm.sh new file mode 100644 index 0000000..678f671 --- /dev/null +++ b/scripts/main/remove-vm.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# This script deletes the Windows VM in case it already exists. Call this script like this `./delete-vm.sh` +##################################################################################################### + +sudo virsh destroy --domain "${VM_NAME}" +sudo virsh undefine --domain "${VM_NAME}" --nvram + +# TODO: consider moving this to vm.sh and maybe make it usable like this: +# vm.sh remove +# vm.sh install +# vm.sh start \ No newline at end of file diff --git a/scripts/setup.sh b/scripts/main/setup.sh similarity index 56% rename from scripts/setup.sh rename to scripts/main/setup.sh index 117a0f9..75be0c9 100755 --- a/scripts/setup.sh +++ b/scripts/main/setup.sh @@ -1,27 +1,21 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This script installs all missing and required dependencies and also adds required kernel parameters. It's called like this: `./setup.sh` +# If you want to automatically reboot the system if necessary (e.g. to load new kernel params) run with: `./setup.sh auto`. +# This won't just reboot the system, but also create a temporary service that will execute `mbpt.sh auto` on the next boot. +# TODO: the service creation shouldn'T be part of setup.sh. It should be in the auto section of mbpt.sh. +##################################################################################################### mkdir -p "${THIRDPARTY_DIR}" -function commandsAvailable() { - commandsMissing=() - for currentCommand in $1; do - if ! command -v $currentCommand &> /dev/null; then - commandsMissing+=("$currentCommand") - fi - done - if ((${#commandsMissing[@]})); then - echo "Missing commands: ${commandsMissing[@]}" - return 1 # Some commands are missing - else - return 0 - fi -} +# TODO: parse requirements.json and install dependencies automatically # TODO: complete this list -if ! commandsAvailable "wget curl vim screen git crudini remmina spicy genisoimage uuid iasl docker dumpet imake g++ virt-install qemu-system-x86_64 systool"; then - sudo $DISTRO_UTILS_DIR/install-dependencies +if ! "${COMMON_UTILS_TOOLS_DIR}/commands-available" "wget curl vim screen git crudini remmina spicy genisoimage uuid iasl docker dumpet imake g++ virt-install qemu-system-x86_64 systool"; then + sudo "$DISTRO_UTILS_DIR/install-dependencies" else echo "[Skipped] Required packages already installed." fi @@ -37,61 +31,51 @@ if runtimeKernelHasParam "iommu=1" && \ REBOOT_REQUIRED=false echo "[Skipped] Kernel parameters are already set." else - sudo $UTILS_DIR/set-kernel-params + sudo "$COMMON_UTILS_SETUP_DIR/set-kernel-params" REBOOT_REQUIRED=true fi if [[ "$(docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then - sudo $UTILS_DIR/ovmf-vbios-patch-setup + sudo "$COMMON_UTILS_SETUP_DIR/ovmf-vbios-patch-setup" else echo "[Skipped] Image 'ovmf-vbios-patch' has already been built." fi -source "$UTILS_DIR/gpu-check" +source "$COMMON_UTILS_LIBS_DIR/gpu-check" if [ "$HAS_INTEL_GPU" = true ]; then - sudo $DISTRO_UTILS_DIR/intel-setup + sudo "$DISTRO_UTILS_DIR/intel-setup" fi if [ "$HAS_AMD_GPU" = true ]; then - sudo $DISTRO_UTILS_DIR/amd-setup + sudo "$DISTRO_UTILS_DIR/amd-setup" fi if [ "$HAS_NVIDIA_GPU" = true ]; then - sudo $DISTRO_UTILS_DIR/nvidia-setup + sudo "$DISTRO_UTILS_DIR/nvidia-setup" fi if [ "$SUPPORTS_OPTIMUS" = true ]; then - sudo $DISTRO_UTILS_DIR/bumblebee-setup + sudo "$DISTRO_UTILS_DIR/bumblebee-setup" fi -if [ ! -f "${PROJECT_DIR}/acpi-tables/fake-battery.aml" ]; then - sudo $UTILS_DIR/build-fake-battery-ssdt +if [ ! -f "${ACPI_TABLES_DIR}/fake-battery.aml" ]; then + sudo "$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssdt" else echo "[Skipped] Fake ACPI SSDT battery has already been built." fi -if [ ! -f "${PROJECT_DIR}/thirdparty/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then - sudo $DISTRO_UTILS_DIR/vbios-finder-installer/vbiosfinder +if [ ! -f "${THIRDPARTY_DIR}/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then + sudo "$DISTRO_UTILS_DIR/vbios-finder-installer/vbiosfinder" else echo "[Skipped] VBiosFinder is already set up." fi -if [ ! -f "${PROJECT_DIR}/thirdparty/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${PROJECT_DIR}/thirdparty/LookingGlass/client/build/looking-glass-client" ]; then - sudo $DISTRO_UTILS_DIR/looking-glass-setup +if [ ! -f "${THIRDPARTY_DIR}/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" ]; then + sudo "$DISTRO_UTILS_DIR/looking-glass-setup" else echo "[Skipped] Looking Glass is already set up." fi -#if [ ! -f "${PROJECT_DIR}/thirdparty/schily-tools/mkisofs/OBJ/x86_64-linux-gcc/mkisofs" ]; then -# sudo $UTILS_DIR/schily-tools-setup -#else -# echo "[Skipped] Schily Tools is already set up." -#fi - -#echo "> Generating vFloppy for auto Widnows Installation..." -#sudo ${SCRIPT_DIR}/generate-autounattend-vfd.sh -# TODO: add check if files have changed and vfd needs to be regenerated - echo "> Generating helper-iso for auto Windows Configuration / Driver installation..." -sudo ${SCRIPT_DIR}/generate-helper-iso.sh +sudo ${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh # TODO: add check if files have changed and helper iso needs to be regenerated @@ -99,7 +83,7 @@ if [ "$1" = "auto" ]; then if [ REBOOT_REQUIRED = true ]; then echo "> Creating a temporary service that will run on next reboot and create the Windows VM" echo "exit because this has not been tested yet" - exit + exit # TODO: TEST THIS sudo echo "[Unit] Description=MobilePassthroughInitSetup After=multi-user.target network.target diff --git a/scripts/start-vm.sh b/scripts/main/vm.sh similarity index 97% rename from scripts/start-vm.sh rename to scripts/main/vm.sh index 9dfb935..a2b29e5 100755 --- a/scripts/start-vm.sh +++ b/scripts/main/vm.sh @@ -1,8 +1,13 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig +##################################################################################################### +# This script can create a VM and install Windows in i,t if called like this: `./vm.sh install` +# or start the previously created Windows VM, if called like this: `./vm.sh` +##################################################################################################### + if [ "$1" = "install" ]; then VM_INSTALL=true else @@ -10,10 +15,10 @@ else fi VM_START_MODE="qemu" # qemu or virt-install -#source "$UTILS_DIR/gpu-check" +#source "$COMMON_UTILS_LIBS_DIR/gpu-check" shopt -s expand_aliases -alias driver="sudo '$UTILS_DIR/driver-util'" -alias vgpu="sudo '$UTILS_DIR/vgpu-util'" +alias driver="sudo '$COMMON_UTILS_TOOLS_DIR/driver-util'" +alias vgpu="sudo '$COMMON_UTILS_TOOLS_DIR/vgpu-util'" VIRT_INSTALL_PARAMS=() QEMU_PARAMS=() @@ -120,7 +125,6 @@ if [[ ${DRIVE_IMG} == /dev/* ]]; then elif [[ ${DRIVE_IMG} == *.img ]]; then echo "> Using a virtual OS drive..." if [ ! -f "${DRIVE_IMG}" ]; then - #sudo $DISTRO_UTILS_DIR/prepare-vm echo "> Creating a virtual disk for the VM..." qemu-img create -f raw "${DRIVE_IMG}" "${VM_DISK_SIZE}" sudo chown "$(whoami):$(id -gn "$(whoami)")" "${DRIVE_IMG}" @@ -346,7 +350,7 @@ fi if [ "$USE_FAKE_BATTERY" = true ]; then echo "> Using fake battery..." if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ]; then - mv "${PROJECT_DIR}/acpi-tables/fake-battery.aml" "${VM_FILES_DIR}/fake-battery.aml" + mv "${ACPI_TABLES_DIR}/fake-battery.aml" "${VM_FILES_DIR}/fake-battery.aml" fi FAKE_BATTERY_SSDT_TABLE="$(readlink -f "${VM_FILES_DIR}/fake-battery.aml")" if [ "$VM_START_MODE" = "qemu" ]; then diff --git a/scripts/make-windows-iso-auto-bootable b/scripts/make-windows-iso-auto-bootable deleted file mode 100755 index 95717ba..0000000 --- a/scripts/make-windows-iso-auto-bootable +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env bash - -# WARNING: THIS SCRIPT DOES NOT WORK YET! -# WARNING: THIS SCRIPT DOES NOT WORK YET! -# WARNING: THIS SCRIPT DOES NOT WORK YET! - -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" - -# Variable containing the path to the windows.iso -WIN10_IMG="$1" - -TMP="./tmp" -ISO_FILES="${TMP}/iso-files" -ISO_MP="${TMP}/iso-mountpoint" - -sudo rm -rf "${TMP}" -mkdir -p "${ISO_FILES}" -mkdir -p "${ISO_MP}" -sudo mount -t udf "${WIN10_IMG}" "${ISO_MP}" -sudo cp -Rva ${ISO_MP}/* "${ISO_FILES}" -sudo umount "${ISO_MP}" - -# Make modifications to the Windows ISO -#BOOT_DIR="${ISO_FILES}/efi/microsoft/boot" -#sudo mv "${BOOT_DIR}/cdboot.efi" "${BOOT_DIR}/tmp.efi" -#sudo mv "${BOOT_DIR}/cdboot_noprompt.efi" "${BOOT_DIR}/cdboot.efi" -#sudo mv "${BOOT_DIR}/tmp.efi" "${BOOT_DIR}/cdboot_noprompt.efi" - -# Extract the boot.img -#BOOT_SECTOR_LENGTH="$(isoinfo -d -i "${WIN10_IMG}" | grep "Nsect " | grep -o "[^ ]*$")" -#STARTING_SECTOR="$(isoinfo -d -i ./vm-files/windows10.iso | grep "Bootoff " | grep -o "[^ ]*$")" -#dd if="${WIN10_IMG}" of="${ISO_FILES}/boot.img" bs=2048 count="${BOOT_SECTOR_LENGTH}" skip="${STARTING_SECTOR}" - - -# Extract boot load segment address and size -BOOT_LOAD_SEG="$(dumpet -i "${WIN10_IMG}" | grep "Media load segment: " | cut -d ':' -f2 | cut -d ' ' -f2)" -BOOT_LOAD_SIZE="$(dumpet -i "${WIN10_IMG}" | grep "Load Sectors: " | grep -o "[^:]*$" | cut -d ' ' -f2 | head -1)" - -EFI_STARTING_SECTOR="$(dumpet -i "${WIN10_IMG}" | grep "Load LBA: " | grep -o "[^:]*$" | cut -d ' ' -f2 | tail -1)" - -echo "EFI_STARTING_SECTOR: $EFI_STARTING_SECTOR" - -sudo dd if="${WIN10_IMG}" of="${ISO_FILES}/efi.dmp" bs=2048 count=1 skip="${EFI_STARTING_SECTOR}" -EFI_BOOT_LOAD_SIZE="$(file "${ISO_FILES}/efi.dmp" | grep -oP 'sectors (\d+)' | cut -d ' ' -f2)" -echo "EFI_BOOT_LOAD_SIZE: $EFI_BOOT_LOAD_SIZE" -sudo rm -f "${ISO_FILES}/efi.dmp" -sudo rm -f "${ISO_FILES}/efi/win_efi_boot.img" -sudo dd if="${WIN10_IMG}" of="${ISO_FILES}/efi/win_efi_boot.img" bs=2048 count="${EFI_BOOT_LOAD_SIZE}" skip="${EFI_STARTING_SECTOR}" - -sudo rm -rf "${ISO_FILES}/efi/microsoft/boot/cdboot.efi" -sudo mv "${ISO_FILES}/efi/microsoft/boot/cdboot_noprompt.efi" "${ISO_FILES}/efi/microsoft/boot/cdboot.efi" -sudo rm -rf "${ISO_FILES}/efi/microsoft/boot/efisys.bin" -sudo mv "${ISO_FILES}/efi/microsoft/boot/efisys_noprompt.bin" "${ISO_FILES}/efi/microsoft/boot/efisys.bin" - -#mkdir -p /tmp/bbb -#sudo mount -o loop,ro "${ISO_FILES}/boot_efi.img" /tmp/bbb -#sudo cp /tmp/bbb/EFI/BOOT/BOOTX64.EFI "${ISO_FILES}/boot.efi" - -#sudo umount /tmp/bbb -#sudo rm -f "${ISO_FILES}/boot.efi.img" - - -# Extract meta data : -SYSTEM_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "System id: " | cut -d ' ' -f3-)" -VOLUME_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Volume id: " | cut -d ' ' -f3-)" -VOLUME_SET_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Volume set id: " | cut -d ' ' -f4-)" -PUBLISHER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Publisher id: " | cut -d ' ' -f3-)" # Always uppercase -ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "ID '" | cut -d "'" -f2)" -DATA_PREPARER_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Data preparer id: " | cut -d ' ' -f4-)" -APPLICATION_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Application id: " | cut -d ' ' -f3-)" -COPYRIGHT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Copyright file id: " | cut -d ' ' -f4-)" -ABSTRACT_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Abstract file id: " | cut -d ' ' -f4-)" -BIBLIOGRAPHIC_FILE_ID="$(isoinfo -d -i "${WIN10_IMG}" | grep "Bibliographic file id: " | cut -d ' ' -f4-)" - - -sudo rm -f "${WIN10_IMG}.tmp.iso" -sudo "${PROJECT_DIR}/thirdparty/schily-tools/mkisofs/OBJ/x86_64-linux-gcc/mkisofs" \ - -appid "${APPLICATION_ID}" \ - -copyright "${COPYRIGHT_FILE_ID}" \ - -abstract "${ABSTRACT_FILE_ID}" \ - -biblio "${BIBLIOGRAPHIC_FILE_ID}" \ - -preparer "${DATA_PREPARER_ID}" \ - -publisher "${PUBLISHER_ID}" \ - -sysid "${SYSTEM_ID}" \ - -volid "${VOLUME_ID}" \ - -volset "${VOLUME_SET_ID}" \ - -no-emul-boot \ - -b boot/etfsboot.com \ - -boot-load-seg "${BOOT_LOAD_SEG}" \ - -boot-load-size "${BOOT_LOAD_SIZE}" \ - -eltorito-alt-boot \ - -no-emul-boot \ - -eltorito-boot "efi/win_efi_boot.img" \ - -boot-load-size 1 \ - -iso-level 4 \ - -UDF \ - -o "${WIN10_IMG}.tmp.iso" \ - "${ISO_FILES}" - - #-e boot.efi.img \ - #-boot-info-table \ - #-D \ - #-N \ - #-relaxed-filenames \ - #-allow-lowercase \ - #-o "${WIN10_IMG}.tmp.iso" \ - #"${ISO_FILES}" - - -echo "BOOT_LOAD_SEG: ${BOOT_LOAD_SEG}" -echo "BOOT_LOAD_SIZE: ${BOOT_LOAD_SIZE}" -echo "-------" -echo "SYSTEM_ID: ${SYSTEM_ID}" -echo "VOLUME_ID: ${VOLUME_ID}" -echo "VOLUME_SET_ID: ${VOLUME_SET_ID}" -echo "PUBLISHER_ID: ${PUBLISHER_ID}" -echo "ID: ${ID}" -echo "DATA_PREPARER_ID: ${DATA_PREPARER_ID}" -echo "APPLICATION_ID: ${APPLICATION_ID}" -echo "COPYRIGHT_FILE_ID: ${COPYRIGHT_FILE_ID}" -echo "ABSTRACT_FILE_ID: ${ABSTRACT_FILE_ID}" -echo "BIBLIOGRAPHIC_FILE_ID: ${BIBLIOGRAPHIC_FILE_ID}" - - -# Show difference between new and old image as reported by isoinfo -echo -echo "-------------- isoinfo diff -----------------" -colordiff <(isoinfo -d -i "${WIN10_IMG}") <(isoinfo -d -i "${WIN10_IMG}.tmp.iso") - -# Show difference between new and old image as reported by dumpet -echo -echo " -------------- dumpet diff -----------------" -colordiff <(dumpet -i "${WIN10_IMG}") <(dumpet -i "${WIN10_IMG}.tmp.iso") - - - -# Method from: https://www.g-loaded.eu/2007/04/25/how-to-create-a-windows-bootable-cd-with-mkisofs/ -#sudo mkisofs -o "${WIN10_IMG}.tmp.iso" -b "boot.img" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 \ -# -iso-level 2 -udf \ -# -J -l -D -N -joliet-long -relaxed-filenames "${ISO_FILES}" - -#sudo mkisofs \ -# -b "boot.img" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 \ -# -iso-level 2 -J -l -D -N -joliet-long -relaxed-filenames \ -# -V "WINDOWS10_AUTOBOOT" \ -# -o "${WIN10_IMG}.tmp.iso" "${ISO_FILES}" - - -#sudo mkisofs -D -r -V "WINDOWS10_AUTOBOOT" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o "${WIN10_IMG}.tmp" "${ISO_FILES}" -#sudo rm "${WIN10_IMG}" -#sudo mv "${WIN10_IMG}.tmp.iso" "${WIN10_IMG}" diff --git a/utils/common/libs/gpu-check b/scripts/utils/common/libs/gpu-check similarity index 60% rename from utils/common/libs/gpu-check rename to scripts/utils/common/libs/gpu-check index 20499b6..383e9bc 100755 --- a/utils/common/libs/gpu-check +++ b/scripts/utils/common/libs/gpu-check @@ -1,5 +1,11 @@ #!/usr/bin/env bash +##################################################################################################### +# This script is not meant to be executed. It should be `source`d. +# It creates a bunch of variables telling you what kinds of GPUs the system has. +# Use it like this: `source "./gpu-check.sh"` +##################################################################################################### + LSHW_DISPLAY_OUTPUT="$(sudo lshw -C display)" if echo -e "$LSHW_DISPLAY_OUTPUT" | grep " vendor: " | grep -qi "intel"; then export HAS_INTEL_GPU=true diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers new file mode 100644 index 0000000..d55655e --- /dev/null +++ b/scripts/utils/common/libs/helpers @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +##################################################################################################### +# This script has to be sourced and is not meant to be executed directly! +# How to use: Insert the following two lines without the `#` symbols below the shebang of all scripts in this project that need it: +# while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +# source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +##################################################################################################### + + +SCRIPTS_DIR="${PROJECT_DIR}/scripts" + MAIN_SCRIPTS_DIR="${SCRIPTS_DIR}/main" + UTILS_DIR="${SCRIPTS_DIR}/utils" + COMMON_UTILS_DIR="${UTILS_DIR}/common" + COMMON_UTILS_LIB_DIR="${COMMON_UTILS_DIR}/lib" + COMMON_UTILS_SETUP_DIR="${COMMON_UTILS_DIR}/setup" + COMMON_UTILS_TOOLS_DIR="${COMMON_UTILS_DIR}/tools" + DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")" +THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" +ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" +HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" +LOG_BASE_DIR="${PROJECT_DIR}/logs" + +shopt -s expand_aliases + +# TODO create aliases for all scripts? (Maybe a bad idea because it makes debugging more difficult) + +function loadConfig() { + # If user.conf doesn't exist use the default.conf + if [ -f "${PROJECT_DIR}/user.conf" ]; then + echo "> Loading config from ${PROJECT_DIR}/user.conf" + source "${PROJECT_DIR}/user.conf" + elif [ -f "${PROJECT_DIR}/default.conf" ]; then + echo "> Warning: No user.conf found, falling back to default.conf" + echo "> Loading config from ${PROJECT_DIR}/default.conf" + source "${PROJECT_DIR}/default.conf" + else + echo "> Error: No user.conf or user.conf found!" + exit + fi +} \ No newline at end of file diff --git a/utils/common/setup/build-fake-battery-ssdt b/scripts/utils/common/setup/build-fake-battery-ssdt similarity index 51% rename from utils/common/setup/build-fake-battery-ssdt rename to scripts/utils/common/setup/build-fake-battery-ssdt index 7ab1b65..0f40132 100755 --- a/utils/common/setup/build-fake-battery-ssdt +++ b/scripts/utils/common/setup/build-fake-battery-ssdt @@ -1,7 +1,10 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +##################################################################################################### # This script compiles the asm source code for the SSDT table that contains a fake battery for the VM. +# Usage: `./build-fake-battery-ssdt` +##################################################################################################### iasl "${ACPI_TABLES_DIR}/fake-battery.asl" # creates fake-battery.aml \ No newline at end of file diff --git a/utils/common/setup/extract-vbios b/scripts/utils/common/setup/extract-vbios similarity index 59% rename from utils/common/setup/extract-vbios rename to scripts/utils/common/setup/extract-vbios index 17a23fc..17d2651 100755 --- a/utils/common/setup/extract-vbios +++ b/scripts/utils/common/setup/extract-vbios @@ -1,6 +1,13 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + + +##################################################################################################### +# WARNING: THIS SCRIPT WORKS ON ALMOST NO SYSTEM +# This script tries to extract the vBIOS ROM form your dGPU. +# usage: `./extract-vbios` +##################################################################################################### function extractNvideaVbios() { if which optirun ; then @@ -12,13 +19,13 @@ function extractNvideaVbios() { fi if [ ! -f "${UTILS_DIR}/nvflash_linux" ]; then NVFLASH_DOWNLOAD_ID=$(curl https://www.techpowerup.com/download/nvidia-nvflash/ | grep '_linux.zip' -A 5 | grep 'name="id" value="' | cut -d '"' -f6) - wget --post-data "id=${NVFLASH_DOWNLOAD_ID}&server_id=2" https://www.techpowerup.com/download/nvidia-nvflash/ -O ${UTILS_DIR}/nvidia-nvflash.zip - unzip ${UTILS_DIR}/nvidia-nvflash.zip -d ${UTILS_DIR}/ - rm -f ${UTILS_DIR}/nvidia-nvflash.zip - chmod +x ${UTILS_DIR}/nvflash_linux + wget --post-data "id=${NVFLASH_DOWNLOAD_ID}&server_id=2" https://www.techpowerup.com/download/nvidia-nvflash/ -O ${THIRDPARTY_DIR}/nvidia-nvflash.zip + unzip ${THIRDPARTY_DIR}/nvidia-nvflash.zip -d ${THIRDPARTY_DIR}/ + rm -f ${THIRDPARTY_DIR}/nvidia-nvflash.zip + chmod +x ${THIRDPARTY_DIR}/nvflash_linux fi mkdir -p "${VM_FILES_DIR}/vbios-roms" - sudo ${OPTIRUN_PREFIX}${UTILS_DIR}/nvflash_linux --save ${VM_FILES_DIR}/vbios-roms/nvidea_vbios.rom + sudo ${OPTIRUN_PREFIX}${THIRDPARTY_DIR}/nvflash_linux --save ${VM_FILES_DIR}/vbios-roms/nvidea_vbios.rom } function extractVbios() { diff --git a/utils/common/setup/ovmf-vbios-patch-setup b/scripts/utils/common/setup/ovmf-vbios-patch-setup similarity index 59% rename from utils/common/setup/ovmf-vbios-patch-setup rename to scripts/utils/common/setup/ovmf-vbios-patch-setup index ee8cb8f..c700e54 100755 --- a/utils/common/setup/ovmf-vbios-patch-setup +++ b/scripts/utils/common/setup/ovmf-vbios-patch-setup @@ -1,12 +1,14 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +##################################################################################################### # This script builds a Docker image that allows us to patch OVMF_CODE.fd and OVMF_VARS.fd with your vBIOS ROM. # This helps circumvent Nvidia's Error 43 in some cases. +# Usage: `./ovmf-vbios-patch-setup` +##################################################################################################### -mkdir -p "${PROJECT_DIR}/thirdparty" -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" sudo service docker start git clone https://github.com/T-vK/ovmf-with-vbios-patch.git diff --git a/utils/common/setup/set-kernel-params b/scripts/utils/common/setup/set-kernel-params similarity index 86% rename from utils/common/setup/set-kernel-params rename to scripts/utils/common/setup/set-kernel-params index 454b98e..0d46aaa 100755 --- a/utils/common/setup/set-kernel-params +++ b/scripts/utils/common/setup/set-kernel-params @@ -1,6 +1,11 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# Sets a bunch of required kernel parameters +# Usage: `./set-kernel-params` +##################################################################################################### source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/scripts/utils/common/tools/commands-available b/scripts/utils/common/tools/commands-available new file mode 100755 index 0000000..3c83905 --- /dev/null +++ b/scripts/utils/common/tools/commands-available @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +##################################################################################################### +# Checks if all given commands are installed and if not print out the list of missing ones +# Usage: `./commands-available` +##################################################################################################### + +function commandsAvailable() { + commandsMissing=() + for currentCommand in $1; do + if ! command -v $currentCommand &> /dev/null; then + commandsMissing+=("$currentCommand") + fi + done + if ((${#commandsMissing[@]})); then + echo "Missing commands: ${commandsMissing[@]}" + return 1 # Some commands are missing + else + return 0 + fi +} + +commandsAvailable "$1" \ No newline at end of file diff --git a/utils/common/tools/distro-info b/scripts/utils/common/tools/distro-info similarity index 73% rename from utils/common/tools/distro-info rename to scripts/utils/common/tools/distro-info index e2e4cd5..40ccee1 100755 --- a/utils/common/tools/distro-info +++ b/scripts/utils/common/tools/distro-info @@ -1,5 +1,10 @@ #!/usr/bin/env bash +##################################################################################################### +# Determines which Linux distribution and version this is and echoes it out +# Usage: `./distro-info` +##################################################################################################### + if [ -f /etc/os-release ]; then # freedesktop.org and systemd . /etc/os-release diff --git a/utils/common/tools/download-windows-iso b/scripts/utils/common/tools/download-windows-iso similarity index 72% rename from utils/common/tools/download-windows-iso rename to scripts/utils/common/tools/download-windows-iso index 2a059fb..7ae6333 100755 --- a/utils/common/tools/download-windows-iso +++ b/scripts/utils/common/tools/download-windows-iso @@ -1,5 +1,10 @@ #!/usr/bin/env bash +##################################################################################################### +# Downloads a Windows 10 ISO from Microsoft +# Usage: `./download-windows-iso "/path/to/where/you/want/to/save/the/windows.iso" "x64"` +##################################################################################################### + WIN10_IMG_DESTINATION="$1" WIN10_IMG_ARCH="$2" echo "$WIN10_IMG_DESTINATION" diff --git a/utils/common/tools/driver-util b/scripts/utils/common/tools/driver-util similarity index 95% rename from utils/common/tools/driver-util rename to scripts/utils/common/tools/driver-util index 5d41c32..0f06690 100755 --- a/utils/common/tools/driver-util +++ b/scripts/utils/common/tools/driver-util @@ -1,5 +1,10 @@ #!/usr/bin/env bash +##################################################################################################### +# A simple tool to make driverbinding easy. +# Usage: `./driver-util --help` +##################################################################################################### + COMMAND="$1" # Get driver currently used by the given PCI device diff --git a/utils/common/tools/lsiommu b/scripts/utils/common/tools/lsiommu similarity index 58% rename from utils/common/tools/lsiommu rename to scripts/utils/common/tools/lsiommu index 8f540fd..7894ccd 100755 --- a/utils/common/tools/lsiommu +++ b/scripts/utils/common/tools/lsiommu @@ -1,5 +1,10 @@ #!/usr/bin/env bash +##################################################################################################### +# Simple script to list all PCI devices and vGPUs by their IOMMU Group +# Usage: `./lsiommu` +##################################################################################################### + shopt -s nullglob for d in /sys/kernel/iommu_groups/*/devices/*; do n=${d#*/iommu_groups/*}; n=${n%%/*} diff --git a/utils/common/tools/vgpu-util b/scripts/utils/common/tools/vgpu-util similarity index 96% rename from utils/common/tools/vgpu-util rename to scripts/utils/common/tools/vgpu-util index fcb14e8..2f0337d 100755 --- a/utils/common/tools/vgpu-util +++ b/scripts/utils/common/tools/vgpu-util @@ -1,5 +1,10 @@ #!/usr/bin/env bash +##################################################################################################### +# Simple tool to manage vGPUs more easily +# Usage: `./vgpu-tool` +##################################################################################################### + COMMAND="$1" # Load required kernel modules diff --git a/utils/distro-specific/Ubuntu/21.04/amd-setup b/scripts/utils/distro-specific/Fedora/34/amd-setup old mode 100644 new mode 100755 similarity index 81% rename from utils/distro-specific/Ubuntu/21.04/amd-setup rename to scripts/utils/distro-specific/Fedora/34/amd-setup index de46034..3ceda87 --- a/utils/distro-specific/Ubuntu/21.04/amd-setup +++ b/scripts/utils/distro-specific/Fedora/34/amd-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Fedora/34/bumblebee-setup b/scripts/utils/distro-specific/Fedora/34/bumblebee-setup similarity index 95% rename from utils/distro-specific/Fedora/34/bumblebee-setup rename to scripts/utils/distro-specific/Fedora/34/bumblebee-setup index 9eec454..d04affd 100755 --- a/utils/distro-specific/Fedora/34/bumblebee-setup +++ b/scripts/utils/distro-specific/Fedora/34/bumblebee-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Fedora/34/install-dependencies b/scripts/utils/distro-specific/Fedora/34/install-dependencies similarity index 100% rename from utils/distro-specific/Fedora/34/install-dependencies rename to scripts/utils/distro-specific/Fedora/34/install-dependencies diff --git a/utils/distro-specific/Fedora/34/intel-setup b/scripts/utils/distro-specific/Fedora/34/intel-setup similarity index 91% rename from utils/distro-specific/Fedora/34/intel-setup rename to scripts/utils/distro-specific/Fedora/34/intel-setup index 12505de..caf683c 100755 --- a/utils/distro-specific/Fedora/34/intel-setup +++ b/scripts/utils/distro-specific/Fedora/34/intel-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Fedora/34/kernel-param-utils b/scripts/utils/distro-specific/Fedora/34/kernel-param-utils similarity index 100% rename from utils/distro-specific/Fedora/34/kernel-param-utils rename to scripts/utils/distro-specific/Fedora/34/kernel-param-utils diff --git a/utils/distro-specific/Fedora/34/looking-glass-setup b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup similarity index 92% rename from utils/distro-specific/Fedora/34/looking-glass-setup rename to scripts/utils/distro-specific/Fedora/34/looking-glass-setup index 6726010..0206807 100755 --- a/utils/distro-specific/Fedora/34/looking-glass-setup +++ b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup @@ -1,10 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig -mkdir -p "${PROJECT_DIR}/thirdparty" -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" sudo dnf install -y binutils-devel cmake texlive-gnu-freefont fontconfig-devel SDL2-devel SDL2_ttf-devel spice-protocol libX11-devel nettle-devel wayland-protocols-devel gcc libXScrnSaver-devel libXfixes-devel libXi-devel wayland-devel mingw64-gcc-c++ mingw32-nsis @@ -21,7 +20,7 @@ sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-l sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" # Build the (Windows) host application -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidea_capture_api.tgz rm -rf ./Capture_Linux_v8.0.4 tar -xvzf ./nvidea_capture_api.tgz diff --git a/utils/distro-specific/Fedora/34/nvidia-setup b/scripts/utils/distro-specific/Fedora/34/nvidia-setup similarity index 93% rename from utils/distro-specific/Fedora/34/nvidia-setup rename to scripts/utils/distro-specific/Fedora/34/nvidia-setup index 359f7ee..1dafbba 100755 --- a/utils/distro-specific/Fedora/34/nvidia-setup +++ b/scripts/utils/distro-specific/Fedora/34/nvidia-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" @@ -38,4 +38,4 @@ sudo systemctl mask nvidia-fallback echo "Start Bumblebee" sudo systemctl start bumblebeed -sudo ${UTILS_DIR}/extract-vbios +sudo ${COMMON_UTILS_SETUP_DIR}/extract-vbios diff --git a/utils/distro-specific/Fedora/34/vbios-finder-installer b/scripts/utils/distro-specific/Fedora/34/vbios-finder-installer similarity index 87% rename from utils/distro-specific/Fedora/34/vbios-finder-installer rename to scripts/utils/distro-specific/Fedora/34/vbios-finder-installer index 0bd34a7..6e8c7b0 100755 --- a/utils/distro-specific/Fedora/34/vbios-finder-installer +++ b/scripts/utils/distro-specific/Fedora/34/vbios-finder-installer @@ -1,10 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig -mkdir -p "${PROJECT_DIR}/thirdparty" -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" rm -rf VBiosFinder git clone https://github.com/coderobe/VBiosFinder.git diff --git a/utils/distro-specific/Fedora/34/amd-setup b/scripts/utils/distro-specific/Ubuntu/21.04/amd-setup old mode 100755 new mode 100644 similarity index 81% rename from utils/distro-specific/Fedora/34/amd-setup rename to scripts/utils/distro-specific/Ubuntu/21.04/amd-setup index de46034..3ceda87 --- a/utils/distro-specific/Fedora/34/amd-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/amd-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Ubuntu/21.04/bumblebee-setup b/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup similarity index 94% rename from utils/distro-specific/Ubuntu/21.04/bumblebee-setup rename to scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup index 02b4012..c394da9 100755 --- a/utils/distro-specific/Ubuntu/21.04/bumblebee-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Ubuntu/21.04/install-dependencies b/scripts/utils/distro-specific/Ubuntu/21.04/install-dependencies similarity index 100% rename from utils/distro-specific/Ubuntu/21.04/install-dependencies rename to scripts/utils/distro-specific/Ubuntu/21.04/install-dependencies diff --git a/utils/distro-specific/Ubuntu/21.04/intel-setup b/scripts/utils/distro-specific/Ubuntu/21.04/intel-setup similarity index 90% rename from utils/distro-specific/Ubuntu/21.04/intel-setup rename to scripts/utils/distro-specific/Ubuntu/21.04/intel-setup index 698dc51..71fdd9f 100755 --- a/utils/distro-specific/Ubuntu/21.04/intel-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/intel-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Ubuntu/21.04/kernel-param-utils b/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils similarity index 100% rename from utils/distro-specific/Ubuntu/21.04/kernel-param-utils rename to scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils diff --git a/utils/distro-specific/Ubuntu/21.04/looking-glass-setup b/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup similarity index 92% rename from utils/distro-specific/Ubuntu/21.04/looking-glass-setup rename to scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup index 82a32eb..83ecdf4 100755 --- a/utils/distro-specific/Ubuntu/21.04/looking-glass-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup @@ -1,10 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig -mkdir -p "${PROJECT_DIR}/thirdparty" -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" sudo apt install binutils binutils-multiarch-dev cmake texlive-fonts-recommended fonts-freefont-ttf libfontconfig-dev libegl-dev libspice-protocol-dev libsdl2-dev nettle-dev libx11-dev libxi-dev libxinerama-dev libxss-dev libwayland-dev wayland-protocols @@ -21,7 +20,7 @@ sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-l sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" # Build the (Windows) host application -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidea_capture_api.tgz rm -rf ./Capture_Linux_v8.0.4 tar -xvzf ./nvidea_capture_api.tgz diff --git a/utils/distro-specific/Ubuntu/21.04/nvidia-setup b/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup similarity index 95% rename from utils/distro-specific/Ubuntu/21.04/nvidia-setup rename to scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup index fb90119..9817b3b 100755 --- a/utils/distro-specific/Ubuntu/21.04/nvidia-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup @@ -1,6 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig source "$DISTRO_UTILS_DIR/kernel-param-utils" diff --git a/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer b/scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer similarity index 87% rename from utils/distro-specific/Ubuntu/21.04/vbios-finder-installer rename to scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer index 5edbd39..2f272fa 100755 --- a/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer +++ b/scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer @@ -1,10 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadCfg -mkdir -p "${PROJECT_DIR}/thirdparty" -cd "${PROJECT_DIR}/thirdparty" +cd "${THIRDPARTY_DIR}" rm -rf VBiosFinder git clone https://github.com/coderobe/VBiosFinder.git diff --git a/utils/common/libs/helpers b/utils/common/libs/helpers deleted file mode 100644 index 58ffb4b..0000000 --- a/utils/common/libs/helpers +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -# This script has to be sourced and is not meant to be executed directly! -# How to use: -# while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -# source "$PROJECT_DIR/utils/helpers" - -USER_SCRIPTS_DIR="${PROJECT_DIR}/scripts" -UTILS_DIR="${PROJECT_DIR}/utils" -DISTRO=$("${UTILS_DIR}/distro-info") -DISTRO_UTILS_DIR="${UTILS_DIR}/${DISTRO}" -THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" -ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" -LOG_BASE_DIR="${PROJECT_DIR}/logs" - -shopt -s expand_aliases - -function loadConfig() { - # If user.conf doesn't exist use the default.conf - if [ -f "${PROJECT_DIR}/user.conf" ]; then - echo "> Loading config from ${PROJECT_DIR}/user.conf" - source "${PROJECT_DIR}/user.conf" - elif [ -f "${PROJECT_DIR}/default.conf" ]; then - echo "> Warning: No user.conf found, falling back to default.conf" - echo "> Loading config from ${PROJECT_DIR}/default.conf" - source "${PROJECT_DIR}/default.conf" - else - echo "> Error: No user.conf or user.conf found!" - exit - fi -} \ No newline at end of file diff --git a/utils/common/setup/schily-tools-setup b/utils/common/setup/schily-tools-setup deleted file mode 100755 index a32ba52..0000000 --- a/utils/common/setup/schily-tools-setup +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/utils/helpers" - -cd "${THIRDPARTY_DIR}" - -SCHILY_VERSION="2021-06-07" -SCHILY_ARCHIVE="schily-${SCHILY_VERSION}.tar.bz2" -SCHILY_DIR="${PROJECT_DIR}/thirdparty/schily-tools" -sudo rm -rf "${SCHILY_DIR}" -wget "https://altushost-swe.dl.sourceforge.net/project/schilytools/${SCHILY_ARCHIVE}" -O "${SCHILY_ARCHIVE}" -tar -xf "${SCHILY_ARCHIVE}" -rm "${SCHILY_ARCHIVE}" -mv "schily-${SCHILY_VERSION}" "${SCHILY_DIR}" -cd "${SCHILY_DIR}" -./Gmake.linux \ No newline at end of file From 749edfcacb1155228a9746b91d3ea6f7b0556afc Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 3 Aug 2021 03:36:23 +0200 Subject: [PATCH 11/40] Fix typos --- README.md | 6 +++--- scripts/main/vm.sh | 2 +- scripts/utils/common/setup/extract-vbios | 6 +++--- scripts/utils/common/tools/driver-util | 4 ++-- scripts/utils/distro-specific/Fedora/34/looking-glass-setup | 6 +++--- .../utils/distro-specific/Ubuntu/21.04/looking-glass-setup | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4ef19a8..32b203e 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ To achieve that goal I have written a collection of scripts [accessible via mbpt ### In the virtual machine (Windows) -- [x] Automatically install the required drivers (ivshmem and other vfio drivers) +- [x] Automatically install the required drivers (ivshmem, other vfio drivers, Intel/Nvidia display drivers) - [x] Automatically compile/install/start LookingGlass - [x] Automatically configure the network -- [x] Automatically set up RDP +- [ ] Automatically set up RDP - [x] Automatically install and autostart LookingGlass And there is also a lot of advanced stuff that I managed to fully automate, like: @@ -42,7 +42,7 @@ And there is also a lot of advanced stuff that I managed to fully automate, like - The project is currently only compatible with Fedora and Ubuntu out of the box (Support for older Fedora/Ubuntu versions may break over time because I don't test changes made to this repo against older distributions.). (To add support for a new distro, copy one of the folders found in [utils](utils)) and adjust it for your distro.) - This project currently only supports Windows 10 x64 VMs and hopefully Windows 11 x64 VMs at some point. (For older Windows versions you have to figure out the driver installation etc. on your own.) -- Only tested for Intel+Nvidea and Intel+AMD systems. (Although the compatibility-check (./mbpt.sh check) should actually work on any hardware.) +- Only tested for Intel+Nvidia and Intel+AMD systems. (Although the compatibility-check (./mbpt.sh check) should actually work on any hardware.) - Expect bugs. I have only tested this on a handful of devices and I have constantly changed the scripts without testing everything every time. - Automated vBIOS ROM extraction will fail in most cases. You might have to extract it from a BIOS update. (You may not need the vBIOS ROM though.) - This project takes a couple of measures to circumvent Nvidia's infamous Error 43, which you normally see in the Windows device manager when you pass a mobile Nvidia GPU through to a Windows VM. But even with these measures, some systems will still show Error 43. diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index a2b29e5..4637c75 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -516,7 +516,7 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then echo "> Unbinding dGPU from vfio driver..." driver unbind "${DGPU_PCI_ADDRESS}" - if [ "$HOST_DGPU_DRIVER" = "nvidea" ] || [ "$HOST_DGPU_DRIVER" = "nuveau" ]; then + if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nuveau" ]; then echo "> Turn the dGPU off using bumblebee..." sudo bash -c "echo 'OFF' >> /proc/acpi/bbswitch" fi diff --git a/scripts/utils/common/setup/extract-vbios b/scripts/utils/common/setup/extract-vbios index 17d2651..2d6bd7f 100755 --- a/scripts/utils/common/setup/extract-vbios +++ b/scripts/utils/common/setup/extract-vbios @@ -9,7 +9,7 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" # usage: `./extract-vbios` ##################################################################################################### -function extractNvideaVbios() { +function extractNvidiaVbios() { if which optirun ; then USE_BUMBLEBEE=true OPTIRUN_PREFIX="optirun " @@ -25,7 +25,7 @@ function extractNvideaVbios() { chmod +x ${THIRDPARTY_DIR}/nvflash_linux fi mkdir -p "${VM_FILES_DIR}/vbios-roms" - sudo ${OPTIRUN_PREFIX}${THIRDPARTY_DIR}/nvflash_linux --save ${VM_FILES_DIR}/vbios-roms/nvidea_vbios.rom + sudo ${OPTIRUN_PREFIX}${THIRDPARTY_DIR}/nvflash_linux --save ${VM_FILES_DIR}/vbios-roms/nvidia_vbios.rom } function extractVbios() { @@ -38,5 +38,5 @@ function extractVbios() { #echo "Attempting to extract the VBIOS ROM of the Nvidia GPU" #echo "This will probably fail. If you know how to fix it please open an issue and tell me." -#extractNvideaVbios +#extractNvidiaVbios extractVbios $1 $2 \ No newline at end of file diff --git a/scripts/utils/common/tools/driver-util b/scripts/utils/common/tools/driver-util index 0f06690..e9df171 100755 --- a/scripts/utils/common/tools/driver-util +++ b/scripts/utils/common/tools/driver-util @@ -100,8 +100,8 @@ if [ "$COMMAND" = "help" ] || [ "$COMMAND" = "--help" ] || [ "$COMMAND" = "-h" ] echo " #Bind the vfio-pci driver to the device with address 01:00.0" echo " driver-util bind 01:00.0 vfio-pci" echo "" - echo " #Bind the nvidea driver to the device with address 05:00.0" - echo " driver-util bind 05:00.0 nvidea" + echo " #Bind the nvidia driver to the device with address 05:00.0" + echo " driver-util bind 05:00.0 nvidia" echo "" echo " #Bind the amdgpu driver to the device with address 02:00.0" echo " driver-util bind 02:00.0 amdgpu" diff --git a/scripts/utils/distro-specific/Fedora/34/looking-glass-setup b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup index 0206807..198a32f 100755 --- a/scripts/utils/distro-specific/Fedora/34/looking-glass-setup +++ b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup @@ -21,10 +21,10 @@ sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmp # Build the (Windows) host application cd "${THIRDPARTY_DIR}" -wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidea_capture_api.tgz +wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidia_capture_api.tgz rm -rf ./Capture_Linux_v8.0.4 -tar -xvzf ./nvidea_capture_api.tgz -rm ./nvidea_capture_api.tgz +tar -xvzf ./nvidia_capture_api.tgz +rm ./nvidia_capture_api.tgz rm -rf ./LookingGlass/Capture_Linux_v8.0.4 mv ./Capture_Linux_v8.0.4 ./LookingGlass/ cd LookingGlass diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup b/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup index 83ecdf4..0c7c3fa 100755 --- a/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup @@ -21,10 +21,10 @@ sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmp # Build the (Windows) host application cd "${THIRDPARTY_DIR}" -wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidea_capture_api.tgz +wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidia_capture_api.tgz rm -rf ./Capture_Linux_v8.0.4 -tar -xvzf ./nvidea_capture_api.tgz -rm ./nvidea_capture_api.tgz +tar -xvzf ./nvidia_capture_api.tgz +rm ./nvidia_capture_api.tgz rm -rf ./LookingGlass/Capture_Linux_v8.0.4 mv ./Capture_Linux_v8.0.4 ./LookingGlass/ cd LookingGlass From 33e7e3731dfda4df9e01baeffca35a85c18619dc Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 3 Aug 2021 03:56:15 +0200 Subject: [PATCH 12/40] README update --- README.md | 87 +++++++++++++------------------------------------------ 1 file changed, 20 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 32b203e..e5d1181 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # MobilePassThrough ## Introduction -The goal of this project is to make GPU passthrough on notebooks as easy and accessible as possible. +The goal of this project is to make GPU passthrough on x64 notebooks/tablets as easy and accessible as possible. To achieve that goal I have written a collection of scripts [accessible via mbpt.sh](https://github.com/T-vK/MobilePassThrough#how-to-use-mbptsh) that: ### On the host system (Linux): @@ -36,7 +36,7 @@ And there is also a lot of advanced stuff that I managed to fully automate, like ## Currently supported distributions - Fedora 34 - - Ubuntu 21.04 + - Ubuntu 21.04 (not tested in a while) ## Limitations @@ -71,58 +71,20 @@ And there is also a lot of advanced stuff that I managed to fully automate, like ### Installation and configuration - Download and install [standard Fedora](https://getfedora.org/) or the [KDE version](https://spins.fedoraproject.org/kde/) or [Ubuntu](https://ubuntu.com/download/desktop) (ideally in UEFI mode!) -- Make sure to create a user account (with administrator rights) (in case you are asked) +- Make sure to create a user account (with administrator rights) (in case you are asked) so that you can use sudo - Open a terminal and install git by typing the following, pressing enter after each line: ``` bash sudo dnf install git -y # Install git git clone https://github.com/T-vK/MobilePassThrough.git # Clone the project cd MobilePassThrough # Enter the project directory -./mbpt.sh setup # Dependency installation; kernel param config; bumblebee / nvidia driver installation; and much more ... +./mbpt.sh setup # Install dependencies +./mbpt.sh configure # Create a config file interactively +./mbpt.sh auto # Dependency installation; kernel param config; bumblebee / nvidia driver installation; windows ISO download; reboot to load new kernel params; create a helper iso with drivers and autounattended config for Windows; create and start VM; install Windows in the VM fully unattended; install drivers and looking glass in the VM automatically; check for error 43 automatically and show a warning if it occurs +# In the future start the VM with `./mbpt.sh start` ``` -- Reboot your system -- Open a new terminal and type: - -``` bash -cd MobilePassThrough # Enter the project directory -./mbpt.sh check # Check if your system is compatible -# If the script says that your system is compatible you may proceed: -./mbpt.sh configure # Create a config file -# Follow the instructions in your terminal! Then continue: -./mbpt.sh iso # Generate an iso file containing tools, installers, drivers and a Batch script that we need later -``` - -### Installation of Windows 10 in the VM - -- Open TWO terminals, in the first one type: -``` bash -cd MobilePassThrough # Enter the project directory -./mbpt.sh start # Start the VM for the first time -# Make sure you didn't get any critical errors -``` - -- In the second one quickly type: -``` bash -spicy -h localhost -p 5900 -``` -- window should appear giving a GUI to interact with the VM and it will say something like "press any key to boot from cd now". -- Press any key quickly! -- The Windows installer will show. Go through it, it should be simple enough. -- During the installation you may have to manually pick a disk driver for the virtual disk to be recognized. Click "Browse" and select `amd64\w10` from the `virtio-win` CD Drive. -- You should set a password for your user account otherwise you'll have trouble with RDP. -- Once Windows is installed, go to the virtual CD drive that contains the start.bat file and right-click it and click `Run as administrator` and make sure you didn't get any errors. -- Reboot the VM. - -In the future when you want to start the VM, you can open 2 terminals: - -- In the first one run: -``` bash -cd MobilePassThrough # Enter the project directory -./mbpt.sh start -``` - -- Open Remmina and connect to `rdp://192.168.99.2` +- Once the installation finished you should be able to open Remmina and connect to `rdp://192.168.99.2` - Then in the second terminal run: ``` bash @@ -227,18 +189,6 @@ Check out: https://gpu-passthrough.com/ By modding your BIOS/UEFI, you can make features available and change settings that are hidden or non-existent by default. For example: show VT-d settings, show secure boot settings, show muxing related settings and much more. There is a good collection of modding tools on [this site here in the BIOS / UEFI tools section](https://forums.tweaktown.com/gigabyte/30530-overclocking-programs-system-info-benchmarking-stability-tools-post284763.html#post284763). There are many BIOS modding forums out there with lots of people who are more than willing to help even if you're a complete beginner. -# Configuring the Windows VM manually - - - (During the installation you may have to manually pick a disk driver for the virtual disk to be recognized. Click "Browse" and Select ?:\viostor\w10\amd64\ from the virtio-win CD Drive.) - - After the installation open the Windows Device Manager and manually install missing drivers by rightclicking the devices with a warning symbol (not the graphics card though) -> "Update Driver" -> "Browse my computer for driver software" -> Click "Browse..." -> Select the virtio-win CD Drive -> Click OK -> Click Next. - - If under "System devices" you have a device called "PCI standard RAM Controller", then you have to install a different driver for that by downloading [these drivers](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/upstream-virtio/virtio-win10-prewhql-0.1-161.zip), extracting them and then do the previous step for this device, but browse to the extracted folder instead and select that instead. The device should then show up as "IVSHMEM Device". - - I also advice you to enable Widnows Remote Desktop ("Allow remote connections to this computer" in the System Properties) - - For RDP to work properly you might have to set up a password for your Windows user - - I'd also advice you to disable UAC by setting "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA" to 0 because the propts are hidden to Looking Glass. - - Set a static IP for the virtio (TAP) Ethernet adapter in Windows. E.g. 192.168.99.2 - - If you want to use Looking Glass download and install the [Microsoft Visual C++ 2017 Redistributables Package](https://download.microsoft.com/download/8/9/D/89D195E1-1901-4036-9A75-FBE46443FC5A/VC_redist.x64.exe) and download the [latest release of the Looking Glass host](https://github.com/gnif/LookingGlass/releases) - - I'd also put Looking Glass into the startup folder so that it runs automatically every time. - ## Known issues - Sometimes the `./mbpt.sh start` command will fail to start the VM because of this error: "echo: write error: No space left on device". It happens while attempting to create a vGPU for the iGPU. I have no clue why this happens. Sometimes it works if you just try it again, sometimes you need to wait a few minutes before retrying, but other times you actually have to reboot the host system. @@ -251,10 +201,20 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for ## TODO +### High prio +- Fix automatic Nvidia driver installation in the VM (fix chocolatey) +- Add vm remove option to vm.sh +- Finish the requirements.json +- Automatically find and install dependencies by parsing the requirements.json +- Fix static IP +- Fix RDP +- Fix Samba sharing +- Generate libvirt XML + +### Low prio - Add nuveau driver compatibility - Allow the user to decide if he wants bumblebee or not (for Nvidia GPUs) - More detailed output about how the device is muxed -- Fix unattended Windows installation - Create a bootable live version of this project - Create packages (deb, rpm, etc) - Add compatibility for Arch, Debian, etc... @@ -264,13 +224,6 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for - Reduce the size of the ovmf-vbios-patch Docker image - Make the USB passthrough device selection easier (i.e. display a list of devices that can be selected) - Look into hotplugging and check if the GPU can be hotplugged during VM runtime -- Generate libvirt XML -- Check which kernel parameters are currently used to determine if a reboot is necessary - Check if required dependencies are installed for each script -- Check if fake-battery has been built -- Check if patched ovmf exists -- Add a fully unattended mode that runs the setup, then reboots and continues running the compatibility check and creating/installing the VM and starting it. -- Use virt-install to fully automate the windows installation - Add support for multiple VMs -- Add support for Linux guests -- Sanity checks for setup scritps (i.e. check if binaries have actually been compiled / installed) \ No newline at end of file +- Add support for Linux guests \ No newline at end of file From 635eaa1aa0dbaa01dac4542aa6b20fe203f95c0b Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Wed, 4 Aug 2021 19:10:35 +0200 Subject: [PATCH 13/40] Some work on going distro-agnostic --- requirements.json | 51 ----------- requirements.sh | 44 +++++++++ scripts/main/remove-vm.sh | 16 ---- scripts/main/setup.sh | 89 +++++++++++++------ scripts/main/vm.sh | 21 ++++- scripts/utils/common/libs/cpu-check | 14 +++ scripts/utils/common/libs/gpu-check | 2 - scripts/utils/common/libs/helpers | 2 - scripts/utils/common/tools/install-packages | 88 ++++++++++++++++++ .../Fedora/34/kernel-param-utils | 12 +++ .../Fedora/34/looking-glass-setup | 72 +++++++++++++++ .../Ubuntu/21.04/kernel-param-utils | 6 ++ 12 files changed, 318 insertions(+), 99 deletions(-) delete mode 100644 requirements.json create mode 100644 requirements.sh delete mode 100644 scripts/main/remove-vm.sh create mode 100644 scripts/utils/common/libs/cpu-check create mode 100755 scripts/utils/common/tools/install-packages diff --git a/requirements.json b/requirements.json deleted file mode 100644 index 734e2d2..0000000 --- a/requirements.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "kernel-parameters": { - "general": ["iommu=1", "kvm.ignore_msrs=1", "rd.driver.pre=vfio-pci"], - "intel-cpu": ["intel_iommu=on"], - "amd-cpu": ["amd_iommu=on"], - "intel-gpu": ["i915.enable_gvt=1"], - "amd-gpu": [], - "nvidia-gpu": [], - "nuveau-gpu": [], - "bumblebee-nvidia": ["nouveau.modeset=0"], - "bumblebee-nuveau": [] - }, - "dependencies": { - "general": { - "executables": ["sudo", "bash", "mv", "cp", "sed", "awk", "git", "echo", "ls", "wget", "curl", "printf", "cd", "mkdir", "chmod", "chown", "grep", "cut", "which", "", "", "", "", "", "", ""], - "files": [] - }, - "fake-battery": { - "executables": ["iasl"], - "files": [] - }, - "ovmf-vbios-patch": { - "executables": ["git", "docker"], - "files": [] - }, - "generate-vm-config": { - "executables": ["crudini"], - "files": [] - }, - "vbios-finder": { - "executables": ["git", "wget", "curl", "unzip", "ruby", "gem", "bundle", "7za", "make", "innoextract", "upx"], - "files": ["include/ruby/ruby.h"] - }, - "virtualization": { - "executables": ["virt-install", "qemu-system-x86_x64", "virsh"], - "files": ["OVMF/OVMF_CODE.fd", "OVMF/OVMF_VARS.fd", "virtio-win/virtio-win.iso"] // TODO: get the iso using wget, cuz only rhel distros have a package for that anyways - }, - "remote-desktop": { - "executables": ["remmina"], - "files": [] - }, - "file-sharing": { - "executables": ["samba"], // double check - "files": [] - }, - "iGPU-passthrough": { - "executables": ["uuid", "intel-virtual-output"], - "files": [] - } - } -} \ No newline at end of file diff --git a/requirements.sh b/requirements.sh new file mode 100644 index 0000000..54bf37a --- /dev/null +++ b/requirements.sh @@ -0,0 +1,44 @@ +##################################################################################################### +# This file is supposed to be `source`d by the `scripts/main/setup.sh` bash script. +# It specifies which executables and files and kernel parameters what part of this project depends on +# WARNING: File dependencies can't contain spaces at the moment +# Usage: `source ./requirements.txt` +##################################################################################################### + +KERNEL_PARAMS_GENERAL=("iommu=1" "kvm.ignore_msrs=1" "rd.driver.pre=vfio-pci") +KERNEL_PARAMS_INTEL_CPU=("intel_iommu=on") +KERNEL_PARAMS_AMD_CPU=("amd_iommu=on") +KERNEL_PARAMS_INTEL_GPU=("i915.enable_gvt=1") +#KERNEL_PARAMS_AMD_GPU=() +#KERNEL_PARAMS_NVIDIA_GPU=() +KERNEL_PARAMS_BUMBLEBEE_NVIDIA=("nouveau.modeset=0") +#EXEC_DEPS_GENERAL=("sudo" "bash" "mv" "cp" "sed" "awk" "git" "echo" "ls" "wget" "curl" "printf" "cd" "mkdir" "chmod" "chown" "grep" "cut" "which") +EXEC_DEPS_FAKE_BATTERY=("iasl") +EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") +EXEC_DEPS_GENERATE_CONFIG=("crudini") +EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") +FILE_DEPS_VBIOS_FINDER=("/usr/include/{ruby,ruby-2.7}/ruby.h") +EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_x64" "virsh" "virt-viewer" "spicy") +FILE_DEPS_VIRTUALIZATION=("OVMF/OVMF_CODE.fd" "OVMF/OVMF_VARS.fd" "virtio-win/virtio-win.iso") # TODO: get the iso using wget cuz only rhel distros have a package for that anyways +EXEC_DEPS_RDP=("remmina") +EXEC_DEPS_SAMBA=("samba") +EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output") +EXEC_DEPS_HELPER_ISO=("genisoimage") +EXEC_DEPS_UEFI_CHECK=("systool") +EXEC_DEPS_COMPATIBILITY_CHECK=("systool" "lshw" "lspci" "dmidecode" "lsusb" "lsblk" "lscpu") +EXEC_DEPS_CPU_CHECK=("lscpu") +EXEC_DEPS_GPU_CHECK=("lshw") + +############################################################################################################################# + +ALL_EXEC_DEPS="" # Will contain all content of all variables starting with EXEC_DEPS +ALL_EXEC_DEPS_VARS="$(set -o posix ; set | grep -P '^EXEC_DEPS' | cut -d'=' -f1 | tr '\n' ' ')" +for deps in $ALL_EXEC_DEPS_VARS; do + ALL_EXEC_DEPS+="$(eval "echo \" \${$deps[*]}\"")" +done + +ALL_FILE_DEPS="" # Will contain all content of all variables starting with FILE_DEPS +ALL_FILE_DEPS_VARS="$(set -o posix ; set | grep -P '^FILE_DEPS' | cut -d'=' -f1 | tr '\n' ' ')" +for deps in $ALL_FILE_DEPS_VARS; do + ALL_FILE_DEPS+="$(eval "echo \" \${$deps[*]}\"")" +done \ No newline at end of file diff --git a/scripts/main/remove-vm.sh b/scripts/main/remove-vm.sh deleted file mode 100644 index 678f671..0000000 --- a/scripts/main/remove-vm.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -##################################################################################################### -# This script deletes the Windows VM in case it already exists. Call this script like this `./delete-vm.sh` -##################################################################################################### - -sudo virsh destroy --domain "${VM_NAME}" -sudo virsh undefine --domain "${VM_NAME}" --nvram - -# TODO: consider moving this to vm.sh and maybe make it usable like this: -# vm.sh remove -# vm.sh install -# vm.sh start \ No newline at end of file diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 75be0c9..200e2d8 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -9,40 +9,76 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" # TODO: the service creation shouldn'T be part of setup.sh. It should be in the auto section of mbpt.sh. ##################################################################################################### -mkdir -p "${THIRDPARTY_DIR}" +source "${PROJECT_DIR}/requirements.sh" +source "$COMMON_UTILS_LIBS_DIR/cpu-check" +source "$COMMON_UTILS_LIBS_DIR/gpu-check" +source "$DISTRO_UTILS_DIR/kernel-param-utils" +alias getExecPkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --executables" +alias getFilePkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --files" -# TODO: parse requirements.json and install dependencies automatically -# TODO: complete this list -if ! "${COMMON_UTILS_TOOLS_DIR}/commands-available" "wget curl vim screen git crudini remmina spicy genisoimage uuid iasl docker dumpet imake g++ virt-install qemu-system-x86_64 systool"; then - sudo "$DISTRO_UTILS_DIR/install-dependencies" -else - echo "[Skipped] Required packages already installed." -fi +mkdir -p "${THIRDPARTY_DIR}" -source "$DISTRO_UTILS_DIR/kernel-param-utils" +getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need +getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need -if runtimeKernelHasParam "iommu=1" && \ - runtimeKernelHasParam "amd_iommu=on" && \ - runtimeKernelHasParam "intel_iommu=on" && \ - runtimeKernelHasParam "i915.enable_gvt=1" && \ - runtimeKernelHasParam "kvm.ignore_msrs=1" && \ - runtimeKernelHasParam "rd.driver.pre=vfio-pci"; then - REBOOT_REQUIRED=false - echo "[Skipped] Kernel parameters are already set." -else - sudo "$COMMON_UTILS_SETUP_DIR/set-kernel-params" +REBOOT_REQUIRED=false +if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"]; then + echo "> Adding general kernel params..." + addKernelParams "${KERNEL_PARAMS_GENERAL[*]}" REBOOT_REQUIRED=true +elif + echo "> [Skipped] General kernel params already set on running kernel..." + REBOOT_REQUIRED=false +fi + +#if [ $HAS_INTEL_CPU = true ]; then + if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_CPU[*]}"]; then + echo "> Adding Intel CPU-specific kernel params..." + addKernelParams "${KERNEL_PARAMS_INTEL_CPU[*]}" + REBOOT_REQUIRED=true + elif + echo "> [Skipped] Intel CPU-specific kernel params already set on running kernel..." + fi +#fi + +#if [ $HAS_AMD_CPU = true ]; then + if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_AMD_CPU[*]}"]; then + echo "> Adding AMD CPU-specific kernel params..." + addKernelParams "${KERNEL_PARAMS_AMD_CPU[*]}" + REBOOT_REQUIRED=true + elif + echo "> [Skipped] AMD CPU-specific kernel params already set on running kernel..." + fi +#fi + +#if [ $HAS_INTEL_GPU = true ]; then + if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_GPU[*]}"]; then + echo "> Adding Intel GPU-specific kernel params..." + addKernelParams "${KERNEL_PARAMS_INTEL_GPU[*]}" + REBOOT_REQUIRED=true + elif + echo "> [Skipped] Intel GPU-specific kernel params already set on running kernel..." + fi +#fi + +if [ $HAS_NVIDIA_GPU = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user + if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"]; then + echo "> Adding Nvidia GPU-specific kernel params..." + addKernelParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" + REBOOT_REQUIRED=true + elif + echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel..." + fi fi if [[ "$(docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then + echo "> Image 'ovmf-vbios-patch' has already been built." sudo "$COMMON_UTILS_SETUP_DIR/ovmf-vbios-patch-setup" else - echo "[Skipped] Image 'ovmf-vbios-patch' has already been built." + echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." fi -source "$COMMON_UTILS_LIBS_DIR/gpu-check" - if [ "$HAS_INTEL_GPU" = true ]; then sudo "$DISTRO_UTILS_DIR/intel-setup" fi @@ -57,21 +93,24 @@ if [ "$SUPPORTS_OPTIMUS" = true ]; then fi if [ ! -f "${ACPI_TABLES_DIR}/fake-battery.aml" ]; then + echo "> Building fake ACPI SSDT battery..." sudo "$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssdt" else - echo "[Skipped] Fake ACPI SSDT battery has already been built." + echo "> [Skipped] Fake ACPI SSDT battery has already been built." fi if [ ! -f "${THIRDPARTY_DIR}/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then + echo "> Installing VBiosFinder..." sudo "$DISTRO_UTILS_DIR/vbios-finder-installer/vbiosfinder" else - echo "[Skipped] VBiosFinder is already set up." + echo "> [Skipped] VBiosFinder is already set up." fi if [ ! -f "${THIRDPARTY_DIR}/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" ]; then + echo "> Installing Looking Glass..." sudo "$DISTRO_UTILS_DIR/looking-glass-setup" else - echo "[Skipped] Looking Glass is already set up." + echo "> [Skipped] Looking Glass is already set up." fi echo "> Generating helper-iso for auto Windows Configuration / Driver installation..." diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 4637c75..c41b6ea 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -8,15 +8,29 @@ loadConfig # or start the previously created Windows VM, if called like this: `./vm.sh` ##################################################################################################### +VM_START_MODE="qemu" # qemu or virt-install + if [ "$1" = "install" ]; then VM_INSTALL=true -else +elif [ "$1" = "start" ]; then VM_INSTALL=false +elif [ "$1" = "remove" ]; then + if [ $VM_START_MODE = "virt-install" ]; then + sudo virsh destroy --domain "${VM_NAME}" + sudo virsh undefine --domain "${VM_NAME}" --nvram + #elif [ $VM_START_MODE = "qemu" ]; then + # + fi + if [[ ${DRIVE_IMG} == *.img ]]; then + sudo rm -f "${DRIVE_IMG}" + fi + rm -f "${OVMF_VARS_VM}" +else + echo "> Error: No valid vm.sh parameter was found!" + exit 1 fi -VM_START_MODE="qemu" # qemu or virt-install #source "$COMMON_UTILS_LIBS_DIR/gpu-check" -shopt -s expand_aliases alias driver="sudo '$COMMON_UTILS_TOOLS_DIR/driver-util'" alias vgpu="sudo '$COMMON_UTILS_TOOLS_DIR/vgpu-util'" @@ -373,6 +387,7 @@ if [ "$PATCH_OVMF_WITH_VROM" = true ]; then sudo chown "$(whoami):$(id -gn "$(whoami)")" "${PATCHED_OVMF_FILES_DIR}" echo "> Patching OVMF with your vBIOS ROM. This may take a few minutes!" sleep 5 # Ensure the user can read this first + sudo service docker start sudo docker run --rm -ti -v "${PATCHED_OVMF_FILES_DIR}/tmp-build:/build:z" -v "${DGPU_ROM_DIR}:/roms:z" -e "VROM=${DGPU_ROM_NAME}" ovmf-vbios-patch sudo chown "$(whoami):$(id -gn "$(whoami)")" -R "${PATCHED_OVMF_FILES_DIR}/tmp-build" sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_CODE.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" diff --git a/scripts/utils/common/libs/cpu-check b/scripts/utils/common/libs/cpu-check new file mode 100644 index 0000000..a055c76 --- /dev/null +++ b/scripts/utils/common/libs/cpu-check @@ -0,0 +1,14 @@ +##################################################################################################### +# This script is not meant to be executed. It should be `source`d. +# It creates a bunch of variables telling you what kinds of CPUs the system has. +# Use it like this: `source "./cpu-check.sh"` +##################################################################################################### + +LSCPU_OUTPUT="$(sudo lscpu)" +if echo -e "$LSCPU_OUTPUT" | grep "Model name: " | grep -qi "intel"; then + export HAS_INTEL_CPU=true +fi + +if echo -e "$LSCPU_OUTPUT" | grep "Model name: " | grep -qi "AMD"; then + export HAS_AMD_CPU=true +fi \ No newline at end of file diff --git a/scripts/utils/common/libs/gpu-check b/scripts/utils/common/libs/gpu-check index 383e9bc..2691b12 100755 --- a/scripts/utils/common/libs/gpu-check +++ b/scripts/utils/common/libs/gpu-check @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - ##################################################################################################### # This script is not meant to be executed. It should be `source`d. # It creates a bunch of variables telling you what kinds of GPUs the system has. diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index d55655e..c068cad 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - ##################################################################################################### # This script has to be sourced and is not meant to be executed directly! # How to use: Insert the following two lines without the `#` symbols below the shebang of all scripts in this project that need it: diff --git a/scripts/utils/common/tools/install-packages b/scripts/utils/common/tools/install-packages new file mode 100755 index 0000000..0c6d51d --- /dev/null +++ b/scripts/utils/common/tools/install-packages @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +##################################################################################################### +# Simple script to install the package containing the given executable name +# Usage: `./install-packages --executables "curl git wget docker"` +# Usage: `./install-packages --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +SEARCH_MODE="$1" +WANTED_ITEMS="$2" + +function getMissingExecutables() { + EXECUTABLES_MISSING="" + for CURRENT_EXECUTABLE in $1; do + if ! command -v $CURRENT_EXECUTABLE &> /dev/null; then + EXECUTABLES_MISSING+=" $CURRENT_EXECUTABLE" + fi + done + echo "$EXECUTABLES_MISSING" +} + +function getMissingFiles() { + FILES_MISSING="" + for CURRENT_FILE in $1; do + if [ ! -f "$CURRENT_FILE" ]; then + FILES_MISSING+=" $CURRENT_FILE" + fi + done + echo "$FILES_MISSING" +} + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + + if command -v dnf &> /dev/null; then # If package manager is dnf + sudo dnf check-update + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo dnf whatprovides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -2 | tail -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo dnf provides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -2 | tail -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo dnf install -y $PACKAGES_TO_INSTALL + fi + elif command -v apt-get &> /dev/null; then # If package manager is apt + sudo apt-get update + if ! command -v apt-file &> /dev/null; then + apt-get install -y apt-file + fi + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo apt-file search "/usr/bin/$CURRENT_ITEM" | head -1 | cut -d':' -f1)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo apt-file search "$CURRENT_ITEM" | head -1 | cut -d':' -f1))" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo apt-get install -y $PACKAGES_TO_INSTALL + fi + fi + + #echo "Couldn't find packages for: $STILL_MISSING_ITEMS" +} + +if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + echo "Still missing: $(getMissingExecutables "$WANTED_ITEMS")" +elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + echo "Still missing: $(getMissingFiles "$WANTED_ITEMS")" +fi \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/kernel-param-utils b/scripts/utils/distro-specific/Fedora/34/kernel-param-utils index 9f05969..0105634 100755 --- a/scripts/utils/distro-specific/Fedora/34/kernel-param-utils +++ b/scripts/utils/distro-specific/Fedora/34/kernel-param-utils @@ -49,4 +49,16 @@ function applyInitramfsChanges() { function runtimeKernelHasParam() { cmdline="$(cat /proc/cmdline)" [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] +} + +function runtimeKernelHasParams() { + for param in $1; do + runtimeKernelHasParam "$param" + fi +} + +function addKernelParams() { + for param in $1; do + addKernelParam "$param" + fi } \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/looking-glass-setup b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup index 198a32f..66d7f6d 100755 --- a/scripts/utils/distro-specific/Fedora/34/looking-glass-setup +++ b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup @@ -34,3 +34,75 @@ make #wget "https://ci.appveyor.com/api/projects/rainers/visuald/artifacts/cv2pdb.exe?job=Environment%3A%20os%3DVisual%20Studio%202015%2C%20VS%3D14%2C%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202015" -O "cv2pdb.exe" #wine './cv2pdb.exe' './looking-glass-host.exe' makensis './platform/Windows/installer.nsi' + +#``` +#binutils-devel +# - /usr/include/bfd.h +# - /usr/lib64/libbfd.a +# - /usr/lib64/libiberty.a +# +#cmake +# - cmake +# +#texlive-gnu-freefont +# - ??? +# +#fontconfig-devel +# - /usr/include/fontconfig/fontconfig.h +# +#SDL2-devel +# - ??? +# +#SDL2_ttf-devel +# - ??? +# +#spice-protocol +# - /usr/include/spice-1/spice/protocol.h +# - /usr/include/spice-1/spice/vd_agent.h +# +#libX11-devel +# - /usr/include/X11/Xlib.h +# - /usr/include/X11/Xutil.h +# +#nettle-devel +# - /usr/include/nettle/asn1.h +# - /usr/include/nettle/sha1.h +# - /usr/include/nettle/rsa.h +# - /usr/include/nettle/bignum.h +# - +# +#wayland-protocols-devel +# - /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml +# - /usr/share/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml +# - /usr/share/wayland-protocols/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml +# - /usr/share/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml +# +#gcc +# - gcc +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdatomic.h +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/emmintrin.h +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdarg.h +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdbool.h +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stddef.h +# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdint.h +# - +# +#libXScrnSaver-devel +# - /usr/include/X11/extensions/scrnsaver.h +# +#libXfixes-devel +# - /usr/include/X11/extensions/Xfixes.h +# +#libXi-devel +# - /usr/include/X11/extensions/XInput2.h +# +#wayland-devel +# - wayland-scanner +# - /usr/include/wayland-client.h +# - /usr/include/wayland-cursor.h +# - /usr/include/wayland-egl.h +# +#libXinerama-devel +# - /usr/include/X11/extensions/Xinerama.h +#``` \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils b/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils index 9f05969..6f88ba7 100755 --- a/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils +++ b/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils @@ -49,4 +49,10 @@ function applyInitramfsChanges() { function runtimeKernelHasParam() { cmdline="$(cat /proc/cmdline)" [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] +} + +function addKernelParams() { + for param in $1; do + addKernelParam "$param" + fi } \ No newline at end of file From 4105c3ecac4f1374d1c54951b42a213d87ca722b Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Thu, 5 Aug 2021 03:51:31 +0200 Subject: [PATCH 14/40] Make the project way more distro-agnostic --- README.md | 1 + default.conf | 4 - helper-iso-files/Autounattend.xml | 48 +------- mbpt.sh | 2 +- requirements.sh | 76 ++++++++---- scripts/README.md | 3 +- scripts/main/generate-helper-iso.sh | 5 +- scripts/main/generate-vm-config.sh | 1 - scripts/main/iommu-check.sh | 2 +- scripts/main/setup.sh | 65 ++++++----- scripts/main/vm.sh | 14 +-- scripts/utils/common/libs/helpers | 6 +- .../utils/common/setup/download-vfio-drivers | 13 +++ .../utils/common/setup/looking-glass-setup | 50 ++++++++ scripts/utils/common/setup/set-kernel-params | 44 ------- .../setup/vbios-finder-setup} | 2 - scripts/utils/common/tools/get-manager | 24 ++++ scripts/utils/common/tools/install-packages | 8 +- .../common/tools/runtime-kernel-has-params | 14 +++ .../utils/distro-specific/Fedora/34/amd-setup | 8 -- .../distro-specific/Fedora/34/bumblebee-setup | 9 -- .../Fedora/34/install-dependencies | 18 --- .../distro-specific/Fedora/34/intel-setup | 14 --- .../Fedora/34/kernel-param-utils | 64 ----------- .../Fedora/34/looking-glass-setup | 108 ------------------ .../distro-specific/Fedora/34/nvidia-setup | 29 +---- .../distro-specific/Ubuntu/21.04/amd-setup | 8 -- .../Ubuntu/21.04/bumblebee-setup | 10 -- .../Ubuntu/21.04/install-dependencies | 19 --- .../distro-specific/Ubuntu/21.04/intel-setup | 12 -- .../Ubuntu/21.04/kernel-param-utils | 58 ---------- .../Ubuntu/21.04/looking-glass-setup | 36 ------ .../distro-specific/Ubuntu/21.04/nvidia-setup | 30 +---- .../Ubuntu/21.04/vbios-finder-installer | 30 ----- .../utils/manager-specific/initramfs/dracut | 31 +++++ .../utils/manager-specific/kernelparams/grub | 45 ++++++++ .../utils/manager-specific/service/systemd | 1 + 37 files changed, 290 insertions(+), 622 deletions(-) create mode 100644 scripts/utils/common/setup/download-vfio-drivers create mode 100755 scripts/utils/common/setup/looking-glass-setup delete mode 100755 scripts/utils/common/setup/set-kernel-params rename scripts/utils/{distro-specific/Fedora/34/vbios-finder-installer => common/setup/vbios-finder-setup} (90%) create mode 100755 scripts/utils/common/tools/get-manager create mode 100755 scripts/utils/common/tools/runtime-kernel-has-params delete mode 100755 scripts/utils/distro-specific/Fedora/34/amd-setup delete mode 100755 scripts/utils/distro-specific/Fedora/34/install-dependencies delete mode 100755 scripts/utils/distro-specific/Fedora/34/intel-setup delete mode 100755 scripts/utils/distro-specific/Fedora/34/kernel-param-utils delete mode 100755 scripts/utils/distro-specific/Fedora/34/looking-glass-setup delete mode 100644 scripts/utils/distro-specific/Ubuntu/21.04/amd-setup delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/install-dependencies delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/intel-setup delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer create mode 100755 scripts/utils/manager-specific/initramfs/dracut create mode 100755 scripts/utils/manager-specific/kernelparams/grub create mode 100644 scripts/utils/manager-specific/service/systemd diff --git a/README.md b/README.md index e5d1181..9723e8f 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for ## TODO ### High prio +- Install guest tools - Fix automatic Nvidia driver installation in the VM (fix chocolatey) - Add vm remove option to vm.sh - Finish the requirements.json diff --git a/default.conf b/default.conf index 4eeadaf..bd945c0 100644 --- a/default.conf +++ b/default.conf @@ -19,10 +19,6 @@ OVMF_CODE="/usr/share/OVMF/OVMF_CODE.fd" # Required OVMF_VARS="/usr/share/OVMF/OVMF_VARS.fd" # Required OVMF_VARS_VM="${VM_FILES_DIR}/OVMF_VARS_VM.fd" # Required -VIRTIO_WIN_IMG="/usr/share/virtio-win/virtio-win.iso" # Required for driver installation -VIRTIO_WIN_VFD="/usr/share/virtio-win/virtio-win_amd64.vfd" # Required for driver installation - -AUTOUNATTEND_WIN_VFD="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated windows installation HELPER_ISO="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated driver installation, looking glass setup, IP setup, remote desktop setup etc inseide of the VM DGPU_PCI_ADDRESS=01:00.0 # Required; If you don't use Bumblebee, you have to set this to the correct PCI address of your dGPU (see output of lspci) diff --git a/helper-iso-files/Autounattend.xml b/helper-iso-files/Autounattend.xml index 29a5ef2..b4fd3d7 100644 --- a/helper-iso-files/Autounattend.xml +++ b/helper-iso-files/Autounattend.xml @@ -2,55 +2,9 @@ <unattend xmlns="urn:schemas-microsoft-com:unattend"> <settings pass="windowsPE"> <component name="Microsoft-Windows-PnpCustomizationsWinPE" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" processorArchitecture="amd64" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"> - <!-- - This makes the VirtIO drivers available to Windows, assuming that - the VirtIO driver disk at https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso - (see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html#virtio-win-direct-downloads) - is available as drive E: - --> <DriverPaths> <PathAndCredentials wcm:action="add" wcm:keyValue="2"> - <Path>E:\viostor\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="3"> - <Path>E:\NetKVM\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="4"> - <Path>E:\Balloon\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="5"> - <Path>E:\pvpanic\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="6"> - <Path>E:\qemupciserial\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="7"> - <Path>E:\qxldod\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="8"> - <Path>E:\vioinput\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="9"> - <Path>E:\viorng\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="10"> - <Path>E:\vioscsi\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="11"> - <Path>E:\vioserial\w10\amd64</Path> - </PathAndCredentials> - - <PathAndCredentials wcm:action="add" wcm:keyValue="12"> - <Path>E:\vioserial\w10\amd64</Path> + <Path>E:\bin\virtio-drivers\Win10\amd64</Path> </PathAndCredentials> </DriverPaths> </component> diff --git a/mbpt.sh b/mbpt.sh index 9598964..80da84a 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -65,7 +65,7 @@ elif [ "$COMMAND" = "install" ] || [ "$COMMAND" = "create" ]; then elif [ "$COMMAND" = "remove" ]; then sudo "${MAIN_SCRIPTS_DIR}/vm.sh" remove # TODO: implement this elif [ "$COMMAND" = "start" ]; then - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start elif [ "$COMMAND" = "auto" ]; then sudo "${MAIN_SCRIPTS_DIR}/setup.sh" sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" diff --git a/requirements.sh b/requirements.sh index 54bf37a..b73d745 100644 --- a/requirements.sh +++ b/requirements.sh @@ -1,33 +1,67 @@ ##################################################################################################### # This file is supposed to be `source`d by the `scripts/main/setup.sh` bash script. -# It specifies which executables and files and kernel parameters what part of this project depends on +# It specifies which executables and files and kernel parameters which part of this project depends on # WARNING: File dependencies can't contain spaces at the moment # Usage: `source ./requirements.txt` ##################################################################################################### -KERNEL_PARAMS_GENERAL=("iommu=1" "kvm.ignore_msrs=1" "rd.driver.pre=vfio-pci") -KERNEL_PARAMS_INTEL_CPU=("intel_iommu=on") -KERNEL_PARAMS_AMD_CPU=("amd_iommu=on") -KERNEL_PARAMS_INTEL_GPU=("i915.enable_gvt=1") +# TODO: #sudo dnf install -y msr-tools tunctl # TODO: check if these are still needed and if so what for + +# TODO: check if there even is a case where is would be necessary +#INITRAMFS_DRIVERS=("vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "addInitramfsDriver" "vfio") #vfio stub drivers + +# Docs: https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt +# More docs: https://lwn.net/Articles/252826/ +# https://www.kernel.org/doc/Documentation/x86/x86_64/boot-options.txt +KERNEL_PARAMS_GENERAL=("iommu=1") # '1' is not a documented option. stop confusing me wendell! Maybe the "force" option should be used instead? +KERNEL_PARAMS_GENERAL+=("kvm.ignore_msrs=1") # prevent bluescreens when a VM does MSR reads / writes directly +KERNEL_PARAMS_GENERAL+=("rd.driver.pre=vfio-pci") # tell dracut to load vfio-pci first +#KERNEL_PARAMS_GENERAL+=("pcie_acs_override=downstream") # fix /dev/vfio/1 not found error # shouldn't be necessary +#KERNEL_PARAMS_GENERAL+=("acpi_osi=!") # may fix problems with AMI style UEFIs +#KERNEL_PARAMS_GENERAL+=("acpi_osi='Windows 2009'") # may fix problems with AMI style UEFIs +KERNEL_PARAMS_INTEL_CPU=("intel_iommu=on") # enable Intel VT-D ;# using "intel_iommu=on,igfx_off" iGPU gets no iommu group... +#KERNEL_PARAMS_INTEL_CPU+=("915.preliminary_hw_support=1") # add skylake support; probably only necessary with older kernels +KERNEL_PARAMS_AMD_CPU=("amd_iommu=on") # 'on' is not a docuemnted option for this parameter either! This is insanely confusing! +KERNEL_PARAMS_INTEL_GPU=("i915.enable_gvt=1") # enable mediated iGPU passthrough support (GVT-g) on Intel iGPUs #KERNEL_PARAMS_AMD_GPU=() #KERNEL_PARAMS_NVIDIA_GPU=() KERNEL_PARAMS_BUMBLEBEE_NVIDIA=("nouveau.modeset=0") -#EXEC_DEPS_GENERAL=("sudo" "bash" "mv" "cp" "sed" "awk" "git" "echo" "ls" "wget" "curl" "printf" "cd" "mkdir" "chmod" "chown" "grep" "cut" "which") -EXEC_DEPS_FAKE_BATTERY=("iasl") -EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") -EXEC_DEPS_GENERATE_CONFIG=("crudini") -EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") -FILE_DEPS_VBIOS_FINDER=("/usr/include/{ruby,ruby-2.7}/ruby.h") -EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_x64" "virsh" "virt-viewer" "spicy") -FILE_DEPS_VIRTUALIZATION=("OVMF/OVMF_CODE.fd" "OVMF/OVMF_VARS.fd" "virtio-win/virtio-win.iso") # TODO: get the iso using wget cuz only rhel distros have a package for that anyways -EXEC_DEPS_RDP=("remmina") -EXEC_DEPS_SAMBA=("samba") -EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output") -EXEC_DEPS_HELPER_ISO=("genisoimage") -EXEC_DEPS_UEFI_CHECK=("systool") -EXEC_DEPS_COMPATIBILITY_CHECK=("systool" "lshw" "lspci" "dmidecode" "lsusb" "lsblk" "lscpu") -EXEC_DEPS_CPU_CHECK=("lscpu") -EXEC_DEPS_GPU_CHECK=("lshw") + + +# TODO: check if we should use relative paths to be more distribution-gnostic +#EXEC_DEPS_GENERAL=("sudo" "bash" "mv" "cp" "sed" "awk" "git" "echo" "ls" "echo" "printf" "cd" "mkdir" "chmod" "chown" "grep" "cut" "which") +EXEC_DEPS_FAKE_BATTERY=("iasl") # acpica-tools +EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") # git moby-engine +EXEC_DEPS_GENERATE_CONFIG=("crudini") # crudini +EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") # git wget curl-minimal unzip ruby rubygems rubygem-bundler p7zip make innoextract upx +FILE_DEPS_VBIOS_FINDER=("/usr/include/rub*/ruby.h") # ruby-devel +EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "spicy") # qemu-system-x86-core libvirt-client virt-viewer spice-gtk-tools +FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd") # edk2-ovmf +FILE_DEPS_VIRTUALIZATION=("/usr/share/virtio-win/virtio-win.iso") # virtio-win # TODO: get the iso using wget cuz only rhel distros have a package for that anyways +EXEC_DEPS_RDP=("remmina") # remmina +EXEC_DEPS_SAMBA=("samba") # samba +EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output") # uuid xorg-x11-drv-intel +EXEC_DEPS_HELPER_ISO=("genisoimage") # genisoimage +EXEC_DEPS_UEFI_CHECK=("systool") # sysfsutils +EXEC_DEPS_COMPATIBILITY_CHECK=("systool" "lshw" "lspci" "dmidecode" "lsusb" "lsblk" "lscpu") # sysfsutils lshw pciutils dmidecode usbutils util-linux util-linux +EXEC_DEPS_CPU_CHECK=("lscpu") # util-linux +EXEC_DEPS_GPU_CHECK=("lshw") # lshw +EXEC_DEPS_LOOKING_GLASS=("cmake" "gcc" "wayland-scanner" "makensis" "x86_64-w64-mingw32-g++") # cmake gcc-g++ wayland-devel mingw32-nsis mingw64-gcc-c++ +FILE_DEPS_LOOKING_GLASS+=("/usr/include/bfd.h" "/usr/lib64/libbfd.a" "/usr/lib64/libiberty.a") # binutils-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/fontconfig/fontconfig.h") # fontconfig-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/spice-1/spice/protocol.h" "/usr/include/spice-1/spice/vd_agent.h" "") # spice-protocol +FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/Xlib.h" "/usr/include/X11/Xutil.h") # libX11-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/nettle/asn1.h" "/usr/include/nettle/sha1.h" "/usr/include/nettle/rsa.h" "/usr/include/nettle/bignum.h") # nettle-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml" "/usr/share/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml" "/usr/share/wayland-protocols/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml" "/usr/share/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml") # wayland-protocols-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/lib/gcc/x86_64-redhat-linux/11/include/stdatomic.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/emmintrin.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stdarg.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stdbool.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stddef.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stdint.h") # gcc +FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/scrnsaver.h") # libXScrnSaver-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/Xfixes.h") # libXfixes-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/XInput2.h") # libXi-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/wayland-client.h" "/usr/include/wayland-cursor.h" "/usr/include/wayland-egl.h") # wayland-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/Xinerama.h") # libXinerama-devel +FILE_DEPS_LOOKING_GLASS+=("/usr/include/SDL2/SDL.h" "/usr/include/SDL2/SDL_syswm.h") # SDL2-devel (will be removed in B5 probably) +FILE_DEPS_LOOKING_GLASS+=("/usr/include/SDL2/SDL_ttf.h") # SDL2_ttf-devel (will be removed in B5 probably) +#FILE_DEPS_LOOKING_GLASS+=("/usr/share/texlive/texmf-dist/fonts/opentype/public/gnu-freefont/FreeMono.otf") # this file is not actually a dependency # texlive-gnu-freefont # TODO: check if texlive-gnu-freefont is actually a dependency ############################################################################################################################# diff --git a/scripts/README.md b/scripts/README.md index c906b83..c6d0b24 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -6,7 +6,8 @@ scripts # All bash scripts called directly or indirectly by `mb │ ├── libs # Scripts that are not executable and have to be `source`d. │ ├── setup # Scripts that have dependencies on other scripts (or programs in the `thirdparty` directory) in this project. │ └── tools # Scripts that don't have dependencies on other files in this project and could be moved into their own project at some point. - └── distro-specific # Scripts that are distribution-specific. For every distribution/version the exact same set of scripts have to exist (same names, but different content of course). + ├── manager-specific # Scripts that are specific to a certain manager like systemd, dracut or grub. This is used to abstract functionality like creating services, adding kernel parameters and adding drivers to initfsram. + └── distro-specific # Scripts that are distribution-specific. For every distribution/version the exact same set of scripts ├── Fedora # All `Fedora`-specific scripts. │ ├── 34 # All `Fedora 34`-specific scripts. │ └── 35 # All `Fedora 35`-specific scripts. diff --git a/scripts/main/generate-helper-iso.sh b/scripts/main/generate-helper-iso.sh index bef1a12..49482c5 100755 --- a/scripts/main/generate-helper-iso.sh +++ b/scripts/main/generate-helper-iso.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - +loadConfig ##################################################################################################### # This script creates a helper ISO file containing scripts and drivers to fully automate the Windows installation within the VM. ##################################################################################################### @@ -88,5 +88,6 @@ fi rm -rf "${HELPER_ISO_FILES_DIR}/tmp" rm -f "${HELPER_ISO}" + #echo "genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o \"${HELPER_ISO}\" \"${HELPER_ISO_FILES_DIR}\"" -genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o "${HELPER_ISO}" "${HELPER_ISO_FILES_DIR}" +genisoimage -quiet -input-charset utf-8 -J -joliet-long -r -allow-lowercase -allow-multidot -o "${HELPER_ISO}" "${HELPER_ISO_FILES_DIR}" |& grep -v "Warning: " diff --git a/scripts/main/generate-vm-config.sh b/scripts/main/generate-vm-config.sh index ac494c8..6a3a3ce 100755 --- a/scripts/main/generate-vm-config.sh +++ b/scripts/main/generate-vm-config.sh @@ -63,7 +63,6 @@ interactiveCfg "Path to a folder to share with the VM via SMB. (Optional)" SMB_S interactiveCfg "Location of OVMF_VARS.fd." OVMF_VARS interactiveCfg "Where to create Creating a copy of OVMF_VARS.fd (containing the executable firmware code and but the non-volatile variable store) for the VM?" OVMF_VARS_VM interactiveCfg "Location of OVMF_CODE.fd." OVMF_CODE -interactiveCfg "Location of the virtio Windows driver disk." VIRTIO_WIN_IMG interactiveCfg "Location of helper iso or where to create it." HELPER_ISO interactiveCfg "Pass the dGPU through to the VM." DGPU_PASSTHROUGH interactiveCfg "Share the iGPU with the VM to allow using Optimus within the VM to save battery life" SHARE_IGPU diff --git a/scripts/main/iommu-check.sh b/scripts/main/iommu-check.sh index 279ad34..059d681 100755 --- a/scripts/main/iommu-check.sh +++ b/scripts/main/iommu-check.sh @@ -33,7 +33,7 @@ else echo "[Error] VT-D / IOMMU is not enabled in the UEFI! This is required to check which devices are in which IOMMU group and to use GPU passthrough!" fi -if [ $UEFI_VIRTUALIZATION_ENABLED = true ] && [ $UEFI_IOMMU_ENABLED = true ] ; then +if [ "$UEFI_VIRTUALIZATION_ENABLED" = true ] && [ "$UEFI_IOMMU_ENABLED" = true ] ; then exit 0 # success else exit 1 # error diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 200e2d8..91a27cd 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -12,62 +12,65 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" source "${PROJECT_DIR}/requirements.sh" source "$COMMON_UTILS_LIBS_DIR/cpu-check" source "$COMMON_UTILS_LIBS_DIR/gpu-check" -source "$DISTRO_UTILS_DIR/kernel-param-utils" alias getExecPkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --executables" alias getFilePkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --files" +alias kernelParamManager="'${KERNEL_PARAM_MANAGER}'" +alias runtimeKernelHasParams="'${COMMON_UTILS_TOOLS_DIR}/runtime-kernel-has-params'" mkdir -p "${THIRDPARTY_DIR}" +echo "> Find and install packages containing executables that we need..." getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need +echo "> Find and install packages containing files that we need..." getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need REBOOT_REQUIRED=false -if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"]; then +if ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"; then echo "> Adding general kernel params..." - addKernelParams "${KERNEL_PARAMS_GENERAL[*]}" + kernelParamManager add "${KERNEL_PARAMS_GENERAL[*]}" REBOOT_REQUIRED=true -elif +else echo "> [Skipped] General kernel params already set on running kernel..." REBOOT_REQUIRED=false fi -#if [ $HAS_INTEL_CPU = true ]; then - if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_CPU[*]}"]; then +#if [ "$HAS_INTEL_CPU" = true ]; then + if ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_CPU[*]}"; then echo "> Adding Intel CPU-specific kernel params..." - addKernelParams "${KERNEL_PARAMS_INTEL_CPU[*]}" + kernelParamManager add "${KERNEL_PARAMS_INTEL_CPU[*]}" REBOOT_REQUIRED=true - elif + else echo "> [Skipped] Intel CPU-specific kernel params already set on running kernel..." fi #fi -#if [ $HAS_AMD_CPU = true ]; then - if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_AMD_CPU[*]}"]; then +#if [ "$HAS_AMD_CPU" = true ]; then + if ! runtimeKernelHasParams "${KERNEL_PARAMS_AMD_CPU[*]}"; then echo "> Adding AMD CPU-specific kernel params..." - addKernelParams "${KERNEL_PARAMS_AMD_CPU[*]}" + kernelParamManager add "${KERNEL_PARAMS_AMD_CPU[*]}" REBOOT_REQUIRED=true - elif + else echo "> [Skipped] AMD CPU-specific kernel params already set on running kernel..." fi #fi -#if [ $HAS_INTEL_GPU = true ]; then - if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_GPU[*]}"]; then +#if [ "$HAS_INTEL_GPU" = true ]; then + if ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_GPU[*]}"; then echo "> Adding Intel GPU-specific kernel params..." - addKernelParams "${KERNEL_PARAMS_INTEL_GPU[*]}" + kernelParamManager add "${KERNEL_PARAMS_INTEL_GPU[*]}" REBOOT_REQUIRED=true - elif + else echo "> [Skipped] Intel GPU-specific kernel params already set on running kernel..." fi #fi -if [ $HAS_NVIDIA_GPU = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user - if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"]; then +if [ "$HAS_NVIDIA_GPU" = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user + if ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"; then echo "> Adding Nvidia GPU-specific kernel params..." - addKernelParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" + kernelParamManager add "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" REBOOT_REQUIRED=true - elif + else echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel..." fi fi @@ -79,12 +82,6 @@ else echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." fi -if [ "$HAS_INTEL_GPU" = true ]; then - sudo "$DISTRO_UTILS_DIR/intel-setup" -fi -if [ "$HAS_AMD_GPU" = true ]; then - sudo "$DISTRO_UTILS_DIR/amd-setup" -fi if [ "$HAS_NVIDIA_GPU" = true ]; then sudo "$DISTRO_UTILS_DIR/nvidia-setup" fi @@ -101,25 +98,31 @@ fi if [ ! -f "${THIRDPARTY_DIR}/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then echo "> Installing VBiosFinder..." - sudo "$DISTRO_UTILS_DIR/vbios-finder-installer/vbiosfinder" + sudo "$COMMON_UTILS_SETUP_DIR/vbios-finder-setup" else echo "> [Skipped] VBiosFinder is already set up." fi if [ ! -f "${THIRDPARTY_DIR}/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" ]; then echo "> Installing Looking Glass..." - sudo "$DISTRO_UTILS_DIR/looking-glass-setup" + sudo "$COMMON_UTILS_SETUP_DIR/looking-glass-setup" else echo "> [Skipped] Looking Glass is already set up." fi +#if [ ! -f "${THIRDPARTY_DIR}/virtio-win.iso" ]; then +# echo "> Downlaoding virtio drivers..." +# sudo "$COMMON_UTILS_SETUP_DIR/download-vfio-drivers" +#else +# echo "> [Skipped] virtio drivers already downloaded." +#fi + echo "> Generating helper-iso for auto Windows Configuration / Driver installation..." sudo ${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh -# TODO: add check if files have changed and helper iso needs to be regenerated - +# TODO: add check if files have changed and helper iso needs to be regenerated; maybe by using a checksum? if [ "$1" = "auto" ]; then - if [ REBOOT_REQUIRED = true ]; then + if [ "$REBOOT_REQUIRED" = true ]; then echo "> Creating a temporary service that will run on next reboot and create the Windows VM" echo "exit because this has not been tested yet" exit # TODO: TEST THIS diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index c41b6ea..2a39eff 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -99,23 +99,11 @@ if [ $VM_INSTALL = true ]; then fi if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${VIRTIO_WIN_IMG},index=2,media=cdrom") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${VIRTIO_WIN_IMG}") -fi - -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=3,media=cdrom") + QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=2,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") fi -#if [ "$VM_START_MODE" = "qemu" ]; then -# QEMU_PARAMS+=("-fdb" "${AUTOUNATTEND_WIN_VFD}") -#elif [ "$VM_START_MODE" = "virt-install" ]; then -# VIRT_INSTALL_PARAMS+=("--disk" "device=floppy,path=${AUTOUNATTEND_WIN_VFD}") -#fi -#TODO: Uncomment! #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") QEMU_PARAMS+=("-device" "ich9-intel-hda") diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index c068cad..03e8817 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -10,10 +10,14 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" MAIN_SCRIPTS_DIR="${SCRIPTS_DIR}/main" UTILS_DIR="${SCRIPTS_DIR}/utils" COMMON_UTILS_DIR="${UTILS_DIR}/common" - COMMON_UTILS_LIB_DIR="${COMMON_UTILS_DIR}/lib" + COMMON_UTILS_LIBS_DIR="${COMMON_UTILS_DIR}/libs" COMMON_UTILS_SETUP_DIR="${COMMON_UTILS_DIR}/setup" COMMON_UTILS_TOOLS_DIR="${COMMON_UTILS_DIR}/tools" DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")" + MANAGER_UTILS_DIR="${UTILS_DIR}/manager-specific" + INITRAMFS_MANAGER="${MANAGER_UTILS_DIR}/initramfs/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" initramfs)" + SERVICE_MANAGER="${MANAGER_UTILS_DIR}/service/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" service)" + KERNEL_PARAM_MANAGER="${MANAGER_UTILS_DIR}/kernelparams/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" kernelparam)" THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" diff --git a/scripts/utils/common/setup/download-vfio-drivers b/scripts/utils/common/setup/download-vfio-drivers new file mode 100644 index 0000000..93f92e5 --- /dev/null +++ b/scripts/utils/common/setup/download-vfio-drivers @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +##################################################################################################### +# This script compiles the asm source code for the SSDT table that contains a fake battery for the VM. +# Usage: `./build-fake-battery-ssdt` +##################################################################################################### + +VIRTIO_WIN_VERSION="0.1.196" +if [ ! -f "${THIRDPARTY_DIR}/virtio-win.iso" ]; then + wget "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-${VIRTIO_WIN_VERSION}-1/virtio-win.iso" -O "${THIRDPARTY_DIR}/virtio-win.iso" +fi \ No newline at end of file diff --git a/scripts/utils/common/setup/looking-glass-setup b/scripts/utils/common/setup/looking-glass-setup new file mode 100755 index 0000000..976b6e7 --- /dev/null +++ b/scripts/utils/common/setup/looking-glass-setup @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +LOOKING_GLASS_VERSION="B4" +cd "${THIRDPARTY_DIR}" + +if [ ! -f "./LookingGlass" ]; then + # Get the source code + git clone --single-branch --branch "${LOOKING_GLASS_VERSION}" --depth 1 --recursive https://github.com/gnif/LookingGlass.git +fi +CURRENT_LG_VERSION="$(cd LookingGlass && git branch --show-current)" +if [ "$CURRENT_LG_VERSION" != "$LOOKING_GLASS_VERSION" ]; then + # If an old version of Looking Glass is detected, delete the old source code and get a clean copy of the required one + rm -rf LookingGlass + git clone --single-branch --branch "${LOOKING_GLASS_VERSION}" --depth 1 --recursive https://github.com/gnif/LookingGlass.git +fi + +# Clean up (remove old builds etc.) +git clean -fdx + +# Build the (Linux) client application +mkdir LookingGlass/client/build +cd LookingGlass/client/build +cmake ../ +make + +# Utilize systemd-tmpfiles to automatically set required permissions on /dev/shm/looking-glass +sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" +sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" + +# Download the Nvidia Capture SDK if it hasn'T been downlaoded already +cd "${THIRDPARTY_DIR}" +if [ ! -f "./Capture_Linux_v8.0.4" ]; then + wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidia_capture_api.tgz + #rm -rf ./Capture_Linux_v8.0.4 + tar -xvzf ./nvidia_capture_api.tgz + rm ./nvidia_capture_api.tgz +fi + +# Build the (Windows) host application +cp ./Capture_Linux_v8.0.4 ./LookingGlass/ +cd LookingGlass +cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=./host/toolchain-mingw64.cmake -DNVFBC_SDK='./Capture_Linux_v8.0.4' -DUSE_NVFBC=1 ./host +make + +#wget "https://ci.appveyor.com/api/projects/rainers/visuald/artifacts/cv2pdb.exe?job=Environment%3A%20os%3DVisual%20Studio%202015%2C%20VS%3D14%2C%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202015" -O "cv2pdb.exe" +#wine './cv2pdb.exe' './looking-glass-host.exe' +makensis './platform/Windows/installer.nsi' \ No newline at end of file diff --git a/scripts/utils/common/setup/set-kernel-params b/scripts/utils/common/setup/set-kernel-params deleted file mode 100755 index 0d46aaa..0000000 --- a/scripts/utils/common/setup/set-kernel-params +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - -##################################################################################################### -# Sets a bunch of required kernel parameters -# Usage: `./set-kernel-params` -##################################################################################################### - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -echo "Adding kernel parameters..." -# Docs: https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt -# More docs: https://lwn.net/Articles/252826/ -# https://www.kernel.org/doc/Documentation/x86/x86_64/boot-options.txt -echo "Adding kernel parameters to enable IOMMU on Intel/AMD CPUs..." -addKernelParam "iommu=1" # '1' is not a documented option. stop confusing me wendell! Maybe the "force" option should be used instead? -addKernelParam "amd_iommu=on" # 'on' is not a docuemnted option for this parameter either! This is insanely confusing! -addKernelParam "intel_iommu=on" # enable Intel VT-D ;# using "intel_iommu=on,igfx_off" iGPU gets no iommu group... -echo "Adding kernel parameter to enable mediated iGPU passthrough support (GVT-g) on Intel iGPUs..." -addKernelParam "i915.enable_gvt=1" -echo "Adding a kernel parameter to prevent bluescreens when a VM does MSR reads / writes directly..." -addKernelParam "kvm.ignore_msrs=1" -echo "Adding a kernel parameter to tell dracut to load vfio-pci first..." -addKernelParam "rd.driver.pre=vfio-pci" # tell dracut to load vfio-pci first - -# echo "Adding a kernel parameter to add skylake support..." -# addKernelParam "i915.preliminary_hw_support=1" # add skylake support; probably only necessary with older kernels -# echo "Adding a kernel parameter that may fix 'fix /dev/vfio/1 not found' errors..." -# addKernelParam "pcie_acs_override=downstream" # fix /dev/vfio/1 not found error # shouldn't be necessary -#addKernelParam "acpi_osi=!" # may fix problems with AMI style UEFIs -#addKernelParam "acpi_osi='Windows 2009'" # may fix problems with AMI style UEFIs - -#echo "Adding vfio stub drivers to initramfs..." -#addInitramfsDriver vfio_virqfd -#addInitramfsDriver vfio_pci -#addInitramfsDriver vfio_iommu_type1 -#addInitramfsDriver vfio -# -# -#echo "(Re)building initramfs for the current kernel to apply driver changes..." -#applyInitramfsChanges -echo "Applying the kernel parameter changes..." -applyKernelParamChanges diff --git a/scripts/utils/distro-specific/Fedora/34/vbios-finder-installer b/scripts/utils/common/setup/vbios-finder-setup similarity index 90% rename from scripts/utils/distro-specific/Fedora/34/vbios-finder-installer rename to scripts/utils/common/setup/vbios-finder-setup index 6e8c7b0..2e04cca 100755 --- a/scripts/utils/distro-specific/Fedora/34/vbios-finder-installer +++ b/scripts/utils/common/setup/vbios-finder-setup @@ -9,8 +9,6 @@ rm -rf VBiosFinder git clone https://github.com/coderobe/VBiosFinder.git cd VBiosFinder -sudo dnf install ruby rubygem-bundler ruby-devel p7zip innoextract upx -y - wget https://github.com/LongSoft/UEFITool/releases/download/A58/UEFIExtract_NE_A58_linux_x86_64.zip -O ./UEFIExtract.zip unzip ./UEFIExtract.zip -d ./3rdparty/ rm -f ./UEFIExtract.zip diff --git a/scripts/utils/common/tools/get-manager b/scripts/utils/common/tools/get-manager new file mode 100755 index 0000000..061192c --- /dev/null +++ b/scripts/utils/common/tools/get-manager @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +##################################################################################################### +# Determines how the system manages initramfs, kernel parameters and services +# Usage: `./get-manager service` # supports service, initramfs, kernelparams +##################################################################################################### + +COMMAND="$1" + +if [ "$COMMAND" = "service" ]; then + if command -v "systemctl" &> /dev/null; then + echo "systemd" + elif [ -d "/etc/init.d/" ] && command -v "service" &> /dev/null; then + echo "sysvinit" + fi +elif [ "$COMMAND" = "initramfs" ]; then + if [ -d "/etc/dracut.conf.d/" ]; then + echo "dracut" + fi +elif [ "$COMMAND" = "kernelparams" ]; then + if [ -f "/etc/default/grub" ] && [ -f "/etc/grub2-efi.cfg" ]; then + echo "grub" + fi +fi \ No newline at end of file diff --git a/scripts/utils/common/tools/install-packages b/scripts/utils/common/tools/install-packages index 0c6d51d..b758981 100755 --- a/scripts/utils/common/tools/install-packages +++ b/scripts/utils/common/tools/install-packages @@ -34,13 +34,13 @@ function installPackages() { WANTED_ITEMS="$2" if command -v dnf &> /dev/null; then # If package manager is dnf - sudo dnf check-update + sudo dnf check-update > /dev/null PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do if [ "$SEARCH_MODE" = "--executables" ]; then - PACKAGE_TO_INSTALL="$(sudo dnf whatprovides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -2 | tail -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + PACKAGE_TO_INSTALL="$(sudo dnf whatprovides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" elif [ "$SEARCH_MODE" = "--files" ]; then - PACKAGE_TO_INSTALL="$(sudo dnf provides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -2 | tail -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + PACKAGE_TO_INSTALL="$(sudo dnf provides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" fi if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" @@ -52,7 +52,7 @@ function installPackages() { sudo dnf install -y $PACKAGES_TO_INSTALL fi elif command -v apt-get &> /dev/null; then # If package manager is apt - sudo apt-get update + sudo apt-get update > /dev/null if ! command -v apt-file &> /dev/null; then apt-get install -y apt-file fi diff --git a/scripts/utils/common/tools/runtime-kernel-has-params b/scripts/utils/common/tools/runtime-kernel-has-params new file mode 100755 index 0000000..28bf749 --- /dev/null +++ b/scripts/utils/common/tools/runtime-kernel-has-params @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +function runtimeKernelHasParam() { + cmdline="$(cat /proc/cmdline)" + [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] +} + +function runtimeKernelHasParams() { + for param in $1; do + runtimeKernelHasParam "$param" + done +} + +runtimeKernelHasParams "$1" \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/amd-setup b/scripts/utils/distro-specific/Fedora/34/amd-setup deleted file mode 100755 index 3ceda87..0000000 --- a/scripts/utils/distro-specific/Fedora/34/amd-setup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -# This script doesn't do anything yet. \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/bumblebee-setup b/scripts/utils/distro-specific/Fedora/34/bumblebee-setup index d04affd..120f19e 100755 --- a/scripts/utils/distro-specific/Fedora/34/bumblebee-setup +++ b/scripts/utils/distro-specific/Fedora/34/bumblebee-setup @@ -1,15 +1,6 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -echo "Disable Nouveau drivers" -addKernelParam "nouveau.modeset=0" -#sudo grep -qxsF 'blacklist nouveau' "/etc/modprobe.d/blacklist.conf" || echo "blacklist nouveau" | sudo tee -a "/etc/modprobe.d/blacklist.conf" > /dev/null -#sudo grep -qxsF 'exclude=xorg-x11*' "/etc/dnf/dnf.conf" || echo "exclude=xorg-x11*" | sudo tee -a "/etc/dnf/dnf.conf" > /dev/null -#sudo dnf remove xorg-x11-drv-nouveau -y echo "Install third party repositories" sudo dnf install fedora-workstation-repositories -y diff --git a/scripts/utils/distro-specific/Fedora/34/install-dependencies b/scripts/utils/distro-specific/Fedora/34/install-dependencies deleted file mode 100755 index ce2c62b..0000000 --- a/scripts/utils/distro-specific/Fedora/34/install-dependencies +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -echo "Updating software..." -sudo dnf update -y -echo "Installing some useful tools..." -sudo dnf install -y wget curl vim screen git crudini lshw msr-tools sysfsutils tunctl remmina samba spice-gtk-tools genisoimage uuid acpica-tools docker dumpet e2fsprogs-devel imake gcc-c++ -echo "Installing virtualization software..." -sudo dnf install -y qemu #@virtualization - -echo "Installing the Windows VirtIO Repository..." -sudo wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo -O /etc/yum.repos.d/virtio-win.repo -echo "Installing virtio-win..." -sudo dnf install virtio-win -y -echo "Upgrading to latest virtio-win..." -sudo dnf --enablerepo=virtio-win-latest upgrade virtio-win -y -echo "Installing virt-viewer so you can connect to the VM for the windows installation" -sudo dnf install -y virt-viewer -# /usr/share/virtio-win/virtio-win.iso diff --git a/scripts/utils/distro-specific/Fedora/34/intel-setup b/scripts/utils/distro-specific/Fedora/34/intel-setup deleted file mode 100755 index caf683c..0000000 --- a/scripts/utils/distro-specific/Fedora/34/intel-setup +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -#TODO: verify if that actually works: -#echo "Allow using external monitor for notebooks that have the port wired to the dGPU directly" -if ! command -v intel-virtual-output &> /dev/null; then - sudo dnf install -y intel-gpu-tools -fi -#sudo intel-virtual-output # TODO: Check if this should be added to the start-vm.sh -#example usage: xrandr –output eDP1 –mode 1920×1080 –output HDMI1 –mode 1920×1080 –right-of eDP1 diff --git a/scripts/utils/distro-specific/Fedora/34/kernel-param-utils b/scripts/utils/distro-specific/Fedora/34/kernel-param-utils deleted file mode 100755 index 0105634..0000000 --- a/scripts/utils/distro-specific/Fedora/34/kernel-param-utils +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash - -GRUB_CFG_PATH=/etc/default/grub -VFIO_CFG_PATH=/etc/dracut.conf.d/vfio.conf - -function addKernelParam() { - if ! sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then - sudo sed -i "s/^GRUB_CMDLINE_LINUX=\"/&$1 /" "$GRUB_CFG_PATH" - echo "addKernelParam: Added \"$1\" to GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" - else - echo "addKernelParam: No action required. \"$1\" already exists in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" - fi -} -function removeKernelParam() { - if sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then - sudo sed -i "s/$1 //" "$GRUB_CFG_PATH" - echo "removeKernelParam: Removed \"$1\" from GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" - else - echo "removeKernelParam: No action required. \"$1\" is not set in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" - fi -} -function applyKernelParamChanges() { - sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg' -} - -function setGrubTimeout() { - sudo sed -i -r "s/^GRUB_TIMEOUT=[0-9]+/GRUB_TIMEOUT=$1 /" "$GRUB_CFG_PATH" -} - -function addInitramfsDriver() { - driver="$1" - sudo touch "$VFIO_CFG_PATH" - if ! sudo cat "$VFIO_CFG_PATH" | grep --quiet "add_driver+="; then - echo 'add_driver+=" "' >> "$VFIO_CFG_PATH" - fi - if ! sudo cat "$VFIO_CFG_PATH" | grep "add_driver+=" | grep --quiet -P "( |\")$driver( |\")"; then - sudo sed -i "s/^add_driver+=\" \{0,1\}/&$driver /" "$VFIO_CFG_PATH" - echo "addDriverToInitramfs: Added \"$driver\" to add_driver in $VFIO_CFG_PATH" - else - echo "addDriverToInitramfs: No action required. \"$driver\" already exists in add_driver in $VFIO_CFG_PATH" - fi -} - -function applyInitramfsChanges() { - sudo dracut -f --kver `uname -r` - #TODO: Find out if this needs to be executed again after every kernel update. -} - -function runtimeKernelHasParam() { - cmdline="$(cat /proc/cmdline)" - [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] -} - -function runtimeKernelHasParams() { - for param in $1; do - runtimeKernelHasParam "$param" - fi -} - -function addKernelParams() { - for param in $1; do - addKernelParam "$param" - fi -} \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/looking-glass-setup b/scripts/utils/distro-specific/Fedora/34/looking-glass-setup deleted file mode 100755 index 66d7f6d..0000000 --- a/scripts/utils/distro-specific/Fedora/34/looking-glass-setup +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -cd "${THIRDPARTY_DIR}" - -sudo dnf install -y binutils-devel cmake texlive-gnu-freefont fontconfig-devel SDL2-devel SDL2_ttf-devel spice-protocol libX11-devel nettle-devel wayland-protocols-devel gcc libXScrnSaver-devel libXfixes-devel libXi-devel wayland-devel mingw64-gcc-c++ mingw32-nsis - -LOOKING_GLASS_VERSION="B4" - -# Build the (Linux) client application -git clone --single-branch --branch "${LOOKING_GLASS_VERSION}" --depth 1 --recursive https://github.com/gnif/LookingGlass.git -mkdir LookingGlass/client/build -cd LookingGlass/client/build -cmake ../ -make - -sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" -sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" - -# Build the (Windows) host application -cd "${THIRDPARTY_DIR}" -wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidia_capture_api.tgz -rm -rf ./Capture_Linux_v8.0.4 -tar -xvzf ./nvidia_capture_api.tgz -rm ./nvidia_capture_api.tgz -rm -rf ./LookingGlass/Capture_Linux_v8.0.4 -mv ./Capture_Linux_v8.0.4 ./LookingGlass/ -cd LookingGlass -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=./host/toolchain-mingw64.cmake -DNVFBC_SDK='./Capture_Linux_v8.0.4' -DUSE_NVFBC=1 ./host -make - -#wget "https://ci.appveyor.com/api/projects/rainers/visuald/artifacts/cv2pdb.exe?job=Environment%3A%20os%3DVisual%20Studio%202015%2C%20VS%3D14%2C%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202015" -O "cv2pdb.exe" -#wine './cv2pdb.exe' './looking-glass-host.exe' -makensis './platform/Windows/installer.nsi' - -#``` -#binutils-devel -# - /usr/include/bfd.h -# - /usr/lib64/libbfd.a -# - /usr/lib64/libiberty.a -# -#cmake -# - cmake -# -#texlive-gnu-freefont -# - ??? -# -#fontconfig-devel -# - /usr/include/fontconfig/fontconfig.h -# -#SDL2-devel -# - ??? -# -#SDL2_ttf-devel -# - ??? -# -#spice-protocol -# - /usr/include/spice-1/spice/protocol.h -# - /usr/include/spice-1/spice/vd_agent.h -# -#libX11-devel -# - /usr/include/X11/Xlib.h -# - /usr/include/X11/Xutil.h -# -#nettle-devel -# - /usr/include/nettle/asn1.h -# - /usr/include/nettle/sha1.h -# - /usr/include/nettle/rsa.h -# - /usr/include/nettle/bignum.h -# - -# -#wayland-protocols-devel -# - /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml -# - /usr/share/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml -# - /usr/share/wayland-protocols/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml -# - /usr/share/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml -# -#gcc -# - gcc -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdatomic.h -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/emmintrin.h -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdarg.h -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdbool.h -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stddef.h -# - /usr/lib/gcc/x86_64-redhat-linux/11/include/stdint.h -# - -# -#libXScrnSaver-devel -# - /usr/include/X11/extensions/scrnsaver.h -# -#libXfixes-devel -# - /usr/include/X11/extensions/Xfixes.h -# -#libXi-devel -# - /usr/include/X11/extensions/XInput2.h -# -#wayland-devel -# - wayland-scanner -# - /usr/include/wayland-client.h -# - /usr/include/wayland-cursor.h -# - /usr/include/wayland-egl.h -# -#libXinerama-devel -# - /usr/include/X11/extensions/Xinerama.h -#``` \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/nvidia-setup b/scripts/utils/distro-specific/Fedora/34/nvidia-setup index 1dafbba..4a3f62f 100755 --- a/scripts/utils/distro-specific/Fedora/34/nvidia-setup +++ b/scripts/utils/distro-specific/Fedora/34/nvidia-setup @@ -1,12 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -echo "Disable Nouveau drivers" -addKernelParam "nouveau.modeset=0" +#echo "Disable Nouveau drivers" +#addKernelParam "nouveau.modeset=0" #sudo grep -qxsF 'blacklist nouveau' "/etc/modprobe.d/blacklist.conf" || echo "blacklist nouveau" | sudo tee -a "/etc/modprobe.d/blacklist.conf" > /dev/null #sudo grep -qxsF 'exclude=xorg-x11*' "/etc/dnf/dnf.conf" || echo "exclude=xorg-x11*" | sudo tee -a "/etc/dnf/dnf.conf" > /dev/null #sudo dnf remove xorg-x11-drv-nouveau -y @@ -18,24 +15,4 @@ echo "Install third party repositories" sudo dnf config-manager rpmfusion-nonfree-nvidia-driver --set-enabled -y echo "Enable the NVIDIA driver repository" -sudo dnf install akmod-nvidia acpi -y - -echo "Enable the Bumblebee repository" -sudo dnf copr enable chenxiaolong/bumblebee -y - -echo "Install Bumblebee" -sudo dnf install akmod-bbswitch bumblebee primus -y - -echo "Make Bumblebee avialable to the current user" -sudo gpasswd -a $(who -m | awk '{print $1;}') bumblebee - -echo "Enable Bumblebee autostart" -sudo systemctl enable bumblebeed - -echo "Block nvidia-fallback service" -sudo systemctl mask nvidia-fallback - -echo "Start Bumblebee" -sudo systemctl start bumblebeed - -sudo ${COMMON_UTILS_SETUP_DIR}/extract-vbios +sudo dnf install akmod-nvidia acpi -y \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/amd-setup b/scripts/utils/distro-specific/Ubuntu/21.04/amd-setup deleted file mode 100644 index 3ceda87..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/amd-setup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -# This script doesn't do anything yet. \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup b/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup index c394da9..b39b500 100755 --- a/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup @@ -1,20 +1,10 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -echo "Disable Nouveau drivers" -addKernelParam "nouveau.modeset=0" -#sudo grep -qxsF 'blacklist nouveau' "/etc/modprobe.d/blacklist.conf" || echo "blacklist nouveau" | sudo tee -a "/etc/modprobe.d/blacklist.conf" > /dev/null -#sudo grep -qxsF 'exclude=xorg-x11*' "/etc/dnf/dnf.conf" || echo "exclude=xorg-x11*" | sudo tee -a "/etc/dnf/dnf.conf" > /dev/null -#sudo dnf remove xorg-x11-drv-nouveau -y echo "Install third party repositories" sudo add-apt-repository ppa:bumblebee/testing -y - echo "Install Bumblebee" sudo apt install bumblebee bumblebee-nvidia -y diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/install-dependencies b/scripts/utils/distro-specific/Ubuntu/21.04/install-dependencies deleted file mode 100755 index e54fc87..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/install-dependencies +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -echo "Updating software..." -sudo apt upgrade -y -echo "Installing some useful tools..." -sudo apt install -y wget curl git crudini lshw msr-tools sysfsutils uml-utilities remmina samba spice-client-gtk genisoimage uuid acpica-tools docker -echo "Installing virtualization software..." -sudo apt install qemu-kvm qemu-utils qemu-efi ovmf qemu -y - -#echo "Installing the Windows VirtIO Repository..." -#sudo wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo -O /etc/yum.repos.d/virtio-win.repo -echo "Installing virtio-modules" -sudo apt install virtio-modules -y -# TODO: consider: wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso -#echo "Upgrading to latest virtio-win..." -#sudo dnf --enablerepo=virtio-win-latest upgrade virtio-win -y -echo "Installing virt-viewer so you can connect to the VM for the windows installation" -sudo apt install -y virt-viewer -# /usr/share/virtio-win/virtio-win.iso diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/intel-setup b/scripts/utils/distro-specific/Ubuntu/21.04/intel-setup deleted file mode 100755 index 71fdd9f..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/intel-setup +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -#TODO: verify if that actually works: -echo "Allow using external monitor for notebooks that have the port wired to the dGPU directly" -sudo apt install -y intel-gpu-tools -sudo intel-virtual-output -#example usage: xrandr –output eDP1 –mode 1920×1080 –output HDMI1 –mode 1920×1080 –right-of eDP1 diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils b/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils deleted file mode 100755 index 6f88ba7..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/kernel-param-utils +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -GRUB_CFG_PATH=/etc/default/grub -VFIO_CFG_PATH=/etc/dracut.conf.d/vfio.conf - -function addKernelParam() { - if ! sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then - sudo sed -i "s/^GRUB_CMDLINE_LINUX=\"/&$1 /" "$GRUB_CFG_PATH" - echo "addKernelParam: Added \"$1\" to GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" - else - echo "addKernelParam: No action required. \"$1\" already exists in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" - fi -} -function removeKernelParam() { - if sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then - sudo sed -i "s/$1 //" "$GRUB_CFG_PATH" - echo "removeKernelParam: Removed \"$1\" from GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" - else - echo "removeKernelParam: No action required. \"$1\" is not set in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" - fi -} -function applyKernelParamChanges() { - sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg' -} - -function setGrubTimeout() { - sudo sed -i -r "s/^GRUB_TIMEOUT=[0-9]+/GRUB_TIMEOUT=$1 /" "$GRUB_CFG_PATH" -} - -function addInitramfsDriver() { - driver="$1" - sudo touch "$VFIO_CFG_PATH" - if ! sudo cat "$VFIO_CFG_PATH" | grep --quiet "add_driver+="; then - echo 'add_driver+=" "' >> "$VFIO_CFG_PATH" - fi - if ! sudo cat "$VFIO_CFG_PATH" | grep "add_driver+=" | grep --quiet -P "( |\")$driver( |\")"; then - sudo sed -i "s/^add_driver+=\" \{0,1\}/&$driver /" "$VFIO_CFG_PATH" - echo "addDriverToInitramfs: Added \"$driver\" to add_driver in $VFIO_CFG_PATH" - else - echo "addDriverToInitramfs: No action required. \"$driver\" already exists in add_driver in $VFIO_CFG_PATH" - fi -} - -function applyInitramfsChanges() { - sudo dracut -f --kver `uname -r` - #TODO: Find out if this needs to be executed again after every kernel update. -} - -function runtimeKernelHasParam() { - cmdline="$(cat /proc/cmdline)" - [[ $cmdline =~ ^$1.* ]] || [[ $cmdline =~ .*$1$ ]] || [[ $cmdline = *" $1 "* ]] -} - -function addKernelParams() { - for param in $1; do - addKernelParam "$param" - fi -} \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup b/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup deleted file mode 100755 index 0c7c3fa..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/looking-glass-setup +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -cd "${THIRDPARTY_DIR}" - -sudo apt install binutils binutils-multiarch-dev cmake texlive-fonts-recommended fonts-freefont-ttf libfontconfig-dev libegl-dev libspice-protocol-dev libsdl2-dev nettle-dev libx11-dev libxi-dev libxinerama-dev libxss-dev libwayland-dev wayland-protocols - -LOOKING_GLASS_VERSION="B4" - -# Build the (Linux) client application -git clone --single-branch --branch "${LOOKING_GLASS_VERSION}" --depth 1 --recursive https://github.com/gnif/LookingGlass.git -mkdir LookingGlass/client/build -cd LookingGlass/client/build -cmake ../ -make - -sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" -sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" - -# Build the (Windows) host application -cd "${THIRDPARTY_DIR}" -wget https://developer.nvidia.com/capture_sdk/downloads/v8.0.4/linux -O ./nvidia_capture_api.tgz -rm -rf ./Capture_Linux_v8.0.4 -tar -xvzf ./nvidia_capture_api.tgz -rm ./nvidia_capture_api.tgz -rm -rf ./LookingGlass/Capture_Linux_v8.0.4 -mv ./Capture_Linux_v8.0.4 ./LookingGlass/ -cd LookingGlass -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=./host/toolchain-mingw64.cmake -DNVFBC_SDK='./Capture_Linux_v8.0.4' -DUSE_NVFBC=1 ./host -make - -#wget "https://ci.appveyor.com/api/projects/rainers/visuald/artifacts/cv2pdb.exe?job=Environment%3A%20os%3DVisual%20Studio%202015%2C%20VS%3D14%2C%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202015" -O "cv2pdb.exe" -#wine './cv2pdb.exe' './looking-glass-host.exe' -makensis './platform/Windows/installer.nsi' diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup b/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup index 9817b3b..0781e84 100755 --- a/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup +++ b/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup @@ -1,37 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadConfig - -source "$DISTRO_UTILS_DIR/kernel-param-utils" - -echo "Disable Nouveau drivers" -addKernelParam "nouveau.modeset=0" -#sudo grep -qxsF 'blacklist nouveau' "/etc/modprobe.d/blacklist.conf" || echo "blacklist nouveau" | sudo tee -a "/etc/modprobe.d/blacklist.conf" > /dev/null -#sudo grep -qxsF 'exclude=xorg-x11*' "/etc/dnf/dnf.conf" || echo "exclude=xorg-x11*" | sudo tee -a "/etc/dnf/dnf.conf" > /dev/null -#sudo dnf remove xorg-x11-drv-nouveau -y echo "Install third party repositories" sudo add-apt-repository ppa:graphics-drivers/ppa -y echo "Auto-install NVIDIA Drivers with ubuntu-drivers" -sudo ubuntu-drivers install -y - -echo "Add Bumblebee repository" -sudo add-apt-repository ppa:bumblebee/testing -y - - -echo "Install Bumblebee" -sudo apt install bumblebee bumblebee-nvidia primus -y - -echo "Make Bumblebee available to the current user" -sudo usermod -aG bumblebee $(whoami) - -echo "Enable Bumblebee autostart" -sudo systemctl enable bumblebeed - -echo "Block nvidia-fallback service" -sudo systemctl mask nvidia-fallback - -echo "Start Bumblebee" -sudo systemctl start bumblebeed +sudo ubuntu-drivers install -y \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer b/scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer deleted file mode 100755 index 2f272fa..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/vbios-finder-installer +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" -loadCfg - -cd "${THIRDPARTY_DIR}" - -rm -rf VBiosFinder -git clone https://github.com/coderobe/VBiosFinder.git -cd VBiosFinder - -sudo apt install ruby ruby-rubygems ruby-bundler ruby-dev p7zip innoextract upx -y - -wget https://github.com/LongSoft/UEFITool/releases/download/A58/UEFIExtract_NE_A58_linux_x86_64.zip -O ./UEFIExtract.zip -unzip ./UEFIExtract.zip -d ./3rdparty/ -rm -f ./UEFIExtract.zip - -git clone https://github.com/awilliam/rom-parser.git -cd rom-parser - -bundle install --path=vendor/bundle -gem install bundler:1.17.3 - -make -mv ./rom-fixer ../3rdparty/ -mv ./rom-parser ../3rdparty/ -cd .. - -bundle install --path=vendor/bundle - diff --git a/scripts/utils/manager-specific/initramfs/dracut b/scripts/utils/manager-specific/initramfs/dracut new file mode 100755 index 0000000..fa19b64 --- /dev/null +++ b/scripts/utils/manager-specific/initramfs/dracut @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +VFIO_CFG_PATH=/etc/dracut.conf.d/vfio.conf + +COMMAND="$1" # Supported comamnds: add-driver, apply +PARAM="$2" + +function addInitramfsDriver() { + driver="$1" + sudo touch "$VFIO_CFG_PATH" + if ! sudo cat "$VFIO_CFG_PATH" | grep --quiet "add_driver+="; then + echo 'add_driver+=" "' >> "$VFIO_CFG_PATH" + fi + if ! sudo cat "$VFIO_CFG_PATH" | grep "add_driver+=" | grep --quiet -P "( |\")$driver( |\")"; then + sudo sed -i "s/^add_driver+=\" \{0,1\}/&$driver /" "$VFIO_CFG_PATH" + echo "addDriverToInitramfs: Added \"$driver\" to add_driver in $VFIO_CFG_PATH" + else + echo "addDriverToInitramfs: No action required. \"$driver\" already exists in add_driver in $VFIO_CFG_PATH" + fi +} + +function applyInitramfsChanges() { + sudo dracut -f --kver `uname -r` + #TODO: Find out if this needs to be executed again after every kernel update. +} + +if [ "$COMMAND" = "add-driver" ]; then + addInitramfsDriver "$PARAM" +elif [ "$COMMAND" = "apply" ]; then + applyInitramfsChanges +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/kernelparams/grub b/scripts/utils/manager-specific/kernelparams/grub new file mode 100755 index 0000000..086b22e --- /dev/null +++ b/scripts/utils/manager-specific/kernelparams/grub @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +GRUB_CFG_PATH=/etc/default/grub + +COMMAND="$1" # Supported comamnds: add, remove, apply +PARAM="$2" + +function addKernelParam() { + if ! sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then + sudo sed -i "s/^GRUB_CMDLINE_LINUX=\"/&$1 /" "$GRUB_CFG_PATH" + echo "addKernelParam: Added \"$1\" to GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" + else + echo "addKernelParam: No action required. \"$1\" already exists in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" + fi +} +function addKernelParams() { + for param in $1; do + addKernelParam "$param" + fi +} +function removeKernelParam() { + if sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then + sudo sed -i "s/$1 //" "$GRUB_CFG_PATH" + echo "removeKernelParam: Removed \"$1\" from GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" + else + echo "removeKernelParam: No action required. \"$1\" is not set in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" + fi +} +function removeKernelParams() { + for param in $1; do + removeKernelParam "$param" + fi +} + +function applyKernelParamChanges() { + sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg' +} + +if [ "$COMMAND" = "add" ]; then + addKernelParams "$PARAM" +elif [ "$COMMAND" = "remove" ]; then + removeKernelParams "$PARAM" +elif [ "$COMMAND" = "apply" ]; then + applyKernelParamChanges +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/service/systemd b/scripts/utils/manager-specific/service/systemd new file mode 100644 index 0000000..16e811a --- /dev/null +++ b/scripts/utils/manager-specific/service/systemd @@ -0,0 +1 @@ +# TODO create temporary autostart service From 5dabe62fff01082ee4d7aa2f7e83c1acf4d52c20 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Thu, 5 Aug 2021 04:39:31 +0200 Subject: [PATCH 15/40] Refactor package manager abstraction --- scripts/main/setup.sh | 4 +- scripts/utils/common/libs/gpu-check | 0 scripts/utils/common/libs/helpers | 1 + .../utils/common/setup/download-vfio-drivers | 0 scripts/utils/common/tools/get-manager | 10 ++- .../common/tools/get-missing-executables | 18 ++++ scripts/utils/common/tools/get-missing-files | 18 ++++ scripts/utils/common/tools/install-packages | 88 ------------------- scripts/utils/common/tools/lsiommu | 0 scripts/utils/manager-specific/package/apt | 52 +++++++++++ scripts/utils/manager-specific/package/dnf | 49 +++++++++++ .../utils/manager-specific/service/systemd | 1 + 12 files changed, 149 insertions(+), 92 deletions(-) mode change 100755 => 100644 scripts/utils/common/libs/gpu-check mode change 100644 => 100755 scripts/utils/common/setup/download-vfio-drivers create mode 100755 scripts/utils/common/tools/get-missing-executables create mode 100755 scripts/utils/common/tools/get-missing-files delete mode 100755 scripts/utils/common/tools/install-packages mode change 100755 => 100644 scripts/utils/common/tools/lsiommu create mode 100755 scripts/utils/manager-specific/package/apt create mode 100755 scripts/utils/manager-specific/package/dnf mode change 100644 => 100755 scripts/utils/manager-specific/service/systemd diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 91a27cd..ee7404d 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -13,8 +13,8 @@ source "${PROJECT_DIR}/requirements.sh" source "$COMMON_UTILS_LIBS_DIR/cpu-check" source "$COMMON_UTILS_LIBS_DIR/gpu-check" -alias getExecPkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --executables" -alias getFilePkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --files" +alias getExecPkg="'${PACKAGE_MANAGER}' --executables" +alias getFilePkg="'${PACKAGE_MANAGER}' --files" alias kernelParamManager="'${KERNEL_PARAM_MANAGER}'" alias runtimeKernelHasParams="'${COMMON_UTILS_TOOLS_DIR}/runtime-kernel-has-params'" diff --git a/scripts/utils/common/libs/gpu-check b/scripts/utils/common/libs/gpu-check old mode 100755 new mode 100644 diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index 03e8817..f54493e 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -18,6 +18,7 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" INITRAMFS_MANAGER="${MANAGER_UTILS_DIR}/initramfs/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" initramfs)" SERVICE_MANAGER="${MANAGER_UTILS_DIR}/service/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" service)" KERNEL_PARAM_MANAGER="${MANAGER_UTILS_DIR}/kernelparams/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" kernelparam)" + PACKAGE_MANAGER="${MANAGER_UTILS_DIR}/package/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" package)" THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" diff --git a/scripts/utils/common/setup/download-vfio-drivers b/scripts/utils/common/setup/download-vfio-drivers old mode 100644 new mode 100755 diff --git a/scripts/utils/common/tools/get-manager b/scripts/utils/common/tools/get-manager index 061192c..859fb6b 100755 --- a/scripts/utils/common/tools/get-manager +++ b/scripts/utils/common/tools/get-manager @@ -1,8 +1,8 @@ #!/usr/bin/env bash ##################################################################################################### -# Determines how the system manages initramfs, kernel parameters and services -# Usage: `./get-manager service` # supports service, initramfs, kernelparams +# Determines how the system manages initramfs, packages, kernel parameters and services +# Usage: `./get-manager service` # supports service, initramfs, kernelparams, package ##################################################################################################### COMMAND="$1" @@ -21,4 +21,10 @@ elif [ "$COMMAND" = "kernelparams" ]; then if [ -f "/etc/default/grub" ] && [ -f "/etc/grub2-efi.cfg" ]; then echo "grub" fi +elif [ "$COMMAND" = "package" ]; then + if command -v dnf &> /dev/null; then + echo "dnf" + elif command -v apt-get &> /dev/null; then + echo "apt" + fi fi \ No newline at end of file diff --git a/scripts/utils/common/tools/get-missing-executables b/scripts/utils/common/tools/get-missing-executables new file mode 100755 index 0000000..f2f952d --- /dev/null +++ b/scripts/utils/common/tools/get-missing-executables @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +##################################################################################################### +# Simple script to check which executables in a given list are not installed +# Usage: `./get-missing-executables "curl git wget docker"` +##################################################################################################### + +function getMissingExecutables() { + EXECUTABLES_MISSING="" + for CURRENT_EXECUTABLE in $1; do + if ! command -v $CURRENT_EXECUTABLE &> /dev/null; then + EXECUTABLES_MISSING+=" $CURRENT_EXECUTABLE" + fi + done + echo "$EXECUTABLES_MISSING" +} + +getMissingExecutables "$1" \ No newline at end of file diff --git a/scripts/utils/common/tools/get-missing-files b/scripts/utils/common/tools/get-missing-files new file mode 100755 index 0000000..f6eed8c --- /dev/null +++ b/scripts/utils/common/tools/get-missing-files @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +##################################################################################################### +# Simple script to check which files in a given list do not exist +# Usage: `./get-missing-files "curl git wget docker"` +##################################################################################################### + +function getMissingFiles() { + FILES_MISSING="" + for CURRENT_FILE in $1; do + if [ ! -f "$CURRENT_FILE" ]; then + FILES_MISSING+=" $CURRENT_FILE" + fi + done + echo "$FILES_MISSING" +} + +getMissingFiles "$1" \ No newline at end of file diff --git a/scripts/utils/common/tools/install-packages b/scripts/utils/common/tools/install-packages deleted file mode 100755 index b758981..0000000 --- a/scripts/utils/common/tools/install-packages +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash - -##################################################################################################### -# Simple script to install the package containing the given executable name -# Usage: `./install-packages --executables "curl git wget docker"` -# Usage: `./install-packages --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` -##################################################################################################### - -SEARCH_MODE="$1" -WANTED_ITEMS="$2" - -function getMissingExecutables() { - EXECUTABLES_MISSING="" - for CURRENT_EXECUTABLE in $1; do - if ! command -v $CURRENT_EXECUTABLE &> /dev/null; then - EXECUTABLES_MISSING+=" $CURRENT_EXECUTABLE" - fi - done - echo "$EXECUTABLES_MISSING" -} - -function getMissingFiles() { - FILES_MISSING="" - for CURRENT_FILE in $1; do - if [ ! -f "$CURRENT_FILE" ]; then - FILES_MISSING+=" $CURRENT_FILE" - fi - done - echo "$FILES_MISSING" -} - -function installPackages() { - SEARCH_MODE="$1" - WANTED_ITEMS="$2" - - if command -v dnf &> /dev/null; then # If package manager is dnf - sudo dnf check-update > /dev/null - PACKAGES_TO_INSTALL="" - for CURRENT_ITEM in $WANTED_ITEMS; do - if [ "$SEARCH_MODE" = "--executables" ]; then - PACKAGE_TO_INSTALL="$(sudo dnf whatprovides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" - elif [ "$SEARCH_MODE" = "--files" ]; then - PACKAGE_TO_INSTALL="$(sudo dnf provides "$CURRENT_ITEM" 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" - fi - if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then - PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" - else - STILL_MISSING_ITEMS+=" $CURRENT_ITEM" - fi - done - if [ "$PACKAGES_TO_INSTALL" != "" ]; then - sudo dnf install -y $PACKAGES_TO_INSTALL - fi - elif command -v apt-get &> /dev/null; then # If package manager is apt - sudo apt-get update > /dev/null - if ! command -v apt-file &> /dev/null; then - apt-get install -y apt-file - fi - PACKAGES_TO_INSTALL="" - for CURRENT_ITEM in $WANTED_ITEMS; do - if [ "$SEARCH_MODE" = "--executables" ]; then - PACKAGE_TO_INSTALL="$(sudo apt-file search "/usr/bin/$CURRENT_ITEM" | head -1 | cut -d':' -f1)" - elif [ "$SEARCH_MODE" = "--files" ]; then - PACKAGE_TO_INSTALL="$(sudo apt-file search "$CURRENT_ITEM" | head -1 | cut -d':' -f1))" - fi - if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then - PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" - else - STILL_MISSING_ITEMS+=" $CURRENT_ITEM" - fi - done - if [ "$PACKAGES_TO_INSTALL" != "" ]; then - sudo apt-get install -y $PACKAGES_TO_INSTALL - fi - fi - - #echo "Couldn't find packages for: $STILL_MISSING_ITEMS" -} - -if [ "$SEARCH_MODE" = "--executables" ]; then - MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" - installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" - echo "Still missing: $(getMissingExecutables "$WANTED_ITEMS")" -elif [ "$SEARCH_MODE" = "--files" ]; then - MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" - installPackages "$SEARCH_MODE" "$MISSING_FILES" - echo "Still missing: $(getMissingFiles "$WANTED_ITEMS")" -fi \ No newline at end of file diff --git a/scripts/utils/common/tools/lsiommu b/scripts/utils/common/tools/lsiommu old mode 100755 new mode 100644 diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt new file mode 100755 index 0000000..66f4ba0 --- /dev/null +++ b/scripts/utils/manager-specific/package/apt @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# Simple script to install the packages containing the given executable names or file names +# Usage: `./apt --executables "curl git wget docker"` +# Usage: `./apt --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" + +SEARCH_MODE="$1" +WANTED_ITEMS="$2" + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + + sudo apt-get update > /dev/null + if ! command -v apt-file &> /dev/null; then + apt-get install -y apt-file + fi + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM | head -1 | cut -d':' -f1)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo apt-file search $CURRENT_ITEM | head -1 | cut -d':' -f1))" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo apt-get install -y $PACKAGES_TO_INSTALL + fi +} + +if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + echo "Still missing: $(getMissingExecutables "$WANTED_ITEMS")" +elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + echo "Still missing: $(getMissingFiles "$WANTED_ITEMS")" +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/package/dnf b/scripts/utils/manager-specific/package/dnf new file mode 100755 index 0000000..1f53f27 --- /dev/null +++ b/scripts/utils/manager-specific/package/dnf @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# Simple script to install the packages containing the given executable names or files +# Usage: `./dnf --executables "curl git wget docker"` +# Usage: `./dnf --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" + +SEARCH_MODE="$1" +WANTED_ITEMS="$2" + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + + sudo dnf check-update > /dev/null + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo dnf provides {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo dnf provides $CURRENT_ITEM 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo dnf install -y $PACKAGES_TO_INSTALL + fi +} + +if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + echo "Still missing: $(getMissingExecutables "$WANTED_ITEMS")" +elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + echo "Still missing: $(getMissingFiles "$WANTED_ITEMS")" +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/service/systemd b/scripts/utils/manager-specific/service/systemd old mode 100644 new mode 100755 index 16e811a..5d779f6 --- a/scripts/utils/manager-specific/service/systemd +++ b/scripts/utils/manager-specific/service/systemd @@ -1 +1,2 @@ +#!/usr/bin/env bash # TODO create temporary autostart service From 64426d1526840abeb043108c5d03ed0ccda03208 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Thu, 5 Aug 2021 18:46:06 +0200 Subject: [PATCH 16/40] Cleanup and bugfixes --- .gitignore | 3 +- README.md | 14 +- helper-iso-files/Autounattend.xml | 8 +- helper-iso-files/mbpt-helper.bat | 2 +- .../scripts/chocolatey-install.ps1 | 698 ++++++++++++++++++ helper-iso-files/scripts/gpu-check.ps1 | 27 +- helper-iso-files/scripts/network-check.ps1 | 4 +- mbpt.sh | 41 +- requirements.sh | 4 +- scripts/main/compatibility-check.sh | 73 +- scripts/main/generate-helper-iso.sh | 4 +- scripts/main/generate-vm-config.sh | 10 +- scripts/main/setup.sh | 122 +-- scripts/main/vm.sh | 103 ++- scripts/utils/common/libs/helpers | 1 + .../utils/common/setup/download-vfio-drivers | 13 - scripts/utils/common/tools/get-manager | 20 + scripts/utils/common/tools/lsiommu | 0 .../gui-terminal/gnome-terminal | 9 + .../manager-specific/gui-terminal/konsole | 9 + .../utils/manager-specific/gui-terminal/st | 9 + .../gui-terminal/x-terminal-emulator | 9 + .../utils/manager-specific/initramfs/dracut | 2 +- .../utils/manager-specific/kernelparams/grub | 2 +- scripts/utils/manager-specific/package/apt | 16 +- scripts/utils/manager-specific/package/dnf | 16 +- .../utils/manager-specific/service/systemd | 31 +- 27 files changed, 1058 insertions(+), 192 deletions(-) create mode 100644 helper-iso-files/scripts/chocolatey-install.ps1 delete mode 100755 scripts/utils/common/setup/download-vfio-drivers mode change 100644 => 100755 scripts/utils/common/tools/lsiommu create mode 100755 scripts/utils/manager-specific/gui-terminal/gnome-terminal create mode 100755 scripts/utils/manager-specific/gui-terminal/konsole create mode 100755 scripts/utils/manager-specific/gui-terminal/st create mode 100755 scripts/utils/manager-specific/gui-terminal/x-terminal-emulator diff --git a/.gitignore b/.gitignore index 524de09..70b5af3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,9 @@ /thirdparty /user.conf /helper-iso-files/bin -/utils/nvflash_linux /helper-iso-files/drivers +/helper-iso-files/.checksum +/utils/nvflash_linux /tmp .*.swp .*.swo diff --git a/README.md b/README.md index 9723e8f..80fbcff 100644 --- a/README.md +++ b/README.md @@ -202,15 +202,12 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for ## TODO ### High prio -- Install guest tools +- Test service auto reboot +- Test on Ubuntu - Fix automatic Nvidia driver installation in the VM (fix chocolatey) -- Add vm remove option to vm.sh -- Finish the requirements.json -- Automatically find and install dependencies by parsing the requirements.json -- Fix static IP - Fix RDP - Fix Samba sharing -- Generate libvirt XML +- Add virt-install version check because 2.2.1 doesn't seem to support the --xml flag ### Low prio - Add nuveau driver compatibility @@ -218,7 +215,7 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for - More detailed output about how the device is muxed - Create a bootable live version of this project - Create packages (deb, rpm, etc) -- Add compatibility for Arch, Debian, etc... +- Add compatibility for Arch, Debian, Pop OS etc... - Make this project work better on systems that already have a non-default GPU driver installed - Make it easy to uninstall the dependencies and undo the changes to the systm config (like kernel parameters) - Find a way to circumvent Error 43 for AMD GPUs like the `Radeon RX Vega M GL` @@ -227,4 +224,5 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for - Look into hotplugging and check if the GPU can be hotplugged during VM runtime - Check if required dependencies are installed for each script - Add support for multiple VMs -- Add support for Linux guests \ No newline at end of file +- Add support for Linux guests +- Add support for Desktop PCs \ No newline at end of file diff --git a/helper-iso-files/Autounattend.xml b/helper-iso-files/Autounattend.xml index b4fd3d7..6bf5590 100644 --- a/helper-iso-files/Autounattend.xml +++ b/helper-iso-files/Autounattend.xml @@ -177,11 +177,17 @@ <Order>4</Order> <RequiresUserInput>false</RequiresUserInput> <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\network-check.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\network-check.ps1"</CommandLine> - <Description>Wait for a Network connection and install Chocolatey if possible</Description> + <Description>Wait for a Network connection</Description> </SynchronousCommand> <SynchronousCommand wcm:action="add"> <Order>5</Order> <RequiresUserInput>false</RequiresUserInput> + <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\chocolatey-install.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\chocolatey-install.ps1"</CommandLine> + <Description>Install Chocolatey if possible</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <Order>6</Order> + <RequiresUserInput>false</RequiresUserInput> <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\gpu-check.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\gpu-check.ps1"</CommandLine> <Description>Check for GPU Errors and install drivers if possible and necessary</Description> </SynchronousCommand> diff --git a/helper-iso-files/mbpt-helper.bat b/helper-iso-files/mbpt-helper.bat index d60e21f..e1e6b7d 100644 --- a/helper-iso-files/mbpt-helper.bat +++ b/helper-iso-files/mbpt-helper.bat @@ -30,4 +30,4 @@ powershell -command Set-NetConnectionProfile -Name "Network" -NetworkCategory Pr echo "Enable remote desktop..." reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f -netsh advfirewall firewall set rule group="remote desktop" new enable=Yes +netsh advfirewall firewall set rule group="remote desktop" new enable=Yes \ No newline at end of file diff --git a/helper-iso-files/scripts/chocolatey-install.ps1 b/helper-iso-files/scripts/chocolatey-install.ps1 new file mode 100644 index 0000000..34c9908 --- /dev/null +++ b/helper-iso-files/scripts/chocolatey-install.ps1 @@ -0,0 +1,698 @@ +<# + .SYNOPSIS + Downloads and installs Chocolatey on the local machine. + + .DESCRIPTION + Retrieves the Chocolatey nupkg for the latest or a specified version, and + downloads and installs the application to the local machine. + + .NOTES + ===================================================================== + Copyright 2017 - 2020 Chocolatey Software, Inc, and the + original authors/contributors from ChocolateyGallery + Copyright 2011 - 2017 RealDimensions Software, LLC, and the + original authors/contributors from ChocolateyGallery + at https://github.com/chocolatey/chocolatey.org + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ===================================================================== + + Environment Variables, specified as $env:NAME in PowerShell.exe and %NAME% in cmd.exe. + For explicit proxy, please set $env:chocolateyProxyLocation and optionally $env:chocolateyProxyUser and $env:chocolateyProxyPassword + For an explicit version of Chocolatey, please set $env:chocolateyVersion = 'versionnumber' + To target a different url for chocolatey.nupkg, please set $env:chocolateyDownloadUrl = 'full url to nupkg file' + NOTE: $env:chocolateyDownloadUrl does not work with $env:chocolateyVersion. + To use built-in compression instead of 7zip (requires additional download), please set $env:chocolateyUseWindowsCompression = 'true' + To bypass the use of any proxy, please set $env:chocolateyIgnoreProxy = 'true' + + .LINK + For organizational deployments of Chocolatey, please see https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide + +#> +[CmdletBinding(DefaultParameterSetName = 'Default')] +param( + # The URL to download Chocolatey from. This defaults to the value of + # $env:chocolateyDownloadUrl, if it is set, and otherwise falls back to the + # official Chocolatey community repository to download the Chocolatey package. + [Parameter(Mandatory = $false)] + [string] + $ChocolateyDownloadUrl = $env:chocolateyDownloadUrl, + + # Specifies a target version of Chocolatey to install. By default, the latest + # stable version is installed. This will use the value in + # $env:chocolateyVersion by default, if that environment variable is present. + # This parameter is ignored if -ChocolateyDownloadUrl is set. + [Parameter(Mandatory = $false)] + [string] + $ChocolateyVersion = $env:chocolateyVersion, + + # If set, uses built-in Windows decompression tools instead of 7zip when + # unpacking the downloaded nupkg. This will be set by default if + # $env:chocolateyUseWindowsCompression is set to a value other than 'false' or '0'. + # + # This parameter will be ignored in PS 5+ in favour of using the + # Expand-Archive built in PowerShell cmdlet directly. + [Parameter(Mandatory = $false)] + [switch] + $UseNativeUnzip = $( + $envVar = "$env:chocolateyUseWindowsCompression".Trim() + $value = $null + if ([bool]::TryParse($envVar, [ref] $value)) { + $value + } elseif ([int]::TryParse($envVar, [ref] $value)) { + [bool]$value + } else { + [bool]$envVar + } + ), + + # If set, ignores any configured proxy. This will override any proxy + # environment variables or parameters. This will be set by default if + # $env:chocolateyIgnoreProxy is set to a value other than 'false' or '0'. + [Parameter(Mandatory = $false)] + [switch] + $IgnoreProxy = $( + $envVar = "$env:chocolateyIgnoreProxy".Trim() + $value = $null + if ([bool]::TryParse($envVar, [ref] $value)) { + $value + } + elseif ([int]::TryParse($envVar, [ref] $value)) { + [bool]$value + } + else { + [bool]$envVar + } + ), + + # Specifies the proxy URL to use during the download. This will default to + # the value of $env:chocolateyProxyLocation, if any is set. + [Parameter(ParameterSetName = 'Proxy', Mandatory = $false)] + [string] + $ProxyUrl = $env:chocolateyProxyLocation, + + # Specifies the credential to use for an authenticated proxy. By default, a + # proxy credential will be constructed from the $env:chocolateyProxyUser and + # $env:chocolateyProxyPassword environment variables, if both are set. + [Parameter(ParameterSetName = 'Proxy', Mandatory = $false)] + [System.Management.Automation.PSCredential] + $ProxyCredential +) + +#region Functions + +function Get-Downloader { + <# + .SYNOPSIS + Gets a System.Net.WebClient that respects relevant proxies to be used for + downloading data. + + .DESCRIPTION + Retrieves a WebClient object that is pre-configured according to specified + environment variables for any proxy and authentication for the proxy. + Proxy information may be omitted if the target URL is considered to be + bypassed by the proxy (originates from the local network.) + + .PARAMETER Url + Target URL that the WebClient will be querying. This URL is not queried by + the function, it is only a reference to determine if a proxy is needed. + + .EXAMPLE + Get-Downloader -Url $fileUrl + + Verifies whether any proxy configuration is needed, and/or whether $fileUrl + is a URL that would need to bypass the proxy, and then outputs the + already-configured WebClient object. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory = $false)] + [string] + $Url, + + [Parameter(Mandatory = $false)] + [string] + $ProxyUrl, + + [Parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $ProxyCredential + ) + + $downloader = New-Object System.Net.WebClient + + $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials + if ($defaultCreds) { + $downloader.Credentials = $defaultCreds + } + + if ($ProxyUrl) { + # Use explicitly set proxy. + Write-Host "Using explicit proxy server '$ProxyUrl'." + $proxy = New-Object System.Net.WebProxy -ArgumentList $ProxyUrl, <# bypassOnLocal: #> $true + + $proxy.Credentials = if ($ProxyCredential) { + $ProxyCredential.GetNetworkCredential() + } elseif ($defaultCreds) { + $defaultCreds + } else { + Write-Warning "Default credentials were null, and no explicitly set proxy credentials were found. Attempting backup method." + (Get-Credential).GetNetworkCredential() + } + + if (-not $proxy.IsBypassed($Url)) { + $downloader.Proxy = $proxy + } + } else { + Write-Host "Not using proxy." + } + + $downloader +} + +function Request-String { + <# + .SYNOPSIS + Downloads content from a remote server as a string. + + .DESCRIPTION + Downloads target string content from a URL and outputs the resulting string. + Any existing proxy that may be in use will be utilised. + + .PARAMETER Url + URL to download string data from. + + .PARAMETER ProxyConfiguration + A hashtable containing proxy parameters (ProxyUrl and ProxyCredential) + + .EXAMPLE + Request-String https://community.chocolatey.org/install.ps1 + + Retrieves the contents of the string data at the targeted URL and outputs + it to the pipeline. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string] + $Url, + + [Parameter(Mandatory = $false)] + [hashtable] + $ProxyConfiguration + ) + + (Get-Downloader $url @ProxyConfiguration).DownloadString($url) +} + +function Request-File { + <# + .SYNOPSIS + Downloads a file from a given URL. + + .DESCRIPTION + Downloads a target file from a URL to the specified local path. + Any existing proxy that may be in use will be utilised. + + .PARAMETER Url + URL of the file to download from the remote host. + + .PARAMETER File + Local path for the file to be downloaded to. + + .PARAMETER ProxyConfiguration + A hashtable containing proxy parameters (ProxyUrl and ProxyCredential) + + .EXAMPLE + Request-File -Url https://community.chocolatey.org/install.ps1 -File $targetFile + + Downloads the install.ps1 script to the path specified in $targetFile. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory = $false)] + [string] + $Url, + + [Parameter(Mandatory = $false)] + [string] + $File, + + [Parameter(Mandatory = $false)] + [hashtable] + $ProxyConfiguration + ) + + Write-Host "Downloading $url to $file" + (Get-Downloader $url @ProxyConfiguration).DownloadFile($url, $file) +} + +function Set-PSConsoleWriter { + <# + .SYNOPSIS + Workaround for a bug in output stream handling PS v2 or v3. + + .DESCRIPTION + PowerShell v2/3 caches the output stream. Then it throws errors due to the + FileStream not being what is expected. Fixes "The OS handle's position is + not what FileStream expected. Do not use a handle simultaneously in one + FileStream and in Win32 code or another FileStream." error. + + .EXAMPLE + Set-PSConsoleWriter + + .NOTES + General notes + #> + + [CmdletBinding()] + param() + if ($PSVersionTable.PSVersion.Major -gt 3) { + return + } + + try { + # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) + + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" + $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) + [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) + + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) + $field.SetValue($consoleHost, [Console]::Out) + + [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) + $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) + $field2.SetValue($consoleHost, [Console]::Error) + } catch { + Write-Warning "Unable to apply redirection fix." + } +} + +function Test-ChocolateyInstalled { + [CmdletBinding()] + param() + + $checkPath = if ($env:ChocolateyInstall) { $env:ChocolateyInstall } else { "$env:PROGRAMDATA\chocolatey" } + + if ($Command = Get-Command choco -CommandType Application -ErrorAction Ignore) { + # choco is on the PATH, assume it's installed + Write-Warning "'choco' was found at '$($Command.Path)'." + $true + } + elseif (-not (Test-Path $checkPath)) { + # Install folder doesn't exist + $false + } + elseif (-not (Get-ChildItem -Path $checkPath)) { + # Install folder exists but is empty + $false + } + else { + # Install folder exists and is not empty + Write-Warning "Files from a previous installation of Chocolatey were found at '$($CheckPath)'." + $true + } +} + +function Install-7zip { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string] + $Path, + + [Parameter(Mandatory = $false)] + [hashtable] + $ProxyConfiguration + ) + + if (-not (Test-Path ($Path))) { + Write-Host "Downloading 7-Zip commandline tool prior to extraction." + Request-File -Url 'https://community.chocolatey.org/7za.exe' -File $Path -ProxyConfiguration $ProxyConfiguration + + } + else { + Write-Host "7zip already present, skipping installation." + } +} + +#endregion Functions + +#region Pre-check + +# Ensure we have all our streams setup correctly, needed for older PSVersions. +Set-PSConsoleWriter + +if (Test-ChocolateyInstalled) { + $message = @( + "An existing Chocolatey installation was detected. Installation will not continue." + "For security reasons, this script will not overwrite existing installations." + "" + "Please use `choco upgrade chocolatey` to handle upgrades of Chocolatey itself." + ) -join [Environment]::NewLine + + Write-Warning $message + + return +} + +#endregion Pre-check + +#region Setup + +$proxyConfig = if ($IgnoreProxy -or -not $ProxyUrl) { + @{} +} else { + $config = @{ + ProxyUrl = $ProxyUrl + } + + if ($ProxyCredential) { + $config['ProxyCredential'] = $ProxyCredential + } elseif ($env:chocolateyProxyUser -and $env:chocolateyProxyPassword) { + $securePass = ConvertTo-SecureString $env:chocolateyProxyPassword -AsPlainText -Force + $config['ProxyCredential'] = [System.Management.Automation.PSCredential]::new($env:chocolateyProxyUser, $securePass) + } + + $config +} + +# Attempt to set highest encryption available for SecurityProtocol. +# PowerShell will not set this by default (until maybe .NET 4.6.x). This +# will typically produce a message for PowerShell v2 (just an info +# message though) +try { + # Set TLS 1.2 (3072) as that is the minimum required by Chocolatey.org. + # Use integers because the enumeration value for TLS 1.2 won't exist + # in .NET 4.0, even though they are addressable if .NET 4.5+ is + # installed (.NET 4.5 is an in-place upgrade). + Write-Host "Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)" + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 +} +catch { + $errorMessage = @( + 'Unable to set PowerShell to use TLS 1.2. This is required for contacting Chocolatey as of 03 FEB 2020.' + 'https://blog.chocolatey.org/2020/01/remove-support-for-old-tls-versions/.' + 'If you see underlying connection closed or trust errors, you may need to do one or more of the following:' + '(1) upgrade to .NET Framework 4.5+ and PowerShell v3+,' + '(2) Call [System.Net.ServicePointManager]::SecurityProtocol = 3072; in PowerShell prior to attempting installation,' + '(3) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally),' + '(4) use the Download + PowerShell method of install.' + 'See https://docs.chocolatey.org/en-us/choco/setup for all install options.' + ) -join [Environment]::NewLine + Write-Warning $errorMessage +} + +if ($ChocolateyDownloadUrl) { + if ($ChocolateyVersion) { + Write-Warning "Ignoring -ChocolateyVersion parameter ($ChocolateyVersion) because -ChocolateyDownloadUrl is set." + } + + Write-Host "Downloading Chocolatey from: $ChocolateyDownloadUrl" +} elseif ($ChocolateyVersion) { + Write-Host "Downloading specific version of Chocolatey: $ChocolateyVersion" + $ChocolateyDownloadUrl = "https://community.chocolatey.org/api/v2/package/chocolatey/$ChocolateyVersion" +} else { + Write-Host "Getting latest version of the Chocolatey package for download." + $queryString = [uri]::EscapeUriString("((Id eq 'chocolatey') and (not IsPrerelease)) and IsLatestVersion") + $queryUrl = 'https://community.chocolatey.org/api/v2/Packages()?$filter={0}' -f $queryString + + [xml]$result = Request-String -Url $queryUrl -ProxyConfiguration $proxyConfig + $ChocolateyDownloadUrl = $result.feed.entry.content.src +} + +if (-not $env:TEMP) { + $env:TEMP = Join-Path $env:SystemDrive -ChildPath 'temp' +} + +$chocoTempDir = Join-Path $env:TEMP -ChildPath "chocolatey" +$tempDir = Join-Path $chocoTempDir -ChildPath "chocoInstall" + +if (-not (Test-Path $tempDir -PathType Container)) { + $null = New-Item -Path $tempDir -ItemType Directory +} + +$file = Join-Path $tempDir "chocolatey.zip" + +#endregion Setup + +#region Download & Extract Chocolatey + +Write-Host "Getting Chocolatey from $ChocolateyDownloadUrl." +Request-File -Url $ChocolateyDownloadUrl -File $file -ProxyConfiguration $proxyConfig + +Write-Host "Extracting $file to $tempDir" +if ($PSVersionTable.PSVersion.Major -lt 5) { + # Determine unzipping method + # 7zip is the most compatible pre-PSv5.1 so use it unless asked to use builtin + if ($UseNativeUnzip) { + Write-Host 'Using built-in compression to unzip' + + try { + $shellApplication = New-Object -ComObject Shell.Application + $zipPackage = $shellApplication.NameSpace($file) + $destinationFolder = $shellApplication.NameSpace($tempDir) + $destinationFolder.CopyHere($zipPackage.Items(), 0x10) + } catch { + Write-Warning "Unable to unzip package using built-in compression. Set `$env:chocolateyUseWindowsCompression = ''` or omit -UseNativeUnzip and retry to use 7zip to unzip." + throw $_ + } + } else { + $7zaExe = Join-Path $tempDir -ChildPath '7za.exe' + Install-7zip -Path $7zaExe -ProxyConfiguration $proxyConfig + + $params = 'x -o"{0}" -bd -y "{1}"' -f $tempDir, $file + + # use more robust Process as compared to Start-Process -Wait (which doesn't + # wait for the process to finish in PowerShell v3) + $process = New-Object System.Diagnostics.Process + + try { + $process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo -ArgumentList $7zaExe, $params + $process.StartInfo.RedirectStandardOutput = $true + $process.StartInfo.UseShellExecute = $false + $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + + $null = $process.Start() + $process.BeginOutputReadLine() + $process.WaitForExit() + + $exitCode = $process.ExitCode + } + finally { + $process.Dispose() + } + + $errorMessage = "Unable to unzip package using 7zip. Perhaps try setting `$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:" + if ($exitCode -ne 0) { + $errorDetails = switch ($exitCode) { + 1 { "Some files could not be extracted" } + 2 { "7-Zip encountered a fatal error while extracting the files" } + 7 { "7-Zip command line error" } + 8 { "7-Zip out of memory" } + 255 { "Extraction cancelled by the user" } + default { "7-Zip signalled an unknown error (code $exitCode)" } + } + + throw ($errorMessage, $errorDetails -join [Environment]::NewLine) + } + } +} else { + Microsoft.PowerShell.Archive\Expand-Archive -Path $file -DestinationPath $tempDir -Force +} + +#endregion Download & Extract Chocolatey + +#region Install Chocolatey + +Write-Host "Installing Chocolatey on the local machine" +$toolsFolder = Join-Path $tempDir -ChildPath "tools" +$chocoInstallPS1 = Join-Path $toolsFolder -ChildPath "chocolateyInstall.ps1" + +& $chocoInstallPS1 + +Write-Host 'Ensuring Chocolatey commands are on the path' +$chocoInstallVariableName = "ChocolateyInstall" +$chocoPath = [Environment]::GetEnvironmentVariable($chocoInstallVariableName) + +if (-not $chocoPath) { + $chocoPath = "$env:ALLUSERSPROFILE\Chocolatey" +} + +if (-not (Test-Path ($chocoPath))) { + $chocoPath = "$env:PROGRAMDATA\chocolatey" +} + +$chocoExePath = Join-Path $chocoPath -ChildPath 'bin' + +# Update current process PATH environment variable if it needs updating. +if ($env:Path -notlike "*$chocoExePath*") { + $env:Path = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine); +} + +Write-Host 'Ensuring chocolatey.nupkg is in the lib folder' +$chocoPkgDir = Join-Path $chocoPath -ChildPath 'lib\chocolatey' +$nupkg = Join-Path $chocoPkgDir -ChildPath 'chocolatey.nupkg' + +if (-not (Test-Path $chocoPkgDir -PathType Container)) { + $null = New-Item -ItemType Directory -Path $chocoPkgDir +} + +Copy-Item -Path $file -Destination $nupkg -Force -ErrorAction SilentlyContinue + +#endregion Install Chocolatey + +# SIG # Begin signature block +# MIIZvwYJKoZIhvcNAQcCoIIZsDCCGawCAQExDzANBglghkgBZQMEAgEFADB5Bgor +# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBiXTlbpVQOoJeX +# rGtqATyaDXeEHi6Q2pKb3p02Iq/tc6CCFKgwggT+MIID5qADAgECAhANQkrgvjqI +# /2BAIc4UAPDdMA0GCSqGSIb3DQEBCwUAMHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQK +# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xMTAvBgNV +# BAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJlZCBJRCBUaW1lc3RhbXBpbmcgQ0EwHhcN +# MjEwMTAxMDAwMDAwWhcNMzEwMTA2MDAwMDAwWjBIMQswCQYDVQQGEwJVUzEXMBUG +# A1UEChMORGlnaUNlcnQsIEluYy4xIDAeBgNVBAMTF0RpZ2lDZXJ0IFRpbWVzdGFt +# cCAyMDIxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwuZhhGfFivUN +# CKRFymNrUdc6EUK9CnV1TZS0DFC1JhD+HchvkWsMlucaXEjvROW/m2HNFZFiWrj/ +# ZwucY/02aoH6KfjdK3CF3gIY83htvH35x20JPb5qdofpir34hF0edsnkxnZ2OlPR +# 0dNaNo/Go+EvGzq3YdZz7E5tM4p8XUUtS7FQ5kE6N1aG3JMjjfdQJehk5t3Tjy9X +# tYcg6w6OLNUj2vRNeEbjA4MxKUpcDDGKSoyIxfcwWvkUrxVfbENJCf0mI1P2jWPo +# GqtbsR0wwptpgrTb/FZUvB+hh6u+elsKIC9LCcmVp42y+tZji06lchzun3oBc/gZ +# 1v4NSYS9AQIDAQABo4IBuDCCAbQwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQC +# MAAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwgwQQYDVR0gBDowODA2BglghkgBhv1s +# BwEwKTAnBggrBgEFBQcCARYbaHR0cDovL3d3dy5kaWdpY2VydC5jb20vQ1BTMB8G +# A1UdIwQYMBaAFPS24SAd/imu0uRhpbKiJbLIFzVuMB0GA1UdDgQWBBQ2RIaOpLqw +# Zr68KC0dRDbd42p6vDBxBgNVHR8EajBoMDKgMKAuhixodHRwOi8vY3JsMy5kaWdp +# Y2VydC5jb20vc2hhMi1hc3N1cmVkLXRzLmNybDAyoDCgLoYsaHR0cDovL2NybDQu +# ZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC10cy5jcmwwgYUGCCsGAQUFBwEBBHkw +# dzAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tME8GCCsGAQUF +# BzAChkNodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNlcnRTSEEyQXNz +# dXJlZElEVGltZXN0YW1waW5nQ0EuY3J0MA0GCSqGSIb3DQEBCwUAA4IBAQBIHNy1 +# 6ZojvOca5yAOjmdG/UJyUXQKI0ejq5LSJcRwWb4UoOUngaVNFBUZB3nw0QTDhtk7 +# vf5EAmZN7WmkD/a4cM9i6PVRSnh5Nnont/PnUp+Tp+1DnnvntN1BIon7h6JGA078 +# 9P63ZHdjXyNSaYOC+hpT7ZDMjaEXcw3082U5cEvznNZ6e9oMvD0y0BvL9WH8dQgA +# dryBDvjA4VzPxBFy5xtkSdgimnUVQvUtMjiB2vRgorq0Uvtc4GEkJU+y38kpqHND +# Udq9Y9YfW5v3LhtPEx33Sg1xfpe39D+E68Hjo0mh+s6nv1bPull2YYlffqe0jmd4 +# +TaY4cso2luHpoovMIIFMDCCBBigAwIBAgIQBAkYG1/Vu2Z1U0O1b5VQCDANBgkq +# hkiG9w0BAQsFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5j +# MRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBB +# c3N1cmVkIElEIFJvb3QgQ0EwHhcNMTMxMDIyMTIwMDAwWhcNMjgxMDIyMTIwMDAw +# WjByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQL +# ExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3Vy +# ZWQgSUQgQ29kZSBTaWduaW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB +# CgKCAQEA+NOzHH8OEa9ndwfTCzFJGc/Q+0WZsTrbRPV/5aid2zLXcep2nQUut4/6 +# kkPApfmJ1DcZ17aq8JyGpdglrA55KDp+6dFn08b7KSfH03sjlOSRI5aQd4L5oYQj +# ZhJUM1B0sSgmuyRpwsJS8hRniolF1C2ho+mILCCVrhxKhwjfDPXiTWAYvqrEsq5w +# MWYzcT6scKKrzn/pfMuSoeU7MRzP6vIK5Fe7SrXpdOYr/mzLfnQ5Ng2Q7+S1TqSp +# 6moKq4TzrGdOtcT3jNEgJSPrCGQ+UpbB8g8S9MWOD8Gi6CxR93O8vYWxYoNzQYIH +# 5DiLanMg0A9kczyen6Yzqf0Z3yWT0QIDAQABo4IBzTCCAckwEgYDVR0TAQH/BAgw +# BgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwEwYDVR0lBAwwCgYIKwYBBQUHAwMweQYI +# KwYBBQUHAQEEbTBrMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j +# b20wQwYIKwYBBQUHMAKGN2h0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdp +# Q2VydEFzc3VyZWRJRFJvb3RDQS5jcnQwgYEGA1UdHwR6MHgwOqA4oDaGNGh0dHA6 +# Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJRFJvb3RDQS5jcmww +# OqA4oDaGNGh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJ +# RFJvb3RDQS5jcmwwTwYDVR0gBEgwRjA4BgpghkgBhv1sAAIEMCowKAYIKwYBBQUH +# AgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCgYIYIZIAYb9bAMwHQYD +# VR0OBBYEFFrEuXsqCqOl6nEDwGD5LfZldQ5YMB8GA1UdIwQYMBaAFEXroq/0ksuC +# MS1Ri6enIZ3zbcgPMA0GCSqGSIb3DQEBCwUAA4IBAQA+7A1aJLPzItEVyCx8JSl2 +# qB1dHC06GsTvMGHXfgtg/cM9D8Svi/3vKt8gVTew4fbRknUPUbRupY5a4l4kgU4Q +# pO4/cY5jDhNLrddfRHnzNhQGivecRk5c/5CxGwcOkRX7uq+1UcKNJK4kxscnKqEp +# KBo6cSgCPC6Ro8AlEeKcFEehemhor5unXCBc2XGxDI+7qPjFEmifz0DLQESlE/Dm +# ZAwlCEIysjaKJAL+L3J+HNdJRZboWR3p+nRka7LrZkPas7CM1ekN3fYBIM6ZMWM9 +# CBoYs4GbT8aTEAb8B4H6i9r5gkn3Ym6hU/oSlBiFLpKR6mhsRDKyZqHnGKSaZFHv +# MIIFMTCCBBmgAwIBAgIQCqEl1tYyG35B5AXaNpfCFTANBgkqhkiG9w0BAQsFADBl +# MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +# d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv +# b3QgQ0EwHhcNMTYwMTA3MTIwMDAwWhcNMzEwMTA3MTIwMDAwWjByMQswCQYDVQQG +# EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl +# cnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3VyZWQgSUQgVGltZXN0 +# YW1waW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvdAy7kvN +# j3/dqbqCmcU5VChXtiNKxA4HRTNREH3Q+X1NaH7ntqD0jbOI5Je/YyGQmL8TvFfT +# w+F+CNZqFAA49y4eO+7MpvYyWf5fZT/gm+vjRkcGGlV+Cyd+wKL1oODeIj8O/36V +# +/OjuiI+GKwR5PCZA207hXwJ0+5dyJoLVOOoCXFr4M8iEA91z3FyTgqt30A6XLdR +# 4aF5FMZNJCMwXbzsPGBqrC8HzP3w6kfZiFBe/WZuVmEnKYmEUeaC50ZQ/ZQqLKfk +# dT66mA+Ef58xFNat1fJky3seBdCEGXIX8RcG7z3N1k3vBkL9olMqT4UdxB08r8/a +# rBD13ays6Vb/kwIDAQABo4IBzjCCAcowHQYDVR0OBBYEFPS24SAd/imu0uRhpbKi +# JbLIFzVuMB8GA1UdIwQYMBaAFEXroq/0ksuCMS1Ri6enIZ3zbcgPMBIGA1UdEwEB +# /wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMBMGA1UdJQQMMAoGCCsGAQUFBwMI +# MHkGCCsGAQUFBwEBBG0wazAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNl +# cnQuY29tMEMGCCsGAQUFBzAChjdodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20v +# RGlnaUNlcnRBc3N1cmVkSURSb290Q0EuY3J0MIGBBgNVHR8EejB4MDqgOKA2hjRo +# dHRwOi8vY3JsNC5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1cmVkSURSb290Q0Eu +# Y3JsMDqgOKA2hjRodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1 +# cmVkSURSb290Q0EuY3JsMFAGA1UdIARJMEcwOAYKYIZIAYb9bAACBDAqMCgGCCsG +# AQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAsGCWCGSAGG/WwH +# ATANBgkqhkiG9w0BAQsFAAOCAQEAcZUS6VGHVmnN793afKpjerN4zwY3QITvS4S/ +# ys8DAv3Fp8MOIEIsr3fzKx8MIVoqtwU0HWqumfgnoma/Capg33akOpMP+LLR2HwZ +# YuhegiUexLoceywh4tZbLBQ1QwRostt1AuByx5jWPGTlH0gQGF+JOGFNYkYkh2OM +# kVIsrymJ5Xgf1gsUpYDXEkdws3XVk4WTfraSZ/tTYYmo9WuWwPRYaQ18yAGxuSh1 +# t5ljhSKMYcp5lH5Z/IwP42+1ASa2bKXuh1Eh5Fhgm7oMLSttosR+u8QlK0cCCHxJ +# rhO24XxCQijGGFbPQTS2Zl22dHv1VjMiLyI2skuiSpXY9aaOUjCCBTkwggQhoAMC +# AQICEAq50xD7ISvojIGz0sLozlEwDQYJKoZIhvcNAQELBQAwcjELMAkGA1UEBhMC +# VVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3LmRpZ2ljZXJ0 +# LmNvbTExMC8GA1UEAxMoRGlnaUNlcnQgU0hBMiBBc3N1cmVkIElEIENvZGUgU2ln +# bmluZyBDQTAeFw0yMTA0MjcwMDAwMDBaFw0yNDA0MzAyMzU5NTlaMHcxCzAJBgNV +# BAYTAlVTMQ8wDQYDVQQIEwZLYW5zYXMxDzANBgNVBAcTBlRvcGVrYTEiMCAGA1UE +# ChMZQ2hvY29sYXRleSBTb2Z0d2FyZSwgSW5jLjEiMCAGA1UEAxMZQ2hvY29sYXRl +# eSBTb2Z0d2FyZSwgSW5jLjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +# AKFxp42p47c7eHNsNhgxzG+/9A1I8Th+kj40YQJH4Vh0M7a61f39I/FELNYGuyCe +# 0+z/sg+T+4VmT/JMiI2hc75yokTjkv3Yt1+fqABzCMadr+PZ/9ttIVJ5db3P2Uzc +# Ml5wXBdCV5ZH/w4oKcP53VmYcHQEDm/RtAJ9TxlPtLS734oAqrKqBmsnJCI98FWp +# d6z1FK5rv7RJVeZoGsl/2eMcB/ko0Vj9MSCbWvXNjDF9yy4Tl5h2vb+y7K1Qmk3X +# yb0OYB1ibva9rQozGgogEa5DL0OdoMj6cyJ6Cx2GQv2wjKwiKfs9zCOTDH2VGa0i +# okDbsd+BvUxovQ6eSnBFj5UCAwEAAaOCAcQwggHAMB8GA1UdIwQYMBaAFFrEuXsq +# CqOl6nEDwGD5LfZldQ5YMB0GA1UdDgQWBBRO8wUYXZXrKVBqUW35p9FeNJoEgzAO +# BgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwdwYDVR0fBHAwbjA1 +# oDOgMYYvaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC1jcy1n +# MS5jcmwwNaAzoDGGL2h0dHA6Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9zaGEyLWFzc3Vy +# ZWQtY3MtZzEuY3JsMEsGA1UdIAREMEIwNgYJYIZIAYb9bAMBMCkwJwYIKwYBBQUH +# AgEWG2h0dHA6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAIBgZngQwBBAEwgYQGCCsG +# AQUFBwEBBHgwdjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29t +# ME4GCCsGAQUFBzAChkJodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNl +# cnRTSEEyQXNzdXJlZElEQ29kZVNpZ25pbmdDQS5jcnQwDAYDVR0TAQH/BAIwADAN +# BgkqhkiG9w0BAQsFAAOCAQEAoXGdwcDMMV6xQldozbWoxGTn6chlwO4hJ8aAlwOM +# wexEvDudrlifsiGI1j46wqc9WR8+Ev8w1dIcbqif4inGIHb8GvL22Goq+lB08F7y +# YU3Ry0kOCtJx7JELlID0SI7bYndg17TJUQoAb5iTYD9aEoHMIKlGyQyVGvsp4ubo +# O8CC8Owx+Qq148yXY+to4360U2lzZvUtMpPiiSJTm4BamNgC32xgGwpN5lvk0m3R +# lDdqQQQgBCzrf+ZIMBmXMw4kxY0r/K/g1TkKI9VyiEnRaNQlQisAyYBWVnaHw2EJ +# ck6/bxwdYSA+Sz/Op0N0iEl8MX4At3XQlMGvAI1xhAbrwDGCBG0wggRpAgEBMIGG +# MHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsT +# EHd3dy5kaWdpY2VydC5jb20xMTAvBgNVBAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJl +# ZCBJRCBDb2RlIFNpZ25pbmcgQ0ECEAq50xD7ISvojIGz0sLozlEwDQYJYIZIAWUD +# BAIBBQCggYQwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx +# DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAvBgkq +# hkiG9w0BCQQxIgQgey25OsHafMX1HWLKRJb0Sf/lMMX5vF0EAhjyQlfUDzgwDQYJ +# KoZIhvcNAQEBBQAEggEAC0wtyHWaoYbiMY8PXKaNf16zoeuj5jYAuvx0B/nzJ27A +# tP/Mo9SC1Z4M2iEps/LDScRoy3N8pCI8NQBDjWGGkjW5ScFvF7a042DcurR+LE30 +# aa4d7Y0MT8O+vhQDcVCmB7JB+9E6/7+qpD1vVfs1zYw1cprCZoOejttDCEvlvsAN +# VrPKixhxbLcLu/5KV9qUBUWW9vEz8/WL1IcNcsfwd61+JWa116CXeyoLKqWXJIPF +# uNnULZTs/E2BY1JYBKIfzvSi3QWg/uWvJucdGdbLib4d1gEXxLtHk+aDOLTXRG12 +# yjMdCF1FhyeC+hyWSgwyXZ0V9zRGpiS+IjarelHVDqGCAjAwggIsBgkqhkiG9w0B +# CQYxggIdMIICGQIBATCBhjByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNl +# cnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdp +# Q2VydCBTSEEyIEFzc3VyZWQgSUQgVGltZXN0YW1waW5nIENBAhANQkrgvjqI/2BA +# Ic4UAPDdMA0GCWCGSAFlAwQCAQUAoGkwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEH +# ATAcBgkqhkiG9w0BCQUxDxcNMjEwNjE3MDg0MjQzWjAvBgkqhkiG9w0BCQQxIgQg +# Osdf/2XOopSIGgniCq9vRS6UGDVJ7TingAmrcmwYcWowDQYJKoZIhvcNAQEBBQAE +# ggEAs50N1tQOpzvCCO9R4hCcaMY0jsOm7QOOk257yySmEFbtgmKUpNmyyfwK0Wl/ +# Ti1IOTOQ1oz7Wz6Q/kEgPoZAbuAhXKH+At6Vwa98Jp3GG6abokNohPI3cWGJbS3u +# rJEKZay3+1fGNaYOCpIqkhpnVqyTNoLlNBLcGOkq7FgBKsomtQSO9ejFluS1woKY +# wK7EiXjzDwFG18DmnUuRpO4xrdmcbh7m3MnC95DjYcFFzKr/xxideicJAGZSHOo1 +# nQorVQyPcXQe4Nl2JHAr3R6RTeaXgq6We4LSdMsO5BAyduh/w4nicahwAv5wgIsw +# cUvCYQiMMXCU2x9vsn8B5wKETQ== +# SIG # End signature block diff --git a/helper-iso-files/scripts/gpu-check.ps1 b/helper-iso-files/scripts/gpu-check.ps1 index d8a25f2..a41d114 100644 --- a/helper-iso-files/scripts/gpu-check.ps1 +++ b/helper-iso-files/scripts/gpu-check.ps1 @@ -1,12 +1,12 @@ Add-Type -AssemblyName PresentationFramework -try { - choco -} -catch { - Remove-Item C:\ProgramData\chocolatey -Recurse - [System.Windows.MessageBox]::Show('Chocolatey installation failed! Make sure the VM has Internet access.', "MobilePassThrough - Error") -} +#try { +# choco +#} +#catch { +# Remove-Item C:\ProgramData\chocolatey -Recurse +# [System.Windows.MessageBox]::Show('Chocolatey installation failed! Make sure the VM has Internet access.', "MobilePassThrough - Error") +#} #For formatting: $result = @{Expression = {$_.Name}; Label = "Device Name"}, @@ -23,19 +23,24 @@ if ($driverlessGpus -like '*VEN_1002*') { if ($driverlessGpus -like '*VEN_10DE*') { Write-Host 'Nvidia GPU driver missing' try { - choco install nvidia-display-driver + #choco install nvidia-display-driver + Write-Host 'Automatic GPU driver installation not implemented yet. Please install the Nvidia Display driver manually!' + [System.Windows.MessageBox]::Show('Automatic GPU driver installation not implemented yet. Please install the Nvidia Display driver manually!', "MobilePassThrough - Missing GPU driver") } catch { - [System.Windows.MessageBox]::Show('Failed to automatically install Nvidia Display driver using chocolatey!', "MobilePassThrough - Driver installation failed") + [System.Windows.MessageBox]::Show('Failed to automatically install Nvidia Display driver using chocolatey!', "MobilePassThrough - driver installation failed") } } if ($driverlessGpus -like '*VEN_8086*') { Write-Host 'Intel GPU driver missing' try { - choco install intel-graphics-driver + #choco install intel-graphics-driver + Write-Host 'Automatic GPU driver installation not implemented yet. Please install the Intel Graphics driver manually!' + [System.Windows.MessageBox]::Show('Automatic GPU driver installation not implemented yet. Please install the Intel Graphics driver manually!', "MobilePassThrough - Missing GPU driver") + } catch { - [System.Windows.MessageBox]::Show('Failed to automatically install Intel Graphics driver using chocolatey!', "MobilePassThrough - Driver installation failed") + [System.Windows.MessageBox]::Show('Failed to automatically install Intel Graphics driver using chocolatey!', "MobilePassThrough - driver installation failed") } } diff --git a/helper-iso-files/scripts/network-check.ps1 b/helper-iso-files/scripts/network-check.ps1 index 8242715..895bb08 100644 --- a/helper-iso-files/scripts/network-check.ps1 +++ b/helper-iso-files/scripts/network-check.ps1 @@ -50,6 +50,4 @@ Write-Host "Setting the Network to private..." Set-NetConnectionProfile -Name "Network" -NetworkCategory Private Write-Host "Waiting for chocoltey.org to be reachable. Waiting up to 30 seconds..." -wait-for-chocolatey 30 - -cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\chcolatey-install.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\chcolatey-install.ps1" \ No newline at end of file +wait-for-chocolatey 30 \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index 80da84a..584e1bd 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -19,11 +19,16 @@ function printHelp() { echo ' -h, --help Print usage' echo '' echo 'Commands:' - echo ' setup Install required dependencies and set required kernel parameters' - echo ' check Check if and to what degree your notebook is capable of running a GPU passthrough setup' + echo ' auto Automatically run check, setup and install' echo ' configure Interactively guides you through the creation of your config file' - echo ' iso Generate a helper iso file that contains required drivers and a helper-script for your Windows VM' - echo ' start Start your VM' + echo ' check Check if and to what degree your notebook is capable of running a GPU passthrough setup' + echo ' setup Install required dependencies and set required kernel parameters' + echo ' install Create and install the VM' + echo ' start Start the VM' + # TODO: Split start/install in pre-start, start/install, post-start () + # TODO implement: + #echo ' get-xml Print out the VM configuration as XML' + #echo ' get-qemu Print out the VM configuration as a qemu-system-x86_64 command' echo ' vbios Dump the vBIOS ROM from the running system or extract it from a BIOS update' echo '' echo 'Examples:' @@ -39,9 +44,24 @@ function printHelp() { echo ' # Generate a helper iso file that contains required drivers and a helper-script for your Windows VM' echo ' mbpt.sh iso' echo '' - echo ' # Start your VM' + echo ' # Create the VM and install Windows in it (Will overwrite an older instance if one exists!)' + echo ' mbpt.sh install' + echo '' + echo ' # Start the VM' echo ' mbpt.sh start' echo '' + echo ' # Print the qemu command that would have been used to start the VM' + echo ' mbpt.sh start dry-run' + echo '' + echo ' # Print the qemu command that would have been used to install the VM' + echo ' mbpt.sh install dry-run' + echo '' + echo ' # Print the libvirt XML that would have been used to start the VM' + echo ' mbpt.sh start get-xml' + echo '' + echo ' # Print the libvirt XML that would have been used to install the VM' + echo ' mbpt.sh install get-xml' + echo '' echo ' # Dump the vBIOS ROM of the GPU with the PCI address 01:00.0 to ./my-vbios.rom (This will most likely fail)' echo ' mbpt.sh vbios dump 01:00.0 ./my-vbios.rom' echo '' @@ -61,14 +81,15 @@ elif [ "$COMMAND" = "configure" ]; then elif [ "$COMMAND" = "iso" ]; then "${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh" elif [ "$COMMAND" = "install" ] || [ "$COMMAND" = "create" ]; then - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install $2 elif [ "$COMMAND" = "remove" ]; then - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" remove # TODO: implement this + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" remove elif [ "$COMMAND" = "start" ]; then - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start $2 elif [ "$COMMAND" = "auto" ]; then - sudo "${MAIN_SCRIPTS_DIR}/setup.sh" - sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" + sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 + sudo "${MAIN_SCRIPTS_DIR}/setup.sh" || echo "Exiting..." && exit 1 + sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" || echo "Exiting..." && exit 1 sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install elif [ "$COMMAND" = "vbios" ]; then if [ "$2" == "extract" ]; then diff --git a/requirements.sh b/requirements.sh index b73d745..31cdc1a 100644 --- a/requirements.sh +++ b/requirements.sh @@ -43,7 +43,7 @@ EXEC_DEPS_SAMBA=("samba") # samba EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output") # uuid xorg-x11-drv-intel EXEC_DEPS_HELPER_ISO=("genisoimage") # genisoimage EXEC_DEPS_UEFI_CHECK=("systool") # sysfsutils -EXEC_DEPS_COMPATIBILITY_CHECK=("systool" "lshw" "lspci" "dmidecode" "lsusb" "lsblk" "lscpu") # sysfsutils lshw pciutils dmidecode usbutils util-linux util-linux +EXEC_DEPS_COMPATIBILITY_CHECK=("systool" "lshw" "lspci") # sysfsutils lshw pciutils dmidecode EXEC_DEPS_CPU_CHECK=("lscpu") # util-linux EXEC_DEPS_GPU_CHECK=("lshw") # lshw EXEC_DEPS_LOOKING_GLASS=("cmake" "gcc" "wayland-scanner" "makensis" "x86_64-w64-mingw32-g++") # cmake gcc-g++ wayland-devel mingw32-nsis mingw64-gcc-c++ @@ -53,7 +53,7 @@ FILE_DEPS_LOOKING_GLASS+=("/usr/include/spice-1/spice/protocol.h" "/usr/include/ FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/Xlib.h" "/usr/include/X11/Xutil.h") # libX11-devel FILE_DEPS_LOOKING_GLASS+=("/usr/include/nettle/asn1.h" "/usr/include/nettle/sha1.h" "/usr/include/nettle/rsa.h" "/usr/include/nettle/bignum.h") # nettle-devel FILE_DEPS_LOOKING_GLASS+=("/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml" "/usr/share/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml" "/usr/share/wayland-protocols/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml" "/usr/share/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml") # wayland-protocols-devel -FILE_DEPS_LOOKING_GLASS+=("/usr/lib/gcc/x86_64-redhat-linux/11/include/stdatomic.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/emmintrin.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stdarg.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stdbool.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stddef.h" "/usr/lib/gcc/x86_64-redhat-linux/11/include/stdint.h") # gcc +FILE_DEPS_LOOKING_GLASS+=("/usr/lib/gcc/x86_64-redhat-linux/*/include/stdatomic.h" "/usr/lib/gcc/x86_64-redhat-linux/*/include/emmintrin.h" "/usr/lib/gcc/x86_64-redhat-linux/*/include/smmintrin.h" "/usr/lib/gcc/x86_64-redhat-linux/*/include/stdarg.h" "/usr/lib/gcc/x86_64-redhat-linux/*/include/stdbool.h" "/usr/lib/gcc/x86_64-redhat-linux/*/include/stddef.h" "/usr/lib/gcc/x86_64-redhat-linux/*/include/stdint.h") # gcc FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/scrnsaver.h") # libXScrnSaver-devel FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/Xfixes.h") # libXfixes-devel FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/XInput2.h") # libXi-devel diff --git a/scripts/main/compatibility-check.sh b/scripts/main/compatibility-check.sh index add14ec..c5a3f2e 100755 --- a/scripts/main/compatibility-check.sh +++ b/scripts/main/compatibility-check.sh @@ -11,6 +11,8 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" #LSHW_MOCK="${PROJECT_DIR}/mock-data/$MOCK_SET-lshw" #LSIOMMU_MOCK="${PROJECT_DIR}/mock-data/$MOCK_SET-lsiommu" +source "${PROJECT_DIR}/requirements.sh" + if sudo which optirun &> /dev/null && sudo optirun echo>/dev/null ; then USE_BUMBLEBEE=true OPTIRUN_PREFIX="optirun " @@ -19,8 +21,24 @@ else OPTIRUN_PREFIX="" fi +alias getExecPkg="'${PACKAGE_MANAGER}' --executables" +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias lsiommu="sudo '${OPTIRUN_PREFIX}${COMMON_UTILS_TOOLS_DIR}/lsiommu'" + +MISSING_DEPS=$(getMissingExecutables "${EXEC_DEPS_COMPATIBILITY_CHECK[*]}") +if [ "$MISSING_DEPS" != "" ]; then + echo "Trying to install packages providing: $MISSING_DEPS ..." + getExecPkg "${EXEC_DEPS_COMPATIBILITY_CHECK[*]}" # Find and install packages needed to run this check +fi +MISSING_DEPS=$(getMissingExecutables "${EXEC_DEPS_COMPATIBILITY_CHECK[*]}") +if [ "$MISSING_DEPS" != "" ]; then + echo "ERROR: Failed to install packages providing: $MISSING_DEPS" + echo "Please install them manually and try again!" + exit +fi + if [ -z ${LSIOMMU_MOCK+x} ]; then - IOMMU_GROUPS=$(sudo ${OPTIRUN_PREFIX}${COMMON_UTILS_TOOLS_DIR}/lsiommu) + IOMMU_GROUPS=$(lsiommu) MOCK_MODE=false else IOMMU_GROUPS=$(cat "${LSIOMMU_MOCK}") @@ -178,59 +196,26 @@ else fi fi - # If the device is a laptop #if [ "$(sudo ${OPTIRUN_PREFIX}dmidecode --string chassis-type)" != "Desktop" ] ; then - DEVICE_NAME=$(sudo ${OPTIRUN_PREFIX}dmidecode -s system-product-name) - BIOS_VERSION=$(sudo ${OPTIRUN_PREFIX}dmidecode -s bios-version) - LOG_DIR="${LOG_BASE_DIR}/$DEVICE_NAME/$BIOS_VERSION" - DATE=`date +%Y-%m-%d` - mkdir -p "${LOG_DIR}" - - log_white "[Info] Device name: $DEVICE_NAME" - log_white "[Info] BIOS version: $BIOS_VERSION" - if [ $(echo $IOMMU_GROUPS | grep " VGA compatible controller " | wc -l) = "2" ] && ! echo $IOMMU_GROUPS | grep --quiet " Display controller " ; then log_white "[Info] This system is probably MUXed. (The connection between the GPU(s) and the [internal display]/[display outputs] is multiplexed.)" else log_white "[Info] This system is probably MUX-less. (The connection between the GPU(s) and the [internal display]/[display outputs] is not multiplexed.)" fi - - - - echo ${DATE} > "${LOG_DIR}/date.log" - echo "${IOMMU_GROUPS}" > "${LOG_DIR}/lsiommu.log" - sudo ${OPTIRUN_PREFIX}dmidecode > "${LOG_DIR}/dmidecode.log" - sudo ${OPTIRUN_PREFIX}dmesg > "${LOG_DIR}/dmesg.log" - sudo ${OPTIRUN_PREFIX}lshw > "${LOG_DIR}/lshw.log" - sudo ${OPTIRUN_PREFIX}lshw -short > "${LOG_DIR}/lshw-short.log" - sudo ${OPTIRUN_PREFIX}lshw -class display -businfo > "${LOG_DIR}/lshw-gpu-businfo.log" - sudo ${OPTIRUN_PREFIX}lspci > "${LOG_DIR}/lspci.log" - sudo ${OPTIRUN_PREFIX}lsusb > "${LOG_DIR}/lsusb.log" - sudo ${OPTIRUN_PREFIX}lsblk > "${LOG_DIR}/lsblk.log" - sudo ${OPTIRUN_PREFIX}lscpu > "${LOG_DIR}/lscpu.log" - sudo ${OPTIRUN_PREFIX}dmidecode -t bios > "${LOG_DIR}/bios.log" - sudo ${OPTIRUN_PREFIX}cat /proc/cpuinfo > "${LOG_DIR}/cpuinfo.log" - sudo ${OPTIRUN_PREFIX}cat /proc/meminfo > "${LOG_DIR}/meminfo.log" - log_green "[OK] Logs have been created in ${LOG_DIR}" - echo -e ${LOG_OUTPUT} > "${LOG_DIR}/general.log" #fi +if [ "$MOCK_MODE" = true ]; then + log_red "[Warning] Remember, the above output has been generated using the given mock data and has nothing to do with this system!" +fi + if [ "${UEFI_VIRTUALIZATION_ENABLED}" = true ] && [ "${UEFI_IOMMU_ENABLED}" = true ] && [ "${KERNEL_IOMMU_ENABLED}" = true ] && [ "${IOMMU_COMPATIBILITY_LVL}" -gt "0" ] ; then log_green "If you found a notebook that appears to be GPU passthrough compatible, please open an issue on Github and let me know." if [ "${IOMMU_COMPATIBILITY_LVL}" -gt "1" ] ; then - log_green "You may now proceed and run './mbpt.sh configure' as mentioned in the README." + log_green "You may now proceed and run './mbpt.sh configure' if you haven't already." + else + exit 1 fi -fi - - -#echo "Listing IOMMU Groups..." -#${COMMON_UTILS_TOOLS_DIR}/lsiommu - -#echo "Listing GPU info with lshw..." -#sudo lshw -class display - -#if [ -n ${MOCK_SET+x} ]; then -if [ "$MOCK_MODE" = true ]; then - log_red "[Warning] Remember, the above output has been generated using the given mock data and has nothing to do with this system!" -fi +else + exit 1 +fi \ No newline at end of file diff --git a/scripts/main/generate-helper-iso.sh b/scripts/main/generate-helper-iso.sh index 49482c5..b108c57 100755 --- a/scripts/main/generate-helper-iso.sh +++ b/scripts/main/generate-helper-iso.sh @@ -78,9 +78,9 @@ fi # echo "> devcon driver tool already exist in iso folder..." #fi -if [ ! -f "${HELPER_ISO_FILES_DIR}/scripts/chcolatey-install.ps1" ]; then +if [ ! -f "${HELPER_ISO_FILES_DIR}/scripts/chocolatey-install.ps1" ]; then echo "> Downloading Chocolatey install script..." - wget "https://chocolatey.org/install.ps1" -O "${HELPER_ISO_FILES_DIR}/scripts/chcolatey-install.ps1" + wget "https://chocolatey.org/install.ps1" -O "${HELPER_ISO_FILES_DIR}/scripts/chocolatey-install.ps1" else echo "> Chocolatey install script already exist in iso folder..." fi diff --git a/scripts/main/generate-vm-config.sh b/scripts/main/generate-vm-config.sh index 6a3a3ce..7aed93a 100755 --- a/scripts/main/generate-vm-config.sh +++ b/scripts/main/generate-vm-config.sh @@ -6,7 +6,7 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" # This interactive script creates a custom config file (user.conf) to your liking. ##################################################################################################### -#source "$UTILS_DIR/gpu-check" +#source "$COMMON_UTILS_LIBS_DIR/gpu-check" interactiveCfg() { DEFAULT_VALUE=$(grep -Po "(?<=^$2=).*" "${PROJECT_DIR}/default.conf" | cut -d "#" -f1 | sed 's/^\s*"\(.*\)"\s*$/\1/' | xargs) @@ -91,10 +91,4 @@ interactiveCfg "Patch OVMF with your dGPU ROM if you supply one. (Highly recomme interactiveCfg "List of USB devices to pass through. (Semicolon separated, e.g. vendorid=0x0b12,productid=0x9348;vendorid=0x0b95,productid=0x1790)" USB_DEVICES # TODO: Make selecting USB devices easier # TODO: Auto detect PCI addresses for GPUs -# TODO: Don't ask for Bumblebee if there is no nvidia gpu - -source "$USER_CONFIG_FILE" -if [ ! -f "$INSTALL_IMG" ]; then - echo "'$INSTALL_IMG' does not exist and will be downloaded automatically now. If you don't want that, press Ctrl+C to cancel it." - "$COMMON_UTILS_TOOLS_DIR/download-windows-iso" "$INSTALL_IMG" -fi +# TODO: Don't ask for Bumblebee if there is no nvidia gpu \ No newline at end of file diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index ee7404d..b9356a9 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig ##################################################################################################### # This script installs all missing and required dependencies and also adds required kernel parameters. It's called like this: `./setup.sh` @@ -13,17 +14,54 @@ source "${PROJECT_DIR}/requirements.sh" source "$COMMON_UTILS_LIBS_DIR/cpu-check" source "$COMMON_UTILS_LIBS_DIR/gpu-check" +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" alias getExecPkg="'${PACKAGE_MANAGER}' --executables" alias getFilePkg="'${PACKAGE_MANAGER}' --files" -alias kernelParamManager="'${KERNEL_PARAM_MANAGER}'" -alias runtimeKernelHasParams="'${COMMON_UTILS_TOOLS_DIR}/runtime-kernel-has-params'" +alias kernelParamManager="${KERNEL_PARAM_MANAGER}" +alias runtimeKernelHasParams="${COMMON_UTILS_TOOLS_DIR}/runtime-kernel-has-params" +alias ovmfVbiosPatchSetup="sudo '$COMMON_UTILS_SETUP_DIR/ovmf-vbios-patch-setup'" +alias buildFakeBatterySsdt="sudo '$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssdt'" +alias vbiosFinderSetup="sudo '$COMMON_UTILS_SETUP_DIR/vbios-finder-setup'" +alias lookingGlassSetup="sudo '$COMMON_UTILS_SETUP_DIR/looking-glass-setup'" +alias generateHelperIso="sudo '${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh'" +alias nvidiaSetup="sudo '$DISTRO_UTILS_DIR/nvidia-setup'" +alias bumblebeeSetup="sudo '$DISTRO_UTILS_DIR/bumblebee-setup'" +alias downloadWindowsIso="$COMMON_UTILS_TOOLS_DIR/download-windows-iso" +alias createAutoStartService="'${SERVICE_MANAGER}' create-autostart-service" +alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service" mkdir -p "${THIRDPARTY_DIR}" -echo "> Find and install packages containing executables that we need..." -getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need -echo "> Find and install packages containing files that we need..." -getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need +MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "> Find and install packages containing executables that we need..." + getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need + MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" + if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "> ERROR: Failed to install packages providing the following executables automatically: $MISSING_EXECUTABLES" + fi +else + echo "> [Skipped] Executable dependencies are already installed." +fi + +MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" +if [ "$MISSING_FILES" != "" ]; then + echo "> Find and install packages containing files that we need..." + getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need + MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" + if [ "$MISSING_FILES" != "" ]; then + MISSING_FILES="$(echo "$MISSING_EXECUTABLES" | sed 's/\s\+/\n/g')" # replace spaces with new lines + echo "> ERROR: Failed to install packages providing the following executables automatically:" + echo "$MISSING_FILES" + fi +else + echo "> [Skipped] File dependencies are already installed." +fi + +if [ "$MISSING_EXECUTABLES" != "" ] || [ "$MISSING_FILES" != "" ]; then + exit 1 +fi REBOOT_REQUIRED=false if ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"; then @@ -31,7 +69,7 @@ if ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"; then kernelParamManager add "${KERNEL_PARAMS_GENERAL[*]}" REBOOT_REQUIRED=true else - echo "> [Skipped] General kernel params already set on running kernel..." + echo "> [Skipped] General kernel params already set on running kernel." REBOOT_REQUIRED=false fi @@ -41,7 +79,7 @@ fi kernelParamManager add "${KERNEL_PARAMS_INTEL_CPU[*]}" REBOOT_REQUIRED=true else - echo "> [Skipped] Intel CPU-specific kernel params already set on running kernel..." + echo "> [Skipped] Intel CPU-specific kernel params already set on running kernel." fi #fi @@ -51,7 +89,7 @@ fi kernelParamManager add "${KERNEL_PARAMS_AMD_CPU[*]}" REBOOT_REQUIRED=true else - echo "> [Skipped] AMD CPU-specific kernel params already set on running kernel..." + echo "> [Skipped] AMD CPU-specific kernel params already set on running kernel." fi #fi @@ -61,7 +99,7 @@ fi kernelParamManager add "${KERNEL_PARAMS_INTEL_GPU[*]}" REBOOT_REQUIRED=true else - echo "> [Skipped] Intel GPU-specific kernel params already set on running kernel..." + echo "> [Skipped] Intel GPU-specific kernel params already set on running kernel." fi #fi @@ -71,83 +109,75 @@ if [ "$HAS_NVIDIA_GPU" = true ]; then # TODO: Don't force Bumblebee and the prop kernelParamManager add "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" REBOOT_REQUIRED=true else - echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel..." + echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel." fi fi if [[ "$(docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then echo "> Image 'ovmf-vbios-patch' has already been built." - sudo "$COMMON_UTILS_SETUP_DIR/ovmf-vbios-patch-setup" + ovmfVbiosPatchSetup else echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." fi if [ "$HAS_NVIDIA_GPU" = true ]; then - sudo "$DISTRO_UTILS_DIR/nvidia-setup" + nvidiaSetup fi if [ "$SUPPORTS_OPTIMUS" = true ]; then - sudo "$DISTRO_UTILS_DIR/bumblebee-setup" + bumblebeeSetup fi if [ ! -f "${ACPI_TABLES_DIR}/fake-battery.aml" ]; then echo "> Building fake ACPI SSDT battery..." - sudo "$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssdt" + buildFakeBatterySsdt else echo "> [Skipped] Fake ACPI SSDT battery has already been built." fi -if [ ! -f "${THIRDPARTY_DIR}/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then +if [ ! -f ${THIRDPARTY_DIR}/VBiosFinder/vendor/bundle/ruby/*/bin/coderay ]; then echo "> Installing VBiosFinder..." - sudo "$COMMON_UTILS_SETUP_DIR/vbios-finder-setup" + vbiosFinderSetup else echo "> [Skipped] VBiosFinder is already set up." fi if [ ! -f "${THIRDPARTY_DIR}/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" ]; then echo "> Installing Looking Glass..." - sudo "$COMMON_UTILS_SETUP_DIR/looking-glass-setup" + lookingGlassSetup else echo "> [Skipped] Looking Glass is already set up." fi -#if [ ! -f "${THIRDPARTY_DIR}/virtio-win.iso" ]; then -# echo "> Downlaoding virtio drivers..." -# sudo "$COMMON_UTILS_SETUP_DIR/download-vfio-drivers" -#else -# echo "> [Skipped] virtio drivers already downloaded." -#fi +CHECKSUM_FILE_PATH="$HELPER_ISO_FILES_DIR/.checksum" +PREVIOUS_HELPER_ISO_DIR_CHECKSUM="$(cat "$CHECKSUM_FILE_PATH" 2> /dev/null)" +NEW_HELPER_ISO_DIR_CHECKSUM="$(find "$HELPER_ISO_FILES_DIR" -type f ! -iname ".checksum" -exec md5sum {} + | LC_ALL=C sort | md5sum | cut -d' ' -f1)" +if [ "$PREVIOUS_HELPER_ISO_DIR_CHECKSUM" != "$NEW_HELPER_ISO_DIR_CHECKSUM" ]; then + echo "> Generating helper ISO for auto unattended Windows install, config and driver installation..." + rm -f "$CHECKSUM_FILE_PATH" + generateHelperIso + echo "$NEW_HELPER_ISO_DIR_CHECKSUM" > "$CHECKSUM_FILE_PATH" +else + echo "> [Skipped] Helper ISO for auto unattended Windows install, config and driver installation already generated for the current files." +fi -echo "> Generating helper-iso for auto Windows Configuration / Driver installation..." -sudo ${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh -# TODO: add check if files have changed and helper iso needs to be regenerated; maybe by using a checksum? +if [ ! -f "$INSTALL_IMG" ]; then + echo "Downloading Windows ISO from Microsoft now." + downloadWindowsIso "$INSTALL_IMG" +else + echo "> [Skipped] Windows ISO has already been downloaded." +fi if [ "$1" = "auto" ]; then if [ "$REBOOT_REQUIRED" = true ]; then echo "> Creating a temporary service that will run on next reboot and create the Windows VM" echo "exit because this has not been tested yet" exit # TODO: TEST THIS - sudo echo "[Unit] -Description=MobilePassthroughInitSetup -After=multi-user.target network.target - -[Service] -User=root -Group=root -Type=simple -Environment=DISPLAY=:0 -WorkingDirectory=${PROJECT_DIR} -ExecStart=$(sudo) -u $(loguser) $(which gnome-terminal) -- bash -c \"${PROJECT_DIR}/mbpt.sh auto\" -Restart=never - -[Install] -WantedBy=multi-user.target" > /etc/systemd/system/MobilePassthroughInitSetup.service - sudo systemctl daemon-reload - sudo systemctl enable MobilePassthroughInitSetup.service + createAutoStartService "" echo "> Rebooting in 15 seconds... Press Ctrl+C to reboot now." sleep 15 - sudo systemctl --force reboot + sudo shutdown -r 0 else - sudo systemctl disable MobilePassthroughInitSetup.service &> /dev/null + removeAutoStartService &> /dev/null echo "> No reboot required." fi else diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 2a39eff..0aaa1d9 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -30,6 +30,18 @@ else exit 1 fi +GET_XML=false +DRY_RUN=false +if [ "$1" = "install" ] || [ "$1" = "start" ]; then + if [ "$2" = "dry-run" ]; then + DRY_RUN=true + elif [ "$2" = "get-xml" ]; then + GET_XML=true + echo "> Enforcing VM start mode 'virt-install' to generate the XML..." + VM_START_MODE="virt-install" + fi +fi + #source "$COMMON_UTILS_LIBS_DIR/gpu-check" alias driver="sudo '$COMMON_UTILS_TOOLS_DIR/driver-util'" alias vgpu="sudo '$COMMON_UTILS_TOOLS_DIR/vgpu-util'" @@ -403,12 +415,12 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--boot" "loader=${OVMF_CODE},loader.readonly=yes,loader.type=pflash,nvram.template=${OVMF_VARS_VM},loader_secure=no") fi +QEMU_PARAMS+=("-usb") if [ -z "$USB_DEVICES" ]; then echo "> Not using USB passthrough..." USB_DEVICE_PARAMS="" else echo "> Using USB passthrough..." - QEMU_PARAMS+=("-usb") IFS=';' read -a USB_DEVICES_ARRAY <<< "${USB_DEVICES}" for USB_DEVICE in "${USB_DEVICES_ARRAY[@]}"; do QEMU_PARAMS+=("-device" "usb-host,${USB_DEVICE}") @@ -458,44 +470,26 @@ if [ $VM_INSTALL = true ]; then sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null fi -echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." +if [ "$DRY_RUN" = false ]; then + echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." +fi if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") - bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & - echo "> Starting the spice client @${SPICE_PORT}..." - bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & - - echo "> Starting the Virtual Machine using qemu..." - echo "" - - printf "sudo qemu-system-x86_64" - for param in "${QEMU_PARAMS[@]}"; do - if [[ "${param}" == -* ]]; then - printf " \\\\\n ${param}" - elif [[ $param = *" "* ]]; then - printf " \"${param}\"" - else - printf " ${param}" - fi - done - echo "" - echo "" - sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" -elif [ "$VM_START_MODE" = "virt-install" ]; then - bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + if [ "$DRY_RUN" = false ]; then + bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & - echo "> Starting the Virtual Machine using virt-install..." + echo "> Starting the spice client @localhost:${SPICE_PORT}..." + bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & - #VIRT_INSTALL_PARAMS+=("--debug") - for param in "${QEMU_PARAMS[@]}"; do - VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") - done + echo "> Starting the Virtual Machine using qemu..." + fi - #if [ $VM_INSTALL = true ]; then + if [ "$DRY_RUN" = true ]; then + echo "> Generating qemu-system-x86_64 command (dry-run)..." echo "" - printf "sudo virt-install" - for param in "${VIRT_INSTALL_PARAMS[@]}"; do + printf "sudo qemu-system-x86_64" + for param in "${QEMU_PARAMS[@]}"; do if [[ "${param}" == -* ]]; then printf " \\\\\n ${param}" elif [[ $param = *" "* ]]; then @@ -506,11 +500,50 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then done echo "" echo "" - sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + else + sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" + fi +elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$DRY_RUN" = false ]; then + bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + + echo "> Starting the Virtual Machine using virt-install..." + fi + #VIRT_INSTALL_PARAMS+=("--debug") + for param in "${QEMU_PARAMS[@]}"; do + VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") + done + + #if [ $VM_INSTALL = true ]; then + if [ "$DRY_RUN" = true ]; then + echo "> Generating virt-install command (dry-run)..." + echo "" + printf "sudo virt-install" + for param in "${VIRT_INSTALL_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" + elif [ "$GET_XML" = true ]; then + VIRT_INSTALL_PARAMS+=("--print-xml") + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + else + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + fi #else - # virsh start "${VM_NAME}" + # if [ "$DRY_RUN" = true ]; then + # echo "" + # printf "sudo virt-install" + # else + # virsh start "${VM_NAME}" + # fi #fi - fi # This gets executed when the vm exits diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index f54493e..ed510b8 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -19,6 +19,7 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" SERVICE_MANAGER="${MANAGER_UTILS_DIR}/service/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" service)" KERNEL_PARAM_MANAGER="${MANAGER_UTILS_DIR}/kernelparams/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" kernelparam)" PACKAGE_MANAGER="${MANAGER_UTILS_DIR}/package/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" package)" + GUI_TERMINAL="${MANAGER_UTILS_DIR}/package/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" package)" THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" diff --git a/scripts/utils/common/setup/download-vfio-drivers b/scripts/utils/common/setup/download-vfio-drivers deleted file mode 100755 index 93f92e5..0000000 --- a/scripts/utils/common/setup/download-vfio-drivers +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - -##################################################################################################### -# This script compiles the asm source code for the SSDT table that contains a fake battery for the VM. -# Usage: `./build-fake-battery-ssdt` -##################################################################################################### - -VIRTIO_WIN_VERSION="0.1.196" -if [ ! -f "${THIRDPARTY_DIR}/virtio-win.iso" ]; then - wget "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-${VIRTIO_WIN_VERSION}-1/virtio-win.iso" -O "${THIRDPARTY_DIR}/virtio-win.iso" -fi \ No newline at end of file diff --git a/scripts/utils/common/tools/get-manager b/scripts/utils/common/tools/get-manager index 859fb6b..fb6a0f7 100755 --- a/scripts/utils/common/tools/get-manager +++ b/scripts/utils/common/tools/get-manager @@ -12,19 +12,39 @@ if [ "$COMMAND" = "service" ]; then echo "systemd" elif [ -d "/etc/init.d/" ] && command -v "service" &> /dev/null; then echo "sysvinit" + else + exit 1 fi elif [ "$COMMAND" = "initramfs" ]; then if [ -d "/etc/dracut.conf.d/" ]; then echo "dracut" + else + exit 1 fi elif [ "$COMMAND" = "kernelparams" ]; then if [ -f "/etc/default/grub" ] && [ -f "/etc/grub2-efi.cfg" ]; then echo "grub" + else + exit 1 fi elif [ "$COMMAND" = "package" ]; then if command -v dnf &> /dev/null; then echo "dnf" elif command -v apt-get &> /dev/null; then echo "apt" + else + exit 1 + fi +elif [ "$COMMAND" = "gui-terminal" ]; then + if command -v gnome-terminal &> /dev/null; then + echo "gnome-terminal" + elif command -v konsole &> /dev/null; then + echo "konsole" + elif command -v x-terminal-emulator &> /dev/null; then + echo "x-terminal-emulator" + elif command -v st &> /dev/null; then + echo "st" + else + exit 1 fi fi \ No newline at end of file diff --git a/scripts/utils/common/tools/lsiommu b/scripts/utils/common/tools/lsiommu old mode 100644 new mode 100755 diff --git a/scripts/utils/manager-specific/gui-terminal/gnome-terminal b/scripts/utils/manager-specific/gui-terminal/gnome-terminal new file mode 100755 index 0000000..e0d2d3f --- /dev/null +++ b/scripts/utils/manager-specific/gui-terminal/gnome-terminal @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" + +if [ "$COMMAND" = "run-with-command" ]; then + gnome-terminal -- bash -c \"$1\" +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/gui-terminal/konsole b/scripts/utils/manager-specific/gui-terminal/konsole new file mode 100755 index 0000000..7c3e10b --- /dev/null +++ b/scripts/utils/manager-specific/gui-terminal/konsole @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" + +if [ "$COMMAND" = "run-with-command" ]; then + konsole -e \"$1\" +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/gui-terminal/st b/scripts/utils/manager-specific/gui-terminal/st new file mode 100755 index 0000000..844480b --- /dev/null +++ b/scripts/utils/manager-specific/gui-terminal/st @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" + +if [ "$COMMAND" = "run-with-command" ]; then + st -e \"$1\" +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator b/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator new file mode 100755 index 0000000..ba6c89b --- /dev/null +++ b/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" + +if [ "$COMMAND" = "run-with-command" ]; then + x-terminal-emulator -e \"$1\" +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/initramfs/dracut b/scripts/utils/manager-specific/initramfs/dracut index fa19b64..0974369 100755 --- a/scripts/utils/manager-specific/initramfs/dracut +++ b/scripts/utils/manager-specific/initramfs/dracut @@ -2,7 +2,7 @@ VFIO_CFG_PATH=/etc/dracut.conf.d/vfio.conf -COMMAND="$1" # Supported comamnds: add-driver, apply +COMMAND="$1" # Supported commands: add-driver, apply PARAM="$2" function addInitramfsDriver() { diff --git a/scripts/utils/manager-specific/kernelparams/grub b/scripts/utils/manager-specific/kernelparams/grub index 086b22e..7be867b 100755 --- a/scripts/utils/manager-specific/kernelparams/grub +++ b/scripts/utils/manager-specific/kernelparams/grub @@ -2,7 +2,7 @@ GRUB_CFG_PATH=/etc/default/grub -COMMAND="$1" # Supported comamnds: add, remove, apply +COMMAND="$1" # Supported commands: add, remove, apply PARAM="$2" function addKernelParam() { diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index 66f4ba0..8a563b9 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -44,9 +44,21 @@ function installPackages() { if [ "$SEARCH_MODE" = "--executables" ]; then MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" - echo "Still missing: $(getMissingExecutables "$WANTED_ITEMS")" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" elif [ "$SEARCH_MODE" = "--files" ]; then MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" installPackages "$SEARCH_MODE" "$MISSING_FILES" - echo "Still missing: $(getMissingFiles "$WANTED_ITEMS")" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" +else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 +fi +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" +fi +if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" +fi +if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/package/dnf b/scripts/utils/manager-specific/package/dnf index 1f53f27..8fed04d 100755 --- a/scripts/utils/manager-specific/package/dnf +++ b/scripts/utils/manager-specific/package/dnf @@ -41,9 +41,21 @@ function installPackages() { if [ "$SEARCH_MODE" = "--executables" ]; then MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" - echo "Still missing: $(getMissingExecutables "$WANTED_ITEMS")" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" elif [ "$SEARCH_MODE" = "--files" ]; then MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" installPackages "$SEARCH_MODE" "$MISSING_FILES" - echo "Still missing: $(getMissingFiles "$WANTED_ITEMS")" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" +else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 +fi +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" +fi +if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" +fi +if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/service/systemd b/scripts/utils/manager-specific/service/systemd index 5d779f6..f8feba9 100755 --- a/scripts/utils/manager-specific/service/systemd +++ b/scripts/utils/manager-specific/service/systemd @@ -1,2 +1,31 @@ #!/usr/bin/env bash -# TODO create temporary autostart service +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" + +SERVICE_NAME="MobilePassthroughInitSetup" +if [ "$COMMAND" = "create-autostart-service" ]; then +COMMAND_TO_RUN="$1" +EXEC_START="$(GUI_TERMINAL run-with-command "$COMMAND_TO_RUN")" +sudo echo "[Unit] +Description=${SERVICE_NAME} +After=multi-user.target network.target + +[Service] +User=root +Group=root +Type=simple +Environment=DISPLAY=:0 +WorkingDirectory=${PROJECT_DIR} +ExecStart=$(sudo) -u $(loguser) ${EXEC_START} +Restart=never + +[Install] +WantedBy=multi-user.target" > /etc/systemd/system/${SERVICE_NAME}.service + +sudo systemctl daemon-reload +sudo systemctl enable ${SERVICE_NAME}.service +elif [ "$COMMAND" = "remove-autostart-service" ]; then +sudo systemctl disable ${SERVICE_NAME}.service &> /dev/null +fi \ No newline at end of file From 1ff095d0498ef66b2f988ed20c778babc3b3530e Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Thu, 5 Aug 2021 23:59:14 +0200 Subject: [PATCH 17/40] A bunch of bugfixes --- mbpt.sh | 6 +- requirements.sh | 3 +- scripts/main/setup.sh | 32 ++++++----- scripts/utils/common/libs/helpers | 18 +++--- scripts/utils/common/tools/get-manager | 2 +- .../gui-terminal/gnome-terminal | 6 +- .../manager-specific/gui-terminal/konsole | 5 +- .../utils/manager-specific/gui-terminal/st | 5 +- .../gui-terminal/x-terminal-emulator | 5 +- .../utils/manager-specific/kernelparams/grub | 6 +- scripts/utils/manager-specific/package/apt | 15 +++-- scripts/utils/manager-specific/package/dnf | 55 +++++++++++-------- .../utils/manager-specific/service/systemd | 21 +++---- 13 files changed, 97 insertions(+), 82 deletions(-) diff --git a/mbpt.sh b/mbpt.sh index 584e1bd..dff3fd8 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -87,8 +87,8 @@ elif [ "$COMMAND" = "remove" ]; then elif [ "$COMMAND" = "start" ]; then sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start $2 elif [ "$COMMAND" = "auto" ]; then - sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 - sudo "${MAIN_SCRIPTS_DIR}/setup.sh" || echo "Exiting..." && exit 1 + #sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 + sudo "${MAIN_SCRIPTS_DIR}/setup.sh" auto || echo "Exiting..." && exit 1 sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" || echo "Exiting..." && exit 1 sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install elif [ "$COMMAND" = "vbios" ]; then @@ -100,4 +100,4 @@ elif [ "$COMMAND" = "vbios" ]; then elif [ "$2" == "dump" ]; then sudo "${COMMON_UTILS_SETUP_DIR}/extract-vbios" "$3" "$4" fi -fi \ No newline at end of file +fi diff --git a/requirements.sh b/requirements.sh index 31cdc1a..8cdf4c1 100644 --- a/requirements.sh +++ b/requirements.sh @@ -37,7 +37,6 @@ EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" FILE_DEPS_VBIOS_FINDER=("/usr/include/rub*/ruby.h") # ruby-devel EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "spicy") # qemu-system-x86-core libvirt-client virt-viewer spice-gtk-tools FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd") # edk2-ovmf -FILE_DEPS_VIRTUALIZATION=("/usr/share/virtio-win/virtio-win.iso") # virtio-win # TODO: get the iso using wget cuz only rhel distros have a package for that anyways EXEC_DEPS_RDP=("remmina") # remmina EXEC_DEPS_SAMBA=("samba") # samba EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output") # uuid xorg-x11-drv-intel @@ -75,4 +74,4 @@ ALL_FILE_DEPS="" # Will contain all content of all variables starting with FILE_ ALL_FILE_DEPS_VARS="$(set -o posix ; set | grep -P '^FILE_DEPS' | cut -d'=' -f1 | tr '\n' ' ')" for deps in $ALL_FILE_DEPS_VARS; do ALL_FILE_DEPS+="$(eval "echo \" \${$deps[*]}\"")" -done \ No newline at end of file +done diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index b9356a9..e4ea510 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -16,9 +16,10 @@ source "$COMMON_UTILS_LIBS_DIR/gpu-check" alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" -alias getExecPkg="'${PACKAGE_MANAGER}' --executables" -alias getFilePkg="'${PACKAGE_MANAGER}' --files" -alias kernelParamManager="${KERNEL_PARAM_MANAGER}" +alias updatePkgInfo="'${PACKAGE_MANAGER}' update" +alias getExecPkg="'${PACKAGE_MANAGER}' install --executables" +alias getFilePkg="'${PACKAGE_MANAGER}' install --files" +alias addKernelParams="sudo '${KERNEL_PARAM_MANAGER}' add" alias runtimeKernelHasParams="${COMMON_UTILS_TOOLS_DIR}/runtime-kernel-has-params" alias ovmfVbiosPatchSetup="sudo '$COMMON_UTILS_SETUP_DIR/ovmf-vbios-patch-setup'" alias buildFakeBatterySsdt="sudo '$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssdt'" @@ -35,6 +36,8 @@ mkdir -p "${THIRDPARTY_DIR}" MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "> Update package info..." + updatePkgInfo echo "> Find and install packages containing executables that we need..." getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" @@ -47,6 +50,8 @@ fi MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" if [ "$MISSING_FILES" != "" ]; then + echo "> Update package info..." + updatePkgInfo echo "> Find and install packages containing files that we need..." getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" @@ -66,17 +71,16 @@ fi REBOOT_REQUIRED=false if ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"; then echo "> Adding general kernel params..." - kernelParamManager add "${KERNEL_PARAMS_GENERAL[*]}" + addKernelParams "${KERNEL_PARAMS_GENERAL[*]}" REBOOT_REQUIRED=true else echo "> [Skipped] General kernel params already set on running kernel." - REBOOT_REQUIRED=false fi #if [ "$HAS_INTEL_CPU" = true ]; then if ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_CPU[*]}"; then echo "> Adding Intel CPU-specific kernel params..." - kernelParamManager add "${KERNEL_PARAMS_INTEL_CPU[*]}" + addKernelParams "${KERNEL_PARAMS_INTEL_CPU[*]}" REBOOT_REQUIRED=true else echo "> [Skipped] Intel CPU-specific kernel params already set on running kernel." @@ -86,7 +90,7 @@ fi #if [ "$HAS_AMD_CPU" = true ]; then if ! runtimeKernelHasParams "${KERNEL_PARAMS_AMD_CPU[*]}"; then echo "> Adding AMD CPU-specific kernel params..." - kernelParamManager add "${KERNEL_PARAMS_AMD_CPU[*]}" + addKernelParams "${KERNEL_PARAMS_AMD_CPU[*]}" REBOOT_REQUIRED=true else echo "> [Skipped] AMD CPU-specific kernel params already set on running kernel." @@ -96,7 +100,7 @@ fi #if [ "$HAS_INTEL_GPU" = true ]; then if ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_GPU[*]}"; then echo "> Adding Intel GPU-specific kernel params..." - kernelParamManager add "${KERNEL_PARAMS_INTEL_GPU[*]}" + addKernelParams "${KERNEL_PARAMS_INTEL_GPU[*]}" REBOOT_REQUIRED=true else echo "> [Skipped] Intel GPU-specific kernel params already set on running kernel." @@ -106,7 +110,7 @@ fi if [ "$HAS_NVIDIA_GPU" = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user if ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"; then echo "> Adding Nvidia GPU-specific kernel params..." - kernelParamManager add "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" + addKernelParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" REBOOT_REQUIRED=true else echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel." @@ -170,12 +174,10 @@ fi if [ "$1" = "auto" ]; then if [ "$REBOOT_REQUIRED" = true ]; then echo "> Creating a temporary service that will run on next reboot and create the Windows VM" - echo "exit because this has not been tested yet" - exit # TODO: TEST THIS - createAutoStartService "" + createAutoStartService "${PROJECT_DIR}/mbpt.sh auto" echo "> Rebooting in 15 seconds... Press Ctrl+C to reboot now." - sleep 15 - sudo shutdown -r 0 + #sleep 300 + #sudo shutdown -r 0 else removeAutoStartService &> /dev/null echo "> No reboot required." @@ -186,4 +188,4 @@ else else echo "> No reboot required." fi -fi \ No newline at end of file +fi diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index ed510b8..9d398fb 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -15,11 +15,11 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" COMMON_UTILS_TOOLS_DIR="${COMMON_UTILS_DIR}/tools" DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")" MANAGER_UTILS_DIR="${UTILS_DIR}/manager-specific" - INITRAMFS_MANAGER="${MANAGER_UTILS_DIR}/initramfs/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" initramfs)" + INITRAMFS_MANAGER="${MANAGER_UTILS_DIR}/initramfs/$(sudo "${COMMON_UTILS_TOOLS_DIR}/get-manager" initramfs)" SERVICE_MANAGER="${MANAGER_UTILS_DIR}/service/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" service)" - KERNEL_PARAM_MANAGER="${MANAGER_UTILS_DIR}/kernelparams/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" kernelparam)" + KERNEL_PARAM_MANAGER="${MANAGER_UTILS_DIR}/kernelparams/$(sudo "${COMMON_UTILS_TOOLS_DIR}/get-manager" kernelparams)" PACKAGE_MANAGER="${MANAGER_UTILS_DIR}/package/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" package)" - GUI_TERMINAL="${MANAGER_UTILS_DIR}/package/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" package)" + GUI_TERMINAL="${MANAGER_UTILS_DIR}/gui-terminal/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" gui-terminal)" THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" @@ -27,19 +27,17 @@ LOG_BASE_DIR="${PROJECT_DIR}/logs" shopt -s expand_aliases -# TODO create aliases for all scripts? (Maybe a bad idea because it makes debugging more difficult) - function loadConfig() { # If user.conf doesn't exist use the default.conf if [ -f "${PROJECT_DIR}/user.conf" ]; then - echo "> Loading config from ${PROJECT_DIR}/user.conf" + #echo "> Loading config from ${PROJECT_DIR}/user.conf" source "${PROJECT_DIR}/user.conf" elif [ -f "${PROJECT_DIR}/default.conf" ]; then - echo "> Warning: No user.conf found, falling back to default.conf" - echo "> Loading config from ${PROJECT_DIR}/default.conf" + #echo "> Warning: No user.conf found, falling back to default.conf" + #echo "> Loading config from ${PROJECT_DIR}/default.conf" source "${PROJECT_DIR}/default.conf" else - echo "> Error: No user.conf or user.conf found!" + #echo "> Error: No user.conf or user.conf found!" exit fi -} \ No newline at end of file +} diff --git a/scripts/utils/common/tools/get-manager b/scripts/utils/common/tools/get-manager index fb6a0f7..05d960e 100755 --- a/scripts/utils/common/tools/get-manager +++ b/scripts/utils/common/tools/get-manager @@ -47,4 +47,4 @@ elif [ "$COMMAND" = "gui-terminal" ]; then else exit 1 fi -fi \ No newline at end of file +fi diff --git a/scripts/utils/manager-specific/gui-terminal/gnome-terminal b/scripts/utils/manager-specific/gui-terminal/gnome-terminal index e0d2d3f..e554fb8 100755 --- a/scripts/utils/manager-specific/gui-terminal/gnome-terminal +++ b/scripts/utils/manager-specific/gui-terminal/gnome-terminal @@ -1,9 +1,9 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" COMMAND="$1" +COMMAND_TO_EXECUTE="$2" if [ "$COMMAND" = "run-with-command" ]; then - gnome-terminal -- bash -c \"$1\" -fi \ No newline at end of file + gnome-terminal -- bash -c "$COMMAND_TO_EXECUTE" +fi diff --git a/scripts/utils/manager-specific/gui-terminal/konsole b/scripts/utils/manager-specific/gui-terminal/konsole index 7c3e10b..bf69d38 100755 --- a/scripts/utils/manager-specific/gui-terminal/konsole +++ b/scripts/utils/manager-specific/gui-terminal/konsole @@ -3,7 +3,8 @@ while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f source "$PROJECT_DIR/scripts/utils/common/libs/helpers" COMMAND="$1" +COMMAND_TO_EXECUTE="$2" if [ "$COMMAND" = "run-with-command" ]; then - konsole -e \"$1\" -fi \ No newline at end of file + konsole -e "$COMMAND_TO_EXECUTE" +fi diff --git a/scripts/utils/manager-specific/gui-terminal/st b/scripts/utils/manager-specific/gui-terminal/st index 844480b..148248f 100755 --- a/scripts/utils/manager-specific/gui-terminal/st +++ b/scripts/utils/manager-specific/gui-terminal/st @@ -3,7 +3,8 @@ while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f source "$PROJECT_DIR/scripts/utils/common/libs/helpers" COMMAND="$1" +COMMAND_TO_EXECUTE="$2" if [ "$COMMAND" = "run-with-command" ]; then - st -e \"$1\" -fi \ No newline at end of file + st -e "$COMMAND_TO_EXECUTE" +fi diff --git a/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator b/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator index ba6c89b..83ae614 100755 --- a/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator +++ b/scripts/utils/manager-specific/gui-terminal/x-terminal-emulator @@ -3,7 +3,8 @@ while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f source "$PROJECT_DIR/scripts/utils/common/libs/helpers" COMMAND="$1" +COMMAND_TO_EXECUTE="$2" if [ "$COMMAND" = "run-with-command" ]; then - x-terminal-emulator -e \"$1\" -fi \ No newline at end of file + x-terminal-emulator -e "$COMMAND_TO_EXECUTE" +fi diff --git a/scripts/utils/manager-specific/kernelparams/grub b/scripts/utils/manager-specific/kernelparams/grub index 7be867b..81c8dc6 100755 --- a/scripts/utils/manager-specific/kernelparams/grub +++ b/scripts/utils/manager-specific/kernelparams/grub @@ -16,7 +16,7 @@ function addKernelParam() { function addKernelParams() { for param in $1; do addKernelParam "$param" - fi + done } function removeKernelParam() { if sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then @@ -29,7 +29,7 @@ function removeKernelParam() { function removeKernelParams() { for param in $1; do removeKernelParam "$param" - fi + done } function applyKernelParamChanges() { @@ -42,4 +42,4 @@ elif [ "$COMMAND" = "remove" ]; then removeKernelParams "$PARAM" elif [ "$COMMAND" = "apply" ]; then applyKernelParamChanges -fi \ No newline at end of file +fi diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index 8a563b9..e741b71 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -12,16 +12,19 @@ loadConfig alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" -SEARCH_MODE="$1" -WANTED_ITEMS="$2" +COMMAND="$1" +SEARCH_MODE="$2" +WANTED_ITEMS="$3" + +function updatePackageInfo() { + sudo apt-get update +} function installPackages() { SEARCH_MODE="$1" WANTED_ITEMS="$2" - - sudo apt-get update > /dev/null if ! command -v apt-file &> /dev/null; then - apt-get install -y apt-file + sudo apt-get install -y apt-file fi PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do @@ -61,4 +64,4 @@ if [ "$MISSING_FILES" != "" ]; then fi if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then exit 1 -fi \ No newline at end of file +fi diff --git a/scripts/utils/manager-specific/package/dnf b/scripts/utils/manager-specific/package/dnf index 8fed04d..8fbe163 100755 --- a/scripts/utils/manager-specific/package/dnf +++ b/scripts/utils/manager-specific/package/dnf @@ -12,14 +12,18 @@ loadConfig alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" -SEARCH_MODE="$1" -WANTED_ITEMS="$2" +COMMAND="$1" +SEARCH_MODE="$2" +WANTED_ITEMS="$3" + +function updatePackageInfo() { + sudo dnf check-update +} function installPackages() { SEARCH_MODE="$1" WANTED_ITEMS="$2" - sudo dnf check-update > /dev/null PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do if [ "$SEARCH_MODE" = "--executables" ]; then @@ -38,24 +42,29 @@ function installPackages() { fi } -if [ "$SEARCH_MODE" = "--executables" ]; then - MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" - installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" - MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" -elif [ "$SEARCH_MODE" = "--files" ]; then - MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" - installPackages "$SEARCH_MODE" "$MISSING_FILES" - MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" -else - echo "ERROR: Invalid mode or no mode at all was speficied!" - exit 1 -fi -if [ "$MISSING_EXECUTABLES" != "" ]; then - echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" -fi -if [ "$MISSING_FILES" != "" ]; then - echo "ERROR: Still missing package providing the following files: $MISSING_FILES" +if [ "$COMMAND" = "install" ]; then + if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 + fi + if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" + fi + if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" + fi + if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 + fi +elif [ "$COMMAND" = "update" ]; then + updatePackageInfo fi -if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then - exit 1 -fi \ No newline at end of file + diff --git a/scripts/utils/manager-specific/service/systemd b/scripts/utils/manager-specific/service/systemd index f8feba9..7ef51d5 100755 --- a/scripts/utils/manager-specific/service/systemd +++ b/scripts/utils/manager-specific/service/systemd @@ -6,26 +6,27 @@ COMMAND="$1" SERVICE_NAME="MobilePassthroughInitSetup" if [ "$COMMAND" = "create-autostart-service" ]; then -COMMAND_TO_RUN="$1" -EXEC_START="$(GUI_TERMINAL run-with-command "$COMMAND_TO_RUN")" -sudo echo "[Unit] + COMMAND_TO_RUN="$2" + EXEC_START="'$GUI_TERMINAL' run-with-command '$COMMAND_TO_RUN'" + + sudo echo "[Unit] Description=${SERVICE_NAME} After=multi-user.target network.target [Service] -User=root -Group=root +User=$(logname) +Group=$(id -gn $(logname)) Type=simple Environment=DISPLAY=:0 WorkingDirectory=${PROJECT_DIR} -ExecStart=$(sudo) -u $(loguser) ${EXEC_START} +ExecStart=${EXEC_START} Restart=never [Install] WantedBy=multi-user.target" > /etc/systemd/system/${SERVICE_NAME}.service -sudo systemctl daemon-reload -sudo systemctl enable ${SERVICE_NAME}.service + sudo systemctl daemon-reload + sudo systemctl enable ${SERVICE_NAME}.service elif [ "$COMMAND" = "remove-autostart-service" ]; then -sudo systemctl disable ${SERVICE_NAME}.service &> /dev/null -fi \ No newline at end of file + sudo systemctl disable ${SERVICE_NAME}.service &> /dev/null +fi From 6b7747deaad70c612f6f64516509f020e5b90b0e Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Fri, 13 Aug 2021 07:42:44 -0400 Subject: [PATCH 18/40] Fix compatibility check dependency installation --- scripts/main/compatibility-check.sh | 125 +++++++++------------ scripts/utils/common/libs/helpers | 20 +++- scripts/utils/manager-specific/package/dnf | 3 + 3 files changed, 75 insertions(+), 73 deletions(-) diff --git a/scripts/main/compatibility-check.sh b/scripts/main/compatibility-check.sh index c5a3f2e..126ee25 100755 --- a/scripts/main/compatibility-check.sh +++ b/scripts/main/compatibility-check.sh @@ -21,20 +21,23 @@ else OPTIRUN_PREFIX="" fi -alias getExecPkg="'${PACKAGE_MANAGER}' --executables" +alias updatePkgInfo="'${PACKAGE_MANAGER}' update" +alias getExecPkg="'${PACKAGE_MANAGER}' install --executables" alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" alias lsiommu="sudo '${OPTIRUN_PREFIX}${COMMON_UTILS_TOOLS_DIR}/lsiommu'" MISSING_DEPS=$(getMissingExecutables "${EXEC_DEPS_COMPATIBILITY_CHECK[*]}") if [ "$MISSING_DEPS" != "" ]; then - echo "Trying to install packages providing: $MISSING_DEPS ..." + echo_white "[Info] Update package info..." + updatePkgInfo + echo_white "[Info] Trying to install packages providing: $MISSING_DEPS ..." getExecPkg "${EXEC_DEPS_COMPATIBILITY_CHECK[*]}" # Find and install packages needed to run this check fi MISSING_DEPS=$(getMissingExecutables "${EXEC_DEPS_COMPATIBILITY_CHECK[*]}") if [ "$MISSING_DEPS" != "" ]; then - echo "ERROR: Failed to install packages providing: $MISSING_DEPS" - echo "Please install them manually and try again!" - exit + echo_red "[Error] Failed to install packages providing: $MISSING_DEPS" + echo_red "[Info] Please install them manually and try again!" + exit 1 fi if [ -z ${LSIOMMU_MOCK+x} ]; then @@ -51,60 +54,38 @@ else GPU_INFO=$(cat "${LSHW_MOCK}") fi -LOG_OUTPUT="" -function log() { - LOG_OUTPUT="${LOG_OUTPUT}$@\n" -} - -NC='\033[0m' # No Color -RED='\033[0;31m' -GREEN='\033[0;32m' -ORANGE='\033[1;33m' - -function log_red() { - echo -e "${RED}$@${NC}" - log "$@" -} -function log_green() { - echo -e "${GREEN}$@${NC}" - log "$@" -} -function log_orange() { - echo -e "${ORANGE}$@${NC}" - log "$@" -} -function log_white() { - echo -e "$@" -} - if [ "$MOCK_MODE" = true ]; then - log_red "[Warning] Using mock data! The following output has nothing to do with this system!" + echo_red "[Warning] Using mock data! The following output has nothing to do with this system!" +fi + +# Check if kernel is configured correctly +if cat /proc/cmdline | grep --quiet iommu ; then + KERNEL_IOMMU_ENABLED=true + echo_green "[OK] The IOMMU kernel parameters are set." +else + KERNEL_IOMMU_ENABLED=false + echo_red "[Error] The iommu kernel parameters are missing! You have to add them in order to use GPU passthrough!" fi # Check if UEFI is configured correctly if systool -m kvm_intel -v &> /dev/null || systool -m kvm_amd -v &> /dev/null ; then UEFI_VIRTUALIZATION_ENABLED=true - log_green "[OK] VT-X / AMD-V virtualization is enabled in the UEFI." + echo_green "[OK] VT-X / AMD-V virtualization is enabled in the UEFI." else UEFI_VIRTUALIZATION_ENABLED=false - log_orange "[Warning] VT-X / AMD-V virtualization is not enabled in the UEFI! This is required to run virtual machines!" + echo_orange "[Warning] VT-X / AMD-V virtualization is not enabled in the UEFI! This feature is required to run virtual machines!" fi if [ "$IOMMU_GROUPS" != "" ] ; then UEFI_IOMMU_ENABLED=true - log_green "[OK] VT-D / IOMMU is enabled in the UEFI." + echo_green "[OK] VT-D / IOMMU is enabled in the UEFI." else - UEFI_IOMMU_ENABLED=false - log_red "[Error] VT-D / IOMMU is not enabled in the UEFI! This is required to check which devices are in which IOMMU group and to use GPU passthrough!" -fi - -# Check if kernel is configured correctly -if cat /proc/cmdline | grep --quiet iommu ; then - KERNEL_IOMMU_ENABLED=true - log_green "[OK] The IOMMU kernel parameters are set." -else - KERNEL_IOMMU_ENABLED=false - log_red "[Error] The iommu kernel parameters are missing! You have to add them in roder to use GPU passthrough!" + if [ "${KERNEL_IOMMU_ENABLED}" = true ] ; then + UEFI_IOMMU_ENABLED=false + echo_red "[Error] VT-D / IOMMU is not enabled in the UEFI! This feature is required to check which devices are in which IOMMU group and to use GPU passthrough!" + else + echo_orange "[Warning] VT-D / IOMMU might possibly not enabled in the UEFI. This feature is required to check which devices are in which IOMMU group and to use GPU passthrough!" + fi fi GPU_IDS=($(echo "${GPU_INFO}" | grep "pci@" | cut -d " " -f 1 | cut -d ":" -f 2-)) @@ -115,23 +96,23 @@ for GPU_ID in "${GPU_IDS[@]}"; do GPU_IOMMU_GROUP=$(echo "${IOMMU_GROUPS}" | grep "${GPU_ID}" | cut -d " " -f 3) if [ "$GPU_IOMMU_GROUP" == "" ] ; then - log_red "[Error] Failed to find the IOMMU group of the GPU with the ID ${GPU_ID}! Have you enabled iommu in the UEFI and kernel?" + echo_red "[Error] Failed to find the IOMMU group of the GPU with the ID ${GPU_ID}! Have you enabled iommu in the UEFI and kernel?" else OTHER_DEVICES_IN_GPU_GROUP=$(echo "${IOMMU_GROUPS}" | grep "IOMMU Group ${GPU_IOMMU_GROUP} " | grep -v ${GPU_ID} | grep -v " Audio device " | grep -v " PCI bridge ") OTHER_DEVICES_IN_GPU_GROUP_NO_GPUS=$(echo "${OTHER_DEVICES_IN_GPU_GROUP}" | grep -v " VGA compatible controller " | grep -v " 3D controller ") if [ "$OTHER_DEVICES_IN_GPU_GROUP" == "" ] ; then - log_green "[Success] GPU with ID '${GPU_ID}' could be passed through to a virtual machine!" + echo_green "[Success] GPU with ID '${GPU_ID}' could be passed through to a virtual machine!" GOOD_GPUS+=("$GPU_ID") elif [ "$OTHER_DEVICES_IN_GPU_GROUP_NO_GPUS" = "" ] ; then - log_orange "[Warning] GPU with ID '${GPU_ID}' could be passed through to a virtual machine, but only together with the following devices: " - log_orange "${OTHER_DEVICES_IN_GPU_GROUP}" + echo_orange "[Warning] GPU with ID '${GPU_ID}' could be passed through to a virtual machine, but only together with the following devices: " + echo_orange "${OTHER_DEVICES_IN_GPU_GROUP}" GOOD_GPUS+=("${GPU_ID}") else - log_orange "[Problem] Other devices have been found in the IOMMU group of the GPU with the ID '${GPU_ID}'. Depending on the devices, this could make it impossible to pass this GPU through to a virtual machine!" - log_orange "The devices found in this GPU's IOMMU Group are:" - log_red "${OTHER_DEVICES_IN_GPU_GROUP}" - log_white "[Info] It might be possible to get it to work by putting the devices in different slots on the motherboard and/or by using the ACS override patch. Otherwise you'll probably have to get a different motherboard. If you're on a laptop, there is nothing you can do as far as I'm aware. Although it would theoretically be possible for ACS support for laptops to exist. TODO: Find a way to check if the current machine has support for that." + echo_orange "[Problem] Other devices have been found in the IOMMU group of the GPU with the ID '${GPU_ID}'. Depending on the devices, this could make it impossible to pass this GPU through to a virtual machine!" + echo_orange "The devices found in this GPU's IOMMU Group are:" + echo_red "${OTHER_DEVICES_IN_GPU_GROUP}" + echo_white "[Info] It might be possible to get it to work by putting the devices in different slots on the motherboard and/or by using the ACS override patch. Otherwise you'll probably have to get a different motherboard. If you're on a laptop, there is nothing you can do as far as I'm aware. Although it would theoretically be possible for ACS support for laptops to exist. TODO: Find a way to check if the current machine has support for that." BAD_GPUS+=("${GPU_ID}") fi fi @@ -157,41 +138,41 @@ IOMMU_COMPATIBILITY_LVL=0 # 0: no GPUs to pass through; 1: at least 1 GPU for pt if [ "${#GOOD_GPUS[@]}" == "0" ] ; then if [ "${#GPU_IDS[@]}" == "0" ] ; then - log_red "[Warning] Failed to find any GPUs! Assuning this is correct, GPU passthrough is obviously impossible on this system in the current configuration!" + echo_red "[Warning] Failed to find any GPUs! Assuning this is correct, GPU passthrough is obviously impossible on this system in the current configuration!" else - log_red "[Warning] This script was not able to identify a GPU in this that could be passed through to a VM!" + echo_red "[Warning] This script was not able to identify a GPU in this that could be passed through to a VM!" fi else - log_green "[Success] There are ${#GOOD_GPUS[@]} GPU(s) in this system that could be passed through to a VM!" + echo_green "[Success] There are ${#GOOD_GPUS[@]} GPU(s) in this system that could be passed through to a VM!" - log_white "" + echo_white "" GPU_LIST=$(echo -e "${GPU_LIST}" | column -t -s'|') while read -r line; do if echo "${line}" | grep --quiet Yes ; then - log_green "${line}" + echo_green "${line}" elif echo "${line}" | grep --quiet No ; then - log_red "${line}" + echo_red "${line}" else - log_orange "${line}" + echo_orange "${line}" fi done <<< "${GPU_LIST}" - log_white "" + echo_white "" if [ ${#GOOD_GPUS[@]} != 1 ] && grep -qE '^([0-9]+)( \1)*$' <<< $(echo $(echo "${IOMMU_GROUPS}" | grep -E $(echo "${GOOD_GPUS[@]}" | tr ' ' '|') | cut -d " " -f 3)) ; then if [ ${#BAD_GPUS[@]} == 0 ] ; then IOMMU_COMPATIBILITY_LVL=1 - log_orange "[Warning] All GPUs in this system are in the same IOMMU group. This would make GPU passthrough difficult (not impossible) because your host machine would be left without a GPU!" + echo_orange "[Warning] All GPUs in this system are in the same IOMMU group. This would make GPU passthrough difficult (not impossible) because your host machine would be left without a GPU!" else IOMMU_COMPATIBILITY_LVL=2 - log_green "[Warning] Some of your GPUs are in the same IOMMU group. This means they could only be passed through together. You could still use a GPU that's in another group for your host system. (E.g. the one with the PCI address 'pci@0000:'${BAD_GPUS[0]} " + echo_green "[Warning] Some of your GPUs are in the same IOMMU group. This means they could only be passed through together. You could still use a GPU that's in another group for your host system. (E.g. the one with the PCI address 'pci@0000:'${BAD_GPUS[0]} " fi else if [ "${#GPU_IDS[@]}" == "1" ] ; then IOMMU_COMPATIBILITY_LVL=1 - log_orange "[Warning] Only 1 GPU found! (Counting all GPUs, not just dedicated ones.) This would make GPU passthrough difficult (not impossible) because your host machine would be left without a GPU!" + echo_orange "[Warning] Only 1 GPU found! (Counting all GPUs, not just dedicated ones.) This would make GPU passthrough difficult (not impossible) because your host machine would be left without a GPU!" else IOMMU_COMPATIBILITY_LVL=2 - log_green "[OK] You have GPUs that are not in the same IOMMU group. At least one of these could be passed through to a VM and at least one of the remaining ones could be used for the host system." + echo_green "[OK] You have GPUs that are not in the same IOMMU group. At least one of these could be passed through to a VM and at least one of the remaining ones could be used for the host system." fi fi fi @@ -199,23 +180,23 @@ fi # If the device is a laptop #if [ "$(sudo ${OPTIRUN_PREFIX}dmidecode --string chassis-type)" != "Desktop" ] ; then if [ $(echo $IOMMU_GROUPS | grep " VGA compatible controller " | wc -l) = "2" ] && ! echo $IOMMU_GROUPS | grep --quiet " Display controller " ; then - log_white "[Info] This system is probably MUXed. (The connection between the GPU(s) and the [internal display]/[display outputs] is multiplexed.)" + echo_white "[Info] This system is probably MUXed. (The connection between the GPU(s) and the [internal display]/[display outputs] is multiplexed.)" else - log_white "[Info] This system is probably MUX-less. (The connection between the GPU(s) and the [internal display]/[display outputs] is not multiplexed.)" + echo_white "[Info] This system is probably MUX-less. (The connection between the GPU(s) and the [internal display]/[display outputs] is not multiplexed.)" fi #fi if [ "$MOCK_MODE" = true ]; then - log_red "[Warning] Remember, the above output has been generated using the given mock data and has nothing to do with this system!" + echo_red "[Warning] Remember, the above output has been generated using the given mock data and has nothing to do with this system!" fi if [ "${UEFI_VIRTUALIZATION_ENABLED}" = true ] && [ "${UEFI_IOMMU_ENABLED}" = true ] && [ "${KERNEL_IOMMU_ENABLED}" = true ] && [ "${IOMMU_COMPATIBILITY_LVL}" -gt "0" ] ; then - log_green "If you found a notebook that appears to be GPU passthrough compatible, please open an issue on Github and let me know." + echo_green "If you found a notebook that appears to be GPU passthrough compatible, please open an issue on Github and let me know." if [ "${IOMMU_COMPATIBILITY_LVL}" -gt "1" ] ; then - log_green "You may now proceed and run './mbpt.sh configure' if you haven't already." + echo_green "You may now proceed and run './mbpt.sh configure' if you haven't already." else exit 1 fi else exit 1 -fi \ No newline at end of file +fi diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index 9d398fb..bd4c083 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -25,7 +25,23 @@ ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" LOG_BASE_DIR="${PROJECT_DIR}/logs" -shopt -s expand_aliases +C_NC='\033[0m' # No Color +C_RED='\033[0;31m' +C_GREEN='\033[0;32m' +C_ORANGE='\033[1;33m' + +function echo_red() { + echo -e "${C_RED}$@${C_NC}" +} +function echo_green() { + echo -e "${C_GREEN}$@${C_NC}" +} +function echo_orange() { + echo -e "${C_ORANGE}$@${C_NC}" +} +function echo_white() { + echo -e "$@" +} function loadConfig() { # If user.conf doesn't exist use the default.conf @@ -41,3 +57,5 @@ function loadConfig() { exit fi } + +shopt -s expand_aliases diff --git a/scripts/utils/manager-specific/package/dnf b/scripts/utils/manager-specific/package/dnf index 8fbe163..af98e80 100755 --- a/scripts/utils/manager-specific/package/dnf +++ b/scripts/utils/manager-specific/package/dnf @@ -66,5 +66,8 @@ if [ "$COMMAND" = "install" ]; then fi elif [ "$COMMAND" = "update" ]; then updatePackageInfo +else + echo "ERROR: Invalid command" + exit 1 fi From 7e52aae02b031f3897f8b95a62c56d7c58e1f629 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Sun, 15 Aug 2021 15:08:19 +0200 Subject: [PATCH 19/40] Make sure to install lshw and lscpu before using it --- scripts/main/setup.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index e4ea510..ede1239 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -11,8 +11,6 @@ loadConfig ##################################################################################################### source "${PROJECT_DIR}/requirements.sh" -source "$COMMON_UTILS_LIBS_DIR/cpu-check" -source "$COMMON_UTILS_LIBS_DIR/gpu-check" alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" @@ -77,6 +75,9 @@ else echo "> [Skipped] General kernel params already set on running kernel." fi +source "$COMMON_UTILS_LIBS_DIR/cpu-check" +source "$COMMON_UTILS_LIBS_DIR/gpu-check" + #if [ "$HAS_INTEL_CPU" = true ]; then if ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_CPU[*]}"; then echo "> Adding Intel CPU-specific kernel params..." From 9431063ac3659de83e7d391b54f4e2440d096857 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Mon, 16 Aug 2021 04:25:58 +0200 Subject: [PATCH 20/40] Started implementing an option to generate a bootable Live version of this project --- .gitignore | 1 + README.md | 11 +- default.conf | 16 ++- live-iso-files/get-mbpt.sh | 31 +++++ live-iso-files/mbpt.desktop | 8 ++ mbpt.sh | 2 + requirements.sh | 6 +- scripts/main/generate-live-iso.sh | 125 ++++++++++++++++++ scripts/main/generate-vm-config.sh | 4 +- scripts/main/setup.sh | 10 +- scripts/main/vm.sh | 8 +- scripts/utils/common/libs/helpers | 1 + .../utils/common/setup/looking-glass-setup | 33 +++++ .../utils/common/tools/download-windows-iso | 7 +- 14 files changed, 242 insertions(+), 21 deletions(-) create mode 100755 live-iso-files/get-mbpt.sh create mode 100644 live-iso-files/mbpt.desktop create mode 100755 scripts/main/generate-live-iso.sh diff --git a/.gitignore b/.gitignore index 70b5af3..55eac3e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /helper-iso-files/bin /helper-iso-files/drivers /helper-iso-files/.checksum +/live-iso-files/*.iso /utils/nvflash_linux /tmp .*.swp diff --git a/README.md b/README.md index 80fbcff..3e998d8 100644 --- a/README.md +++ b/README.md @@ -202,8 +202,13 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for ## TODO ### High prio -- Test service auto reboot +- Create a bootable live version of this project +- Find a good way to share a prebuilt ISO - Test on Ubuntu +- Add auto option for RAM, CPU Cores and DGPU driver +- Document all the new features +- Create a first Beta release +- Test with an Nvidia notebook - Fix automatic Nvidia driver installation in the VM (fix chocolatey) - Fix RDP - Fix Samba sharing @@ -213,13 +218,13 @@ Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for - Add nuveau driver compatibility - Allow the user to decide if he wants bumblebee or not (for Nvidia GPUs) - More detailed output about how the device is muxed -- Create a bootable live version of this project +- Test service auto reboot - Create packages (deb, rpm, etc) - Add compatibility for Arch, Debian, Pop OS etc... - Make this project work better on systems that already have a non-default GPU driver installed - Make it easy to uninstall the dependencies and undo the changes to the systm config (like kernel parameters) - Find a way to circumvent Error 43 for AMD GPUs like the `Radeon RX Vega M GL` -- Reduce the size of the ovmf-vbios-patch Docker image +- Reduce the size of the ovmf-vbios-patch Docker image or build it completely outside of docker - Make the USB passthrough device selection easier (i.e. display a list of devices that can be selected) - Look into hotplugging and check if the GPU can be hotplugged during VM runtime - Check if required dependencies are installed for each script diff --git a/default.conf b/default.conf index bd945c0..b831076 100644 --- a/default.conf +++ b/default.conf @@ -1,7 +1,7 @@ -VM_NAME="WindowsVM" # Required +VM_NAME="MBPT_WindowsVM" # Required -CPU_CORE_COUNT=1 # Required -RAM_SIZE=8G # Required +CPU_CORE_COUNT=2 # Required +RAM_SIZE=4G # Required VM_DISK_SIZE=40G # Required once, Changing this after the drive image has been created has no effect VM_FILES_DIR="${PROJECT_DIR}/vm-files" # Required ; The folder into which all files for your VM will be saved @@ -27,14 +27,14 @@ IGPU_PCI_ADDRESS=00:02.0 # Recommended; required for mediated iGPU passthrough. DGPU_PASSTHROUGH=true # Recommended -SHARE_IGPU=true # Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) +SHARE_IGPU=false # Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) -HOST_DGPU_DRIVER=nvidia # Only tested with "nvidia" and "amdgpu", not tested with "nouveau" +HOST_DGPU_DRIVER=amdgpu # Only tested with "nvidia" and "amdgpu", not tested with "nouveau" VIRTUAL_INPUT_TYPE="usb-tablet" # "usb-tablet", "virtio" or "". If keyboard input doesn't work properly for you, you may want to use "virtio" instead of "usb-tablet" MAC_ADDRESS="" # Required -NETWORK_MODE=TAP # Currently only supports TAP (bridged, NAT and none don't work atm) +NETWORK_MODE=TAP # This option is currently ignored (bridged, NAT and none don't work atm) USE_LOOKING_GLASS=true # Optional LOOKING_GLASS_MAX_SCREEN_WIDTH=1920 # Recommended (bigger resolutions will result in a bigger buffer with worse performance) @@ -44,7 +44,7 @@ LOOKING_GLASS_VERSION=B4 # Recommended USE_SPICE=true # Required for Windows installation and recommended for Looking Glass SPICE_PORT=5900 # 5900 is recommended -USE_DMA_BUF=true # Optional +USE_DMA_BUF=false # Optional USE_QXL=true # Required for RDP @@ -52,6 +52,8 @@ USE_FAKE_BATTERY="true" # Recommended to avoid Error 43 PATCH_OVMF_WITH_VROM="true" # Recommended to avoid Error 43 +VM_START_MODE="qemu" # Recommended (qemu or virt-install) + # USB devices to pass through automatically while the VM is running. Separated by semicolons! # (See output of lsusb for vendorid/productid or hostbus/hostaddr) USB_DEVICES="" diff --git a/live-iso-files/get-mbpt.sh b/live-iso-files/get-mbpt.sh new file mode 100755 index 0000000..4d3c33d --- /dev/null +++ b/live-iso-files/get-mbpt.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +echo "Disabling sleep and force keeping the screen on..." +sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target +gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0 +gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0 +gsettings set org.gnome.desktop.session idle-delay 0 + +printf "%s" "Waiting for an Internet connection ..." +while ! timeout 0.2 ping -c 1 -n github.com &> /dev/null +do + printf "%c" "." + sleep 1 +done +printf "\n%s\n" "Connected!" + +if ! command -v git &> /dev/null; then + echo "Installing git..." + sudo dnf install -y git +fi + +echo "Downloading the MobilePassThrough project..." +sudo mkdir /run/initramfs/live/mbpt +sudo chown liveuser:liveuser /run/initramfs/live/mbpt +cd /run/initramfs/live/mbpt +git clone -b "unattended-win-install" https://github.com/T-vK/MobilePassThrough.git +cd MobilePassThrough +echo "Starting MobilePassThrough in auto mode..." +./mbpt.sh auto +$SHELL +sleep infinity \ No newline at end of file diff --git a/live-iso-files/mbpt.desktop b/live-iso-files/mbpt.desktop new file mode 100644 index 0000000..e2f0cd5 --- /dev/null +++ b/live-iso-files/mbpt.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=MobilePassThrough +Exec=/usr/bin/gnome-terminal -- /home/liveuser/Downloads/get-mbpt.sh +Terminal=false +Type=Application +StartupNotify=true +NoDisplay=true +X-GNOME-Autostart-enabled=true \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index dff3fd8..feee00c 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -86,6 +86,8 @@ elif [ "$COMMAND" = "remove" ]; then sudo "${MAIN_SCRIPTS_DIR}/vm.sh" remove elif [ "$COMMAND" = "start" ]; then sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start $2 +elif [ "$COMMAND" = "live" ]; then + sudo "${MAIN_SCRIPTS_DIR}/generate-live-iso.sh" "$2" elif [ "$COMMAND" = "auto" ]; then #sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 sudo "${MAIN_SCRIPTS_DIR}/setup.sh" auto || echo "Exiting..." && exit 1 diff --git a/requirements.sh b/requirements.sh index 8cdf4c1..b4be4ad 100644 --- a/requirements.sh +++ b/requirements.sh @@ -35,8 +35,8 @@ EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") # git moby-engine EXEC_DEPS_GENERATE_CONFIG=("crudini") # crudini EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") # git wget curl-minimal unzip ruby rubygems rubygem-bundler p7zip make innoextract upx FILE_DEPS_VBIOS_FINDER=("/usr/include/rub*/ruby.h") # ruby-devel -EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "spicy") # qemu-system-x86-core libvirt-client virt-viewer spice-gtk-tools -FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd") # edk2-ovmf +EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat") # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat +FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd" "/usr/share/libvirt/networks/default.xml") # edk2-ovmf libvirt-daemon-config-network EXEC_DEPS_RDP=("remmina") # remmina EXEC_DEPS_SAMBA=("samba") # samba EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output") # uuid xorg-x11-drv-intel @@ -61,7 +61,7 @@ FILE_DEPS_LOOKING_GLASS+=("/usr/include/X11/extensions/Xinerama.h") # libXineram FILE_DEPS_LOOKING_GLASS+=("/usr/include/SDL2/SDL.h" "/usr/include/SDL2/SDL_syswm.h") # SDL2-devel (will be removed in B5 probably) FILE_DEPS_LOOKING_GLASS+=("/usr/include/SDL2/SDL_ttf.h") # SDL2_ttf-devel (will be removed in B5 probably) #FILE_DEPS_LOOKING_GLASS+=("/usr/share/texlive/texmf-dist/fonts/opentype/public/gnu-freefont/FreeMono.otf") # this file is not actually a dependency # texlive-gnu-freefont # TODO: check if texlive-gnu-freefont is actually a dependency - +EXEC_DEPS_LIVE_ISO+=("wget" "xorriso" "mksquashfs" "unsquashfs") # wget xorriso squashfs-tools ############################################################################################################################# ALL_EXEC_DEPS="" # Will contain all content of all variables starting with EXEC_DEPS diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh new file mode 100755 index 0000000..031470b --- /dev/null +++ b/scripts/main/generate-live-iso.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias updatePkgInfo="'${PACKAGE_MANAGER}' update" +alias getExecPkg="'${PACKAGE_MANAGER}' install --executables" + +DRIVE="$1" + +if [ "$DRIVE" = "" ]; then + echo "ERROR: Missing parameter. You have to specify the device onto which to flash the Live ISO! E.g. /dev/sda" + exit 1 +fi + +ISO_DOWNLOAD_URL="https://download.fedoraproject.org/pub/fedora/linux/releases/34/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-34-1.2.iso" +ISO_FILE="${LIVE_ISO_FILES_DIR}/Fedora-Workstation-Live-x86_64-34-1.2.iso" +ISO_FILE_MODIFIED="${LIVE_ISO_FILES_DIR}/Fedora-Workstation-Live-x86_64-34-1.2.modified.iso" + +SOURCE_SQUASHFS_IMG="/LiveOS/squashfs.img" +SQUASHFS_IMG="/tmp/squashfs.img" +SQUASHFS_EXTRACTED="/tmp/squashfs-extracted" +SQUASHFS_IMG_MODIFIED="/tmp/squashfs.modified.img" + +ROOTFS_IMG="${SQUASHFS_EXTRACTED}/LiveOS/rootfs.img" +ROOTFS_MOUNTPOINT="/tmp/rootfs-mountpoint" + +MISSING_EXECUTABLES="$(getMissingExecutables "$EXEC_DEPS_LIVE_ISO")" + +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "> Update package info..." + updatePkgInfo + echo "> Find and install packages containing executables that we need..." + getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need + MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" + if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "> ERROR: Failed to install packages providing the following executables automatically: $MISSING_EXECUTABLES" + fi +else + echo "> [Skipped] Executable dependencies are already installed." +fi + +if [ ! -f "${ISO_FILE}" ]; then + echo "> Downloading Fedora ISO..." + wget "${ISO_DOWNLOAD_URL}" -c -O "${ISO_FILE}.part" + mv "${ISO_FILE}.part" "${ISO_FILE}" +else + echo "> [Skipped] Fedora ISO already downloaded." +fi + +sudo rm -rf "${ISO_FILE_MODIFIED}" + +echo "> Extract the squashfs image and unsquash it" +sudo rm -f "${SQUASHFS_IMG}" +xorriso -dev "${ISO_FILE}" -osirrox "on" -extract "${SOURCE_SQUASHFS_IMG}" "${SQUASHFS_IMG}" +sudo unsquashfs -d "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG}" # Unsquash the squashfs and mount the rootfs in read-write mode +sudo rm -f "${SQUASHFS_IMG}" + +echo "> Mount the rootfs image of the unsquashed squashfs image" +sudo umount --force "${ROOTFS_MOUNTPOINT}" +sudo rm -rf "${ROOTFS_MOUNTPOINT}" +sudo mkdir -p "${ROOTFS_MOUNTPOINT}" +sudo mount -o loop,rw "${ROOTFS_IMG}" "${ROOTFS_MOUNTPOINT}" + +echo "> Add files to the rootfs" +sudo mkdir "${ROOTFS_MOUNTPOINT}/etc/skel/Downloads/" +sudo mkdir -p "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart" +sudo cp "/home/fedora/Projects/MobilePassThrough/live-iso-files/get-mbpt.sh" "${ROOTFS_MOUNTPOINT}/etc/skel/Downloads/" +sudo cp "/home/fedora/Projects/MobilePassThrough/live-iso-files/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" +sudo cp "/home/fedora/Projects/MobilePassThrough/live-iso-files/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/usr/share/applications/" + +echo "> Unmount the rootfs image again" +sudo umount "${ROOTFS_MOUNTPOINT}" + +echo "> Make a new squashfs image from the unsquashed modified squashfs image" +sudo mksquashfs "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG_MODIFIED}" -b 1024k -comp xz -Xbcj x86 -e boot +sudo rm -rf "${SQUASHFS_EXTRACTED}" + +echo "> Overwrite the squashfs image inside the ISO with the modified one" +xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -md5 "all" -compliance no_emul_toc \ +-update "${SQUASHFS_IMG_MODIFIED}" "/LiveOS/squashfs.img" \ +-boot_image any replay + +echo "> Remove modified squashfs image" +sudo rm -f "${SQUASHFS_IMG_MODIFIED}" + +echo "> Flashing ISO to USB drive" +mp="$(mount | grep "$DRIVE" | cut -d' ' -f3)" # get mountpoint for device +if [ "$mp" != "" ]; then + echo "$DRIVE is still mounted. Unmounting $DRIVE now..." + umount --force "$mp" +fi +yes "" | sudo /home/fedora/Downloads/livecd-tools/tools/livecd-iso-to-disk.sh --format ext4 --efi --force --overlay-size-mb 8000 "$ISO_FILE_MODIFIED" "$DRIVE" + +exit + +# TODO: Figure out a way to add kernel parameters to the ISO + +#addKernelParams "iommu=1 intel_iommu=on amd_iommu=on kvm.ignore_msrs=1 rd.driver.pre=vfio-pci i915.enable_gvt=1 nouveau.modeset=0" + +#GRUB_CFG_PATH="${ROOTFS_MOUNTPOINT}/etc/default/grub" +function addKernelParams() { + sudo rm -f "/tmp/grub.conf" + sudo rm -f "/tmp/isolinux.cfg" + sudo rm -f "/tmp/BOOT.conf" + sudo rm -f "/tmp/grub.cfg" + + xorriso -dev "${ISO_FILE}" -osirrox "on" -extract "/isolinux/grub.conf" "/tmp/grub.conf" \ + -extract "/isolinux/isolinux.cfg" "/tmp/isolinux.cfg" \ + -extract "/EFI/BOOT/BOOT.conf" "/tmp/BOOT.conf" \ + -extract "/EFI/BOOT/grub.cfg" "/tmp/grub.cfg" + + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/grub.conf" + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/isolinux.cfg" + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/BOOT.conf" + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/grub.cfg" + + xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -compliance no_emul_toc \ + -update "/tmp/grub.conf" "/isolinux/grub.conf" \ + -update "/tmp/isolinux.cfg" "/isolinux/isolinux.cfg" \ + -update "/tmp/BOOT.conf" "/EFI/BOOT/BOOT.conf" \ + -update "/tmp/grub.cfg" "/EFI/BOOT/grub.cfg" \ + -boot_image any replay +} \ No newline at end of file diff --git a/scripts/main/generate-vm-config.sh b/scripts/main/generate-vm-config.sh index 7aed93a..442b4ac 100755 --- a/scripts/main/generate-vm-config.sh +++ b/scripts/main/generate-vm-config.sh @@ -88,7 +88,9 @@ interactiveCfg "Enable dma-buf. (Yet another way to get display access to your V interactiveCfg "Enable QXL. (Required for Windows installation; has to be disabled after the Nvidia driver has been installed!)" USE_QXL interactiveCfg "Provide the VM with a fake battery (Highly recommended to avoid Error 43)" USE_FAKE_BATTERY interactiveCfg "Patch OVMF with your dGPU ROM if you supply one. (Highly recommended to avoid Error 43)" PATCH_OVMF_WITH_VROM +interactiveCfg "Tool to use to start/install the VM. (qemu or virt-install)" VM_START_MODE interactiveCfg "List of USB devices to pass through. (Semicolon separated, e.g. vendorid=0x0b12,productid=0x9348;vendorid=0x0b95,productid=0x1790)" USB_DEVICES # TODO: Make selecting USB devices easier # TODO: Auto detect PCI addresses for GPUs -# TODO: Don't ask for Bumblebee if there is no nvidia gpu \ No newline at end of file +# TODO: Don't ask for Bumblebee if there is no nvidia gpu +# TODO: Add auto option for CPU cores, RAM and dGPU driver \ No newline at end of file diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index ede1239..1c1848a 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -33,9 +33,14 @@ alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service" mkdir -p "${THIRDPARTY_DIR}" MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" -if [ "$MISSING_EXECUTABLES" != "" ]; then +MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" + +if [ "$MISSING_EXECUTABLES" != "" ] || [ "$MISSING_FILES" != "" ]; then echo "> Update package info..." updatePkgInfo +fi + +if [ "$MISSING_EXECUTABLES" != "" ]; then echo "> Find and install packages containing executables that we need..." getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" @@ -46,10 +51,7 @@ else echo "> [Skipped] Executable dependencies are already installed." fi -MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" if [ "$MISSING_FILES" != "" ]; then - echo "> Update package info..." - updatePkgInfo echo "> Find and install packages containing files that we need..." getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 0aaa1d9..e240d0a 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -8,8 +8,6 @@ loadConfig # or start the previously created Windows VM, if called like this: `./vm.sh` ##################################################################################################### -VM_START_MODE="qemu" # qemu or virt-install - if [ "$1" = "install" ]; then VM_INSTALL=true elif [ "$1" = "start" ]; then @@ -116,6 +114,12 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") fi +if [ "$VM_START_MODE" = "virt-install" ]; then + if ! sudo virsh net-list | grep default | grep --quiet active; then + sudo virsh net-start default + fi +fi + #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") QEMU_PARAMS+=("-device" "ich9-intel-hda") diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index bd4c083..a34537c 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -23,6 +23,7 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" THIRDPARTY_DIR="${PROJECT_DIR}/thirdparty" ACPI_TABLES_DIR="${PROJECT_DIR}/acpi-tables" HELPER_ISO_FILES_DIR="${PROJECT_DIR}/helper-iso-files" +LIVE_ISO_FILES_DIR="${PROJECT_DIR}/live-iso-files" LOG_BASE_DIR="${PROJECT_DIR}/logs" C_NC='\033[0m' # No Color diff --git a/scripts/utils/common/setup/looking-glass-setup b/scripts/utils/common/setup/looking-glass-setup index 976b6e7..2fcd025 100755 --- a/scripts/utils/common/setup/looking-glass-setup +++ b/scripts/utils/common/setup/looking-glass-setup @@ -29,6 +29,39 @@ make # Utilize systemd-tmpfiles to automatically set required permissions on /dev/shm/looking-glass sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" sudo bash -c "echo 'f /dev/shm/looking-glass 0660 $(logname) kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" +sudo systemd-tmpfiles --create /etc/tmpfiles.d/10-looking-glass.conf + +# Adjust permissions for systems with AppArmor +if [ -d "/etc/apparmor.d" ]; then + if ! sudo cat /etc/apparmor.d/local/abstractions/libvirt-qemu | grep --quiet '/dev/shm/looking-glass rw,'; then + sudo bash -c "echo '/dev/shm/looking-glass rw,' >> /etc/apparmor.d/local/abstractions/libvirt-qemu" + sudo systemctl restart apparmor + fi +fi + +# Adjust permissions for systems with SELinux +if [ -d "/etc/selinux" ]; then + TE_FILE="./lookingglass-fix-qemu.te" + MOD_FILE="./lookingglass-fix-qemu.mod" + PP_FILE="./lookingglass-fix-qemu.pp" + echo "module lookingglass-fix-qemu 1.0;" > "${TE_FILE}" + echo "" >> "${TE_FILE}" + echo "require {" >> "${TE_FILE}" + echo " type tmpfs_t;" >> "${TE_FILE}" + echo " type svirt_t;" >> "${TE_FILE}" + echo " class file { getattr map open };" >> "${TE_FILE}" + echo "}" >> "${TE_FILE}" + echo "" >> "${TE_FILE}" + echo "#============= svirt_t ==============" >> "${TE_FILE}" + echo "allow svirt_t tmpfs_t:file { getattr open };" >> "${TE_FILE}" + echo "" >> "${TE_FILE}" + echo "#!!!! This avc can be allowed using the boolean 'domain_can_mmap_files'" >> "${TE_FILE}" + echo "allow svirt_t tmpfs_t:file map;" >> "${TE_FILE}" + + checkmodule -M -m -o "${MOD_FILE}" "${TE_FILE}" + semodule_package -o "${PP_FILE}" -m "${MOD_FILE}" + sudo semodule -i "${PP_FILE}" +fi # Download the Nvidia Capture SDK if it hasn'T been downlaoded already cd "${THIRDPARTY_DIR}" diff --git a/scripts/utils/common/tools/download-windows-iso b/scripts/utils/common/tools/download-windows-iso index 7ae6333..d909d29 100755 --- a/scripts/utils/common/tools/download-windows-iso +++ b/scripts/utils/common/tools/download-windows-iso @@ -21,7 +21,12 @@ echo "$WINDOWS_10_ISO_URL" echo "Making sure the URL comes from a trusted Microsoft domain..." if [[ $WINDOWS_10_ISO_URL == https://software-download.microsoft.com/* ]] ; then echo "Downloading the Windows 10 installation iso..." - wget "$WINDOWS_10_ISO_URL" -O "$WIN10_IMG_DESTINATION" + if [ ! -f "${WIN10_IMG_DESTINATION}" ]; then + wget "${WINDOWS_10_ISO_URL}" -c -O "${WIN10_IMG_DESTINATION}.part" + mv "${WIN10_IMG_DESTINATION}.part" "${WIN10_IMG_DESTINATION}" + else + echo "Skipping download because the Windows ISO already exists: ${WIN10_IMG_DESTINATION}" + fi else echo "URL validation failed. Please download the Windows 10 iso manually." exit 1 From de691b67e3a45eed27fb554822d7f96810ba66c4 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 17 Aug 2021 03:46:43 +0200 Subject: [PATCH 21/40] Lots of tiny improvements --- README.md | 105 +++++---- default.conf | 12 +- live-iso-files/get-mbpt.sh | 78 +++++-- live-iso-files/mbpt.desktop | 2 +- live-iso-files/rootfs-mod.sh | 6 + mbpt.sh | 11 +- requirements.sh | 6 + scripts/main/generate-live-iso.sh | 183 +++++++++------- scripts/main/setup.sh | 4 +- scripts/main/vm.sh | 202 +++++++++++------- .../utils/common/setup/ovmf-vbios-patch-setup | 1 + 11 files changed, 380 insertions(+), 230 deletions(-) create mode 100755 live-iso-files/rootfs-mod.sh diff --git a/README.md b/README.md index 3e998d8..e9d365f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,14 @@ ## Introduction The goal of this project is to make GPU passthrough on x64 notebooks/tablets as easy and accessible as possible. -To achieve that goal I have written a collection of scripts [accessible via mbpt.sh](https://github.com/T-vK/MobilePassThrough#how-to-use-mbptsh) that: +To achieve that goal I have written a collection of scripts [accessible via mbpt.sh](https://github.com/T-vK/MobilePassThrough#how-to-use-mbptsh) + +### MBPT vs MBPT Live + +- (Work in progress; I'm 99% there. Only the kernel params are missing.) You can either flash the MBPT Live ISO to a USB device and boot it to try it out without actually messing with your system. ([Download here](https://github.com/T-vK/MobilePassThrough/releases) or run `./mbpt.sh live build` to build it yourself.) +- Or you can let `./mbpt.sh auto` set everything up on your exisitng Linux installation. + +Either way it is 100% automated, no user interaction required: ### On the host system (Linux): @@ -40,7 +47,7 @@ And there is also a lot of advanced stuff that I managed to fully automate, like ## Limitations -- The project is currently only compatible with Fedora and Ubuntu out of the box (Support for older Fedora/Ubuntu versions may break over time because I don't test changes made to this repo against older distributions.). (To add support for a new distro, copy one of the folders found in [utils](utils)) and adjust it for your distro.) +- The project is currently only really being tested on Fedora and Ubuntu. But it has been written in a somewhat distribution-agnostic way, meaning it might just work on other distributions and if not, you might just have to add a new script to `scripts/utils/manager-specific/`. (For example the project currently supports the package managers `dnf` and `apt`, if your distro uses `pacman`, you have to add a pacman script that can be called the same way as the [apt script](scripts/utils/manager-specific/package/apt).) - This project currently only supports Windows 10 x64 VMs and hopefully Windows 11 x64 VMs at some point. (For older Windows versions you have to figure out the driver installation etc. on your own.) - Only tested for Intel+Nvidia and Intel+AMD systems. (Although the compatibility-check (./mbpt.sh check) should actually work on any hardware.) - Expect bugs. I have only tested this on a handful of devices and I have constantly changed the scripts without testing everything every time. @@ -55,43 +62,39 @@ And there is also a lot of advanced stuff that I managed to fully automate, like - Provide the VM with a fake battery - Provide the VM with the vBios ROMs - Patch OVMF, hardcoding your dGPU vBIOS ROM in it - - (Another measure you can scripttake yourself is installing a recent Nvidia driver in your VM. See [this](https://nvidia.custhelp.com/app/answers/detail/a_id/5173/~/geforce-gpu-passthrough-for-windows-virtual-machine-%28beta%29)) + - Installing the latest Nvidia driver + - (Another measure you can take yourself is installing a recent Nvidia driver in your VM. See [this](https://nvidia.custhelp.com/app/answers/detail/a_id/5173/~/geforce-gpu-passthrough-for-windows-virtual-machine-%28beta%29)) - Other projects that may help, but are very outdated and currently don't work: [NVIDIA-vBIOS-VFIO-Patcher](https://github.com/Matoking/NVIDIA-vBIOS-VFIO-Patcher), [nvidia-kvm-patcher](https://github.com/sk1080/nvidia-kvm-patcher). ## How to use? ### BIOS/UEFI configuration +- Enable `Intel VT-x` / `AMD-V` as well as `Intel VT-d` / AMD's `IOMMU` in the BIOS / UEFI. - On some (gaming) notebooks the integrated graphics of the CPU are disabled. If that is the case for you, you need to enable them in the BIOS/UEFI. (Some vendors actually disable the CPU integrated GPU completely and don't offer UEFI options to enable it. Modding your BIOS could potentially fix that. See the "UEFI / BIOS modding" for more information on that.) - You might also have to disable secure boot in the UEFI. (Mainly to use Nvida's proprietary driver on Linux while your VM is not running.) - It might also be necessary to disable fastboot in the UEFI. -- It is highly recommended to have your Linux installed in UEFI mode (rather than in legacy mode). - If you drive doesn't show up during the installation in UEFI mode, make sure the SATA mode is set to AHCI in the UEFI, even if you don't use SATA. +- It is highly recommended to have your Linux installed/booted in UEFI mode (rather than in legacy mode). +- If your drive doesn't show up during the installation in UEFI mode, make sure the SATA mode is set to AHCI in the UEFI, even if you don't use SATA. ### Installation and configuration -- Download and install [standard Fedora](https://getfedora.org/) or the [KDE version](https://spins.fedoraproject.org/kde/) or [Ubuntu](https://ubuntu.com/download/desktop) (ideally in UEFI mode!) -- Make sure to create a user account (with administrator rights) (in case you are asked) so that you can use sudo -- Open a terminal and install git by typing the following, pressing enter after each line: - -``` bash -sudo dnf install git -y # Install git -git clone https://github.com/T-vK/MobilePassThrough.git # Clone the project -cd MobilePassThrough # Enter the project directory -./mbpt.sh setup # Install dependencies -./mbpt.sh configure # Create a config file interactively -./mbpt.sh auto # Dependency installation; kernel param config; bumblebee / nvidia driver installation; windows ISO download; reboot to load new kernel params; create a helper iso with drivers and autounattended config for Windows; create and start VM; install Windows in the VM fully unattended; install drivers and looking glass in the VM automatically; check for error 43 automatically and show a warning if it occurs -# In the future start the VM with `./mbpt.sh start` -``` - +- Open a terminal and install git and MobilePassThrough by typing the following, pressing enter after each line: + ``` Bash + sudo dnf install git -y # Install git + git clone https://github.com/T-vK/MobilePassThrough.git # Clone the project + cd MobilePassThrough # Enter the project directory + ./mbpt.sh configure # Create a custom config file interactively (optional) + ./mbpt.sh auto # Dependency installation; kernel param config; bumblebee / nvidia driver installation; windows ISO download; reboot to load new kernel params; create a helper iso with drivers and autounattended config for Windows; create and start VM; install Windows in the VM fully unattended; install drivers and looking glass in the VM automatically; check for error 43 automatically and show a warning if it occurs + ``` - Once the installation finished you should be able to open Remmina and connect to `rdp://192.168.99.2` - - Then in the second terminal run: -``` bash -cd MobilePassThrough # Enter the project directory -cd ./thirdparty/LookingGlass/client/build/ # Enter the directoy containing the looking glass client executable -./looking-glass-client # Run the looking glass client -``` + ``` Bash + cd MobilePassThrough # Enter the project directory + cd ./thirdparty/LookingGlass/client/build/ # Enter the directoy containing the looking glass client executable + ./looking-glass-client # Run the looking glass client + ``` +- From now on, start the VM with `./mbpt.sh start` ## How to use mbpt.sh @@ -104,14 +107,15 @@ mbpt.sh is a wrapper script for a collection of tools that help with GPU passthr Options: -h, --help Print usage - -v, --version Print version information Commands: - setup Install required dependencies and set required kernel parameters - check Check if and to what degree your notebook is capable of running a GPU passthrough setup + auto Automatically run check, setup and install configure Interactively guides you through the creation of your config file - iso Generate a helper iso file that contains required drivers and a helper-script for your Windows VM - start Start your VM + check Check if and to what degree your notebook is capable of running a GPU passthrough setup + setup Install required dependencies and set required kernel parameters + install Create and install the VM + start Start the VM + live Create / Flash a Live ISO image of this project vbios Dump the vBIOS ROM from the running system or extract it from a BIOS update Examples: @@ -122,14 +126,35 @@ Examples: mbpt.sh check # Interactively guides you through the creation of your config file - mbpt.sh confi`gure + mbpt.sh configure # Generate a helper iso file that contains required drivers and a helper-script for your Windows VM mbpt.sh iso - # Start your VM + # Create the VM and install Windows in it (Will overwrite an older instance if one exists!) + mbpt.sh install + + # Start the VM mbpt.sh start + # Create a Live ISO + mbpt.sh live buid + + # Flash a Live ISO to the USB drive /dev/sdx + mbpt.sh live flash /dev/sdx + + # Print the qemu command that would have been used to start the VM + mbpt.sh start dry-run + + # Print the qemu command that would have been used to install the VM + mbpt.sh install dry-run + + # Print the libvirt XML that would have been used to start the VM + mbpt.sh start get-xml + + # Print the libvirt XML that would have been used to install the VM + mbpt.sh install get-xml + # Dump the vBIOS ROM of the GPU with the PCI address 01:00.0 to ./my-vbios.rom (This will most likely fail) mbpt.sh vbios dump 01:00.0 ./my-vbios.rom @@ -137,7 +162,7 @@ Examples: mbpt.sh vbios extract /path/to/my-bios-update.exe ./my-roms ``` -## Requirements to get GPU-passthrough to work on mobile +## Hardware requirements to get GPU-passthrough to work on mobile - Device needs to be (mostly) compatible with Linux. Note: most Laptops should be these days @@ -168,12 +193,7 @@ Examples: Possible workaround: Modding your BIOS/UEFI using tools like UEFITool, AMIBCP etc. (See "UEFI / BIOS modding" below) - The GPU you want to pass through, has to be in an IOMMU group that doesn't have other devices in it that the host system needs. - Possible workaround: You might be able to tear the groups further apart using the ACS override patch, but it's no magic cure, there are drawbacks. - - -The last point really seems to be the biggest hurdle, but since it's just a software issue, it should be possible to get this to work. -We just need some smart people to fix one of these patches or to make them more accessible. - + Possible workaround: You might be able to tear the groups further apart using the ACS override patch, but it's no magic cure, there are drawbacks. ## Potentially useful hardware tools @@ -189,9 +209,6 @@ Check out: https://gpu-passthrough.com/ By modding your BIOS/UEFI, you can make features available and change settings that are hidden or non-existent by default. For example: show VT-d settings, show secure boot settings, show muxing related settings and much more. There is a good collection of modding tools on [this site here in the BIOS / UEFI tools section](https://forums.tweaktown.com/gigabyte/30530-overclocking-programs-system-info-benchmarking-stability-tools-post284763.html#post284763). There are many BIOS modding forums out there with lots of people who are more than willing to help even if you're a complete beginner. -## Known issues -- Sometimes the `./mbpt.sh start` command will fail to start the VM because of this error: "echo: write error: No space left on device". It happens while attempting to create a vGPU for the iGPU. I have no clue why this happens. Sometimes it works if you just try it again, sometimes you need to wait a few minutes before retrying, but other times you actually have to reboot the host system. - ## Credits Credits to [Wendell from Level1Techs](https:`//level1techs.com/) for his GPU passthrough guides/videos and [Misairu-G for his Optimus laptop dGPU passthrough guide](https://gist.github.com/Misairu-G/616f7b2756c488148b7309addc940b28). @@ -199,13 +216,13 @@ Without them I would have never even thought about creating this project. Thank Credits to [korewaChino](https://github.com/T-vK/MobilePassThrough/pull/13) for adding support for Ubuntu! +Credits to [Cole Robinson](https://blog.wikichoon.com/) for giving me a lot of incredibly valuable hard to find information on `virt-install`! + ## TODO ### High prio - Create a bootable live version of this project -- Find a good way to share a prebuilt ISO - Test on Ubuntu -- Add auto option for RAM, CPU Cores and DGPU driver - Document all the new features - Create a first Beta release - Test with an Nvidia notebook diff --git a/default.conf b/default.conf index b831076..3c33de0 100644 --- a/default.conf +++ b/default.conf @@ -1,7 +1,7 @@ VM_NAME="MBPT_WindowsVM" # Required CPU_CORE_COUNT=2 # Required -RAM_SIZE=4G # Required +RAM_SIZE=auto # Required (e.g. 8G, 10G or auto) VM_DISK_SIZE=40G # Required once, Changing this after the drive image has been created has no effect VM_FILES_DIR="${PROJECT_DIR}/vm-files" # Required ; The folder into which all files for your VM will be saved @@ -21,15 +21,15 @@ OVMF_VARS_VM="${VM_FILES_DIR}/OVMF_VARS_VM.fd" # Required HELPER_ISO="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated driver installation, looking glass setup, IP setup, remote desktop setup etc inseide of the VM -DGPU_PCI_ADDRESS=01:00.0 # Required; If you don't use Bumblebee, you have to set this to the correct PCI address of your dGPU (see output of lspci) +DGPU_PCI_ADDRESS=auto # Required; If you don't use Bumblebee, you have to set this to the correct PCI address of your dGPU (see output of lspci) # This project has only been tested with Bumblebee enabled. -IGPU_PCI_ADDRESS=00:02.0 # Recommended; required for mediated iGPU passthrough. you can cehck your iGPU PCI address using lspci +IGPU_PCI_ADDRESS=auto # Recommended; required for mediated iGPU passthrough. you can cehck your iGPU PCI address using lspci DGPU_PASSTHROUGH=true # Recommended -SHARE_IGPU=false # Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) +SHARE_IGPU=auto # Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) -HOST_DGPU_DRIVER=amdgpu # Only tested with "nvidia" and "amdgpu", not tested with "nouveau" +HOST_DGPU_DRIVER=auto # Only tested with "nvidia" and "amdgpu", not tested with "nouveau" VIRTUAL_INPUT_TYPE="usb-tablet" # "usb-tablet", "virtio" or "". If keyboard input doesn't work properly for you, you may want to use "virtio" instead of "usb-tablet" @@ -52,7 +52,7 @@ USE_FAKE_BATTERY="true" # Recommended to avoid Error 43 PATCH_OVMF_WITH_VROM="true" # Recommended to avoid Error 43 -VM_START_MODE="qemu" # Recommended (qemu or virt-install) +VM_START_MODE="virt-install" # Recommended (qemu or virt-install) # USB devices to pass through automatically while the VM is running. Separated by semicolons! # (See output of lsusb for vendorid/productid or hostbus/hostaddr) diff --git a/live-iso-files/get-mbpt.sh b/live-iso-files/get-mbpt.sh index 4d3c33d..7df6232 100755 --- a/live-iso-files/get-mbpt.sh +++ b/live-iso-files/get-mbpt.sh @@ -6,26 +6,70 @@ gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0 gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0 gsettings set org.gnome.desktop.session idle-delay 0 -printf "%s" "Waiting for an Internet connection ..." -while ! timeout 0.2 ping -c 1 -n github.com &> /dev/null -do +printf "%s" "Waiting for a device supporting big files with at least 60Gb of free storage to be mounted ..." +REQUIRED_DISK_SPACE=60 #Gigabytes +MBPT_BASE_PATH="" +while sleep 1; do printf "%c" "." - sleep 1 + devices="$(sudo df --output=avail,target -B 1G | sed 's/^ *//')" + while IFS= read -r deviceLine; do + availableSpace=$(echo "$deviceLine" | cut -d' ' -f1) + mountpoint="$(echo "$deviceLine" | cut -d' ' -f2-)" + if [[ $availableSpace -ge $REQUIRED_DISK_SPACE ]]; then + if sudo fallocate -l "${REQUIRED_DISK_SPACE}G" "${mountpoint}/size_test.bin"; then + sudo rm -f "${mountpoint}/_size_test.bin" + MBPT_BASE_PATH="$(echo "${mountpoint}/mbpt" | tr -s '/')" + break + #else + # echo "Device mounted at '$mountpoint' doesn't support big files" + fi + fi + done <<< "$devices" + if [ "$MBPT_BASE_PATH" != "" ]; then + break + fi done -printf "\n%s\n" "Connected!" +printf "\n%s\n" "Device found! Files will be stored under: $MBPT_BASE_PATH" +sudo mkdir -p "$MBPT_BASE_PATH" +sudo chown "$(logname):$(id -gn "$(logname)")" "$MBPT_BASE_PATH" +cd "$MBPT_BASE_PATH" -if ! command -v git &> /dev/null; then - echo "Installing git..." - sudo dnf install -y git -fi +if [ ! -d "${MBPT_BASE_PATH}/MobilePassThrough" ]; then + printf "%s" "Waiting for an Internet connection ..." + while ! timeout 5 ping -c 1 -n github.com &> /dev/null; do + printf "%c" "." + sleep 1 + done + printf "\n%s\n" "Connected!" + + requiredDomains="github.com mirrors.fedoraproject.org fedorapeople.org developer.nvidia.com tb.rg-adguard.net software-download.microsoft.com download.microsoft.com chocolatey.org" # www.techpowerup.com + + for domain in $requiredDomains; do + printf "%s" "Waiting for $domain to be available ..." + while ! timeout 5 ping -c 1 -n $domain &> /dev/null; do + printf "%c" "." + sleep 1 + done + printf "\n%s\n" "$domain is available!" + done -echo "Downloading the MobilePassThrough project..." -sudo mkdir /run/initramfs/live/mbpt -sudo chown liveuser:liveuser /run/initramfs/live/mbpt -cd /run/initramfs/live/mbpt -git clone -b "unattended-win-install" https://github.com/T-vK/MobilePassThrough.git -cd MobilePassThrough -echo "Starting MobilePassThrough in auto mode..." -./mbpt.sh auto + if ! command -v git &> /dev/null; then + echo "Installing git..." + sudo dnf install -y git + fi + + echo "Downloading the MobilePassThrough project..." + git clone -b "unattended-win-install" https://github.com/T-vK/MobilePassThrough.git + cd MobilePassThrough + echo "Run MobilePassThrough compatibility check..." + ./mbpt.sh check + echo "Starting MobilePassThrough in auto mode..." + ./mbpt.sh auto +else + echo "Run MobilePassThrough compatibility check..." + ./mbpt.sh check + echo "Starting MobilePassThrough VM..." + ./mbpt.sh start +fi $SHELL sleep infinity \ No newline at end of file diff --git a/live-iso-files/mbpt.desktop b/live-iso-files/mbpt.desktop index e2f0cd5..3ce7d6c 100644 --- a/live-iso-files/mbpt.desktop +++ b/live-iso-files/mbpt.desktop @@ -1,6 +1,6 @@ [Desktop Entry] Name=MobilePassThrough -Exec=/usr/bin/gnome-terminal -- /home/liveuser/Downloads/get-mbpt.sh +Exec=/usr/bin/gnome-terminal --maximize -- /home/liveuser/get-mbpt.sh Terminal=false Type=Application StartupNotify=true diff --git a/live-iso-files/rootfs-mod.sh b/live-iso-files/rootfs-mod.sh new file mode 100755 index 0000000..62994b5 --- /dev/null +++ b/live-iso-files/rootfs-mod.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +mkdir -p /etc/skel/.config/autostart/ +cp /dev/shm/tmp/get-mbpt.sh /etc/skel/ +cp /dev/shm/tmp/mbpt.desktop /etc/skel/.config/autostart/ +cp /dev/shm/tmp/mbpt.desktop /usr/share/applications/ \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index feee00c..5b8b212 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -25,6 +25,7 @@ function printHelp() { echo ' setup Install required dependencies and set required kernel parameters' echo ' install Create and install the VM' echo ' start Start the VM' + echo ' live Create / Flash a Live ISO image of this project' # TODO: Split start/install in pre-start, start/install, post-start () # TODO implement: #echo ' get-xml Print out the VM configuration as XML' @@ -50,6 +51,12 @@ function printHelp() { echo ' # Start the VM' echo ' mbpt.sh start' echo '' + echo ' # Create a Live ISO' + echo ' mbpt.sh live buid' + echo '' + echo ' # Flash a Live ISO to the USB drive /dev/sdx' + echo ' mbpt.sh live flash /dev/sdx' + echo '' echo ' # Print the qemu command that would have been used to start the VM' echo ' mbpt.sh start dry-run' echo '' @@ -78,7 +85,7 @@ elif [ "$COMMAND" = "check" ]; then sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" elif [ "$COMMAND" = "configure" ]; then "${MAIN_SCRIPTS_DIR}/generate-vm-config.sh" -elif [ "$COMMAND" = "iso" ]; then +elif [ "$COMMAND" = "helper-iso" ]; then "${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh" elif [ "$COMMAND" = "install" ] || [ "$COMMAND" = "create" ]; then sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install $2 @@ -87,7 +94,7 @@ elif [ "$COMMAND" = "remove" ]; then elif [ "$COMMAND" = "start" ]; then sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start $2 elif [ "$COMMAND" = "live" ]; then - sudo "${MAIN_SCRIPTS_DIR}/generate-live-iso.sh" "$2" + sudo "${MAIN_SCRIPTS_DIR}/generate-live-iso.sh" "$2" "$3" elif [ "$COMMAND" = "auto" ]; then #sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 sudo "${MAIN_SCRIPTS_DIR}/setup.sh" auto || echo "Exiting..." && exit 1 diff --git a/requirements.sh b/requirements.sh index b4be4ad..64595d9 100644 --- a/requirements.sh +++ b/requirements.sh @@ -75,3 +75,9 @@ ALL_FILE_DEPS_VARS="$(set -o posix ; set | grep -P '^FILE_DEPS' | cut -d'=' -f1 for deps in $ALL_FILE_DEPS_VARS; do ALL_FILE_DEPS+="$(eval "echo \" \${$deps[*]}\"")" done + +ALL_KERNEL_PARAMS="" # Will contain all content of all variables starting with KERNEL_PARAMS +ALL_KERNEL_PARAMS_VARS="$(set -o posix ; set | grep -P '^KERNEL_PARAMS' | cut -d'=' -f1 | tr '\n' ' ')" +for params in $ALL_KERNEL_PARAMS_VARS; do + ALL_KERNEL_PARAMS+="$(eval "echo \" \${$params[*]}\"")" +done diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh index 031470b..6ebb44e 100755 --- a/scripts/main/generate-live-iso.sh +++ b/scripts/main/generate-live-iso.sh @@ -3,16 +3,14 @@ while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f source "$PROJECT_DIR/scripts/utils/common/libs/helpers" loadConfig +source "${PROJECT_DIR}/requirements.sh" + alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" alias updatePkgInfo="'${PACKAGE_MANAGER}' update" alias getExecPkg="'${PACKAGE_MANAGER}' install --executables" -DRIVE="$1" - -if [ "$DRIVE" = "" ]; then - echo "ERROR: Missing parameter. You have to specify the device onto which to flash the Live ISO! E.g. /dev/sda" - exit 1 -fi +MODE="$1" +DRIVE="$2" ISO_DOWNLOAD_URL="https://download.fedoraproject.org/pub/fedora/linux/releases/34/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-34-1.2.iso" ISO_FILE="${LIVE_ISO_FILES_DIR}/Fedora-Workstation-Live-x86_64-34-1.2.iso" @@ -41,85 +39,110 @@ else echo "> [Skipped] Executable dependencies are already installed." fi -if [ ! -f "${ISO_FILE}" ]; then - echo "> Downloading Fedora ISO..." - wget "${ISO_DOWNLOAD_URL}" -c -O "${ISO_FILE}.part" - mv "${ISO_FILE}.part" "${ISO_FILE}" +if [ ! -d "${THIRDPARTY_DIR}/livecd-tools" ]; then + echo "> Downlaoding and installing livecd-tools..." + mkdir -p "${THIRDPARTY_DIR}" + cd "${THIRDPARTY_DIR}" + git clone --depth=1 https://github.com/livecd-tools/livecd-tools.git + cd livecd-tools + sudo make install + sudo pip3 install urlgrabber else - echo "> [Skipped] Fedora ISO already downloaded." + echo "> [Skipped] livecd-tools already installed." fi -sudo rm -rf "${ISO_FILE_MODIFIED}" - -echo "> Extract the squashfs image and unsquash it" -sudo rm -f "${SQUASHFS_IMG}" -xorriso -dev "${ISO_FILE}" -osirrox "on" -extract "${SOURCE_SQUASHFS_IMG}" "${SQUASHFS_IMG}" -sudo unsquashfs -d "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG}" # Unsquash the squashfs and mount the rootfs in read-write mode -sudo rm -f "${SQUASHFS_IMG}" - -echo "> Mount the rootfs image of the unsquashed squashfs image" -sudo umount --force "${ROOTFS_MOUNTPOINT}" -sudo rm -rf "${ROOTFS_MOUNTPOINT}" -sudo mkdir -p "${ROOTFS_MOUNTPOINT}" -sudo mount -o loop,rw "${ROOTFS_IMG}" "${ROOTFS_MOUNTPOINT}" - -echo "> Add files to the rootfs" -sudo mkdir "${ROOTFS_MOUNTPOINT}/etc/skel/Downloads/" -sudo mkdir -p "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart" -sudo cp "/home/fedora/Projects/MobilePassThrough/live-iso-files/get-mbpt.sh" "${ROOTFS_MOUNTPOINT}/etc/skel/Downloads/" -sudo cp "/home/fedora/Projects/MobilePassThrough/live-iso-files/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" -sudo cp "/home/fedora/Projects/MobilePassThrough/live-iso-files/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/usr/share/applications/" - -echo "> Unmount the rootfs image again" -sudo umount "${ROOTFS_MOUNTPOINT}" - -echo "> Make a new squashfs image from the unsquashed modified squashfs image" -sudo mksquashfs "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG_MODIFIED}" -b 1024k -comp xz -Xbcj x86 -e boot -sudo rm -rf "${SQUASHFS_EXTRACTED}" - -echo "> Overwrite the squashfs image inside the ISO with the modified one" -xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -md5 "all" -compliance no_emul_toc \ --update "${SQUASHFS_IMG_MODIFIED}" "/LiveOS/squashfs.img" \ --boot_image any replay - -echo "> Remove modified squashfs image" -sudo rm -f "${SQUASHFS_IMG_MODIFIED}" - -echo "> Flashing ISO to USB drive" -mp="$(mount | grep "$DRIVE" | cut -d' ' -f3)" # get mountpoint for device -if [ "$mp" != "" ]; then - echo "$DRIVE is still mounted. Unmounting $DRIVE now..." - umount --force "$mp" -fi -yes "" | sudo /home/fedora/Downloads/livecd-tools/tools/livecd-iso-to-disk.sh --format ext4 --efi --force --overlay-size-mb 8000 "$ISO_FILE_MODIFIED" "$DRIVE" +cd "${PROJECT_DIR}" + +#editliveos --extra-kernel-args "$ALL_KERNEL_PARAMS" -o "${LIVE_ISO_FILES_DIR}" -n "mbpt" "${ISO_FILE_MODIFIED}" -exit +#exit -# TODO: Figure out a way to add kernel parameters to the ISO +function build() { + if [ ! -f "${ISO_FILE}" ]; then + echo "> Downloading Fedora ISO..." + wget "${ISO_DOWNLOAD_URL}" -c -O "${ISO_FILE}.part" + mv "${ISO_FILE}.part" "${ISO_FILE}" + else + echo "> [Skipped] Fedora ISO already downloaded." + fi -#addKernelParams "iommu=1 intel_iommu=on amd_iommu=on kvm.ignore_msrs=1 rd.driver.pre=vfio-pci i915.enable_gvt=1 nouveau.modeset=0" + sudo rm -rf "${ISO_FILE_MODIFIED}" + + #echo "> Extracting the squashfs image and unsquash it..." + #sudo rm -f "${SQUASHFS_IMG}" + #xorriso -dev "${ISO_FILE}" -osirrox "on" -extract "${SOURCE_SQUASHFS_IMG}" "${SQUASHFS_IMG}" + #sudo rm -rf "${SQUASHFS_EXTRACTED}" + #sudo unsquashfs -d "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG}" # Unsquash the squashfs and mount the rootfs in read-write mode + #sudo rm -f "${SQUASHFS_IMG}" + + #echo "> Mounting the rootfs image of the unsquashed squashfs image..." + #sudo umount --force "${ROOTFS_MOUNTPOINT}" + #sudo rm -rf "${ROOTFS_MOUNTPOINT}" + #sudo mkdir -p "${ROOTFS_MOUNTPOINT}" + #sudo mount -o loop,rw "${ROOTFS_IMG}" "${ROOTFS_MOUNTPOINT}" + + #echo "> Adding files to the rootfs..." + #sudo mkdir -p "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" + #sudo cp "${LIVE_ISO_FILES_DIR}/get-mbpt.sh" "${ROOTFS_MOUNTPOINT}/etc/skel/" + #sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" + #sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/usr/share/applications/" + + #echo "> Unmounting the rootfs image again..." + #sudo umount "${ROOTFS_MOUNTPOINT}" + #sudo rm -rf "${ROOTFS_MOUNTPOINT}" + + #echo "> Making a new squashfs image from the unsquashed modified squashfs image..." + #sudo mksquashfs "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG_MODIFIED}" -b 1024k -comp xz -Xbcj x86 -e boot + #sudo rm -rf "${SQUASHFS_EXTRACTED}" + + #echo "> Overwriting the squashfs image inside the ISO with the modified one..." + #xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -md5 "all" -compliance no_emul_toc \ + #-update "${SQUASHFS_IMG_MODIFIED}" "/LiveOS/squashfs.img" \ + #-boot_image any replay + + echo "> Rebuilding the ISO adding kernel parameters and some files..." + sudo rm -f "/tmp/get-mbpt.sh" + sudo rm -f "/tmp/mbpt.desktop" + sudo cp "${LIVE_ISO_FILES_DIR}/get-mbpt.sh" "/tmp/get-mbpt.sh" + sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "/tmp/mbpt.desktop" + + #echo "> Rebuilding the ISO adding kernel parameters and the modified squashfs image..." + sudo editliveos \ + --noshell \ + --script "${LIVE_ISO_FILES_DIR}/rootfs-mod.sh" \ + --extra-kernel-args "$ALL_KERNEL_PARAMS" \ + --output "${LIVE_ISO_FILES_DIR}" \ + --name "mbpt" \ + "${ISO_FILE}" + + mv "${LIVE_ISO_FILES_DIR}/mbpt-"*.iso "${ISO_FILE_MODIFIED}" -#GRUB_CFG_PATH="${ROOTFS_MOUNTPOINT}/etc/default/grub" -function addKernelParams() { - sudo rm -f "/tmp/grub.conf" - sudo rm -f "/tmp/isolinux.cfg" - sudo rm -f "/tmp/BOOT.conf" - sudo rm -f "/tmp/grub.cfg" + sudo rm -f "/tmp/get-mbpt.sh" + sudo rm -f "/tmp/mbpt.desktop" - xorriso -dev "${ISO_FILE}" -osirrox "on" -extract "/isolinux/grub.conf" "/tmp/grub.conf" \ - -extract "/isolinux/isolinux.cfg" "/tmp/isolinux.cfg" \ - -extract "/EFI/BOOT/BOOT.conf" "/tmp/BOOT.conf" \ - -extract "/EFI/BOOT/grub.cfg" "/tmp/grub.cfg" - - sudo sed -i "s/rd.live.image/$1 &/" "/tmp/grub.conf" - sudo sed -i "s/rd.live.image/$1 &/" "/tmp/isolinux.cfg" - sudo sed -i "s/rd.live.image/$1 &/" "/tmp/BOOT.conf" - sudo sed -i "s/rd.live.image/$1 &/" "/tmp/grub.cfg" - - xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -compliance no_emul_toc \ - -update "/tmp/grub.conf" "/isolinux/grub.conf" \ - -update "/tmp/isolinux.cfg" "/isolinux/isolinux.cfg" \ - -update "/tmp/BOOT.conf" "/EFI/BOOT/BOOT.conf" \ - -update "/tmp/grub.cfg" "/EFI/BOOT/grub.cfg" \ - -boot_image any replay -} \ No newline at end of file + #echo "> Removing modified squashfs image..." + #sudo rm -f "${SQUASHFS_IMG_MODIFIED}" +} + +function flash() { + echo "> Flashing ISO to USB drive" + mp="$(mount | grep "$DRIVE" | cut -d' ' -f3)" # get mountpoint for device + if [ "$mp" != "" ]; then + echo "$DRIVE is still mounted. Unmounting $DRIVE now..." + sudo umount --force "$mp" + fi + yes "" | sudo livecd-iso-to-disk --format ext4 --efi --force --overlay-size-mb 8000 "${ISO_FILE_MODIFIED}" "$DRIVE" +} + +if [ "$MODE" = "flash" ]; then + if [ "$DRIVE" = "" ]; then + echo "ERROR: Missing parameter. You have to specify the device onto which to flash the Live ISO! E.g. /dev/sda" + exit 1 + fi + if [ ! -f "${ISO_FILE_MODIFIED}" ]; then + build + fi + flash +elif [ "$MODE" = "build" ]; then + build +fi diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 1c1848a..d42afe1 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -120,8 +120,8 @@ if [ "$HAS_NVIDIA_GPU" = true ]; then # TODO: Don't force Bumblebee and the prop fi fi -if [[ "$(docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then - echo "> Image 'ovmf-vbios-patch' has already been built." +if [[ "$(sudo docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then + echo "> Building 'ovmf-vbios-patch' Docker Image..." ovmfVbiosPatchSetup else echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index e240d0a..cc816a1 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -81,6 +81,11 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--vcpu" "${CPU_CORE_COUNT}") fi +if [ "$RAM_SIZE" = "auto" ]; then + FREE_RAM="$(free -g | grep 'Mem: ' | tr -s ' ' | cut -d ' ' -f4)" + RAM_SIZE="$((FREE_RAM-2))G" +fi + if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-m" "${RAM_SIZE}") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -177,26 +182,6 @@ else fi fi -echo "> Retrieving and parsing DGPU IDs..." -DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) -DGPU_VENDOR_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f1) -DGPU_DEVICE_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f2) -DGPU_SS_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -vnn -d "${DGPU_IDS}" | grep "Subsystem:" | grep -oP "\w+:\w+") -DGPU_SS_VENDOR_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f1) -DGPU_SS_DEVICE_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f2) - -if [ -z "$DGPU_IDS" ]; then - echo "> Error: Failed to retrieve DGPU IDs!" - echo "> DGPU_PCI_ADDRESS: ${DGPU_PCI_ADDRESS}" - echo "> DGPU_IDS: $DGPU_IDS" - echo "> DGPU_VENDOR_ID: $DGPU_VENDOR_ID" - echo "> DGPU_DEVICE_ID: $DGPU_DEVICE_ID" - echo "> DGPU_SS_IDS: $DGPU_SS_IDS" - echo "> DGPU_SS_VENDOR_ID: $DGPU_SS_VENDOR_ID" - echo "> DGPU_SS_DEVICE_ID: $DGPU_SS_DEVICE_ID" - exit -fi - echo "> Loading vfio-pci kernel module..." sudo modprobe vfio-pci @@ -235,6 +220,45 @@ fi if [ "$DGPU_PASSTHROUGH" = true ]; then echo "> Using dGPU passthrough..." + + if [ "$DGPU_PCI_ADDRESS" = "auto" ]; then + availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" + + while IFS= read -r pciAddress; do + gpuId="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" + if [[ "$gpuInfo" != *"Intel"* ]]; then + DGPU_PCI_ADDRESS="$pciAddress" + break + fi + done <<< "$availableGpusIds" + fi + + if [ "$HOST_DGPU_DRIVER" = "auto" ]; then + HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" + fi + + echo "> dGPU is: '$DGPU_PCI_ADDRESS' with driver '$HOST_DGPU_DRIVER'" + + echo "> Retrieving and parsing DGPU IDs..." + DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) + DGPU_VENDOR_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f1) + DGPU_DEVICE_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f2) + DGPU_SS_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -vnn -d "${DGPU_IDS}" | grep "Subsystem:" | grep -oP "\w+:\w+") + DGPU_SS_VENDOR_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f1) + DGPU_SS_DEVICE_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f2) + + if [ -z "$DGPU_IDS" ]; then + echo "> Error: Failed to retrieve DGPU IDs!" + echo "> DGPU_PCI_ADDRESS: ${DGPU_PCI_ADDRESS}" + echo "> DGPU_IDS: $DGPU_IDS" + echo "> DGPU_VENDOR_ID: $DGPU_VENDOR_ID" + echo "> DGPU_DEVICE_ID: $DGPU_DEVICE_ID" + echo "> DGPU_SS_IDS: $DGPU_SS_IDS" + echo "> DGPU_SS_VENDOR_ID: $DGPU_SS_VENDOR_ID" + echo "> DGPU_SS_DEVICE_ID: $DGPU_SS_DEVICE_ID" + exit 1 + fi + echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." driver unbind "${DGPU_PCI_ADDRESS}" echo "> Binding dGPU to VFIO driver..." @@ -275,67 +299,86 @@ else echo "> Not using dGPU passthrough..." fi -if [ "$SHARE_IGPU" = true ]; then - echo "> Using mediated iGPU passthrough..." - vgpu init # load required kernel modules +if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then - # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. - # So for now we can't create a new vGPU every time the VM starts. - #vgpu remove "${IGPU_PCI_ADDRESS}" &> /dev/null # Ensure there are no vGPUs before creating a new one - VGPU_UUID="$(vgpu get "${IGPU_PCI_ADDRESS}" | head -1)" - if [ "$VGPU_UUID" == "" ]; then - echo "> Creating a vGPU for mediated iGPU passthrough..." - VGPU_UUID="$(vgpu create "${IGPU_PCI_ADDRESS}")" - if [ "$?" = "1" ]; then - echo "> Failed creating a vGPU. Try again. If you still get this error, you have to reboot. This seems to be a bug in Linux." - exit 1 - fi + if [ "$IGPU_PCI_ADDRESS" = "auto" ]; then + availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" + + while IFS= read -r pciAddress; do + gpuInfo="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" + if [[ "$gpuInfo" == *"Intel"* ]]; then + IGPU_PCI_ADDRESS="$pciAddress" + break + fi + done <<< "$availableGpusIds" fi - # TODO: same as for iGPU - if [ "$VM_START_MODE" = "qemu" ]; then - - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - DMA_BUF_PARAM=",display=on,x-igd-opregion=on" - else - echo "> Not using dma-buf..." - DMA_BUF_PARAM="" + if [ "$IGPU_PCI_ADDRESS" != "auto" ]; then + echo "> Using mediated iGPU passthrough..." + echo "> iGPU is: $IGPU_PCI_ADDRESS" + + vgpu init # load required kernel modules + + # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. + # So for now we can't create a new vGPU every time the VM starts. + #vgpu remove "${IGPU_PCI_ADDRESS}" &> /dev/null # Ensure there are no vGPUs before creating a new one + VGPU_UUID="$(vgpu get "${IGPU_PCI_ADDRESS}" | head -1)" + if [ "$VGPU_UUID" == "" ]; then + echo "> Creating a vGPU for mediated iGPU passthrough..." + VGPU_UUID="$(vgpu create "${IGPU_PCI_ADDRESS}")" + if [ "$?" = "1" ]; then + echo "> Failed creating a vGPU. Try again. If you still get this error, you have to reboot. This seems to be a bug in Linux." + exit 1 + fi fi + + # TODO: same as for iGPU + if [ "$VM_START_MODE" = "qemu" ]; then - if [ -z "$IGPU_ROM" ]; then - echo "> Not using IGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" - else - echo "> Using IGPU vBIOS override..." - IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" - fi + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + DMA_BUF_PARAM=",display=on,x-igd-opregion=on" + else + echo "> Not using dma-buf..." + DMA_BUF_PARAM="" + fi - QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G - elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") - GVTG_DISPLAY_STATE="on" - else - echo "> Not using dma-buf..." - GVTG_DISPLAY_STATE="off" - fi + if [ -z "$IGPU_ROM" ]; then + echo "> Not using IGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + else + echo "> Using IGPU vBIOS override..." + IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" + fi - if [ -z "$IGPU_ROM" ]; then - echo "> Not using IGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" - fi - VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") - - if [ ! -z "$IGPU_ROM" ]; then - echo "> Using IGPU vBIOS override..." - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") + GVTG_DISPLAY_STATE="on" + else + echo "> Not using dma-buf..." + GVTG_DISPLAY_STATE="off" + fi + + if [ -z "$IGPU_ROM" ]; then + echo "> Not using IGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") + + if [ ! -z "$IGPU_ROM" ]; then + echo "> Using IGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + fi fi + else + echo "> No iGPU found. - Not using mediated iGPU passthrough..." fi else echo "> Not using mediated iGPU passthrough..." @@ -474,14 +517,16 @@ if [ $VM_INSTALL = true ]; then sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null fi -if [ "$DRY_RUN" = false ]; then +if [ "$DRY_RUN" = false ] && [ $VM_INSTALL = true ]; then echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." fi if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") if [ "$DRY_RUN" = false ]; then - bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & + if [ $VM_INSTALL = true ]; then + QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") + bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & + fi echo "> Starting the spice client @localhost:${SPICE_PORT}..." bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & @@ -509,8 +554,9 @@ if [ "$VM_START_MODE" = "qemu" ]; then fi elif [ "$VM_START_MODE" = "virt-install" ]; then if [ "$DRY_RUN" = false ]; then - bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & - + if [ $VM_INSTALL = true ]; then + bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + fi echo "> Starting the Virtual Machine using virt-install..." fi #VIRT_INSTALL_PARAMS+=("--debug") diff --git a/scripts/utils/common/setup/ovmf-vbios-patch-setup b/scripts/utils/common/setup/ovmf-vbios-patch-setup index c700e54..72acd5a 100755 --- a/scripts/utils/common/setup/ovmf-vbios-patch-setup +++ b/scripts/utils/common/setup/ovmf-vbios-patch-setup @@ -11,6 +11,7 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" cd "${THIRDPARTY_DIR}" sudo service docker start +rm -rf ovmf-with-vbios-patch git clone https://github.com/T-vK/ovmf-with-vbios-patch.git cd ovmf-with-vbios-patch sudo docker build -t ovmf-vbios-patch . \ No newline at end of file From 2b87dbb2ee139a994e414f03fd7d167d70747ee0 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 17 Aug 2021 16:54:59 +0200 Subject: [PATCH 22/40] Fix Live ISO kernel parameters --- README.md | 2 +- live-iso-files/rootfs-mod.sh | 6 -- mbpt.sh | 16 +++- scripts/main/generate-live-iso.sh | 144 +++++++++++++++++++----------- scripts/main/setup.sh | 7 +- 5 files changed, 107 insertions(+), 68 deletions(-) delete mode 100755 live-iso-files/rootfs-mod.sh diff --git a/README.md b/README.md index e9d365f..a69c455 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ To achieve that goal I have written a collection of scripts [accessible via mbpt ### MBPT vs MBPT Live -- (Work in progress; I'm 99% there. Only the kernel params are missing.) You can either flash the MBPT Live ISO to a USB device and boot it to try it out without actually messing with your system. ([Download here](https://github.com/T-vK/MobilePassThrough/releases) or run `./mbpt.sh live build` to build it yourself.) +- You can either flash the MBPT Live ISO to a USB device and boot it to try it out without actually messing with your system. ([Download here](https://github.com/T-vK/MobilePassThrough/releases) or run `./mbpt.sh live build` to build it yourself.) - Or you can let `./mbpt.sh auto` set everything up on your exisitng Linux installation. Either way it is 100% automated, no user interaction required: diff --git a/live-iso-files/rootfs-mod.sh b/live-iso-files/rootfs-mod.sh deleted file mode 100755 index 62994b5..0000000 --- a/live-iso-files/rootfs-mod.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -mkdir -p /etc/skel/.config/autostart/ -cp /dev/shm/tmp/get-mbpt.sh /etc/skel/ -cp /dev/shm/tmp/mbpt.desktop /etc/skel/.config/autostart/ -cp /dev/shm/tmp/mbpt.desktop /usr/share/applications/ \ No newline at end of file diff --git a/mbpt.sh b/mbpt.sh index 5b8b212..71abd19 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -97,9 +97,19 @@ elif [ "$COMMAND" = "live" ]; then sudo "${MAIN_SCRIPTS_DIR}/generate-live-iso.sh" "$2" "$3" elif [ "$COMMAND" = "auto" ]; then #sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 - sudo "${MAIN_SCRIPTS_DIR}/setup.sh" auto || echo "Exiting..." && exit 1 - sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" || echo "Exiting..." && exit 1 - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install + sudo "${MAIN_SCRIPTS_DIR}/setup.sh" auto + if [ $? -eq 0 ]; then + sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" + if [ $? -eq 0 ]; then + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install + else + echo "Exiting..." + exit 1 + fi + else + echo "Exiting..." + exit 1 + fi elif [ "$COMMAND" = "vbios" ]; then if [ "$2" == "extract" ]; then mkdir -p "$4/" diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh index 6ebb44e..77c99a7 100755 --- a/scripts/main/generate-live-iso.sh +++ b/scripts/main/generate-live-iso.sh @@ -53,11 +53,7 @@ fi cd "${PROJECT_DIR}" -#editliveos --extra-kernel-args "$ALL_KERNEL_PARAMS" -o "${LIVE_ISO_FILES_DIR}" -n "mbpt" "${ISO_FILE_MODIFIED}" - -#exit - -function build() { +function build_method_1() { if [ ! -f "${ISO_FILE}" ]; then echo "> Downloading Fedora ISO..." wget "${ISO_DOWNLOAD_URL}" -c -O "${ISO_FILE}.part" @@ -68,45 +64,21 @@ function build() { sudo rm -rf "${ISO_FILE_MODIFIED}" - #echo "> Extracting the squashfs image and unsquash it..." - #sudo rm -f "${SQUASHFS_IMG}" - #xorriso -dev "${ISO_FILE}" -osirrox "on" -extract "${SOURCE_SQUASHFS_IMG}" "${SQUASHFS_IMG}" - #sudo rm -rf "${SQUASHFS_EXTRACTED}" - #sudo unsquashfs -d "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG}" # Unsquash the squashfs and mount the rootfs in read-write mode - #sudo rm -f "${SQUASHFS_IMG}" - - #echo "> Mounting the rootfs image of the unsquashed squashfs image..." - #sudo umount --force "${ROOTFS_MOUNTPOINT}" - #sudo rm -rf "${ROOTFS_MOUNTPOINT}" - #sudo mkdir -p "${ROOTFS_MOUNTPOINT}" - #sudo mount -o loop,rw "${ROOTFS_IMG}" "${ROOTFS_MOUNTPOINT}" - - #echo "> Adding files to the rootfs..." - #sudo mkdir -p "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" - #sudo cp "${LIVE_ISO_FILES_DIR}/get-mbpt.sh" "${ROOTFS_MOUNTPOINT}/etc/skel/" - #sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" - #sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/usr/share/applications/" - - #echo "> Unmounting the rootfs image again..." - #sudo umount "${ROOTFS_MOUNTPOINT}" - #sudo rm -rf "${ROOTFS_MOUNTPOINT}" - - #echo "> Making a new squashfs image from the unsquashed modified squashfs image..." - #sudo mksquashfs "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG_MODIFIED}" -b 1024k -comp xz -Xbcj x86 -e boot - #sudo rm -rf "${SQUASHFS_EXTRACTED}" - - #echo "> Overwriting the squashfs image inside the ISO with the modified one..." - #xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -md5 "all" -compliance no_emul_toc \ - #-update "${SQUASHFS_IMG_MODIFIED}" "/LiveOS/squashfs.img" \ - #-boot_image any replay - echo "> Rebuilding the ISO adding kernel parameters and some files..." - sudo rm -f "/tmp/get-mbpt.sh" - sudo rm -f "/tmp/mbpt.desktop" - sudo cp "${LIVE_ISO_FILES_DIR}/get-mbpt.sh" "/tmp/get-mbpt.sh" - sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "/tmp/mbpt.desktop" + TMP_SCRIPT="/tmp/tmp-rootfs-setup.sh" + sudo rm -f "${TMP_SCRIPT}" + echo "#!/usr/bin/env bash" > "${TMP_SCRIPT}" + echo "mkdir -p /etc/skel/.config/autostart/" >> "${TMP_SCRIPT}" + echo "IFS='' read -r -d '' GET_MBPT_SCRIPT <<\"EOF\"" >> "${TMP_SCRIPT}" + echo "$(cat ${LIVE_ISO_FILES_DIR}/get-mbpt.sh)" >> "${TMP_SCRIPT}" + echo "EOF" >> "${TMP_SCRIPT}" + echo 'echo "$GET_MBPT_SCRIPT" > /etc/skel/' >> "${TMP_SCRIPT}" + echo "IFS='' read -r -d '' GET_MBPT_DESKTOP_FILE <<\"EOF\"" >> "${TMP_SCRIPT}" + echo "$(cat ${LIVE_ISO_FILES_DIR}/mbpt.desktop)" >> "${TMP_SCRIPT}" + echo "EOF" >> "${TMP_SCRIPT}" + echo 'echo "$GET_MBPT_DESKTOP_FILE" > /etc/skel/.config/autostart/' >> "${TMP_SCRIPT}" + echo 'echo "$GET_MBPT_DESKTOP_FILE" > /usr/share/applications/' >> "${TMP_SCRIPT}" - #echo "> Rebuilding the ISO adding kernel parameters and the modified squashfs image..." sudo editliveos \ --noshell \ --script "${LIVE_ISO_FILES_DIR}/rootfs-mod.sh" \ @@ -117,32 +89,96 @@ function build() { mv "${LIVE_ISO_FILES_DIR}/mbpt-"*.iso "${ISO_FILE_MODIFIED}" - sudo rm -f "/tmp/get-mbpt.sh" - sudo rm -f "/tmp/mbpt.desktop" + sudo rm -f "${TMP_SCRIPT}" +} + +function build_method_2() { + if [ ! -f "${ISO_FILE}" ]; then + echo "> Downloading Fedora ISO..." + wget "${ISO_DOWNLOAD_URL}" -c -O "${ISO_FILE}.part" + mv "${ISO_FILE}.part" "${ISO_FILE}" + else + echo "> [Skipped] Fedora ISO already downloaded." + fi + + sudo rm -rf "${ISO_FILE_MODIFIED}" + + echo "> Extracting the squashfs image and unsquash it..." + sudo rm -f "/tmp/grub.conf" + sudo rm -f "/tmp/isolinux.cfg" + sudo rm -f "/tmp/BOOT.conf" + sudo rm -f "/tmp/grub.cfg" + sudo rm -f "${SQUASHFS_IMG}" + xorriso -dev "${ISO_FILE}" -osirrox "on" \ + -extract "${SOURCE_SQUASHFS_IMG}" "${SQUASHFS_IMG}" \ + -extract "/isolinux/grub.conf" "/tmp/grub.conf" \ + -extract "/isolinux/isolinux.cfg" "/tmp/isolinux.cfg" \ + -extract "/EFI/BOOT/BOOT.conf" "/tmp/BOOT.conf" \ + -extract "/EFI/BOOT/grub.cfg" "/tmp/grub.cfg" + sudo rm -rf "${SQUASHFS_EXTRACTED}" + sudo unsquashfs -d "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG}" # Unsquash the squashfs and mount the rootfs in read-write mode + sudo rm -f "${SQUASHFS_IMG}" + + echo "> Mounting the rootfs image of the unsquashed squashfs image..." + sudo umount --force "${ROOTFS_MOUNTPOINT}" + sudo rm -rf "${ROOTFS_MOUNTPOINT}" + sudo mkdir -p "${ROOTFS_MOUNTPOINT}" + sudo mount -o loop,rw "${ROOTFS_IMG}" "${ROOTFS_MOUNTPOINT}" + + echo "> Adding files to the rootfs..." + sudo mkdir -p "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" + sudo cp "${LIVE_ISO_FILES_DIR}/get-mbpt.sh" "${ROOTFS_MOUNTPOINT}/etc/skel/" + sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/etc/skel/.config/autostart/" + sudo cp "${LIVE_ISO_FILES_DIR}/mbpt.desktop" "${ROOTFS_MOUNTPOINT}/usr/share/applications/" + + echo "> Unmounting the rootfs image again..." + sudo umount "${ROOTFS_MOUNTPOINT}" + sudo rm -rf "${ROOTFS_MOUNTPOINT}" + + echo "> Making a new squashfs image from the unsquashed modified squashfs image..." + sudo mksquashfs "${SQUASHFS_EXTRACTED}" "${SQUASHFS_IMG_MODIFIED}" -b 1024k -comp xz -Xbcj x86 -e boot + sudo rm -rf "${SQUASHFS_EXTRACTED}" + + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/grub.conf" + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/isolinux.cfg" + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/BOOT.conf" + sudo sed -i "s/rd.live.image/$1 &/" "/tmp/grub.cfg" + + echo "> Overwriting the squashfs image inside the ISO with the modified one..." + xorriso -indev "${ISO_FILE}" -outdev "${ISO_FILE_MODIFIED}" -md5 "all" -compliance no_emul_toc \ + -update "${SQUASHFS_IMG_MODIFIED}" "/LiveOS/squashfs.img" \ + -update "/tmp/grub.conf" "/isolinux/grub.conf" \ + -update "/tmp/isolinux.cfg" "/isolinux/isolinux.cfg" \ + -update "/tmp/BOOT.conf" "/EFI/BOOT/BOOT.conf" \ + -update "/tmp/grub.cfg" "/EFI/BOOT/grub.cfg" \ + -boot_image any replay - #echo "> Removing modified squashfs image..." - #sudo rm -f "${SQUASHFS_IMG_MODIFIED}" + echo "> Removing modified squashfs image..." + sudo rm -f "${SQUASHFS_IMG_MODIFIED}" } function flash() { echo "> Flashing ISO to USB drive" - mp="$(mount | grep "$DRIVE" | cut -d' ' -f3)" # get mountpoint for device - if [ "$mp" != "" ]; then - echo "$DRIVE is still mounted. Unmounting $DRIVE now..." - sudo umount --force "$mp" + mps="$(mount | grep "$DRIVE" | cut -d' ' -f3)" # get mountpoint for device + if [ "$mps" != "" ]; then + echo "> $DRIVE is still mounted." + while IFS= read -r mp; do + echo "> Unmounting partition mounted at ${mp}..." + sudo umount --force "$mp" + done <<< "$mps" fi - yes "" | sudo livecd-iso-to-disk --format ext4 --efi --force --overlay-size-mb 8000 "${ISO_FILE_MODIFIED}" "$DRIVE" + yes "" | sudo livecd-iso-to-disk --format ext4 --efi --force --overlay-size-mb 8000 --extra-kernel-args "$ALL_KERNEL_PARAMS" "${ISO_FILE_MODIFIED}" "$DRIVE" } if [ "$MODE" = "flash" ]; then if [ "$DRIVE" = "" ]; then - echo "ERROR: Missing parameter. You have to specify the device onto which to flash the Live ISO! E.g. /dev/sda" + echo "> [Error] Missing parameter. You have to specify the device onto which to flash the Live ISO! E.g. /dev/sda" exit 1 fi if [ ! -f "${ISO_FILE_MODIFIED}" ]; then - build + build_method_1 fi flash elif [ "$MODE" = "build" ]; then - build + build_method_1 fi diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index d42afe1..8f81998 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -176,11 +176,10 @@ fi if [ "$1" = "auto" ]; then if [ "$REBOOT_REQUIRED" = true ]; then - echo "> Creating a temporary service that will run on next reboot and create the Windows VM" + echo "> Creating a temporary service that will run on next reboot and continue the installation..." createAutoStartService "${PROJECT_DIR}/mbpt.sh auto" - echo "> Rebooting in 15 seconds... Press Ctrl+C to reboot now." - #sleep 300 - #sudo shutdown -r 0 + echo "> Rebooting in 30 seconds... Press Ctrl+C to cancel." + sleep 30 && sudo shutdown -r 0 else removeAutoStartService &> /dev/null echo "> No reboot required." From c539256b87a8fc2702b45f586bed1ed79fb38db5 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 17 Aug 2021 17:41:40 +0200 Subject: [PATCH 23/40] Improve MBPT auto mode --- mbpt.sh | 4 ++-- scripts/main/vm.sh | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mbpt.sh b/mbpt.sh index 71abd19..979e818 100755 --- a/mbpt.sh +++ b/mbpt.sh @@ -96,12 +96,12 @@ elif [ "$COMMAND" = "start" ]; then elif [ "$COMMAND" = "live" ]; then sudo "${MAIN_SCRIPTS_DIR}/generate-live-iso.sh" "$2" "$3" elif [ "$COMMAND" = "auto" ]; then - #sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" || echo "Exiting..." && exit 1 + #sudo "${MAIN_SCRIPTS_DIR}/compatibility-check.sh" sudo "${MAIN_SCRIPTS_DIR}/setup.sh" auto if [ $? -eq 0 ]; then sudo "${MAIN_SCRIPTS_DIR}/iommu-check.sh" if [ $? -eq 0 ]; then - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" install + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" auto else echo "Exiting..." exit 1 diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index cc816a1..cdb4bd8 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -12,6 +12,12 @@ if [ "$1" = "install" ]; then VM_INSTALL=true elif [ "$1" = "start" ]; then VM_INSTALL=false +elif [ "$1" = "auto" ]; then + if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then + VM_INSTALL=false + else + VM_INSTALL=true + fi elif [ "$1" = "remove" ]; then if [ $VM_START_MODE = "virt-install" ]; then sudo virsh destroy --domain "${VM_NAME}" From 8365d92c7b3729c46daecaa1652ec4565d6eb404 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 17 Aug 2021 19:13:13 +0200 Subject: [PATCH 24/40] Fix live ISO generation --- scripts/main/generate-live-iso.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh index 77c99a7..9d271dc 100755 --- a/scripts/main/generate-live-iso.sh +++ b/scripts/main/generate-live-iso.sh @@ -72,16 +72,18 @@ function build_method_1() { echo "IFS='' read -r -d '' GET_MBPT_SCRIPT <<\"EOF\"" >> "${TMP_SCRIPT}" echo "$(cat ${LIVE_ISO_FILES_DIR}/get-mbpt.sh)" >> "${TMP_SCRIPT}" echo "EOF" >> "${TMP_SCRIPT}" - echo 'echo "$GET_MBPT_SCRIPT" > /etc/skel/' >> "${TMP_SCRIPT}" + echo 'echo "$GET_MBPT_SCRIPT" > /etc/skel/get-mbpt.sh' >> "${TMP_SCRIPT}" + echo "chmod +x /etc/skel/get-mbpt.sh" >> "${TMP_SCRIPT}" echo "IFS='' read -r -d '' GET_MBPT_DESKTOP_FILE <<\"EOF\"" >> "${TMP_SCRIPT}" echo "$(cat ${LIVE_ISO_FILES_DIR}/mbpt.desktop)" >> "${TMP_SCRIPT}" echo "EOF" >> "${TMP_SCRIPT}" - echo 'echo "$GET_MBPT_DESKTOP_FILE" > /etc/skel/.config/autostart/' >> "${TMP_SCRIPT}" - echo 'echo "$GET_MBPT_DESKTOP_FILE" > /usr/share/applications/' >> "${TMP_SCRIPT}" + echo 'echo "$GET_MBPT_DESKTOP_FILE" > /etc/skel/.config/autostart/mbpt.desktop' >> "${TMP_SCRIPT}" + echo 'echo "$GET_MBPT_DESKTOP_FILE" > /usr/share/applications/mbpt.desktop' >> "${TMP_SCRIPT}" + sudo chmod +x "${TMP_SCRIPT}" sudo editliveos \ --noshell \ - --script "${LIVE_ISO_FILES_DIR}/rootfs-mod.sh" \ + --script "${TMP_SCRIPT}" \ --extra-kernel-args "$ALL_KERNEL_PARAMS" \ --output "${LIVE_ISO_FILES_DIR}" \ --name "mbpt" \ From eaf3c022524f63475f5f32d83169de66f69cd771 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 17 Aug 2021 23:02:16 +0200 Subject: [PATCH 25/40] Fix some bugs in vm.sh --- live-iso-files/get-mbpt.sh | 29 +++++----- scripts/main/vm.sh | 108 +++++++++++++++++++------------------ 2 files changed, 70 insertions(+), 67 deletions(-) diff --git a/live-iso-files/get-mbpt.sh b/live-iso-files/get-mbpt.sh index 7df6232..65e8d10 100755 --- a/live-iso-files/get-mbpt.sh +++ b/live-iso-files/get-mbpt.sh @@ -11,12 +11,15 @@ REQUIRED_DISK_SPACE=60 #Gigabytes MBPT_BASE_PATH="" while sleep 1; do printf "%c" "." - devices="$(sudo df --output=avail,target -B 1G | sed 's/^ *//')" + devices="$(sudo df --output=avail,target -B 1G 2> /dev/null | sed 's/^ *//')" while IFS= read -r deviceLine; do availableSpace=$(echo "$deviceLine" | cut -d' ' -f1) mountpoint="$(echo "$deviceLine" | cut -d' ' -f2-)" - if [[ $availableSpace -ge $REQUIRED_DISK_SPACE ]]; then - if sudo fallocate -l "${REQUIRED_DISK_SPACE}G" "${mountpoint}/size_test.bin"; then + if [ -d "${mountpoint}/mbpt/MobilePassThrough" ]; then + MBPT_BASE_PATH="$(echo "${mountpoint}/mbpt" | tr -s '/')" + break + elif [[ $availableSpace -ge $REQUIRED_DISK_SPACE ]]; then + if sudo fallocate -l "${REQUIRED_DISK_SPACE}G" "${mountpoint}/size_test.bin" &> /dev/null; then sudo rm -f "${mountpoint}/_size_test.bin" MBPT_BASE_PATH="$(echo "${mountpoint}/mbpt" | tr -s '/')" break @@ -60,16 +63,12 @@ if [ ! -d "${MBPT_BASE_PATH}/MobilePassThrough" ]; then echo "Downloading the MobilePassThrough project..." git clone -b "unattended-win-install" https://github.com/T-vK/MobilePassThrough.git - cd MobilePassThrough - echo "Run MobilePassThrough compatibility check..." - ./mbpt.sh check - echo "Starting MobilePassThrough in auto mode..." - ./mbpt.sh auto -else - echo "Run MobilePassThrough compatibility check..." - ./mbpt.sh check - echo "Starting MobilePassThrough VM..." - ./mbpt.sh start fi -$SHELL -sleep infinity \ No newline at end of file + +cd MobilePassThrough +echo "Run MobilePassThrough compatibility check..." +./mbpt.sh check +echo "Starting MobilePassThrough in auto mode..." +./mbpt.sh auto + +$SHELL \ No newline at end of file diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index cdb4bd8..71a7d48 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -19,16 +19,17 @@ elif [ "$1" = "auto" ]; then VM_INSTALL=true fi elif [ "$1" = "remove" ]; then - if [ $VM_START_MODE = "virt-install" ]; then + if [ "$VM_START_MODE" = "virt-install" ]; then sudo virsh destroy --domain "${VM_NAME}" sudo virsh undefine --domain "${VM_NAME}" --nvram - #elif [ $VM_START_MODE = "qemu" ]; then + #elif [ "$VM_START_MODE" = "qemu" ]; then # fi if [[ ${DRIVE_IMG} == *.img ]]; then sudo rm -f "${DRIVE_IMG}" fi rm -f "${OVMF_VARS_VM}" + exit else echo "> Error: No valid vm.sh parameter was found!" exit 1 @@ -111,7 +112,7 @@ QEMU_PARAMS+=("-boot" "menu=on") QEMU_PARAMS+=("-boot" "once=d") QEMU_PARAMS+=("-k" "en-us") -if [ $VM_INSTALL = true ]; then +if [ "$VM_INSTALL" = true ]; then if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -168,7 +169,7 @@ else exit fi -if [ ! -f "${OVMF_VARS_VM}" ] || [ $VM_INSTALL = true ]; then +if [ ! -f "${OVMF_VARS_VM}" ] || [ "$VM_INSTALL" = true ]; then echo "> Creating fresh OVMF_VARS copy for this VM..." sudo rm -f "${OVMF_VARS_VM}" sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" @@ -333,54 +334,57 @@ if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then echo "> Creating a vGPU for mediated iGPU passthrough..." VGPU_UUID="$(vgpu create "${IGPU_PCI_ADDRESS}")" if [ "$?" = "1" ]; then - echo "> Failed creating a vGPU. Try again. If you still get this error, you have to reboot. This seems to be a bug in Linux." - exit 1 + echo "> Failed creating a vGPU. (You can try again. If you still get this error, you have to reboot. This seems to be a bug in Linux.)" + echo "> Continuing without mediated iGPU passthrough..." + VGPU_UUID="" fi fi - # TODO: same as for iGPU - if [ "$VM_START_MODE" = "qemu" ]; then - - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - DMA_BUF_PARAM=",display=on,x-igd-opregion=on" - else - echo "> Not using dma-buf..." - DMA_BUF_PARAM="" - fi + if [ "$VGPU_UUID" != "" ]; then + # TODO: same as for iGPU + if [ "$VM_START_MODE" = "qemu" ]; then + + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + DMA_BUF_PARAM=",display=on,x-igd-opregion=on" + else + echo "> Not using dma-buf..." + DMA_BUF_PARAM="" + fi - if [ -z "$IGPU_ROM" ]; then - echo "> Not using IGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" - else - echo "> Using IGPU vBIOS override..." - IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" - fi + if [ -z "$IGPU_ROM" ]; then + echo "> Not using IGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + else + echo "> Using IGPU vBIOS override..." + IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" + fi - QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G - elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") - GVTG_DISPLAY_STATE="on" - else - echo "> Not using dma-buf..." - GVTG_DISPLAY_STATE="off" - fi + QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") + GVTG_DISPLAY_STATE="on" + else + echo "> Not using dma-buf..." + GVTG_DISPLAY_STATE="off" + fi - if [ -z "$IGPU_ROM" ]; then - echo "> Not using IGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" - fi - VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") - - if [ ! -z "$IGPU_ROM" ]; then - echo "> Using IGPU vBIOS override..." - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + if [ -z "$IGPU_ROM" ]; then + echo "> Not using IGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") + + if [ ! -z "$IGPU_ROM" ]; then + echo "> Using IGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + fi fi fi else @@ -448,7 +452,7 @@ if [ "$PATCH_OVMF_WITH_VROM" = true ]; then sudo rm -rf "${PATCHED_OVMF_FILES_DIR}/tmp-build" fi OVMF_CODE="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" - if [ $VM_INSTALL = true ]; then + if [ "$VM_INSTALL" = true ]; then echo "> Creating fresh copy of patched OVMF VARS..." rm -f "${OVMF_VARS_VM}" sudo cp "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" "${OVMF_VARS_VM}" @@ -517,19 +521,19 @@ fi #sudo bash -c "echo 'user = root' >> /etc/libvirt/qemu.conf" #sudo systemctl restart libvirtd -if [ $VM_INSTALL = true ]; then +if [ "$VM_INSTALL" = true ]; then echo "> Deleting VM if it already exists..." sudo virsh destroy --domain "${VM_NAME}" &> /dev/null sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null fi -if [ "$DRY_RUN" = false ] && [ $VM_INSTALL = true ]; then +if [ "$DRY_RUN" = false ] && [ "$VM_INSTALL" = true ]; then echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." fi if [ "$VM_START_MODE" = "qemu" ]; then if [ "$DRY_RUN" = false ]; then - if [ $VM_INSTALL = true ]; then + if [ "$VM_INSTALL" = true ]; then QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & fi @@ -560,7 +564,7 @@ if [ "$VM_START_MODE" = "qemu" ]; then fi elif [ "$VM_START_MODE" = "virt-install" ]; then if [ "$DRY_RUN" = false ]; then - if [ $VM_INSTALL = true ]; then + if [ "$VM_INSTALL" = true ]; then bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & fi echo "> Starting the Virtual Machine using virt-install..." @@ -570,7 +574,7 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") done - #if [ $VM_INSTALL = true ]; then + #if [ "$VM_INSTALL" = true ]; then if [ "$DRY_RUN" = true ]; then echo "> Generating virt-install command (dry-run)..." echo "" From 011aef9f0bf7d593f3846a303494dd26444d8370 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Wed, 18 Aug 2021 03:29:16 +0200 Subject: [PATCH 26/40] Remove automatic bumblebee and proprietary nvidia driver installation --- README.md | 2 +- live-iso-files/get-mbpt.sh | 29 ++++++----- requirements.sh | 2 +- scripts/main/compatibility-check.sh | 8 +++ scripts/main/setup.sh | 52 +++++++++---------- .../utils/common/setup/ovmf-vbios-patch-setup | 10 ++-- 6 files changed, 57 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index a69c455..449e0e6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Either way it is 100% automated, no user interaction required: - [x] Automatically install the required dependencies - [x] Automatically configure the kernel parameters to support GPU passthrough -- [x] Automatically install Bumblebee and the Nvidia GPU driver if required +- [ ] Automatically install Bumblebee and the Nvidia GPU driver if required (I removed this feature because it was too error-prone. Instead we'll just use nuveau or whatever is installed already.) - [x] Automatically check if and to what extend your device is compatible with GPU passthrough. - [x] Automatically create and configure a virtual machine that is fully configured for GPU passthrough. - [x] Automatically download the Windows 10 installation iso from Microsoft. diff --git a/live-iso-files/get-mbpt.sh b/live-iso-files/get-mbpt.sh index 65e8d10..5b0e091 100755 --- a/live-iso-files/get-mbpt.sh +++ b/live-iso-files/get-mbpt.sh @@ -1,12 +1,10 @@ #!/usr/bin/env bash -echo "Disabling sleep and force keeping the screen on..." +echo "> Disabling sleep and force keeping the screen on..." sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target -gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0 -gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0 gsettings set org.gnome.desktop.session idle-delay 0 -printf "%s" "Waiting for a device supporting big files with at least 60Gb of free storage to be mounted ..." +printf "%s" "> Waiting for a device supporting big files with at least 60Gb of free storage to be mounted ..." REQUIRED_DISK_SPACE=60 #Gigabytes MBPT_BASE_PATH="" while sleep 1; do @@ -24,7 +22,7 @@ while sleep 1; do MBPT_BASE_PATH="$(echo "${mountpoint}/mbpt" | tr -s '/')" break #else - # echo "Device mounted at '$mountpoint' doesn't support big files" + # echo "> Device mounted at '$mountpoint' doesn't support big files" fi fi done <<< "$devices" @@ -32,43 +30,46 @@ while sleep 1; do break fi done -printf "\n%s\n" "Device found! Files will be stored under: $MBPT_BASE_PATH" +printf "\n%s\n" "> Device found! Files will be stored under: $MBPT_BASE_PATH" sudo mkdir -p "$MBPT_BASE_PATH" sudo chown "$(logname):$(id -gn "$(logname)")" "$MBPT_BASE_PATH" cd "$MBPT_BASE_PATH" if [ ! -d "${MBPT_BASE_PATH}/MobilePassThrough" ]; then - printf "%s" "Waiting for an Internet connection ..." + printf "%s" "> Waiting for an Internet connection ..." while ! timeout 5 ping -c 1 -n github.com &> /dev/null; do printf "%c" "." sleep 1 done - printf "\n%s\n" "Connected!" + printf "\n%s\n" "> Connected!" requiredDomains="github.com mirrors.fedoraproject.org fedorapeople.org developer.nvidia.com tb.rg-adguard.net software-download.microsoft.com download.microsoft.com chocolatey.org" # www.techpowerup.com for domain in $requiredDomains; do - printf "%s" "Waiting for $domain to be available ..." + printf "%s" "> Waiting for $domain to be available ..." while ! timeout 5 ping -c 1 -n $domain &> /dev/null; do printf "%c" "." sleep 1 done - printf "\n%s\n" "$domain is available!" + printf "\n%s\n" "> $domain is available!" done if ! command -v git &> /dev/null; then - echo "Installing git..." + echo "> Installing git..." sudo dnf install -y git fi - echo "Downloading the MobilePassThrough project..." + echo "> Downloading the MobilePassThrough project..." git clone -b "unattended-win-install" https://github.com/T-vK/MobilePassThrough.git +else + echo "[Skipped] MobilePassThrough appears to have been set up already in a previous boot." fi cd MobilePassThrough -echo "Run MobilePassThrough compatibility check..." +echo "> Running MobilePassThrough compatibility check..." ./mbpt.sh check -echo "Starting MobilePassThrough in auto mode..." +echo "> Waiting for 10 seconds before continuing..." +echo "> Starting MobilePassThrough in auto mode..." ./mbpt.sh auto $SHELL \ No newline at end of file diff --git a/requirements.sh b/requirements.sh index 64595d9..63ee97e 100644 --- a/requirements.sh +++ b/requirements.sh @@ -25,7 +25,7 @@ KERNEL_PARAMS_AMD_CPU=("amd_iommu=on") # 'on' is not a docuemnted option for thi KERNEL_PARAMS_INTEL_GPU=("i915.enable_gvt=1") # enable mediated iGPU passthrough support (GVT-g) on Intel iGPUs #KERNEL_PARAMS_AMD_GPU=() #KERNEL_PARAMS_NVIDIA_GPU=() -KERNEL_PARAMS_BUMBLEBEE_NVIDIA=("nouveau.modeset=0") +#KERNEL_PARAMS_BUMBLEBEE_NVIDIA=("nouveau.modeset=0") # TODO: check if we should use relative paths to be more distribution-gnostic diff --git a/scripts/main/compatibility-check.sh b/scripts/main/compatibility-check.sh index 126ee25..62df12e 100755 --- a/scripts/main/compatibility-check.sh +++ b/scripts/main/compatibility-check.sh @@ -95,6 +95,14 @@ BAD_GPUS=() for GPU_ID in "${GPU_IDS[@]}"; do GPU_IOMMU_GROUP=$(echo "${IOMMU_GROUPS}" | grep "${GPU_ID}" | cut -d " " -f 3) + if [ "$GPU_IOMMU_GROUP" == "" ] ; then # Compensate for Intel iGPUs sometimes not having an IOMMU group at all + GPU_NAME="$(lspci -s "${GPU_ID}" | cut -d' ' -f2-)" + if echo "${GPU_NAME}" | grep --quiet "Intel"; then + GPU_IOMMU_GROUP="N/A" + IOMMU_GROUPS+=$'\n'"IOMMU GROUP N/A ${GPU_ID} ${GPU_NAME}" + fi + fi + if [ "$GPU_IOMMU_GROUP" == "" ] ; then echo_red "[Error] Failed to find the IOMMU group of the GPU with the ID ${GPU_ID}! Have you enabled iommu in the UEFI and kernel?" else diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 8f81998..817753d 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -41,23 +41,23 @@ if [ "$MISSING_EXECUTABLES" != "" ] || [ "$MISSING_FILES" != "" ]; then fi if [ "$MISSING_EXECUTABLES" != "" ]; then - echo "> Find and install packages containing executables that we need..." + echo "> Finding and installing packages containing executables that we need..." getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" if [ "$MISSING_EXECUTABLES" != "" ]; then - echo "> ERROR: Failed to install packages providing the following executables automatically: $MISSING_EXECUTABLES" + echo "> [Error] Failed to install packages providing the following executables automatically: $MISSING_EXECUTABLES" fi else echo "> [Skipped] Executable dependencies are already installed." fi if [ "$MISSING_FILES" != "" ]; then - echo "> Find and install packages containing files that we need..." + echo "> Finding and installing packages containing files that we need..." getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" if [ "$MISSING_FILES" != "" ]; then MISSING_FILES="$(echo "$MISSING_EXECUTABLES" | sed 's/\s\+/\n/g')" # replace spaces with new lines - echo "> ERROR: Failed to install packages providing the following executables automatically:" + echo "> [Error] Failed to install packages providing the following executables automatically:" echo "$MISSING_FILES" fi else @@ -110,29 +110,22 @@ source "$COMMON_UTILS_LIBS_DIR/gpu-check" fi #fi -if [ "$HAS_NVIDIA_GPU" = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user - if ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"; then - echo "> Adding Nvidia GPU-specific kernel params..." - addKernelParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" - REBOOT_REQUIRED=true - else - echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel." - fi -fi - -if [[ "$(sudo docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then - echo "> Building 'ovmf-vbios-patch' Docker Image..." - ovmfVbiosPatchSetup -else - echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." -fi +#if [ "$HAS_NVIDIA_GPU" = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user +# if ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"; then +# echo "> Adding Nvidia GPU-specific kernel params..." +# addKernelParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}" +# REBOOT_REQUIRED=true +# else +# echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel." +# fi +#fi -if [ "$HAS_NVIDIA_GPU" = true ]; then - nvidiaSetup -fi -if [ "$SUPPORTS_OPTIMUS" = true ]; then - bumblebeeSetup -fi +#if [ "$HAS_NVIDIA_GPU" = true ]; then +# nvidiaSetup +#fi +#if [ "$SUPPORTS_OPTIMUS" = true ]; then +# bumblebeeSetup +#fi if [ ! -f "${ACPI_TABLES_DIR}/fake-battery.aml" ]; then echo "> Building fake ACPI SSDT battery..." @@ -174,6 +167,13 @@ else echo "> [Skipped] Windows ISO has already been downloaded." fi +if [[ "$(sudo docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then + echo "> Building 'ovmf-vbios-patch' Docker Image..." + ovmfVbiosPatchSetup +else + echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." +fi + if [ "$1" = "auto" ]; then if [ "$REBOOT_REQUIRED" = true ]; then echo "> Creating a temporary service that will run on next reboot and continue the installation..." diff --git a/scripts/utils/common/setup/ovmf-vbios-patch-setup b/scripts/utils/common/setup/ovmf-vbios-patch-setup index 72acd5a..3dc8fff 100755 --- a/scripts/utils/common/setup/ovmf-vbios-patch-setup +++ b/scripts/utils/common/setup/ovmf-vbios-patch-setup @@ -11,7 +11,9 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" cd "${THIRDPARTY_DIR}" sudo service docker start -rm -rf ovmf-with-vbios-patch -git clone https://github.com/T-vK/ovmf-with-vbios-patch.git -cd ovmf-with-vbios-patch -sudo docker build -t ovmf-vbios-patch . \ No newline at end of file +#rm -rf ovmf-with-vbios-patch +#git clone https://github.com/T-vK/ovmf-with-vbios-patch.git +#cd ovmf-with-vbios-patch +#sudo docker build -t ovmf-vbios-patch . +sudo docker pull tavk/ovmf-vbios-patch:1.0.1-edk2-stable201905 # Pull instead of build because the root partition of the Live version is too small. +# TODO: Get rid of Docker and build this thing natively \ No newline at end of file From 478e775c5da70ae9ebe4c605096837bff2e1844f Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Mon, 23 Aug 2021 04:20:26 +0200 Subject: [PATCH 27/40] Fix Looking Glass and Nvidia support; Add auto option for RAM, CPU etc; Started work on auto detecting best display output method... --- README.md | 6 +- default.conf | 46 +- helper-iso-files/Autounattend.xml | 33 +- helper-iso-files/mbpt-helper.bat | 63 +- .../scripts/chcolatey-install.ps1 | 698 ------------------ .../scripts/disable-mouse-acceleration.ps1 | 7 + helper-iso-files/scripts/gpu-check.ps1 | 59 +- helper-iso-files/scripts/mbpt-startup.bat | 1 + live-iso-files/get-mbpt.sh | 12 +- requirements.sh | 2 +- scripts/main/generate-helper-iso.sh | 16 + scripts/main/generate-live-iso.sh | 2 +- scripts/main/setup.sh | 4 +- scripts/main/vm.sh | 163 ++-- 14 files changed, 294 insertions(+), 818 deletions(-) delete mode 100644 helper-iso-files/scripts/chcolatey-install.ps1 create mode 100644 helper-iso-files/scripts/disable-mouse-acceleration.ps1 create mode 100644 helper-iso-files/scripts/mbpt-startup.bat diff --git a/README.md b/README.md index 449e0e6..9556672 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Either way it is 100% automated, no user interaction required: - [x] Automatically install the required dependencies - [x] Automatically configure the kernel parameters to support GPU passthrough -- [ ] Automatically install Bumblebee and the Nvidia GPU driver if required (I removed this feature because it was too error-prone. Instead we'll just use nuveau or whatever is installed already.) +- [ ] Automatically install Bumblebee and the Nvidia GPU driver if required (I removed this feature because it was too error-prone. Instead we'll just use nouveau or whatever is installed already.) - [x] Automatically check if and to what extend your device is compatible with GPU passthrough. - [x] Automatically create and configure a virtual machine that is fully configured for GPU passthrough. - [x] Automatically download the Windows 10 installation iso from Microsoft. @@ -28,7 +28,7 @@ Either way it is 100% automated, no user interaction required: - [x] Automatically install the required drivers (ivshmem, other vfio drivers, Intel/Nvidia display drivers) - [x] Automatically compile/install/start LookingGlass - [x] Automatically configure the network -- [ ] Automatically set up RDP +- [x] Automatically set up RDP - [x] Automatically install and autostart LookingGlass And there is also a lot of advanced stuff that I managed to fully automate, like: @@ -232,7 +232,7 @@ Credits to [Cole Robinson](https://blog.wikichoon.com/) for giving me a lot of i - Add virt-install version check because 2.2.1 doesn't seem to support the --xml flag ### Low prio -- Add nuveau driver compatibility +- Add nouveau driver compatibility - Allow the user to decide if he wants bumblebee or not (for Nvidia GPUs) - More detailed output about how the device is muxed - Test service auto reboot diff --git a/default.conf b/default.conf index 3c33de0..0511995 100644 --- a/default.conf +++ b/default.conf @@ -1,6 +1,6 @@ VM_NAME="MBPT_WindowsVM" # Required -CPU_CORE_COUNT=2 # Required +CPU_CORE_COUNT=auto # Required (e.g. 8, 12 or auto) RAM_SIZE=auto # Required (e.g. 8G, 10G or auto) VM_DISK_SIZE=40G # Required once, Changing this after the drive image has been created has no effect @@ -31,7 +31,7 @@ SHARE_IGPU=auto # Recommended to save battery life (this is mediated iGPU passth HOST_DGPU_DRIVER=auto # Only tested with "nvidia" and "amdgpu", not tested with "nouveau" -VIRTUAL_INPUT_TYPE="usb-tablet" # "usb-tablet", "virtio" or "". If keyboard input doesn't work properly for you, you may want to use "virtio" instead of "usb-tablet" +VIRTUAL_INPUT_TYPE="virtio" # "usb-tablet", "virtio" or "". If keyboard input doesn't work properly for you, you may want to use "virtio" instead of "usb-tablet" MAC_ADDRESS="" # Required NETWORK_MODE=TAP # This option is currently ignored (bridged, NAT and none don't work atm) @@ -44,15 +44,55 @@ LOOKING_GLASS_VERSION=B4 # Recommended USE_SPICE=true # Required for Windows installation and recommended for Looking Glass SPICE_PORT=5900 # 5900 is recommended +USE_SPICE_CLIENT="true" # Required for installation + USE_DMA_BUF=false # Optional USE_QXL=true # Required for RDP +DISPLAY_MODE=1 + +# DISPLAY_MODES +# if [ "$DISPLAY_MODE" == 1 ]; then +# if [ "$DMA_BUF_AVAILABLE" == true ]; then +# LOOKING_GLASS=true +# DMA_BUF=true +# QXL=false +# RDP=false +# else +# DMA_BUF=false +# RDP=true +# if [ "$VM_INSTALL" == true ]; then +# QXL=true +# LOOKING_GLASS=false +# else +# QXL=false +# LOOKING_GLASS=true +# fi +# fi +# elif [ "$DISPLAY_MODE" == 2 ]; then +# RDP=true +# if [ "$DMA_BUF_AVAILABLE" == true ]; then +# LOOKING_GLASS=true +# DMA_BUF=true +# QXL=false +# else +# DMA_BUF=false +# if [ "$VM_INSTALL" == true ]; then +# QXL=true +# LOOKING_GLASS=false +# else +# QXL=false +# LOOKING_GLASS=true +# fi +# fi +# fi + USE_FAKE_BATTERY="true" # Recommended to avoid Error 43 PATCH_OVMF_WITH_VROM="true" # Recommended to avoid Error 43 -VM_START_MODE="virt-install" # Recommended (qemu or virt-install) +VM_START_MODE="qemu" # Required (qemu or virt-install) # USB devices to pass through automatically while the VM is running. Separated by semicolons! # (See output of lsusb for vendorid/productid or hostbus/hostaddr) diff --git a/helper-iso-files/Autounattend.xml b/helper-iso-files/Autounattend.xml index 6bf5590..d6b0f5d 100644 --- a/helper-iso-files/Autounattend.xml +++ b/helper-iso-files/Autounattend.xml @@ -156,40 +156,11 @@ </OOBE> <TimeZone>UTC</TimeZone> <FirstLogonCommands> - <SynchronousCommand wcm:action="add"> - <CommandLine>cmd.exe /c wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE</CommandLine> - <Order>1</Order> - <Description>Disable password expiration for Administrator user</Description> - </SynchronousCommand> <SynchronousCommand wcm:action="add"> <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\mbpt-helper.bat cmd /c %i:\mbpt-helper.bat"</CommandLine> - <Description>Install drivers, change some settings and install Looking Glass</Description> - <Order>2</Order> - <RequiresUserInput>false</RequiresUserInput> - </SynchronousCommand> - <SynchronousCommand wcm:action="add"> - <Order>3</Order> - <Description>Set-ExecutionPolicy Unrestricted</Description> - <RequiresUserInput>false</RequiresUserInput> - <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy Unrestricted"</CommandLine> - </SynchronousCommand> - <SynchronousCommand wcm:action="add"> - <Order>4</Order> - <RequiresUserInput>false</RequiresUserInput> - <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\network-check.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\network-check.ps1"</CommandLine> - <Description>Wait for a Network connection</Description> - </SynchronousCommand> - <SynchronousCommand wcm:action="add"> - <Order>5</Order> - <RequiresUserInput>false</RequiresUserInput> - <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\chocolatey-install.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\chocolatey-install.ps1"</CommandLine> - <Description>Install Chocolatey if possible</Description> - </SynchronousCommand> - <SynchronousCommand wcm:action="add"> - <Order>6</Order> + <Description>Install drivers, guest tools, looking glass, enable RDP, etc.</Description> + <Order>1</Order> <RequiresUserInput>false</RequiresUserInput> - <CommandLine>cmd /q /c "FOR %i IN (A B C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %i:\scripts\gpu-check.ps1 cmd /c powershell -executionpolicy unrestricted -file %i:\scripts\gpu-check.ps1"</CommandLine> - <Description>Check for GPU Errors and install drivers if possible and necessary</Description> </SynchronousCommand> </FirstLogonCommands> </component> diff --git a/helper-iso-files/mbpt-helper.bat b/helper-iso-files/mbpt-helper.bat index e1e6b7d..e30a0fc 100644 --- a/helper-iso-files/mbpt-helper.bat +++ b/helper-iso-files/mbpt-helper.bat @@ -1,19 +1,59 @@ cd /D %~dp0 +echo "Set poweshell execution policy to unrestricted..." +powershell -Command "Set-ExecutionPolicy Unrestricted + +echo "Disable password expiration for Administrator user..." +wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE + echo "Installing required Visual C++ Redistributable Package..." .\bin\VC_redist.x64.exe /install /passive /norestart +echo "Install vfio drivers..." +certutil -addstore "TrustedPublisher" .\RedHat.cer +%WINDIR%\system32\pnputil.exe /add-driver .\bin\virtio-drivers\Win10\amd64\*.inf /subdirs /install + +echo "Disable mouse acceleration..." +powershell -executionpolicy unrestricted -file .\scripts\disable-mouse-acceleration.ps1 + +echo "Install Spice guest tools..." +.\bin\spice-guest-tools.exe /S + +echo "Install Spice WebDAV daemon..." +.\bin\spice-webdavd.msi /passive /norestart + echo "Install Looking Glass to Program Files ..." -:: mkdir "%ProgramFiles%\LookingGlass" -:: xcopy /s ".\bin\looking-glass-host.exe" "%ProgramFiles%\LookingGlass\looking-glass-host.exe" .\bin\looking-glass-host-setup.exe /S -echo "MobilePassThrough Helper, Register Looking Glass as a startup application..." -reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "LookingGlass" /t REG_SZ /f /d "%ProgramFiles%\Looking Glass (host)\looking-glass-host.exe -f" +echo "Changing the virtual Ethernet adapter to a private one to allow RDP access..." +for /F "skip=3 tokens=1,2,3* delims= " %%G in ('netsh interface show interface') DO ( + echo "Setting %%J to private..." + powershell -command Set-NetConnectionProfile -InterfaceAlias "Network" -NetworkCategory Private +) -echo "Install vfio drivers..." -certutil -addstore "TrustedPublisher" .\RedHat.cer -%WINDIR%\system32\pnputil.exe /add-driver .\bin\virtio-drivers\Win10\amd64\*.inf /subdirs /install +echo "Enable remote desktop..." +reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f +netsh advfirewall firewall set rule group="remote desktop" new enable=Yes + +echo "Copy gpu-check script to startup..." +md "%APPDATA%\mbpt" +copy .\scripts\gpu-check.ps1 "%APPDATA%\mbpt" +copy .\scripts\mbpt-startup.bat "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup" + +echo "Wait until we're connected to the Internet..." +powershell -executionpolicy unrestricted -file .\scripts\network-check.ps1 + +echo "Install Chocolatey if possible..." +powershell -executionpolicy unrestricted -file .\scripts\chocolatey-install.ps1 + +echo "Run GPU check..." +powershell -executionpolicy unrestricted -file .\scripts\gpu-check.ps1 unattended + +echo "Done! Shutting down the VM in 30 seconds..." + +shutdown -s + +pause ::echo "Set static IP for vfio network device..." :: TODO: Find the correct network adapter name @@ -23,11 +63,4 @@ certutil -addstore "TrustedPublisher" .\RedHat.cer :: netsh int ip set dns "Local Area Connection" static 192.168.99.1 primary ::echo "Waiting for 5 seconds..." -::timeout /t 5 /nobreak > nul - -echo "Change the virtual Ethernet adapter to a private one to allow RDP access..." -powershell -command Set-NetConnectionProfile -Name "Network" -NetworkCategory Private - -echo "Enable remote desktop..." -reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f -netsh advfirewall firewall set rule group="remote desktop" new enable=Yes \ No newline at end of file +::timeout /t 5 /nobreak > nul \ No newline at end of file diff --git a/helper-iso-files/scripts/chcolatey-install.ps1 b/helper-iso-files/scripts/chcolatey-install.ps1 deleted file mode 100644 index 34c9908..0000000 --- a/helper-iso-files/scripts/chcolatey-install.ps1 +++ /dev/null @@ -1,698 +0,0 @@ -<# - .SYNOPSIS - Downloads and installs Chocolatey on the local machine. - - .DESCRIPTION - Retrieves the Chocolatey nupkg for the latest or a specified version, and - downloads and installs the application to the local machine. - - .NOTES - ===================================================================== - Copyright 2017 - 2020 Chocolatey Software, Inc, and the - original authors/contributors from ChocolateyGallery - Copyright 2011 - 2017 RealDimensions Software, LLC, and the - original authors/contributors from ChocolateyGallery - at https://github.com/chocolatey/chocolatey.org - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ===================================================================== - - Environment Variables, specified as $env:NAME in PowerShell.exe and %NAME% in cmd.exe. - For explicit proxy, please set $env:chocolateyProxyLocation and optionally $env:chocolateyProxyUser and $env:chocolateyProxyPassword - For an explicit version of Chocolatey, please set $env:chocolateyVersion = 'versionnumber' - To target a different url for chocolatey.nupkg, please set $env:chocolateyDownloadUrl = 'full url to nupkg file' - NOTE: $env:chocolateyDownloadUrl does not work with $env:chocolateyVersion. - To use built-in compression instead of 7zip (requires additional download), please set $env:chocolateyUseWindowsCompression = 'true' - To bypass the use of any proxy, please set $env:chocolateyIgnoreProxy = 'true' - - .LINK - For organizational deployments of Chocolatey, please see https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide - -#> -[CmdletBinding(DefaultParameterSetName = 'Default')] -param( - # The URL to download Chocolatey from. This defaults to the value of - # $env:chocolateyDownloadUrl, if it is set, and otherwise falls back to the - # official Chocolatey community repository to download the Chocolatey package. - [Parameter(Mandatory = $false)] - [string] - $ChocolateyDownloadUrl = $env:chocolateyDownloadUrl, - - # Specifies a target version of Chocolatey to install. By default, the latest - # stable version is installed. This will use the value in - # $env:chocolateyVersion by default, if that environment variable is present. - # This parameter is ignored if -ChocolateyDownloadUrl is set. - [Parameter(Mandatory = $false)] - [string] - $ChocolateyVersion = $env:chocolateyVersion, - - # If set, uses built-in Windows decompression tools instead of 7zip when - # unpacking the downloaded nupkg. This will be set by default if - # $env:chocolateyUseWindowsCompression is set to a value other than 'false' or '0'. - # - # This parameter will be ignored in PS 5+ in favour of using the - # Expand-Archive built in PowerShell cmdlet directly. - [Parameter(Mandatory = $false)] - [switch] - $UseNativeUnzip = $( - $envVar = "$env:chocolateyUseWindowsCompression".Trim() - $value = $null - if ([bool]::TryParse($envVar, [ref] $value)) { - $value - } elseif ([int]::TryParse($envVar, [ref] $value)) { - [bool]$value - } else { - [bool]$envVar - } - ), - - # If set, ignores any configured proxy. This will override any proxy - # environment variables or parameters. This will be set by default if - # $env:chocolateyIgnoreProxy is set to a value other than 'false' or '0'. - [Parameter(Mandatory = $false)] - [switch] - $IgnoreProxy = $( - $envVar = "$env:chocolateyIgnoreProxy".Trim() - $value = $null - if ([bool]::TryParse($envVar, [ref] $value)) { - $value - } - elseif ([int]::TryParse($envVar, [ref] $value)) { - [bool]$value - } - else { - [bool]$envVar - } - ), - - # Specifies the proxy URL to use during the download. This will default to - # the value of $env:chocolateyProxyLocation, if any is set. - [Parameter(ParameterSetName = 'Proxy', Mandatory = $false)] - [string] - $ProxyUrl = $env:chocolateyProxyLocation, - - # Specifies the credential to use for an authenticated proxy. By default, a - # proxy credential will be constructed from the $env:chocolateyProxyUser and - # $env:chocolateyProxyPassword environment variables, if both are set. - [Parameter(ParameterSetName = 'Proxy', Mandatory = $false)] - [System.Management.Automation.PSCredential] - $ProxyCredential -) - -#region Functions - -function Get-Downloader { - <# - .SYNOPSIS - Gets a System.Net.WebClient that respects relevant proxies to be used for - downloading data. - - .DESCRIPTION - Retrieves a WebClient object that is pre-configured according to specified - environment variables for any proxy and authentication for the proxy. - Proxy information may be omitted if the target URL is considered to be - bypassed by the proxy (originates from the local network.) - - .PARAMETER Url - Target URL that the WebClient will be querying. This URL is not queried by - the function, it is only a reference to determine if a proxy is needed. - - .EXAMPLE - Get-Downloader -Url $fileUrl - - Verifies whether any proxy configuration is needed, and/or whether $fileUrl - is a URL that would need to bypass the proxy, and then outputs the - already-configured WebClient object. - #> - [CmdletBinding()] - param( - [Parameter(Mandatory = $false)] - [string] - $Url, - - [Parameter(Mandatory = $false)] - [string] - $ProxyUrl, - - [Parameter(Mandatory = $false)] - [System.Management.Automation.PSCredential] - $ProxyCredential - ) - - $downloader = New-Object System.Net.WebClient - - $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials - if ($defaultCreds) { - $downloader.Credentials = $defaultCreds - } - - if ($ProxyUrl) { - # Use explicitly set proxy. - Write-Host "Using explicit proxy server '$ProxyUrl'." - $proxy = New-Object System.Net.WebProxy -ArgumentList $ProxyUrl, <# bypassOnLocal: #> $true - - $proxy.Credentials = if ($ProxyCredential) { - $ProxyCredential.GetNetworkCredential() - } elseif ($defaultCreds) { - $defaultCreds - } else { - Write-Warning "Default credentials were null, and no explicitly set proxy credentials were found. Attempting backup method." - (Get-Credential).GetNetworkCredential() - } - - if (-not $proxy.IsBypassed($Url)) { - $downloader.Proxy = $proxy - } - } else { - Write-Host "Not using proxy." - } - - $downloader -} - -function Request-String { - <# - .SYNOPSIS - Downloads content from a remote server as a string. - - .DESCRIPTION - Downloads target string content from a URL and outputs the resulting string. - Any existing proxy that may be in use will be utilised. - - .PARAMETER Url - URL to download string data from. - - .PARAMETER ProxyConfiguration - A hashtable containing proxy parameters (ProxyUrl and ProxyCredential) - - .EXAMPLE - Request-String https://community.chocolatey.org/install.ps1 - - Retrieves the contents of the string data at the targeted URL and outputs - it to the pipeline. - #> - [CmdletBinding()] - param( - [Parameter(Mandatory = $true)] - [string] - $Url, - - [Parameter(Mandatory = $false)] - [hashtable] - $ProxyConfiguration - ) - - (Get-Downloader $url @ProxyConfiguration).DownloadString($url) -} - -function Request-File { - <# - .SYNOPSIS - Downloads a file from a given URL. - - .DESCRIPTION - Downloads a target file from a URL to the specified local path. - Any existing proxy that may be in use will be utilised. - - .PARAMETER Url - URL of the file to download from the remote host. - - .PARAMETER File - Local path for the file to be downloaded to. - - .PARAMETER ProxyConfiguration - A hashtable containing proxy parameters (ProxyUrl and ProxyCredential) - - .EXAMPLE - Request-File -Url https://community.chocolatey.org/install.ps1 -File $targetFile - - Downloads the install.ps1 script to the path specified in $targetFile. - #> - [CmdletBinding()] - param( - [Parameter(Mandatory = $false)] - [string] - $Url, - - [Parameter(Mandatory = $false)] - [string] - $File, - - [Parameter(Mandatory = $false)] - [hashtable] - $ProxyConfiguration - ) - - Write-Host "Downloading $url to $file" - (Get-Downloader $url @ProxyConfiguration).DownloadFile($url, $file) -} - -function Set-PSConsoleWriter { - <# - .SYNOPSIS - Workaround for a bug in output stream handling PS v2 or v3. - - .DESCRIPTION - PowerShell v2/3 caches the output stream. Then it throws errors due to the - FileStream not being what is expected. Fixes "The OS handle's position is - not what FileStream expected. Do not use a handle simultaneously in one - FileStream and in Win32 code or another FileStream." error. - - .EXAMPLE - Set-PSConsoleWriter - - .NOTES - General notes - #> - - [CmdletBinding()] - param() - if ($PSVersionTable.PSVersion.Major -gt 3) { - return - } - - try { - # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments - $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" - $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) - - $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" - $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) - [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) - - $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" - $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) - $field.SetValue($consoleHost, [Console]::Out) - - [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) - $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) - $field2.SetValue($consoleHost, [Console]::Error) - } catch { - Write-Warning "Unable to apply redirection fix." - } -} - -function Test-ChocolateyInstalled { - [CmdletBinding()] - param() - - $checkPath = if ($env:ChocolateyInstall) { $env:ChocolateyInstall } else { "$env:PROGRAMDATA\chocolatey" } - - if ($Command = Get-Command choco -CommandType Application -ErrorAction Ignore) { - # choco is on the PATH, assume it's installed - Write-Warning "'choco' was found at '$($Command.Path)'." - $true - } - elseif (-not (Test-Path $checkPath)) { - # Install folder doesn't exist - $false - } - elseif (-not (Get-ChildItem -Path $checkPath)) { - # Install folder exists but is empty - $false - } - else { - # Install folder exists and is not empty - Write-Warning "Files from a previous installation of Chocolatey were found at '$($CheckPath)'." - $true - } -} - -function Install-7zip { - [CmdletBinding()] - param( - [Parameter(Mandatory = $true)] - [string] - $Path, - - [Parameter(Mandatory = $false)] - [hashtable] - $ProxyConfiguration - ) - - if (-not (Test-Path ($Path))) { - Write-Host "Downloading 7-Zip commandline tool prior to extraction." - Request-File -Url 'https://community.chocolatey.org/7za.exe' -File $Path -ProxyConfiguration $ProxyConfiguration - - } - else { - Write-Host "7zip already present, skipping installation." - } -} - -#endregion Functions - -#region Pre-check - -# Ensure we have all our streams setup correctly, needed for older PSVersions. -Set-PSConsoleWriter - -if (Test-ChocolateyInstalled) { - $message = @( - "An existing Chocolatey installation was detected. Installation will not continue." - "For security reasons, this script will not overwrite existing installations." - "" - "Please use `choco upgrade chocolatey` to handle upgrades of Chocolatey itself." - ) -join [Environment]::NewLine - - Write-Warning $message - - return -} - -#endregion Pre-check - -#region Setup - -$proxyConfig = if ($IgnoreProxy -or -not $ProxyUrl) { - @{} -} else { - $config = @{ - ProxyUrl = $ProxyUrl - } - - if ($ProxyCredential) { - $config['ProxyCredential'] = $ProxyCredential - } elseif ($env:chocolateyProxyUser -and $env:chocolateyProxyPassword) { - $securePass = ConvertTo-SecureString $env:chocolateyProxyPassword -AsPlainText -Force - $config['ProxyCredential'] = [System.Management.Automation.PSCredential]::new($env:chocolateyProxyUser, $securePass) - } - - $config -} - -# Attempt to set highest encryption available for SecurityProtocol. -# PowerShell will not set this by default (until maybe .NET 4.6.x). This -# will typically produce a message for PowerShell v2 (just an info -# message though) -try { - # Set TLS 1.2 (3072) as that is the minimum required by Chocolatey.org. - # Use integers because the enumeration value for TLS 1.2 won't exist - # in .NET 4.0, even though they are addressable if .NET 4.5+ is - # installed (.NET 4.5 is an in-place upgrade). - Write-Host "Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)" - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 -} -catch { - $errorMessage = @( - 'Unable to set PowerShell to use TLS 1.2. This is required for contacting Chocolatey as of 03 FEB 2020.' - 'https://blog.chocolatey.org/2020/01/remove-support-for-old-tls-versions/.' - 'If you see underlying connection closed or trust errors, you may need to do one or more of the following:' - '(1) upgrade to .NET Framework 4.5+ and PowerShell v3+,' - '(2) Call [System.Net.ServicePointManager]::SecurityProtocol = 3072; in PowerShell prior to attempting installation,' - '(3) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally),' - '(4) use the Download + PowerShell method of install.' - 'See https://docs.chocolatey.org/en-us/choco/setup for all install options.' - ) -join [Environment]::NewLine - Write-Warning $errorMessage -} - -if ($ChocolateyDownloadUrl) { - if ($ChocolateyVersion) { - Write-Warning "Ignoring -ChocolateyVersion parameter ($ChocolateyVersion) because -ChocolateyDownloadUrl is set." - } - - Write-Host "Downloading Chocolatey from: $ChocolateyDownloadUrl" -} elseif ($ChocolateyVersion) { - Write-Host "Downloading specific version of Chocolatey: $ChocolateyVersion" - $ChocolateyDownloadUrl = "https://community.chocolatey.org/api/v2/package/chocolatey/$ChocolateyVersion" -} else { - Write-Host "Getting latest version of the Chocolatey package for download." - $queryString = [uri]::EscapeUriString("((Id eq 'chocolatey') and (not IsPrerelease)) and IsLatestVersion") - $queryUrl = 'https://community.chocolatey.org/api/v2/Packages()?$filter={0}' -f $queryString - - [xml]$result = Request-String -Url $queryUrl -ProxyConfiguration $proxyConfig - $ChocolateyDownloadUrl = $result.feed.entry.content.src -} - -if (-not $env:TEMP) { - $env:TEMP = Join-Path $env:SystemDrive -ChildPath 'temp' -} - -$chocoTempDir = Join-Path $env:TEMP -ChildPath "chocolatey" -$tempDir = Join-Path $chocoTempDir -ChildPath "chocoInstall" - -if (-not (Test-Path $tempDir -PathType Container)) { - $null = New-Item -Path $tempDir -ItemType Directory -} - -$file = Join-Path $tempDir "chocolatey.zip" - -#endregion Setup - -#region Download & Extract Chocolatey - -Write-Host "Getting Chocolatey from $ChocolateyDownloadUrl." -Request-File -Url $ChocolateyDownloadUrl -File $file -ProxyConfiguration $proxyConfig - -Write-Host "Extracting $file to $tempDir" -if ($PSVersionTable.PSVersion.Major -lt 5) { - # Determine unzipping method - # 7zip is the most compatible pre-PSv5.1 so use it unless asked to use builtin - if ($UseNativeUnzip) { - Write-Host 'Using built-in compression to unzip' - - try { - $shellApplication = New-Object -ComObject Shell.Application - $zipPackage = $shellApplication.NameSpace($file) - $destinationFolder = $shellApplication.NameSpace($tempDir) - $destinationFolder.CopyHere($zipPackage.Items(), 0x10) - } catch { - Write-Warning "Unable to unzip package using built-in compression. Set `$env:chocolateyUseWindowsCompression = ''` or omit -UseNativeUnzip and retry to use 7zip to unzip." - throw $_ - } - } else { - $7zaExe = Join-Path $tempDir -ChildPath '7za.exe' - Install-7zip -Path $7zaExe -ProxyConfiguration $proxyConfig - - $params = 'x -o"{0}" -bd -y "{1}"' -f $tempDir, $file - - # use more robust Process as compared to Start-Process -Wait (which doesn't - # wait for the process to finish in PowerShell v3) - $process = New-Object System.Diagnostics.Process - - try { - $process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo -ArgumentList $7zaExe, $params - $process.StartInfo.RedirectStandardOutput = $true - $process.StartInfo.UseShellExecute = $false - $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden - - $null = $process.Start() - $process.BeginOutputReadLine() - $process.WaitForExit() - - $exitCode = $process.ExitCode - } - finally { - $process.Dispose() - } - - $errorMessage = "Unable to unzip package using 7zip. Perhaps try setting `$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:" - if ($exitCode -ne 0) { - $errorDetails = switch ($exitCode) { - 1 { "Some files could not be extracted" } - 2 { "7-Zip encountered a fatal error while extracting the files" } - 7 { "7-Zip command line error" } - 8 { "7-Zip out of memory" } - 255 { "Extraction cancelled by the user" } - default { "7-Zip signalled an unknown error (code $exitCode)" } - } - - throw ($errorMessage, $errorDetails -join [Environment]::NewLine) - } - } -} else { - Microsoft.PowerShell.Archive\Expand-Archive -Path $file -DestinationPath $tempDir -Force -} - -#endregion Download & Extract Chocolatey - -#region Install Chocolatey - -Write-Host "Installing Chocolatey on the local machine" -$toolsFolder = Join-Path $tempDir -ChildPath "tools" -$chocoInstallPS1 = Join-Path $toolsFolder -ChildPath "chocolateyInstall.ps1" - -& $chocoInstallPS1 - -Write-Host 'Ensuring Chocolatey commands are on the path' -$chocoInstallVariableName = "ChocolateyInstall" -$chocoPath = [Environment]::GetEnvironmentVariable($chocoInstallVariableName) - -if (-not $chocoPath) { - $chocoPath = "$env:ALLUSERSPROFILE\Chocolatey" -} - -if (-not (Test-Path ($chocoPath))) { - $chocoPath = "$env:PROGRAMDATA\chocolatey" -} - -$chocoExePath = Join-Path $chocoPath -ChildPath 'bin' - -# Update current process PATH environment variable if it needs updating. -if ($env:Path -notlike "*$chocoExePath*") { - $env:Path = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine); -} - -Write-Host 'Ensuring chocolatey.nupkg is in the lib folder' -$chocoPkgDir = Join-Path $chocoPath -ChildPath 'lib\chocolatey' -$nupkg = Join-Path $chocoPkgDir -ChildPath 'chocolatey.nupkg' - -if (-not (Test-Path $chocoPkgDir -PathType Container)) { - $null = New-Item -ItemType Directory -Path $chocoPkgDir -} - -Copy-Item -Path $file -Destination $nupkg -Force -ErrorAction SilentlyContinue - -#endregion Install Chocolatey - -# SIG # Begin signature block -# MIIZvwYJKoZIhvcNAQcCoIIZsDCCGawCAQExDzANBglghkgBZQMEAgEFADB5Bgor -# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG -# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBiXTlbpVQOoJeX -# rGtqATyaDXeEHi6Q2pKb3p02Iq/tc6CCFKgwggT+MIID5qADAgECAhANQkrgvjqI -# /2BAIc4UAPDdMA0GCSqGSIb3DQEBCwUAMHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQK -# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xMTAvBgNV -# BAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJlZCBJRCBUaW1lc3RhbXBpbmcgQ0EwHhcN -# MjEwMTAxMDAwMDAwWhcNMzEwMTA2MDAwMDAwWjBIMQswCQYDVQQGEwJVUzEXMBUG -# A1UEChMORGlnaUNlcnQsIEluYy4xIDAeBgNVBAMTF0RpZ2lDZXJ0IFRpbWVzdGFt -# cCAyMDIxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwuZhhGfFivUN -# CKRFymNrUdc6EUK9CnV1TZS0DFC1JhD+HchvkWsMlucaXEjvROW/m2HNFZFiWrj/ -# ZwucY/02aoH6KfjdK3CF3gIY83htvH35x20JPb5qdofpir34hF0edsnkxnZ2OlPR -# 0dNaNo/Go+EvGzq3YdZz7E5tM4p8XUUtS7FQ5kE6N1aG3JMjjfdQJehk5t3Tjy9X -# tYcg6w6OLNUj2vRNeEbjA4MxKUpcDDGKSoyIxfcwWvkUrxVfbENJCf0mI1P2jWPo -# GqtbsR0wwptpgrTb/FZUvB+hh6u+elsKIC9LCcmVp42y+tZji06lchzun3oBc/gZ -# 1v4NSYS9AQIDAQABo4IBuDCCAbQwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQC -# MAAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwgwQQYDVR0gBDowODA2BglghkgBhv1s -# BwEwKTAnBggrBgEFBQcCARYbaHR0cDovL3d3dy5kaWdpY2VydC5jb20vQ1BTMB8G -# A1UdIwQYMBaAFPS24SAd/imu0uRhpbKiJbLIFzVuMB0GA1UdDgQWBBQ2RIaOpLqw -# Zr68KC0dRDbd42p6vDBxBgNVHR8EajBoMDKgMKAuhixodHRwOi8vY3JsMy5kaWdp -# Y2VydC5jb20vc2hhMi1hc3N1cmVkLXRzLmNybDAyoDCgLoYsaHR0cDovL2NybDQu -# ZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC10cy5jcmwwgYUGCCsGAQUFBwEBBHkw -# dzAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tME8GCCsGAQUF -# BzAChkNodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNlcnRTSEEyQXNz -# dXJlZElEVGltZXN0YW1waW5nQ0EuY3J0MA0GCSqGSIb3DQEBCwUAA4IBAQBIHNy1 -# 6ZojvOca5yAOjmdG/UJyUXQKI0ejq5LSJcRwWb4UoOUngaVNFBUZB3nw0QTDhtk7 -# vf5EAmZN7WmkD/a4cM9i6PVRSnh5Nnont/PnUp+Tp+1DnnvntN1BIon7h6JGA078 -# 9P63ZHdjXyNSaYOC+hpT7ZDMjaEXcw3082U5cEvznNZ6e9oMvD0y0BvL9WH8dQgA -# dryBDvjA4VzPxBFy5xtkSdgimnUVQvUtMjiB2vRgorq0Uvtc4GEkJU+y38kpqHND -# Udq9Y9YfW5v3LhtPEx33Sg1xfpe39D+E68Hjo0mh+s6nv1bPull2YYlffqe0jmd4 -# +TaY4cso2luHpoovMIIFMDCCBBigAwIBAgIQBAkYG1/Vu2Z1U0O1b5VQCDANBgkq -# hkiG9w0BAQsFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5j -# MRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBB -# c3N1cmVkIElEIFJvb3QgQ0EwHhcNMTMxMDIyMTIwMDAwWhcNMjgxMDIyMTIwMDAw -# WjByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQL -# ExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3Vy -# ZWQgSUQgQ29kZSBTaWduaW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -# CgKCAQEA+NOzHH8OEa9ndwfTCzFJGc/Q+0WZsTrbRPV/5aid2zLXcep2nQUut4/6 -# kkPApfmJ1DcZ17aq8JyGpdglrA55KDp+6dFn08b7KSfH03sjlOSRI5aQd4L5oYQj -# ZhJUM1B0sSgmuyRpwsJS8hRniolF1C2ho+mILCCVrhxKhwjfDPXiTWAYvqrEsq5w -# MWYzcT6scKKrzn/pfMuSoeU7MRzP6vIK5Fe7SrXpdOYr/mzLfnQ5Ng2Q7+S1TqSp -# 6moKq4TzrGdOtcT3jNEgJSPrCGQ+UpbB8g8S9MWOD8Gi6CxR93O8vYWxYoNzQYIH -# 5DiLanMg0A9kczyen6Yzqf0Z3yWT0QIDAQABo4IBzTCCAckwEgYDVR0TAQH/BAgw -# BgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwEwYDVR0lBAwwCgYIKwYBBQUHAwMweQYI -# KwYBBQUHAQEEbTBrMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j -# b20wQwYIKwYBBQUHMAKGN2h0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdp -# Q2VydEFzc3VyZWRJRFJvb3RDQS5jcnQwgYEGA1UdHwR6MHgwOqA4oDaGNGh0dHA6 -# Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJRFJvb3RDQS5jcmww -# OqA4oDaGNGh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJ -# RFJvb3RDQS5jcmwwTwYDVR0gBEgwRjA4BgpghkgBhv1sAAIEMCowKAYIKwYBBQUH -# AgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCgYIYIZIAYb9bAMwHQYD -# VR0OBBYEFFrEuXsqCqOl6nEDwGD5LfZldQ5YMB8GA1UdIwQYMBaAFEXroq/0ksuC -# MS1Ri6enIZ3zbcgPMA0GCSqGSIb3DQEBCwUAA4IBAQA+7A1aJLPzItEVyCx8JSl2 -# qB1dHC06GsTvMGHXfgtg/cM9D8Svi/3vKt8gVTew4fbRknUPUbRupY5a4l4kgU4Q -# pO4/cY5jDhNLrddfRHnzNhQGivecRk5c/5CxGwcOkRX7uq+1UcKNJK4kxscnKqEp -# KBo6cSgCPC6Ro8AlEeKcFEehemhor5unXCBc2XGxDI+7qPjFEmifz0DLQESlE/Dm -# ZAwlCEIysjaKJAL+L3J+HNdJRZboWR3p+nRka7LrZkPas7CM1ekN3fYBIM6ZMWM9 -# CBoYs4GbT8aTEAb8B4H6i9r5gkn3Ym6hU/oSlBiFLpKR6mhsRDKyZqHnGKSaZFHv -# MIIFMTCCBBmgAwIBAgIQCqEl1tYyG35B5AXaNpfCFTANBgkqhkiG9w0BAQsFADBl -# MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 -# d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv -# b3QgQ0EwHhcNMTYwMTA3MTIwMDAwWhcNMzEwMTA3MTIwMDAwWjByMQswCQYDVQQG -# EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl -# cnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3VyZWQgSUQgVGltZXN0 -# YW1waW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvdAy7kvN -# j3/dqbqCmcU5VChXtiNKxA4HRTNREH3Q+X1NaH7ntqD0jbOI5Je/YyGQmL8TvFfT -# w+F+CNZqFAA49y4eO+7MpvYyWf5fZT/gm+vjRkcGGlV+Cyd+wKL1oODeIj8O/36V -# +/OjuiI+GKwR5PCZA207hXwJ0+5dyJoLVOOoCXFr4M8iEA91z3FyTgqt30A6XLdR -# 4aF5FMZNJCMwXbzsPGBqrC8HzP3w6kfZiFBe/WZuVmEnKYmEUeaC50ZQ/ZQqLKfk -# dT66mA+Ef58xFNat1fJky3seBdCEGXIX8RcG7z3N1k3vBkL9olMqT4UdxB08r8/a -# rBD13ays6Vb/kwIDAQABo4IBzjCCAcowHQYDVR0OBBYEFPS24SAd/imu0uRhpbKi -# JbLIFzVuMB8GA1UdIwQYMBaAFEXroq/0ksuCMS1Ri6enIZ3zbcgPMBIGA1UdEwEB -# /wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMBMGA1UdJQQMMAoGCCsGAQUFBwMI -# MHkGCCsGAQUFBwEBBG0wazAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNl -# cnQuY29tMEMGCCsGAQUFBzAChjdodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20v -# RGlnaUNlcnRBc3N1cmVkSURSb290Q0EuY3J0MIGBBgNVHR8EejB4MDqgOKA2hjRo -# dHRwOi8vY3JsNC5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1cmVkSURSb290Q0Eu -# Y3JsMDqgOKA2hjRodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1 -# cmVkSURSb290Q0EuY3JsMFAGA1UdIARJMEcwOAYKYIZIAYb9bAACBDAqMCgGCCsG -# AQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAsGCWCGSAGG/WwH -# ATANBgkqhkiG9w0BAQsFAAOCAQEAcZUS6VGHVmnN793afKpjerN4zwY3QITvS4S/ -# ys8DAv3Fp8MOIEIsr3fzKx8MIVoqtwU0HWqumfgnoma/Capg33akOpMP+LLR2HwZ -# YuhegiUexLoceywh4tZbLBQ1QwRostt1AuByx5jWPGTlH0gQGF+JOGFNYkYkh2OM -# kVIsrymJ5Xgf1gsUpYDXEkdws3XVk4WTfraSZ/tTYYmo9WuWwPRYaQ18yAGxuSh1 -# t5ljhSKMYcp5lH5Z/IwP42+1ASa2bKXuh1Eh5Fhgm7oMLSttosR+u8QlK0cCCHxJ -# rhO24XxCQijGGFbPQTS2Zl22dHv1VjMiLyI2skuiSpXY9aaOUjCCBTkwggQhoAMC -# AQICEAq50xD7ISvojIGz0sLozlEwDQYJKoZIhvcNAQELBQAwcjELMAkGA1UEBhMC -# VVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3LmRpZ2ljZXJ0 -# LmNvbTExMC8GA1UEAxMoRGlnaUNlcnQgU0hBMiBBc3N1cmVkIElEIENvZGUgU2ln -# bmluZyBDQTAeFw0yMTA0MjcwMDAwMDBaFw0yNDA0MzAyMzU5NTlaMHcxCzAJBgNV -# BAYTAlVTMQ8wDQYDVQQIEwZLYW5zYXMxDzANBgNVBAcTBlRvcGVrYTEiMCAGA1UE -# ChMZQ2hvY29sYXRleSBTb2Z0d2FyZSwgSW5jLjEiMCAGA1UEAxMZQ2hvY29sYXRl -# eSBTb2Z0d2FyZSwgSW5jLjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB -# AKFxp42p47c7eHNsNhgxzG+/9A1I8Th+kj40YQJH4Vh0M7a61f39I/FELNYGuyCe -# 0+z/sg+T+4VmT/JMiI2hc75yokTjkv3Yt1+fqABzCMadr+PZ/9ttIVJ5db3P2Uzc -# Ml5wXBdCV5ZH/w4oKcP53VmYcHQEDm/RtAJ9TxlPtLS734oAqrKqBmsnJCI98FWp -# d6z1FK5rv7RJVeZoGsl/2eMcB/ko0Vj9MSCbWvXNjDF9yy4Tl5h2vb+y7K1Qmk3X -# yb0OYB1ibva9rQozGgogEa5DL0OdoMj6cyJ6Cx2GQv2wjKwiKfs9zCOTDH2VGa0i -# okDbsd+BvUxovQ6eSnBFj5UCAwEAAaOCAcQwggHAMB8GA1UdIwQYMBaAFFrEuXsq -# CqOl6nEDwGD5LfZldQ5YMB0GA1UdDgQWBBRO8wUYXZXrKVBqUW35p9FeNJoEgzAO -# BgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwdwYDVR0fBHAwbjA1 -# oDOgMYYvaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC1jcy1n -# MS5jcmwwNaAzoDGGL2h0dHA6Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9zaGEyLWFzc3Vy -# ZWQtY3MtZzEuY3JsMEsGA1UdIAREMEIwNgYJYIZIAYb9bAMBMCkwJwYIKwYBBQUH -# AgEWG2h0dHA6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAIBgZngQwBBAEwgYQGCCsG -# AQUFBwEBBHgwdjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29t -# ME4GCCsGAQUFBzAChkJodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNl -# cnRTSEEyQXNzdXJlZElEQ29kZVNpZ25pbmdDQS5jcnQwDAYDVR0TAQH/BAIwADAN -# BgkqhkiG9w0BAQsFAAOCAQEAoXGdwcDMMV6xQldozbWoxGTn6chlwO4hJ8aAlwOM -# wexEvDudrlifsiGI1j46wqc9WR8+Ev8w1dIcbqif4inGIHb8GvL22Goq+lB08F7y -# YU3Ry0kOCtJx7JELlID0SI7bYndg17TJUQoAb5iTYD9aEoHMIKlGyQyVGvsp4ubo -# O8CC8Owx+Qq148yXY+to4360U2lzZvUtMpPiiSJTm4BamNgC32xgGwpN5lvk0m3R -# lDdqQQQgBCzrf+ZIMBmXMw4kxY0r/K/g1TkKI9VyiEnRaNQlQisAyYBWVnaHw2EJ -# ck6/bxwdYSA+Sz/Op0N0iEl8MX4At3XQlMGvAI1xhAbrwDGCBG0wggRpAgEBMIGG -# MHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsT -# EHd3dy5kaWdpY2VydC5jb20xMTAvBgNVBAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJl -# ZCBJRCBDb2RlIFNpZ25pbmcgQ0ECEAq50xD7ISvojIGz0sLozlEwDQYJYIZIAWUD -# BAIBBQCggYQwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx -# DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAvBgkq -# hkiG9w0BCQQxIgQgey25OsHafMX1HWLKRJb0Sf/lMMX5vF0EAhjyQlfUDzgwDQYJ -# KoZIhvcNAQEBBQAEggEAC0wtyHWaoYbiMY8PXKaNf16zoeuj5jYAuvx0B/nzJ27A -# tP/Mo9SC1Z4M2iEps/LDScRoy3N8pCI8NQBDjWGGkjW5ScFvF7a042DcurR+LE30 -# aa4d7Y0MT8O+vhQDcVCmB7JB+9E6/7+qpD1vVfs1zYw1cprCZoOejttDCEvlvsAN -# VrPKixhxbLcLu/5KV9qUBUWW9vEz8/WL1IcNcsfwd61+JWa116CXeyoLKqWXJIPF -# uNnULZTs/E2BY1JYBKIfzvSi3QWg/uWvJucdGdbLib4d1gEXxLtHk+aDOLTXRG12 -# yjMdCF1FhyeC+hyWSgwyXZ0V9zRGpiS+IjarelHVDqGCAjAwggIsBgkqhkiG9w0B -# CQYxggIdMIICGQIBATCBhjByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNl -# cnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdp -# Q2VydCBTSEEyIEFzc3VyZWQgSUQgVGltZXN0YW1waW5nIENBAhANQkrgvjqI/2BA -# Ic4UAPDdMA0GCWCGSAFlAwQCAQUAoGkwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEH -# ATAcBgkqhkiG9w0BCQUxDxcNMjEwNjE3MDg0MjQzWjAvBgkqhkiG9w0BCQQxIgQg -# Osdf/2XOopSIGgniCq9vRS6UGDVJ7TingAmrcmwYcWowDQYJKoZIhvcNAQEBBQAE -# ggEAs50N1tQOpzvCCO9R4hCcaMY0jsOm7QOOk257yySmEFbtgmKUpNmyyfwK0Wl/ -# Ti1IOTOQ1oz7Wz6Q/kEgPoZAbuAhXKH+At6Vwa98Jp3GG6abokNohPI3cWGJbS3u -# rJEKZay3+1fGNaYOCpIqkhpnVqyTNoLlNBLcGOkq7FgBKsomtQSO9ejFluS1woKY -# wK7EiXjzDwFG18DmnUuRpO4xrdmcbh7m3MnC95DjYcFFzKr/xxideicJAGZSHOo1 -# nQorVQyPcXQe4Nl2JHAr3R6RTeaXgq6We4LSdMsO5BAyduh/w4nicahwAv5wgIsw -# cUvCYQiMMXCU2x9vsn8B5wKETQ== -# SIG # End signature block diff --git a/helper-iso-files/scripts/disable-mouse-acceleration.ps1 b/helper-iso-files/scripts/disable-mouse-acceleration.ps1 new file mode 100644 index 0000000..f2bb08b --- /dev/null +++ b/helper-iso-files/scripts/disable-mouse-acceleration.ps1 @@ -0,0 +1,7 @@ +$code=@' +[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] + public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, int[] pvParam, uint fWinIni); +'@ +Add-Type $code -name Win32 -NameSpace System + +[System.Win32]::SystemParametersInfo(4,0,0,2) \ No newline at end of file diff --git a/helper-iso-files/scripts/gpu-check.ps1 b/helper-iso-files/scripts/gpu-check.ps1 index a41d114..62342ff 100644 --- a/helper-iso-files/scripts/gpu-check.ps1 +++ b/helper-iso-files/scripts/gpu-check.ps1 @@ -15,39 +15,64 @@ Add-Type -AssemblyName PresentationFramework $driverlessGpus = Get-WmiObject -Class Win32_PnpEntity -ComputerName localhost -Namespace Root\CIMV2 | Where-Object {$_.ConfigManagerErrorCode -gt 0 } | Format-Table $result -AutoSize | findstr -i "Video Controller" | findstr -i " 28 " -if ($driverlessGpus -like '*VEN_1002*') { - Write-Host 'AMD GPU driver missing' - Write-Host 'Automatically installing AMD GPU drivers is not supported.' - [System.Windows.MessageBox]::Show("Please install the AMD GPU driver! AMD and Chocolatey unfortunately don't offer a way to do this automatically!", "MobilePassThrough - GPU Driver is missing") +if ($driverlessGpus -like '*VEN_8086*') { + Write-Host 'Intel GPU driver missing' + try { + Write-Host 'Installing the Intel Graphics driver...' + choco install intel-graphics-driver + #Write-Host 'Automatic GPU driver installation not implemented yet. Please install the Intel Graphics driver manually!' + #[System.Windows.MessageBox]::Show('Automatic GPU driver installation not implemented yet. Please install the Intel Graphics driver manually!', "MobilePassThrough - Missing GPU driver") + } + catch { + #If ($Args -ne "unattended") { + # [System.Windows.MessageBox]::Show('Failed to automatically install Intel Graphics driver using chocolatey!', "MobilePassThrough - driver installation failed") + #} + #Write-Host 'Failed to automatically install Intel Graphics driver using chocolatey!' + } } if ($driverlessGpus -like '*VEN_10DE*') { Write-Host 'Nvidia GPU driver missing' try { - #choco install nvidia-display-driver - Write-Host 'Automatic GPU driver installation not implemented yet. Please install the Nvidia Display driver manually!' - [System.Windows.MessageBox]::Show('Automatic GPU driver installation not implemented yet. Please install the Nvidia Display driver manually!', "MobilePassThrough - Missing GPU driver") + Write-Host 'Installing the Nvidia Display driver...' + choco install nvidia-display-driver + #Write-Host 'Automatic GPU driver installation not implemented yet. Please install the Nvidia Display driver manually!' + #[System.Windows.MessageBox]::Show('Automatic GPU driver installation not implemented yet. Please install the Nvidia Display driver manually!', "MobilePassThrough - Missing GPU driver") } catch { - [System.Windows.MessageBox]::Show('Failed to automatically install Nvidia Display driver using chocolatey!', "MobilePassThrough - driver installation failed") + #If ($Args -ne "unattended") { + # [System.Windows.MessageBox]::Show('Failed to automatically install Nvidia Display driver using chocolatey!', "MobilePassThrough - driver installation failed") + #} } } -if ($driverlessGpus -like '*VEN_8086*') { - Write-Host 'Intel GPU driver missing' - try { - #choco install intel-graphics-driver - Write-Host 'Automatic GPU driver installation not implemented yet. Please install the Intel Graphics driver manually!' - [System.Windows.MessageBox]::Show('Automatic GPU driver installation not implemented yet. Please install the Intel Graphics driver manually!', "MobilePassThrough - Missing GPU driver") - +if ($driverlessGpus -like '*VEN_1002*') { + Write-Host 'AMD GPU driver missing' + Write-Host 'Automatically installing AMD GPU drivers is not supported.' + + If ($Args -ne "unattended") { + [System.Windows.MessageBox]::Show("Please install the AMD GPU driver! AMD and Chocolatey unfortunately don't offer a way to do this automatically!", "MobilePassThrough - GPU Driver is missing") } - catch { +} + +$driverlessGpus = Get-WmiObject -Class Win32_PnpEntity -ComputerName localhost -Namespace Root\CIMV2 | Where-Object {$_.ConfigManagerErrorCode -gt 0 } | Format-Table $result -AutoSize | findstr -i "Video Controller" | findstr -i " 28 " +if ($driverlessGpus -like '*VEN_8086*') { + Write-Host 'Failed to automatically install Intel Graphics driver using chocolatey!' + If ($Args -ne "unattended") { [System.Windows.MessageBox]::Show('Failed to automatically install Intel Graphics driver using chocolatey!', "MobilePassThrough - driver installation failed") } } +if ($driverlessGpus -like '*VEN_10DE*') { + Write-Host 'Failed to automatically install Nvidia Display driver using chocolatey!' + If ($Args -ne "unattended") { + [System.Windows.MessageBox]::Show('Failed to automatically install Nvidia Display driver using chocolatey!', "MobilePassThrough - driver installation failed") + } +} $error43Devices = Get-WmiObject -Class Win32_PnpEntity -ComputerName localhost -Namespace Root\CIMV2 | Where-Object {$_.ConfigManagerErrorCode -gt 0 } | Format-Table $result -AutoSize | findstr -i "Video Controller" | findstr -i " 43 " if ($error43Devices) { Write-Host 'Error 43 detected:' Write-Host $error43Devices - [System.Windows.MessageBox]::Show($error43Devices, "MobilePassThrough - Detected Error 43") + If ($Args -ne "unattended") { + [System.Windows.MessageBox]::Show($error43Devices, "MobilePassThrough - Detected Error 43") + } } diff --git a/helper-iso-files/scripts/mbpt-startup.bat b/helper-iso-files/scripts/mbpt-startup.bat new file mode 100644 index 0000000..ae08cc4 --- /dev/null +++ b/helper-iso-files/scripts/mbpt-startup.bat @@ -0,0 +1 @@ +powershell -executionpolicy unrestricted -file %APPDATA%\mbpt\gpu-check.ps1 \ No newline at end of file diff --git a/live-iso-files/get-mbpt.sh b/live-iso-files/get-mbpt.sh index 5b0e091..19ceb74 100755 --- a/live-iso-files/get-mbpt.sh +++ b/live-iso-files/get-mbpt.sh @@ -17,7 +17,9 @@ while sleep 1; do MBPT_BASE_PATH="$(echo "${mountpoint}/mbpt" | tr -s '/')" break elif [[ $availableSpace -ge $REQUIRED_DISK_SPACE ]]; then - if sudo fallocate -l "${REQUIRED_DISK_SPACE}G" "${mountpoint}/size_test.bin" &> /dev/null; then + # Test if the device can handle big files (FAT32 for example can't) + #if sudo fallocate -l "${REQUIRED_DISK_SPACE}G" "${mountpoint}/size_test.bin" &> /dev/null; then + if sudo dd if=/dev/zero of="${mountpoint}/size_test.bin" bs="${REQUIRED_DISK_SPACE}G" seek=60 count=0 &> /dev/null; then sudo rm -f "${mountpoint}/_size_test.bin" MBPT_BASE_PATH="$(echo "${mountpoint}/mbpt" | tr -s '/')" break @@ -68,7 +70,13 @@ fi cd MobilePassThrough echo "> Running MobilePassThrough compatibility check..." ./mbpt.sh check -echo "> Waiting for 10 seconds before continuing..." +if [ $? -eq 0 ]; then + echo "> Waiting for 10 seconds before continuing..." + sleep 10 +else + echo "> Waiting for 30 seconds before continuing..." + sleep 30 +fi echo "> Starting MobilePassThrough in auto mode..." ./mbpt.sh auto diff --git a/requirements.sh b/requirements.sh index 63ee97e..7a821a2 100644 --- a/requirements.sh +++ b/requirements.sh @@ -35,7 +35,7 @@ EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") # git moby-engine EXEC_DEPS_GENERATE_CONFIG=("crudini") # crudini EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") # git wget curl-minimal unzip ruby rubygems rubygem-bundler p7zip make innoextract upx FILE_DEPS_VBIOS_FINDER=("/usr/include/rub*/ruby.h") # ruby-devel -EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat") # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat +EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat" "fdisk" "dd") # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat coreutils util-linux FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd" "/usr/share/libvirt/networks/default.xml") # edk2-ovmf libvirt-daemon-config-network EXEC_DEPS_RDP=("remmina") # remmina EXEC_DEPS_SAMBA=("samba") # samba diff --git a/scripts/main/generate-helper-iso.sh b/scripts/main/generate-helper-iso.sh index b108c57..837c54b 100755 --- a/scripts/main/generate-helper-iso.sh +++ b/scripts/main/generate-helper-iso.sh @@ -28,6 +28,22 @@ else echo "> Visual C++ Redistributable Package 2017 x64 already exist in iso folder..." fi +if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/spice-guest-tools.exe" ]; then + echo "> Downloading Spice Guest Tools..." + wget "https://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-0.141/spice-guest-tools-0.141.exe" -O "${HELPER_ISO_FILES_DIR}/bin/spice-guest-tools.exe" +else + echo "> Spice Guest Tools already exists in iso folder..." +fi + +if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/spice-webdavd.msi" ]; then + echo "> Downloading Spice WebDAV daemon..." + wget "https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x64-2.4.msi" -O "${HELPER_ISO_FILES_DIR}/bin/spice-webdavd.msi" +else + echo "> Spice WebDAV daemon already exists in iso folder..." +fi + +https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x64-2.4.msi + if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host-setup.exe" ]; then #echo "> Downloading Looking Glass Host application..." #wget "https://github.com/gnif/LookingGlass/releases/download/${LOOKING_GLASS_VERSION}/looking-glass-host.exe" -O "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host.exe" diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh index 9d271dc..a6e2b81 100755 --- a/scripts/main/generate-live-iso.sh +++ b/scripts/main/generate-live-iso.sh @@ -169,7 +169,7 @@ function flash() { sudo umount --force "$mp" done <<< "$mps" fi - yes "" | sudo livecd-iso-to-disk --format ext4 --efi --force --overlay-size-mb 8000 --extra-kernel-args "$ALL_KERNEL_PARAMS" "${ISO_FILE_MODIFIED}" "$DRIVE" + yes "" | sudo livecd-iso-to-disk --format ext4 --efi --force --extra-kernel-args "$ALL_KERNEL_PARAMS" "${ISO_FILE_MODIFIED}" "$DRIVE" } if [ "$MODE" = "flash" ]; then diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 817753d..e6f3488 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -167,8 +167,8 @@ else echo "> [Skipped] Windows ISO has already been downloaded." fi -if [[ "$(sudo docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then - echo "> Building 'ovmf-vbios-patch' Docker Image..." +if [[ "$(sudo docker images -q tavk/ovmf-vbios-patch:1.0.1-edk2-stable201905 2> /dev/null)" == "" ]]; then + echo "> Installing 'ovmf-vbios-patch' Docker Image..." ovmfVbiosPatchSetup else echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built." diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 71a7d48..e3b9f23 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -8,10 +8,17 @@ loadConfig # or start the previously created Windows VM, if called like this: `./vm.sh` ##################################################################################################### +echo "> Action: $1" if [ "$1" = "install" ]; then VM_INSTALL=true elif [ "$1" = "start" ]; then VM_INSTALL=false +elif [ "$1" = "stop" ]; then + if [ "$VM_START_MODE" = "virt-install" ]; then + sudo virsh destroy --domain "${VM_NAME}" + elif [ "$VM_START_MODE" = "qemu" ]; then + killall qemu-system-x86_64 + fi elif [ "$1" = "auto" ]; then if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then VM_INSTALL=false @@ -22,8 +29,8 @@ elif [ "$1" = "remove" ]; then if [ "$VM_START_MODE" = "virt-install" ]; then sudo virsh destroy --domain "${VM_NAME}" sudo virsh undefine --domain "${VM_NAME}" --nvram - #elif [ "$VM_START_MODE" = "qemu" ]; then - # + elif [ "$VM_START_MODE" = "qemu" ]; then + killall qemu-system-x86_64 fi if [[ ${DRIVE_IMG} == *.img ]]; then sudo rm -f "${DRIVE_IMG}" @@ -35,6 +42,8 @@ else exit 1 fi +echo "> Start mode: $VM_START_MODE" + GET_XML=false DRY_RUN=false if [ "$1" = "install" ] || [ "$1" = "start" ]; then @@ -82,6 +91,15 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./features/hyperv/vendor_id/@state=on" "--xml" "xpath.set=./features/hyperv/vendor_id/@value='12alphanum'") fi +if [ "$CPU_CORE_COUNT" = "auto" ]; then + AVAILABLE_CPU_CORE_COUNT="$(nproc)" + CPU_CORE_COUNT="$((AVAILABLE_CPU_CORE_COUNT-1))" + if [[ $CPU_CORE_COUNT -gt 16 ]]; then + CPU_CORE_COUNT=16 + fi +fi + +echo "> Using ${CPU_CORE_COUNT} CPU cores..." if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-smp" "${CPU_CORE_COUNT}") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -90,9 +108,15 @@ fi if [ "$RAM_SIZE" = "auto" ]; then FREE_RAM="$(free -g | grep 'Mem: ' | tr -s ' ' | cut -d ' ' -f4)" - RAM_SIZE="$((FREE_RAM-2))G" + RAM_SIZE_GB="$((FREE_RAM-1))" + if [[ $RAM_SIZE_GB -gt 16 ]]; then + RAM_SIZE_GB=16 + fi + RAM_SIZE="${RAM_SIZE_GB}G" fi + +echo "> Using ${RAM_SIZE} of RAM..." if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-m" "${RAM_SIZE}") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -126,14 +150,27 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") fi -if [ "$VM_START_MODE" = "virt-install" ]; then - if ! sudo virsh net-list | grep default | grep --quiet active; then - sudo virsh net-start default - fi +if ! sudo virsh net-list | grep default | grep --quiet active; then + sudo virsh net-start default +fi + +INTERFACE_NAME="$(sudo cat /var/lib/libvirt/dnsmasq/default.conf | grep "^interface=" | cut -d'=' -f2-)" +NETWORK="$(sudo ip route | grep " ${INTERFACE_NAME} " | cut -d' ' -f1)" + +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-net" "nic,model=e1000,macaddr=${MAC_ADDRESS}" "-net" "bridge,br=virbr0") + #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") + #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") + #-net user,hostfwd=tcp::13389-:3389 -net nic +elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--network" "network=default,model=e1000,mac=${MAC_ADDRESS}") + #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[type=network]/mac@address='${MAC_ADDRESS}'") + #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[0]/source@network=default") + #if ! sudo virsh net-list | grep default | grep --quiet active; then + # sudo virsh net-start default + #fi fi -#QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") -#QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") QEMU_PARAMS+=("-device" "ich9-intel-hda") QEMU_PARAMS+=("-device" "hda-output") QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") @@ -201,7 +238,7 @@ if [ "$USE_LOOKING_GLASS" = true ]; then BUFFER_SIZE=$(($BUFFER_SIZE*2)) done LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}" - echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}" + echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}MB" if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}M") @@ -354,10 +391,10 @@ if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then fi if [ -z "$IGPU_ROM" ]; then - echo "> Not using IGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" + echo "> Not using iGPU vBIOS override..." + #IGPU_ROM_PARAM=",rom.bar=on" else - echo "> Using IGPU vBIOS override..." + echo "> Using iGPU vBIOS override..." IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" fi @@ -374,7 +411,7 @@ if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then fi if [ -z "$IGPU_ROM" ]; then - echo "> Not using IGPU vBIOS override..." + echo "> Not using iGPU vBIOS override..." IGPU_ROM_PARAM=",rom.bar=on" fi VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") @@ -382,7 +419,7 @@ if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") if [ ! -z "$IGPU_ROM" ]; then - echo "> Using IGPU vBIOS override..." + echo "> Using iGPU vBIOS override..." VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") fi fi @@ -410,7 +447,8 @@ fi if [ "$USE_QXL" = true ]; then echo "> Using QXL..." if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "qxl,bus=pcie.0,addr=1c.4,id=video.2" "-vga" "qxl") + QEMU_PARAMS+=("-device" "qxl,bus=pcie.0,addr=1c.4,id=video.2") + #QEMU_PARAMS+=("-vga" "qxl") elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--video" "qxl") fi @@ -496,30 +534,42 @@ else echo "> Not using virtual input method for keyboard/mouse input..." fi -#give_qemu_access() { -# local skip_root=true -# local -a paths -# IFS=/ read -r -a paths <<<"$1" -# local i -# for (( i = 1; i < ${#paths[@]}; i++ )); do -# paths[i]="${paths[i-1]}/${paths[i]}" -# done -# paths[0]=/ -# for current_path in "${paths[@]}" ; do -# if [ "$skip_root" = true ] && [ "${current_path}" = "/" ]; then -# continue -# fi -# echo "> Granting qemu access to: '${current_path}'" -# sudo setfacl --modify user:qemu:rx "${current_path}" -# sudo chmod +x "${current_path}" -# done -# #sudo chmod 777 "$1" -#} - -#give_qemu_access "${INSTALL_IMG}" - -#sudo bash -c "echo 'user = root' >> /etc/libvirt/qemu.conf" -#sudo systemctl restart libvirtd +RDP_USER=Administrator +RDP_PASSWORD=admin + +# Run it once because the first time it prints a useless message instead of actually encrypting +echo "$RDP_PASSWORD" | remmina --encrypt-password &> /dev/null + +# Run it again, hoping it always works the second time +RDP_PASSWORD_ENCRYPTED="$(echo "$RDP_PASSWORD" | remmina --encrypt-password | grep 'Encrypted password: ' | cut -d':' -f2- | tr -d ' ')" + +function autoConnectRdp() { + while true; do + VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" + if [ "$VM_IP" != "" ]; then + echo "" + echo "> The IP address of the VM is: ${VM_IP}" + echo "" + echo "> Waiting for RDP to be available in the VM..." + while true; do + if nc -vz "$VM_IP" 3389 &> /dev/null; then + echo "> Opening Remmina to start an RDP connection with the VM..." + remmina -c "rdp://${RDP_USER}:${RDP_PASSWORD_ENCRYPTED}@${VM_IP}" &> /dev/null & + #if [ "$USE_LOOKING_GLASS" = true ]; then + # echo "> Starting the Looking Glass client..." + # sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]' & + #fi + break + fi + done + break + fi + sleep 1 + done +} + +#echo "> Starting RDP autoconnect background task..." +#autoConnectRdp & if [ "$VM_INSTALL" = true ]; then echo "> Deleting VM if it already exists..." @@ -527,6 +577,16 @@ if [ "$VM_INSTALL" = true ]; then sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null fi + + +if [ "$USE_SPICE_CLIENT" = "auto" ] && [ "$USE_SPICE" = true ]; then + if [ "$VM_INSTALL" = true ]; then + USE_SPICE_CLIENT=true + elif [ "$USE_LOOKING_GLASS" = true ]; then + USE_SPICE_CLIENT=false + fi +fi + if [ "$DRY_RUN" = false ] && [ "$VM_INSTALL" = true ]; then echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." fi @@ -538,8 +598,10 @@ if [ "$VM_START_MODE" = "qemu" ]; then bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & fi - echo "> Starting the spice client @localhost:${SPICE_PORT}..." - bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & + if [ "$USE_SPICE_CLIENT" = true ]; then + echo "> Starting the spice client at localhost:${SPICE_PORT}..." + bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & + fi echo "> Starting the Virtual Machine using qemu..." fi @@ -593,8 +655,10 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then elif [ "$GET_XML" = true ]; then VIRT_INSTALL_PARAMS+=("--print-xml") sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" - else + elif [ "$VM_INSTALL" = true ]; then sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + elif [ "$VM_INSTALL" = false ]; then + sudo virsh start "${VM_NAME}" fi #else # if [ "$DRY_RUN" = true ]; then @@ -612,7 +676,7 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then echo "> Unbinding dGPU from vfio driver..." driver unbind "${DGPU_PCI_ADDRESS}" - if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nuveau" ]; then + if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nouveau" ]; then echo "> Turn the dGPU off using bumblebee..." sudo bash -c "echo 'OFF' >> /proc/acpi/bbswitch" fi @@ -621,7 +685,7 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then fi -if [ "$SHARE_IGPU" = true ]; then +if [ "$VGPU_UUID" != "" ]; then echo "> Keeping Intel vGPU for next VM start..." # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. @@ -629,4 +693,13 @@ if [ "$SHARE_IGPU" = true ]; then #echo "> Remove Intel vGPU..." #vgpu remove "${IGPU_PCI_ADDRESS}" "${VGPU_UUID}" +fi + +if [ "$VM_INSTALL" = true ]; then + if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then + exit 0 + else + echo "> [Error] Seems like the installation failed..." + exit 1 + fi fi \ No newline at end of file From 708e580e467ce5e8c37bcff9ee21a0c28c785767 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Mon, 23 Aug 2021 18:45:10 +0200 Subject: [PATCH 28/40] Fix auto dGPU selection --- scripts/main/vm.sh | 136 ++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index e3b9f23..6c221fb 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -91,6 +91,11 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./features/hyperv/vendor_id/@state=on" "--xml" "xpath.set=./features/hyperv/vendor_id/@value='12alphanum'") fi +if [ "$MAC_ADDRESS" = "auto" ]; then + MAC_ADDRESS=$(printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))) +fi +echo "> Using MAC address: ${MAC_ADDRESS}..." + if [ "$CPU_CORE_COUNT" = "auto" ]; then AVAILABLE_CPU_CORE_COUNT="$(nproc)" CPU_CORE_COUNT="$((AVAILABLE_CPU_CORE_COUNT-1))" @@ -115,7 +120,6 @@ if [ "$RAM_SIZE" = "auto" ]; then RAM_SIZE="${RAM_SIZE_GB}G" fi - echo "> Using ${RAM_SIZE} of RAM..." if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-m" "${RAM_SIZE}") @@ -262,14 +266,12 @@ else QEMU_PARAMS+=("-net" "user,smb=${SMB_SHARE_FOLDER}") fi -if [ "$DGPU_PASSTHROUGH" = true ]; then - echo "> Using dGPU passthrough..." - +if [ "$DGPU_PASSTHROUGH" != false ]; then + availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" if [ "$DGPU_PCI_ADDRESS" = "auto" ]; then - availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" - + DGPU_PCI_ADDRESS="" while IFS= read -r pciAddress; do - gpuId="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" + gpuInfo="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" if [[ "$gpuInfo" != *"Intel"* ]]; then DGPU_PCI_ADDRESS="$pciAddress" break @@ -277,67 +279,75 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then done <<< "$availableGpusIds" fi - if [ "$HOST_DGPU_DRIVER" = "auto" ]; then - HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" - fi + if [ "$(echo -e "$availableGpusIds" | wc -l)" -le 1 ]; then + echo "> Not using dGPU passthrough because single GPU passthrough is not supported yet..." + if [ "$DGPU_PCI_ADDRESS" != "" ]; then + echo "> Using dGPU passthrough..." - echo "> dGPU is: '$DGPU_PCI_ADDRESS' with driver '$HOST_DGPU_DRIVER'" - - echo "> Retrieving and parsing DGPU IDs..." - DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) - DGPU_VENDOR_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f1) - DGPU_DEVICE_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f2) - DGPU_SS_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -vnn -d "${DGPU_IDS}" | grep "Subsystem:" | grep -oP "\w+:\w+") - DGPU_SS_VENDOR_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f1) - DGPU_SS_DEVICE_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f2) - - if [ -z "$DGPU_IDS" ]; then - echo "> Error: Failed to retrieve DGPU IDs!" - echo "> DGPU_PCI_ADDRESS: ${DGPU_PCI_ADDRESS}" - echo "> DGPU_IDS: $DGPU_IDS" - echo "> DGPU_VENDOR_ID: $DGPU_VENDOR_ID" - echo "> DGPU_DEVICE_ID: $DGPU_DEVICE_ID" - echo "> DGPU_SS_IDS: $DGPU_SS_IDS" - echo "> DGPU_SS_VENDOR_ID: $DGPU_SS_VENDOR_ID" - echo "> DGPU_SS_DEVICE_ID: $DGPU_SS_DEVICE_ID" - exit 1 - fi - - echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." - driver unbind "${DGPU_PCI_ADDRESS}" - echo "> Binding dGPU to VFIO driver..." - driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" - #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" - # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=pci.1") # DGPU root port - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port,address.type=pci,address.bus=0x0,address.slot=0x1c,address.function=0x0,address.multifunction=on,index=1,alias.name=pci.1") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/model/@name=ioh3420") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/target/@chassis=1") - fi + if [ "$HOST_DGPU_DRIVER" = "auto" ]; then + HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" + fi - if [ "$VM_START_MODE" = "qemu" ]; then - if [ -z "$DGPU_ROM" ]; then - echo "> Not using DGPU vBIOS override..." - DGPU_ROM_PARAM=",rombar=0" - else - echo "> Using DGPU vBIOS override..." - DGPU_ROM_PARAM=",romfile=${DGPU_ROM}" + echo "> dGPU is: '$DGPU_PCI_ADDRESS' with driver '$HOST_DGPU_DRIVER'" + + echo "> Retrieving and parsing DGPU IDs..." + DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) + DGPU_VENDOR_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f1) + DGPU_DEVICE_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f2) + DGPU_SS_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -vnn -d "${DGPU_IDS}" | grep "Subsystem:" | grep -oP "\w+:\w+") + DGPU_SS_VENDOR_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f1) + DGPU_SS_DEVICE_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f2) + + if [ -z "$DGPU_IDS" ]; then + echo "> Error: Failed to retrieve DGPU IDs!" + echo "> DGPU_PCI_ADDRESS: ${DGPU_PCI_ADDRESS}" + echo "> DGPU_IDS: $DGPU_IDS" + echo "> DGPU_VENDOR_ID: $DGPU_VENDOR_ID" + echo "> DGPU_DEVICE_ID: $DGPU_DEVICE_ID" + echo "> DGPU_SS_IDS: $DGPU_SS_IDS" + echo "> DGPU_SS_VENDOR_ID: $DGPU_SS_VENDOR_ID" + echo "> DGPU_SS_DEVICE_ID: $DGPU_SS_DEVICE_ID" + exit 1 fi - QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=pci.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") - elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ -z "$DGPU_ROM" ]; then - echo "> Not using DGPU vBIOS override..." - DGPU_ROM_PARAM=",rom.bar=on" + + echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." + driver unbind "${DGPU_PCI_ADDRESS}" + echo "> Binding dGPU to VFIO driver..." + driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" + #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" + # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=pci.1") # DGPU root port + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port,address.type=pci,address.bus=0x0,address.slot=0x1c,address.function=0x0,address.multifunction=on,index=1,alias.name=pci.1") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/model/@name=ioh3420") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/target/@chassis=1") fi - VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.bus=1,address.type=pci,address.multifunction=on${DGPU_ROM_PARAM}") - if [ ! -z "$DGPU_ROM" ]; then - echo "> Using DGPU vBIOS override..." - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev/rom/@file=${DGPU_ROM}") - QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-device-id=$((16#${DGPU_SS_DEVICE_ID}))") - QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-vendor-id=$((16#${DGPU_SS_VENDOR_ID}))") + + if [ "$VM_START_MODE" = "qemu" ]; then + if [ -z "$DGPU_ROM" ]; then + echo "> Not using DGPU vBIOS override..." + DGPU_ROM_PARAM=",rombar=0" + else + echo "> Using DGPU vBIOS override..." + DGPU_ROM_PARAM=",romfile=${DGPU_ROM}" + fi + QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=pci.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ -z "$DGPU_ROM" ]; then + echo "> Not using DGPU vBIOS override..." + DGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.bus=1,address.type=pci,address.multifunction=on${DGPU_ROM_PARAM}") + if [ ! -z "$DGPU_ROM" ]; then + echo "> Using DGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev/rom/@file=${DGPU_ROM}") + QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-device-id=$((16#${DGPU_SS_DEVICE_ID}))") + QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-vendor-id=$((16#${DGPU_SS_VENDOR_ID}))") + fi fi + else + echo "> Not using dGPU passthrough..." fi else echo "> Not using dGPU passthrough..." From 5d3e6527b17254cad7815f13e002b43aa6d94918 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Tue, 24 Aug 2021 03:59:45 +0200 Subject: [PATCH 29/40] Clean up vm.sh; Add plugin mechanism for display modes --- default.conf | 55 +- scripts/main/generate-helper-iso.sh | 2 - scripts/main/generate-vm-config.sh | 45 +- scripts/main/vm.sh | 680 ++++++++++++-------- scripts/utils/common/libs/helpers | 1 + scripts/utils/common/plugins/display-mode-1 | 27 + scripts/utils/common/plugins/display-mode-2 | 22 + scripts/utils/common/plugins/display-mode-3 | 24 + scripts/utils/common/plugins/display-mode-4 | 22 + scripts/utils/common/plugins/display-mode-5 | 24 + vm-files/network-scripts/nat_ifdown | 18 - vm-files/network-scripts/nat_ifup | 91 --- vm-files/network-scripts/tap_ifdown | 31 - vm-files/network-scripts/tap_ifup | 72 --- 14 files changed, 559 insertions(+), 555 deletions(-) create mode 100644 scripts/utils/common/plugins/display-mode-1 create mode 100644 scripts/utils/common/plugins/display-mode-2 create mode 100644 scripts/utils/common/plugins/display-mode-3 create mode 100644 scripts/utils/common/plugins/display-mode-4 create mode 100644 scripts/utils/common/plugins/display-mode-5 delete mode 100755 vm-files/network-scripts/nat_ifdown delete mode 100755 vm-files/network-scripts/nat_ifup delete mode 100755 vm-files/network-scripts/tap_ifdown delete mode 100755 vm-files/network-scripts/tap_ifup diff --git a/default.conf b/default.conf index 0511995..9e91df8 100644 --- a/default.conf +++ b/default.conf @@ -25,7 +25,7 @@ DGPU_PCI_ADDRESS=auto # Required; If you don't use Bumblebee, you have to set th # This project has only been tested with Bumblebee enabled. IGPU_PCI_ADDRESS=auto # Recommended; required for mediated iGPU passthrough. you can cehck your iGPU PCI address using lspci -DGPU_PASSTHROUGH=true # Recommended +DGPU_PASSTHROUGH=auto # Recommended SHARE_IGPU=auto # Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) @@ -34,59 +34,18 @@ HOST_DGPU_DRIVER=auto # Only tested with "nvidia" and "amdgpu", not tested with VIRTUAL_INPUT_TYPE="virtio" # "usb-tablet", "virtio" or "". If keyboard input doesn't work properly for you, you may want to use "virtio" instead of "usb-tablet" MAC_ADDRESS="" # Required -NETWORK_MODE=TAP # This option is currently ignored (bridged, NAT and none don't work atm) +NETWORK_MODE="bridged" # Supports bridged or none -USE_LOOKING_GLASS=true # Optional -LOOKING_GLASS_MAX_SCREEN_WIDTH=1920 # Recommended (bigger resolutions will result in a bigger buffer with worse performance) -LOOKING_GLASS_MAX_SCREEN_HEIGHT=1080 # Recommended (bigger resolutions will result in a bigger buffer with worse performance) -LOOKING_GLASS_VERSION=B4 # Recommended +LOOKING_GLASS_MAX_SCREEN_WIDTH=1920 # 1920 Recommended (bigger resolutions will result in a bigger buffer with worse performance) +LOOKING_GLASS_MAX_SCREEN_HEIGHT=1080 # 1080 Recommended (bigger resolutions will result in a bigger buffer with worse performance) +LOOKING_GLASS_VERSION=B4 # B4 Recommended USE_SPICE=true # Required for Windows installation and recommended for Looking Glass -SPICE_PORT=5900 # 5900 is recommended +SPICE_PORT=5904 # 5900 is the normal port, but it may already be used by something else on your system like VNC USE_SPICE_CLIENT="true" # Required for installation -USE_DMA_BUF=false # Optional - -USE_QXL=true # Required for RDP - -DISPLAY_MODE=1 - -# DISPLAY_MODES -# if [ "$DISPLAY_MODE" == 1 ]; then -# if [ "$DMA_BUF_AVAILABLE" == true ]; then -# LOOKING_GLASS=true -# DMA_BUF=true -# QXL=false -# RDP=false -# else -# DMA_BUF=false -# RDP=true -# if [ "$VM_INSTALL" == true ]; then -# QXL=true -# LOOKING_GLASS=false -# else -# QXL=false -# LOOKING_GLASS=true -# fi -# fi -# elif [ "$DISPLAY_MODE" == 2 ]; then -# RDP=true -# if [ "$DMA_BUF_AVAILABLE" == true ]; then -# LOOKING_GLASS=true -# DMA_BUF=true -# QXL=false -# else -# DMA_BUF=false -# if [ "$VM_INSTALL" == true ]; then -# QXL=true -# LOOKING_GLASS=false -# else -# QXL=false -# LOOKING_GLASS=true -# fi -# fi -# fi +DISPLAY_MODE=4 # See scripts/utils/common/plugins ; Mode 4 is the only working one atm ; Looking Glass doesn't play nicely yet USE_FAKE_BATTERY="true" # Recommended to avoid Error 43 diff --git a/scripts/main/generate-helper-iso.sh b/scripts/main/generate-helper-iso.sh index 837c54b..b20b119 100755 --- a/scripts/main/generate-helper-iso.sh +++ b/scripts/main/generate-helper-iso.sh @@ -42,8 +42,6 @@ else echo "> Spice WebDAV daemon already exists in iso folder..." fi -https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x64-2.4.msi - if [ ! -f "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host-setup.exe" ]; then #echo "> Downloading Looking Glass Host application..." #wget "https://github.com/gnif/LookingGlass/releases/download/${LOOKING_GLASS_VERSION}/looking-glass-host.exe" -O "${HELPER_ISO_FILES_DIR}/bin/looking-glass-host.exe" diff --git a/scripts/main/generate-vm-config.sh b/scripts/main/generate-vm-config.sh index 442b4ac..f484c4b 100755 --- a/scripts/main/generate-vm-config.sh +++ b/scripts/main/generate-vm-config.sh @@ -33,9 +33,9 @@ interactiveCfg() { # TODO: change modified value on config file USER_CONFIG_FILE } -echo "!!!!!!" -echo "IF IN DOUBT WITH ANY OF THE FOLLOWING, JUST PRESS ENTER TO USE THE RECOMMENDED/DEFAULT VALUE!" -echo "!!!!!!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "!!IF IN DOUBT WITH ANY OF THE FOLLOWING, JUST PRESS ENTER TO USE THE RECOMMENDED/DEFAULT VALUE!!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" interactiveCfg "Where should the VM files be saved?" VM_FILES_DIR echo "> Directory set to '${VM_FILES_DIR}'" @@ -52,11 +52,11 @@ cp "${PROJECT_DIR}/default.conf" "${USER_CONFIG_FILE}" echo "> Config will be created at ${USER_CONFIG_FILE}'" interactiveCfg "What should the name of the VM be?" VM_NAME -interactiveCfg "Where to save the VM drive image?" DRIVE_IMG +interactiveCfg "Where to save the VM drive image? (At least 40G is highly recommended; Can't be changed wihtout a reinstall)" DRIVE_IMG interactiveCfg "How big should the VM drive image be?" VM_DISK_SIZE -interactiveCfg "How many CPU cores should the VM get?" CPU_CORE_COUNT -interactiveCfg "How much RAM should the VM get?" RAM_SIZE -interactiveCfg "Path to your Windows installation iso. (If it doesn't exist it will be downloaded automatically.)" INSTALL_IMG +interactiveCfg "How many CPU cores should the VM get? (e.g. 8 or auto; auto=AVAILABLE_CORES-1G)" CPU_CORE_COUNT +interactiveCfg "How much RAM should the VM get? (e.g. 16G or auto; auto=FREE_RAM-1G)" RAM_SIZE +interactiveCfg "Path to your Windows installation iso. (If it doesn't exist it will be downloaded to that location automatically.)" INSTALL_IMG interactiveCfg "Path to a dGPU ROM. (Optional)" DGPU_ROM interactiveCfg "Path to a iGPU ROM. (Optional)" IGPU_ROM interactiveCfg "Path to a folder to share with the VM via SMB. (Optional)" SMB_SHARE_FOLDER @@ -64,33 +64,22 @@ interactiveCfg "Location of OVMF_VARS.fd." OVMF_VARS interactiveCfg "Where to create Creating a copy of OVMF_VARS.fd (containing the executable firmware code and but the non-volatile variable store) for the VM?" OVMF_VARS_VM interactiveCfg "Location of OVMF_CODE.fd." OVMF_CODE interactiveCfg "Location of helper iso or where to create it." HELPER_ISO -interactiveCfg "Pass the dGPU through to the VM." DGPU_PASSTHROUGH -interactiveCfg "Share the iGPU with the VM to allow using Optimus within the VM to save battery life" SHARE_IGPU -interactiveCfg "dGPU driver used by the Linux host (nvidia, nouveau, amdgpu, radeon). (nouveau & radeon are untested)" HOST_DGPU_DRIVER -interactiveCfg "The PCI address of your dGPU as obtained by 'lspci' or 'optimus lspci'. (01:00.0 if you use Bumblebee)" DGPU_PCI_ADDRESS -interactiveCfg "The PCI address of your iGPU as obtained by 'lspci'. (Usually 00:02.0)" IGPU_PCI_ADDRESS +interactiveCfg "Pass the dGPU through to the VM. (true, false or auto to enable if more than one GPU is in this system)" DGPU_PASSTHROUGH +interactiveCfg "Share the iGPU with the VM to allow using Optimus within the VM to save battery life (true, false or auto to share it only if available)" SHARE_IGPU +interactiveCfg "dGPU driver used by the Linux host (E.g. nvidia, nouveau, amdgpu, radeon or auto to detect it automatically)" HOST_DGPU_DRIVER +interactiveCfg "The PCI address of your dGPU as obtained by 'lspci' or 'optimus lspci'. (E.g. 01:00.0 or auto to detect it automatically)" DGPU_PCI_ADDRESS +interactiveCfg "The PCI address of your iGPU as obtained by 'lspci'. (E.g. 00:02.0 or auto to detect it automatically)" IGPU_PCI_ADDRESS interactiveCfg "Virtual input device mode for keyboard and mouse. (if usb-tablet doesn't work properly, you may want to switch to virtio)" VIRTUAL_INPUT_TYPE -interactiveCfg "MAC address to use or leave empty to generate a random one" MAC_ADDRESS -if [ "$MAC_ADDRESS" == "" ]; then - MAC_ADDRESS=$(printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))) - echo "> MAC_ADDRESS generated: ${MAC_ADDRESS}" - echo "> Set MAC_ADDRESS to '${MAC_ADDRESS}'" - crudini --set "${USER_CONFIG_FILE}" "" "MAC_ADDRESS" "\"${MAC_ADDRESS}\"" -fi -interactiveCfg "Network mode to use? Only supports TAP at the moment." NETWORK_MODE -interactiveCfg "Use Looking Glass to get super low latency video output." USE_LOOKING_GLASS +interactiveCfg "MAC address to use (e.g. 11:22:33:44:55:66 or auto to generate it automatically)" MAC_ADDRESS +interactiveCfg "Network mode to use? Only supports bridge at the moment." NETWORK_MODE interactiveCfg "Max screen width with Looking Glass." LOOKING_GLASS_MAX_SCREEN_WIDTH interactiveCfg "Max screen height with Looking Glass." LOOKING_GLASS_MAX_SCREEN_HEIGHT interactiveCfg "Version of Looking Glass to use (B4 is highly recommended)" LOOKING_GLASS_VERSION -interactiveCfg "Enable spice. (Recommended for Looking Glass, required to install Windows)" USE_SPICE +interactiveCfg "Enable spice. (Leave this on unless you know what you're doing!)" USE_SPICE interactiveCfg "Port to use for spice." SPICE_PORT -interactiveCfg "Enable dma-buf. (Yet another way to get display access to your VM)" USE_DMA_BUF -interactiveCfg "Enable QXL. (Required for Windows installation; has to be disabled after the Nvidia driver has been installed!)" USE_QXL +interactiveCfg "Display mode to use (e.g. 1 or 2 ... see scripts/utils/common/plugins)" DISPLAY_MODE interactiveCfg "Provide the VM with a fake battery (Highly recommended to avoid Error 43)" USE_FAKE_BATTERY interactiveCfg "Patch OVMF with your dGPU ROM if you supply one. (Highly recommended to avoid Error 43)" PATCH_OVMF_WITH_VROM interactiveCfg "Tool to use to start/install the VM. (qemu or virt-install)" VM_START_MODE interactiveCfg "List of USB devices to pass through. (Semicolon separated, e.g. vendorid=0x0b12,productid=0x9348;vendorid=0x0b95,productid=0x1790)" USB_DEVICES -# TODO: Make selecting USB devices easier -# TODO: Auto detect PCI addresses for GPUs -# TODO: Don't ask for Bumblebee if there is no nvidia gpu -# TODO: Add auto option for CPU cores, RAM and dGPU driver \ No newline at end of file +# TODO: Make selecting USB devices easier \ No newline at end of file diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 6c221fb..13cac67 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -8,29 +8,35 @@ loadConfig # or start the previously created Windows VM, if called like this: `./vm.sh` ##################################################################################################### -echo "> Action: $1" -if [ "$1" = "install" ]; then - VM_INSTALL=true -elif [ "$1" = "start" ]; then - VM_INSTALL=false -elif [ "$1" = "stop" ]; then +ORIGINAL_VM_ACTION="$1" +VM_ACTION="$ORIGINAL_VM_ACTION" +if [ "$VM_ACTION" != "auto" ]; then + echo "> Action: $VM_ACTION" +fi + +if [ "$VM_ACTION" = "install" ]; then + VM_ACTION="install" +elif [ "$VM_ACTION" = "start" ]; then + VM_ACTION="start" +elif [ "$VM_ACTION" = "stop" ]; then if [ "$VM_START_MODE" = "virt-install" ]; then sudo virsh destroy --domain "${VM_NAME}" elif [ "$VM_START_MODE" = "qemu" ]; then - killall qemu-system-x86_64 + sudo killall qemu-system-x86_64 &> /dev/null fi -elif [ "$1" = "auto" ]; then +elif [ "$VM_ACTION" = "auto" ]; then if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then - VM_INSTALL=false + VM_ACTION="start" else - VM_INSTALL=true + VM_ACTION="install" fi -elif [ "$1" = "remove" ]; then + echo "> Action: $VM_ACTION" +elif [ "$VM_ACTION" = "remove" ]; then if [ "$VM_START_MODE" = "virt-install" ]; then sudo virsh destroy --domain "${VM_NAME}" sudo virsh undefine --domain "${VM_NAME}" --nvram elif [ "$VM_START_MODE" = "qemu" ]; then - killall qemu-system-x86_64 + sudo killall qemu-system-x86_64 &> /dev/null fi if [[ ${DRIVE_IMG} == *.img ]]; then sudo rm -f "${DRIVE_IMG}" @@ -46,7 +52,7 @@ echo "> Start mode: $VM_START_MODE" GET_XML=false DRY_RUN=false -if [ "$1" = "install" ] || [ "$1" = "start" ]; then +if [ "$VM_ACTION" = "install" ] || [ "$VM_ACTION" = "start" ]; then if [ "$2" = "dry-run" ]; then DRY_RUN=true elif [ "$2" = "get-xml" ]; then @@ -63,6 +69,9 @@ alias vgpu="sudo '$COMMON_UTILS_TOOLS_DIR/vgpu-util'" VIRT_INSTALL_PARAMS=() QEMU_PARAMS=() +##################################################################################### +############################## Set basic VM parameters ############################## +##################################################################################### if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-name" "${VM_NAME}") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -91,11 +100,64 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./features/hyperv/vendor_id/@state=on" "--xml" "xpath.set=./features/hyperv/vendor_id/@value='12alphanum'") fi -if [ "$MAC_ADDRESS" = "auto" ]; then - MAC_ADDRESS=$(printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))) +if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-mem-prealloc") # for virt-install this enabled by default fi -echo "> Using MAC address: ${MAC_ADDRESS}..." +QEMU_PARAMS+=("-rtc" "clock=host,base=localtime") +QEMU_PARAMS+=("-nographic") +QEMU_PARAMS+=("-serial" "none") +QEMU_PARAMS+=("-parallel" "none") +QEMU_PARAMS+=("-boot" "menu=on") +QEMU_PARAMS+=("-boot" "once=d") +QEMU_PARAMS+=("-k" "en-us") + +QEMU_PARAMS+=("-device" "ich9-intel-hda") +QEMU_PARAMS+=("-device" "hda-output") +QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") +# More parameters are added throughout the whole script + +VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") +VIRT_INSTALL_PARAMS+=("--os-variant" "win10") +VIRT_INSTALL_PARAMS+=("--arch=x86_64") + +##################################################################################### +################################# Set up networking ################################# +##################################################################################### +if [ "$NETWORK_MODE" == "bridged" ]; then + echo "> Using network mode ${NETWORK_MODE}..." + if ! sudo virsh net-list | grep default | grep --quiet active; then + sudo virsh net-start default + fi + + if [ "$MAC_ADDRESS" = "auto" ]; then + MAC_ADDRESS=$(printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))) + fi + echo "> Using MAC address: ${MAC_ADDRESS}..." + + INTERFACE_NAME="$(sudo cat /var/lib/libvirt/dnsmasq/default.conf | grep "^interface=" | cut -d'=' -f2-)" + NETWORK="$(sudo ip route | grep " ${INTERFACE_NAME} " | cut -d' ' -f1)" + + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-net" "nic,model=e1000,macaddr=${MAC_ADDRESS}" "-net" "bridge,br=virbr0") + #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") + #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") + #-net user,hostfwd=tcp::13389-:3389 -net nic + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--network" "network=default,model=e1000,mac=${MAC_ADDRESS}") + #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[type=network]/mac@address='${MAC_ADDRESS}'") + #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[0]/source@network=default") + #if ! sudo virsh net-list | grep default | grep --quiet active; then + # sudo virsh net-start default + #fi + fi +else + echo "Networking will not be enabled for this VM..." +fi + +##################################################################################### +################################### Set CPU Cores ################################### +##################################################################################### if [ "$CPU_CORE_COUNT" = "auto" ]; then AVAILABLE_CPU_CORE_COUNT="$(nproc)" CPU_CORE_COUNT="$((AVAILABLE_CPU_CORE_COUNT-1))" @@ -103,7 +165,6 @@ if [ "$CPU_CORE_COUNT" = "auto" ]; then CPU_CORE_COUNT=16 fi fi - echo "> Using ${CPU_CORE_COUNT} CPU cores..." if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-smp" "${CPU_CORE_COUNT}") @@ -111,15 +172,17 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--vcpu" "${CPU_CORE_COUNT}") fi +##################################################################################### +################################### Set RAM size #################################### +##################################################################################### if [ "$RAM_SIZE" = "auto" ]; then - FREE_RAM="$(free -g | grep 'Mem: ' | tr -s ' ' | cut -d ' ' -f4)" + FREE_RAM="$(free -g | grep 'Mem: ' | tr -s ' ' | cut -d ' ' -f7)" RAM_SIZE_GB="$((FREE_RAM-1))" if [[ $RAM_SIZE_GB -gt 16 ]]; then RAM_SIZE_GB=16 fi RAM_SIZE="${RAM_SIZE_GB}G" fi - echo "> Using ${RAM_SIZE} of RAM..." if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-m" "${RAM_SIZE}") @@ -128,19 +191,10 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--memory" "${RAM_SIZE_GB}") fi -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-mem-prealloc") # for virt-install this enabled by default -fi - -QEMU_PARAMS+=("-rtc" "clock=host,base=localtime") -QEMU_PARAMS+=("-nographic") -QEMU_PARAMS+=("-serial" "none") -QEMU_PARAMS+=("-parallel" "none") -QEMU_PARAMS+=("-boot" "menu=on") -QEMU_PARAMS+=("-boot" "once=d") -QEMU_PARAMS+=("-k" "en-us") - -if [ "$VM_INSTALL" = true ]; then +##################################################################################### +############################## Set install media (ISO) ############################## +##################################################################################### +if [ "$VM_ACTION" = "install" ]; then if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -148,43 +202,18 @@ if [ "$VM_INSTALL" = true ]; then fi fi +##################################################################################### +################################## Set helper ISO ################################### +##################################################################################### if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=2,media=cdrom") elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") fi -if ! sudo virsh net-list | grep default | grep --quiet active; then - sudo virsh net-start default -fi - -INTERFACE_NAME="$(sudo cat /var/lib/libvirt/dnsmasq/default.conf | grep "^interface=" | cut -d'=' -f2-)" -NETWORK="$(sudo ip route | grep " ${INTERFACE_NAME} " | cut -d' ' -f1)" - -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-net" "nic,model=e1000,macaddr=${MAC_ADDRESS}" "-net" "bridge,br=virbr0") - #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") - #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") - #-net user,hostfwd=tcp::13389-:3389 -net nic -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--network" "network=default,model=e1000,mac=${MAC_ADDRESS}") - #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[type=network]/mac@address='${MAC_ADDRESS}'") - #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[0]/source@network=default") - #if ! sudo virsh net-list | grep default | grep --quiet active; then - # sudo virsh net-start default - #fi -fi - -QEMU_PARAMS+=("-device" "ich9-intel-hda") -QEMU_PARAMS+=("-device" "hda-output") -QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") -# More parameters are added throughout the whole script - -VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") -VIRT_INSTALL_PARAMS+=("--os-variant" "win10") -VIRT_INSTALL_PARAMS+=("--arch=x86_64") -#VIRT_INSTALL_PARAMS+=("--unattended") - +##################################################################################### +########################### Set/create OS install drive ############################# +##################################################################################### if [[ ${DRIVE_IMG} == /dev/* ]]; then echo "> Using a physical OS drive..." if [ "$VM_START_MODE" = "qemu" ]; then @@ -195,9 +224,13 @@ if [[ ${DRIVE_IMG} == /dev/* ]]; then #QEMU_PARAMS+=("-drive" "file=/dev/sda,if=virtio" "-drive" "file=/dev/sdb,if=virtio" "-drive" "file=/dev/sdc,if=virtio" "-drive" "file=/dev/sdd,if=virtio" "-snapshot") elif [[ ${DRIVE_IMG} == *.img ]]; then echo "> Using a virtual OS drive..." + if [ "$VM_ACTION" = "install" ] && [ -f "${DRIVE_IMG}" ]; then + echo "> Removing old virtual disk..." + sudo rm -rf "${DRIVE_IMG}" + fi if [ ! -f "${DRIVE_IMG}" ]; then echo "> Creating a virtual disk for the VM..." - qemu-img create -f raw "${DRIVE_IMG}" "${VM_DISK_SIZE}" + qemu-img create -f raw "${DRIVE_IMG}" "${VM_DISK_SIZE}" > /dev/null sudo chown "$(whoami):$(id -gn "$(whoami)")" "${DRIVE_IMG}" fi if [ "$VM_START_MODE" = "qemu" ]; then @@ -205,18 +238,16 @@ elif [[ ${DRIVE_IMG} == *.img ]]; then elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") fi + OS_DRIVE_SIZE="$(sudo ls -l --b=G "${DRIVE_IMG}" | cut -d " " -f5)" + echo "> Virtual OS drive has ${OS_DRIVE_SIZE} of storage." else echo "> Error: It appears that no proper OS drive (image) has been provided. Check your 'DRIVE_IMG' var: '${DRIVE_IMG}'" exit fi -if [ ! -f "${OVMF_VARS_VM}" ] || [ "$VM_INSTALL" = true ]; then - echo "> Creating fresh OVMF_VARS copy for this VM..." - sudo rm -f "${OVMF_VARS_VM}" - sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" - sudo chown "$(whoami):$(id -gn "$(whoami)")" "${OVMF_VARS_VM}" -fi - +##################################################################################### +################ Figure out if optirun or DRI_PRIME should be used ################## +##################################################################################### if sudo which optirun &> /dev/null && sudo optirun echo > /dev/null ; then OPTIRUN_PREFIX="optirun " DRI_PRIME_PREFIX="" @@ -226,39 +257,13 @@ else if [ "$SUPPORTS_DRI_PRIME" = true ]; then DRI_PRIME_PREFIX="DRI_PRIME=1 " else - echo "> Warning: Bumblebee is not available or doesn't work properly. Continuing anyway..." - fi -fi - -echo "> Loading vfio-pci kernel module..." -sudo modprobe vfio-pci - -if [ "$USE_LOOKING_GLASS" = true ]; then - echo "> Using Looking Glass..." - echo "> Calculating required buffer size for ${LOOKING_GLASS_MAX_SCREEN_WIDTH}x${LOOKING_GLASS_MAX_SCREEN_HEIGHT} for Looking Glass..." - UNROUNDED_BUFFER_SIZE=$((($LOOKING_GLASS_MAX_SCREEN_WIDTH * $LOOKING_GLASS_MAX_SCREEN_HEIGHT * 4 * 2)/1024/1024+10)) - BUFFER_SIZE=1 - while [[ $BUFFER_SIZE -le $UNROUNDED_BUFFER_SIZE ]]; do - BUFFER_SIZE=$(($BUFFER_SIZE*2)) - done - LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}" - echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}MB" - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") - QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}M") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/@name=looking-glass") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/model/@type=ivshmem-plain") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=${LOOKING_GLASS_BUFFER_SIZE}") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size/@unit=M") + echo "> Bumblebee is not available..." fi - #sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" - #sudo bash -c "echo 'f /dev/shm/looking-glass 0660 qemu kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" - #sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass -else - echo "> Not using Looking Glass..." fi +##################################################################################### +########################## Set up samba share directory ############################# +##################################################################################### if [ -z "$SMB_SHARE_FOLDER" ]; then echo "> Not using SMB share..." else @@ -266,7 +271,11 @@ else QEMU_PARAMS+=("-net" "user,smb=${SMB_SHARE_FOLDER}") fi +##################################################################################### +####################### Set parameters for dGPU passthrough ######################### +##################################################################################### if [ "$DGPU_PASSTHROUGH" != false ]; then + DGPU_PASSTHROUGH=false availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" if [ "$DGPU_PCI_ADDRESS" = "auto" ]; then DGPU_PCI_ADDRESS="" @@ -281,14 +290,17 @@ if [ "$DGPU_PASSTHROUGH" != false ]; then if [ "$(echo -e "$availableGpusIds" | wc -l)" -le 1 ]; then echo "> Not using dGPU passthrough because single GPU passthrough is not supported yet..." - if [ "$DGPU_PCI_ADDRESS" != "" ]; then + elif [ "$DGPU_PCI_ADDRESS" != "" ]; then + DGPU_PASSTHROUGH=true echo "> Using dGPU passthrough..." if [ "$HOST_DGPU_DRIVER" = "auto" ]; then HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" fi - echo "> dGPU is: '$DGPU_PCI_ADDRESS' with driver '$HOST_DGPU_DRIVER'" + DGPU_INFO="$(sudo lspci | grep "$DGPU_PCI_ADDRESS" | cut -d' ' -f2-)" + echo "> dGPU is: $DGPU_INFO" + echo "> dGPU dirver is $HOST_DGPU_DRIVER" echo "> Retrieving and parsing DGPU IDs..." DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) @@ -310,12 +322,6 @@ if [ "$DGPU_PASSTHROUGH" != false ]; then exit 1 fi - echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." - driver unbind "${DGPU_PCI_ADDRESS}" - echo "> Binding dGPU to VFIO driver..." - driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" - #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" - # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=pci.1") # DGPU root port elif [ "$VM_START_MODE" = "virt-install" ]; then @@ -353,9 +359,14 @@ else echo "> Not using dGPU passthrough..." fi -if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then +############################################################################################## +### If mediated iGPU passthrough is enabled, check if vGPU exists or if one can be created ### +############################################################################################## +DMA_BUF_AVAILABLE=false +if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = "auto" ]; then if [ "$IGPU_PCI_ADDRESS" = "auto" ]; then + IGPU_PCI_ADDRESS="" availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" while IFS= read -r pciAddress; do @@ -367,10 +378,7 @@ if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then done <<< "$availableGpusIds" fi - if [ "$IGPU_PCI_ADDRESS" != "auto" ]; then - echo "> Using mediated iGPU passthrough..." - echo "> iGPU is: $IGPU_PCI_ADDRESS" - + if [ "$IGPU_PCI_ADDRESS" != "" ]; then vgpu init # load required kernel modules # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. @@ -381,58 +389,18 @@ if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = auto ]; then echo "> Creating a vGPU for mediated iGPU passthrough..." VGPU_UUID="$(vgpu create "${IGPU_PCI_ADDRESS}")" if [ "$?" = "1" ]; then - echo "> Failed creating a vGPU. (You can try again. If you still get this error, you have to reboot. This seems to be a bug in Linux.)" + echo "> [Error] Failed creating a vGPU. (You can try again. If you still get this error, you have to reboot. This seems to be a bug in Linux.)" echo "> Continuing without mediated iGPU passthrough..." VGPU_UUID="" fi fi - + if [ "$VGPU_UUID" != "" ]; then - # TODO: same as for iGPU - if [ "$VM_START_MODE" = "qemu" ]; then - - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - DMA_BUF_PARAM=",display=on,x-igd-opregion=on" - else - echo "> Not using dma-buf..." - DMA_BUF_PARAM="" - fi - - if [ -z "$IGPU_ROM" ]; then - echo "> Not using iGPU vBIOS override..." - #IGPU_ROM_PARAM=",rom.bar=on" - else - echo "> Using iGPU vBIOS override..." - IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" - fi - - QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G - elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") - GVTG_DISPLAY_STATE="on" - else - echo "> Not using dma-buf..." - GVTG_DISPLAY_STATE="off" - fi - - if [ -z "$IGPU_ROM" ]; then - echo "> Not using iGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" - fi - VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") - - if [ ! -z "$IGPU_ROM" ]; then - echo "> Using iGPU vBIOS override..." - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") - fi - fi + IGPU_INFO="$(sudo lspci | grep "$IGPU_PCI_ADDRESS" | cut -d' ' -f2-)" + echo "> iGPU is: $IGPU_INFO" + echo "> iGPU dirver is: $HOST_DGPU_DRIVER" + echo "> UUID of vGPU is: $VGPU_UUID" + DMA_BUF_AVAILABLE=true fi else echo "> No iGPU found. - Not using mediated iGPU passthrough..." @@ -441,19 +409,108 @@ else echo "> Not using mediated iGPU passthrough..." fi -if [ "$USE_SPICE" = true ]; then - echo "> Using spice on port ${SPICE_PORT}..." - #QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice +##################################################################################### +############################ Load display output plugin ############################# +##################################################################################### +if [ "$DISPLAY_MODE" != "" ]; then + echo "> Loading display-mode-${DISPLAY_MODE} plugin..." + source "${COMMON_UTILS_PLUGINS_DIR}/display-mode-${DISPLAY_MODE}" +else + echo "> [Error] No display mode provided..." +fi + +######################################################################################################### +### If there is a vGPU for mediated iGPU passthrough, set parameters for iGPU passthrough and dma-buf ### +######################################################################################################### +if [ "$VGPU_UUID" != "" ]; then if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + DMA_BUF_PARAM=",display=on,x-igd-opregion=on" + else + echo "> Not using dma-buf..." + DMA_BUF_PARAM="" + fi + + if [ -z "$IGPU_ROM" ]; then + echo "> Not using iGPU vBIOS override..." + #IGPU_ROM_PARAM=",rom.bar=on" + else + echo "> Using iGPU vBIOS override..." + IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" + fi + + QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--channel" "spicevmc,target.address=127.0.0.1:${SPICE_PORT}") - #VIRT_INSTALL_PARAMS+=("--graphics" "spice,port=${SPICE_PORT}") + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") + GVTG_DISPLAY_STATE="on" + else + echo "> Not using dma-buf..." + GVTG_DISPLAY_STATE="off" + fi + + if [ -z "$IGPU_ROM" ]; then + echo "> Not using iGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") + + if [ ! -z "$IGPU_ROM" ]; then + echo "> Using iGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + fi fi +fi + +##################################################################################### +############################### Set Spice parameters ################################ +##################################################################################### +if [ "$USE_SPICE" = true ]; then + if sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN; then + echo "[Error] Something is blocking the SPICE_PORT (${SPICE_PORT})! Change it in your config or kill whatever is blocking it." + else + echo "> Using spice on port ${SPICE_PORT}..." + #QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--channel" "spicevmc,target.address=127.0.0.1:${SPICE_PORT}") + #VIRT_INSTALL_PARAMS+=("--graphics" "spice,port=${SPICE_PORT}") + fi + fi + function waitForSpice() { + while true; do + if sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN &> /dev/null; then + break + fi + sleep 1 + done + } else echo "> Not using Spice..." fi +##################################################################################### +###################### Check if spice client should be started ###################### +##################################################################################### +if [ "$USE_SPICE_CLIENT" = "auto" ] && [ "$USE_SPICE" = true ]; then + if [ "$VM_ACTION" = "install" ]; then + USE_SPICE_CLIENT=true + elif [ "$USE_LOOKING_GLASS" = true ]; then + USE_SPICE_CLIENT=true + fi +fi + +##################################################################################### +############ Set QXL parameters if loaded display output plugin wants it ############ +##################################################################################### if [ "$USE_QXL" = true ]; then echo "> Using QXL..." if [ "$VM_START_MODE" = "qemu" ]; then @@ -461,11 +518,63 @@ if [ "$USE_QXL" = true ]; then #QEMU_PARAMS+=("-vga" "qxl") elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--video" "qxl") + #-video qxl --channel spicevmc fi else echo "> Not using QXL..." fi -#-video qxl --channel spicevmc + +##################################################################################### +####### Set Looking Glass parameters if loaded display output plugin wants it ####### +##################################################################################### +if [ "$USE_LOOKING_GLASS" = true ]; then + echo "> Using Looking Glass..." + echo "> Calculating required buffer size for ${LOOKING_GLASS_MAX_SCREEN_WIDTH}x${LOOKING_GLASS_MAX_SCREEN_HEIGHT} for Looking Glass..." + UNROUNDED_BUFFER_SIZE=$((($LOOKING_GLASS_MAX_SCREEN_WIDTH * $LOOKING_GLASS_MAX_SCREEN_HEIGHT * 4 * 2)/1024/1024+10)) + BUFFER_SIZE=1 + while [[ $BUFFER_SIZE -le $UNROUNDED_BUFFER_SIZE ]]; do + BUFFER_SIZE=$(($BUFFER_SIZE*2)) + done + LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}" + echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}MB" + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") + QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}M") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/@name=looking-glass") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/model/@type=ivshmem-plain") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=${LOOKING_GLASS_BUFFER_SIZE}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size/@unit=M") + fi + #sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" + #sudo bash -c "echo 'f /dev/shm/looking-glass 0660 qemu kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" + #sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass + + function autoConnectLookingGlass() { + while true; do + VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" + if [ "$VM_IP" != "" ]; then + while true; do + if nc -vz "$VM_IP" 3389 &> /dev/null; then + sleep 5 + echo "> Starting the Looking Glass client to connect with the VM..." + sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]' & + break + fi + sleep 1 + done + break + fi + sleep 1 + done + } +else + echo "> Not using Looking Glass..." +fi + +##################################################################################### +########################## Set up fake battery if enabled ########################### +##################################################################################### if [ "$USE_FAKE_BATTERY" = true ]; then echo "> Using fake battery..." if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ]; then @@ -481,6 +590,20 @@ else echo "> Not using fake battery..." fi + +##################################################################################### +########### Create copy of OVMF_VARS_VM which is required for UEFI VMs ############# +##################################################################################### +if [ ! -f "${OVMF_VARS_VM}" ] || [ "$VM_ACTION" = "install" ]; then + echo "> Creating fresh OVMF_VARS copy for this VM..." + sudo rm -f "${OVMF_VARS_VM}" + sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${OVMF_VARS_VM}" +fi + +##################################################################################### +####################### Patch OVMF with vBIOS ROM if enabled ######################## +##################################################################################### if [ "$PATCH_OVMF_WITH_VROM" = true ]; then PATCHED_OVMF_FILES_DIR="${VM_FILES_DIR}/patched-ovmf-files" if [ "$DGPU_ROM" != "" ]; then @@ -500,7 +623,7 @@ if [ "$PATCH_OVMF_WITH_VROM" = true ]; then sudo rm -rf "${PATCHED_OVMF_FILES_DIR}/tmp-build" fi OVMF_CODE="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" - if [ "$VM_INSTALL" = true ]; then + if [ "$VM_ACTION" = "install" ]; then echo "> Creating fresh copy of patched OVMF VARS..." rm -f "${OVMF_VARS_VM}" sudo cp "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" "${OVMF_VARS_VM}" @@ -513,6 +636,9 @@ else echo "> Not using patched OVMF..." fi +##################################################################################### +############################### Set OVMF parameters ################################# +##################################################################################### if [ "$VM_START_MODE" = "qemu" ]; then QEMU_PARAMS+=("-drive" "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}") QEMU_PARAMS+=("-drive" "if=pflash,format=raw,file=${OVMF_VARS_VM}") @@ -520,6 +646,9 @@ elif [ "$VM_START_MODE" = "virt-install" ]; then VIRT_INSTALL_PARAMS+=("--boot" "loader=${OVMF_CODE},loader.readonly=yes,loader.type=pflash,nvram.template=${OVMF_VARS_VM},loader_secure=no") fi +##################################################################################### +########################## Set up USB device passthrough ############################ +##################################################################################### QEMU_PARAMS+=("-usb") if [ -z "$USB_DEVICES" ]; then echo "> Not using USB passthrough..." @@ -533,6 +662,9 @@ else done fi +##################################################################################### +############################### Set up input method ################################# +##################################################################################### if [ "$VIRTUAL_INPUT_TYPE" = "virtio" ]; then echo "> Using virtual input method 'virtio' for keyboard/mouse input..." QEMU_PARAMS+=("-device" "virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2") @@ -544,66 +676,75 @@ else echo "> Not using virtual input method for keyboard/mouse input..." fi -RDP_USER=Administrator -RDP_PASSWORD=admin - -# Run it once because the first time it prints a useless message instead of actually encrypting -echo "$RDP_PASSWORD" | remmina --encrypt-password &> /dev/null - -# Run it again, hoping it always works the second time -RDP_PASSWORD_ENCRYPTED="$(echo "$RDP_PASSWORD" | remmina --encrypt-password | grep 'Encrypted password: ' | cut -d':' -f2- | tr -d ' ')" - -function autoConnectRdp() { - while true; do - VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" - if [ "$VM_IP" != "" ]; then - echo "" - echo "> The IP address of the VM is: ${VM_IP}" - echo "" - echo "> Waiting for RDP to be available in the VM..." - while true; do - if nc -vz "$VM_IP" 3389 &> /dev/null; then - echo "> Opening Remmina to start an RDP connection with the VM..." - remmina -c "rdp://${RDP_USER}:${RDP_PASSWORD_ENCRYPTED}@${VM_IP}" &> /dev/null & - #if [ "$USE_LOOKING_GLASS" = true ]; then - # echo "> Starting the Looking Glass client..." - # sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]' & - #fi - break - fi - done - break - fi - sleep 1 - done -} - -#echo "> Starting RDP autoconnect background task..." -#autoConnectRdp & - -if [ "$VM_INSTALL" = true ]; then - echo "> Deleting VM if it already exists..." - sudo virsh destroy --domain "${VM_NAME}" &> /dev/null - sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null +##################################################################################### +################################### Set up RDP ###################################### +##################################################################################### +if [ "$USE_RDP" = true ] && [ "$NETWORK_MODE" != "none" ]; then + echo "> Using RDP..." + RDP_USER=Administrator + RDP_PASSWORD=admin + # Run it once because the first time it prints a useless message instead of actually encrypting + echo "$RDP_PASSWORD" | remmina --encrypt-password &> /dev/null + # Run it again, hoping it always works the second time + RDP_PASSWORD_ENCRYPTED="$(echo "$RDP_PASSWORD" | remmina --encrypt-password | grep 'Encrypted password: ' | cut -d':' -f2- | tr -d ' ')" + + function autoConnectRdp() { + while true; do + VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" + if [ "$VM_IP" != "" ]; then + echo "" + echo "> The IP address of the VM is: ${VM_IP}" + echo "" + echo "> Waiting for RDP to be available in the VM..." + while true; do + if nc -vz "$VM_IP" 3389 &> /dev/null; then + echo "> Opening Remmina to start an RDP connection with the VM..." + remmina -c "rdp://${RDP_USER}:${RDP_PASSWORD_ENCRYPTED}@${VM_IP}" &> /dev/null & + break + fi + sleep 1 + done + break + fi + sleep 1 + done + } +else + echo "> Not using RDP..." fi +##################################################################################### +################# Load vfio-pci and bind dGPU to vfio-pci driver #################### +##################################################################################### +if [ "$DRY_RUN" = false ]; then + if [ "$DGPU_PASSTHROUGH" = true ] || [ "$SHARE_IGPU" = true ]; then + echo "> Loading vfio-pci kernel module..." + sudo modprobe vfio-pci + fi - -if [ "$USE_SPICE_CLIENT" = "auto" ] && [ "$USE_SPICE" = true ]; then - if [ "$VM_INSTALL" = true ]; then - USE_SPICE_CLIENT=true - elif [ "$USE_LOOKING_GLASS" = true ]; then - USE_SPICE_CLIENT=false + if [ "$DGPU_PASSTHROUGH" = true ]; then + echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." + driver unbind "${DGPU_PCI_ADDRESS}" + echo "> Binding dGPU to VFIO driver..." + driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" + #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" + # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) fi fi -if [ "$DRY_RUN" = false ] && [ "$VM_INSTALL" = true ]; then - echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." +if [ "$VM_ACTION" = "install" ]; then + echo "> Deleting VM if it already exists..." + sudo virsh destroy --domain "${VM_NAME}" &> /dev/null + sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null fi -if [ "$VM_START_MODE" = "qemu" ]; then +##################################################################################### +########################## Start a few background tasks ############################# +##################################################################################### +if [ "$VM_START_MODE" = "qemu" ]; then if [ "$DRY_RUN" = false ]; then - if [ "$VM_INSTALL" = true ]; then + if [ "$VM_ACTION" = "install" ]; then + echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & fi @@ -612,10 +753,29 @@ if [ "$VM_START_MODE" = "qemu" ]; then echo "> Starting the spice client at localhost:${SPICE_PORT}..." bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & fi - - echo "> Starting the Virtual Machine using qemu..." fi +elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$DRY_RUN" = false ]; then + if [ "$VM_ACTION" = "install" ]; then + echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." + bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + fi + fi +fi +if [ "$USE_RDP" = true ] && [ "$NETWORK_MODE" != "none" ]; then + echo "> Starting RDP autoconnect background task..." + autoConnectRdp & +fi +if [ "$USE_LOOKING_GLASS" = true ]; then + echo "> Starting the Looking Glass client..." + #while true; do sleep 1 && echo "lg" && sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN &> /dev/null && sleep 5 && sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]'; done & + autoConnectLookingGlass & +fi +##################################################################################### +################################## Start the VM ##################################### +##################################################################################### +if [ "$VM_START_MODE" = "qemu" ]; then if [ "$DRY_RUN" = true ]; then echo "> Generating qemu-system-x86_64 command (dry-run)..." echo "" @@ -632,58 +792,46 @@ if [ "$VM_START_MODE" = "qemu" ]; then echo "" echo "" else + echo "> Starting the Virtual Machine using qemu..." sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" fi elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ "$DRY_RUN" = false ]; then - if [ "$VM_INSTALL" = true ]; then - bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & - fi - echo "> Starting the Virtual Machine using virt-install..." - fi #VIRT_INSTALL_PARAMS+=("--debug") for param in "${QEMU_PARAMS[@]}"; do VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") done - #if [ "$VM_INSTALL" = true ]; then - if [ "$DRY_RUN" = true ]; then - echo "> Generating virt-install command (dry-run)..." - echo "" - printf "sudo virt-install" - for param in "${VIRT_INSTALL_PARAMS[@]}"; do - if [[ "${param}" == -* ]]; then - printf " \\\\\n ${param}" - elif [[ $param = *" "* ]]; then - printf " \"${param}\"" - else - printf " ${param}" - fi - done - echo "" - echo "" - elif [ "$GET_XML" = true ]; then - VIRT_INSTALL_PARAMS+=("--print-xml") - sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" - elif [ "$VM_INSTALL" = true ]; then - sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" - elif [ "$VM_INSTALL" = false ]; then - sudo virsh start "${VM_NAME}" - fi - #else - # if [ "$DRY_RUN" = true ]; then - # echo "" - # printf "sudo virt-install" - # else - # virsh start "${VM_NAME}" - # fi - #fi + if [ "$DRY_RUN" = true ]; then + echo "> Generating virt-install command (dry-run)..." + echo "" + printf "sudo virt-install" + for param in "${VIRT_INSTALL_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" + elif [ "$GET_XML" = true ]; then + VIRT_INSTALL_PARAMS+=("--print-xml") + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + elif [ "$VM_ACTION" = "install" ]; then + echo "> Starting the Virtual Machine using virt-install..." + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + elif [ "$VM_ACTION" = "start" ]; then + echo "> Starting the Virtual Machine using virsh..." + sudo virsh start "${VM_NAME}" + fi fi -# This gets executed when the vm exits - +##################################################################################### +################ Everything below gets executed when the vm exits ################### +##################################################################################### if [ "$DGPU_PASSTHROUGH" = true ]; then - echo "> Unbinding dGPU from vfio driver..." driver unbind "${DGPU_PCI_ADDRESS}" if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nouveau" ]; then @@ -692,7 +840,6 @@ if [ "$DGPU_PASSTHROUGH" = true ]; then fi echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" - fi if [ "$VGPU_UUID" != "" ]; then @@ -705,8 +852,11 @@ if [ "$VGPU_UUID" != "" ]; then fi -if [ "$VM_INSTALL" = true ]; then +if [ "$VM_ACTION" = "install" ]; then if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then + if [ "$ORIGINAL_VM_ACTION" = "auto" ]; then + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start + fi exit 0 else echo "> [Error] Seems like the installation failed..." diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index a34537c..747ad33 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -11,6 +11,7 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" UTILS_DIR="${SCRIPTS_DIR}/utils" COMMON_UTILS_DIR="${UTILS_DIR}/common" COMMON_UTILS_LIBS_DIR="${COMMON_UTILS_DIR}/libs" + COMMON_UTILS_PLUGINS_DIR="${COMMON_UTILS_DIR}/plugins" COMMON_UTILS_SETUP_DIR="${COMMON_UTILS_DIR}/setup" COMMON_UTILS_TOOLS_DIR="${COMMON_UTILS_DIR}/tools" DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")" diff --git a/scripts/utils/common/plugins/display-mode-1 b/scripts/utils/common/plugins/display-mode-1 new file mode 100644 index 0000000..71a555d --- /dev/null +++ b/scripts/utils/common/plugins/display-mode-1 @@ -0,0 +1,27 @@ +##################################################################################################### +# This script has to be sourced and is not meant to be executed directly! +# It sets the display output configuration. +# How to use: +# source "$PLUGIN_DIR/display-mode-x" +##################################################################################################### + +if [ "$DMA_BUF_AVAILABLE" = true ]; then + USE_QXL=false + USE_DMA_BUF=true + USE_RDP=false + if [ "$VM_ACTION" = "start" ]; then + USE_LOOKING_GLASS=true + elif [ "$VM_ACTION" = "install" ]; then + USE_LOOKING_GLASS=false + fi +else + USE_DMA_BUF=false + USE_RDP=true + if [ "$VM_ACTION" = "install" ]; then + USE_QXL=true + USE_LOOKING_GLASS=false + elif [ "$VM_ACTION" = "start" ]; then + USE_QXL=false + USE_LOOKING_GLASS=true + fi +fi \ No newline at end of file diff --git a/scripts/utils/common/plugins/display-mode-2 b/scripts/utils/common/plugins/display-mode-2 new file mode 100644 index 0000000..bcfdfce --- /dev/null +++ b/scripts/utils/common/plugins/display-mode-2 @@ -0,0 +1,22 @@ +##################################################################################################### +# This script has to be sourced and is not meant to be executed directly! +# It sets the display output configuration. +# How to use: +# source "$PLUGIN_DIR/display-mode-x" +##################################################################################################### + +RDP=true +if [ "$DMA_BUF_AVAILABLE" = true ]; then + USE_LOOKING_GLASS=true + USE_DMA_BUF=true + USE_QXL=false +else + USE_DMA_BUF=false + if [ "$VM_ACTION" = "install" ]; then + USE_QXL=true + USE_LOOKING_GLASS=false + elif [ "$VM_ACTION" = "start" ]; then + USE_QXL=false + USE_LOOKING_GLASS=true + fi +fi \ No newline at end of file diff --git a/scripts/utils/common/plugins/display-mode-3 b/scripts/utils/common/plugins/display-mode-3 new file mode 100644 index 0000000..b318a73 --- /dev/null +++ b/scripts/utils/common/plugins/display-mode-3 @@ -0,0 +1,24 @@ +##################################################################################################### +# This script has to be sourced and is not meant to be executed directly! +# It sets the display output configuration. +# How to use: +# source "$PLUGIN_DIR/display-mode-x" +##################################################################################################### + +if [ "$VM_ACTION" = "install" ]; then + USE_LOOKING_GLASS=false + USE_RDP=false + if [ "$DMA_BUF_AVAILABLE" = true ]; then + USE_DMA_BUF=true + USE_QXL=false + elif [ "$VM_ACTION" = "start" ]; then + USE_DMA_BUF=false + USE_QXL=true + fi +else + USE_SPICE_CLIENT=true + USE_LOOKING_GLASS=true + USE_RDP=true + USE_QXL=true + USE_DMA_BUF=false +fi \ No newline at end of file diff --git a/scripts/utils/common/plugins/display-mode-4 b/scripts/utils/common/plugins/display-mode-4 new file mode 100644 index 0000000..6c4e2fe --- /dev/null +++ b/scripts/utils/common/plugins/display-mode-4 @@ -0,0 +1,22 @@ +##################################################################################################### +# This script has to be sourced and is not meant to be executed directly! +# It sets the display output configuration. +# How to use: +# source "$PLUGIN_DIR/display-mode-x" +##################################################################################################### + +USE_LOOKING_GLASS=false + +if [ "$VM_ACTION" = "start" ]; then + USE_RDP=true +elif [ "$VM_ACTION" = "install" ]; then + USE_RDP=false +fi + +if [ "$DMA_BUF_AVAILABLE" = true ]; then + USE_QXL=false + USE_DMA_BUF=true +else + USE_DMA_BUF=false + USE_RDP=true +fi \ No newline at end of file diff --git a/scripts/utils/common/plugins/display-mode-5 b/scripts/utils/common/plugins/display-mode-5 new file mode 100644 index 0000000..2a02cf0 --- /dev/null +++ b/scripts/utils/common/plugins/display-mode-5 @@ -0,0 +1,24 @@ +##################################################################################################### +# This script has to be sourced and is not meant to be executed directly! +# It sets the display output configuration. +# How to use: +# source "$PLUGIN_DIR/display-mode-x" +##################################################################################################### + +if [ "$VM_ACTION" = "install" ]; then + USE_LOOKING_GLASS=false + USE_RDP=false + if [ "$DMA_BUF_AVAILABLE" = true ]; then + USE_DMA_BUF=true + USE_QXL=false + elif [ "$VM_ACTION" = "start" ]; then + USE_DMA_BUF=false + USE_QXL=true + fi +else + USE_SPICE_CLIENT=true + USE_LOOKING_GLASS=true + USE_RDP=true + USE_QXL=false + USE_DMA_BUF=false +fi \ No newline at end of file diff --git a/vm-files/network-scripts/nat_ifdown b/vm-files/network-scripts/nat_ifdown deleted file mode 100755 index bda185b..0000000 --- a/vm-files/network-scripts/nat_ifdown +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# qemu-ifdown script for QEMU/KVM with NAT network mode - -# set your bridge name -BRIDGE="virbr0" - -if [ -n "$1" ]; then - echo "Tearing down network bridge for $1" > /tmp/temp-nat.log - ip link set $1 down - brctl delif "$BRIDGE" $1 - ip link set "$BRIDGE" down - brctl delbr "$BRIDGE" - iptables -t nat -F - exit 0 -else - echo "Error: no interface specified" > /tmp/temp-nat.log - exit 1 -fi diff --git a/vm-files/network-scripts/nat_ifup b/vm-files/network-scripts/nat_ifup deleted file mode 100755 index 2b130a1..0000000 --- a/vm-files/network-scripts/nat_ifup +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash -# qemu-ifup script for QEMU/KVM with NAT netowrk mode - -# set your bridge name -BRIDGE=virbr0 - -# Network information -NETWORK=192.168.122.0 -NETMASK=255.255.255.0 -# GATEWAY for internal guests is the bridge in host -GATEWAY=192.168.122.1 -DHCPRANGE=192.168.122.2,192.168.122.254 - -# Optionally parameters to enable PXE support -TFTPROOT= -BOOTP= - -function check_bridge() -{ - if brctl show | grep "^$BRIDGE" &> /dev/null; then - return 1 - else - return 0 - fi -} - -function create_bridge() -{ - brctl addbr "$BRIDGE" - brctl stp "$BRIDGE" on - brctl setfd "$BRIDGE" 0 - ifconfig "$BRIDGE" "$GATEWAY" netmask "$NETMASK" up -} - -function enable_ip_forward() -{ - echo 1 > /proc/sys/net/ipv4/ip_forward -} - -function add_filter_rules() -{ - iptables -t nat -A POSTROUTING -s "$NETWORK"/"$NETMASK" \ - ! -d "$NETWORK"/"$NETMASK" -j MASQUERADE -} - -function start_dnsmasq() -{ - # don't run dnsmasq repeatedly - ps -ef | grep "dnsmasq" | grep -v "grep" &> /dev/null - if [ $? -eq 0 ]; then - echo "Warning:dnsmasq is already running. No need to run it again." - return 1 - fi - - dnsmasq \ - --strict-order \ - --except-interface=lo \ - --interface=$BRIDGE \ - --listen-address=$GATEWAY \ - --bind-interfaces \ - --dhcp-range=$DHCPRANGE \ - --conf-file="" \ - --pid-file=/var/run/qemu-dnsmasq-$BRIDGE.pid \ - --dhcp-leasefile=/var/run/qemu-dnsmasq-$BRIDGE.leases \ - --dhcp-no-override \ - ${TFTPROOT:+"--enable-tftp"} \ - ${TFTPROOT:+"--tftp-root=$TFTPROOT"} \ - ${BOOTP:+"--dhcp-boot=$BOOTP"} -} - -function setup_bridge_nat() -{ - check_bridge "$BRIDGE" - if [ $? -eq 0 ]; then - create_bridge - fi - enable_ip_forward - add_filter_rules "$BRIDGE" - start_dnsmasq "$BRIDGE" -} - -# need to check $1 arg before setup -if [ -n "$1" ]; then - setup_bridge_nat - ifconfig "$1" 0.0.0.0 up - brctl addif "$BRIDGE" "$1" - exit 0 -else - echo "Error: no interface specified." - exit 1 -fi diff --git a/vm-files/network-scripts/tap_ifdown b/vm-files/network-scripts/tap_ifdown deleted file mode 100755 index 612d0d8..0000000 --- a/vm-files/network-scripts/tap_ifdown +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# tap device name -TAP=tap0 - -# Network information -NETWORK=192.168.99.0 -NETMASK=255.255.255.0 -GATEWAY=192.168.99.1 - -DNSMASQPID=$(cat "/var/run/qemu-dnsmasq-$TAP.pid") - -if [ ! "$DNSMASQPID" = "" ]; then - kill -s SIGTERM $DNSMASQPID && echo "DNSMASQ terminated" -fi - -ip link set $TAP down -ip addr flush dev $TAP - -iptables -t nat -D POSTROUTING -s $NETWORK/$NETMASK -j MASQUERADE -iptables -D INPUT -i $TAP -s $NETWORK/$NETMASK -d $NETWORK/$NETMASK -j ACCEPT -iptables -D INPUT -i $TAP -p tcp -m tcp --dport 67 -j ACCEPT -iptables -D INPUT -i $TAP -p udp -m udp --dport 67 -j ACCEPT -iptables -D INPUT -i $TAP -p tcp -m tcp --dport 53 -j ACCEPT -iptables -D INPUT -i $TAP -p udp -m udp --dport 53 -j ACCEPT -iptables -D FORWARD -i $TAP -o $TAP -j ACCEPT -iptables -D FORWARD -s $NETWORK/$NETMASK -i $TAP -j ACCEPT -iptables -D FORWARD -s $GATEWAY -i $TAP -j ACCEPT -iptables -D FORWARD -d $NETWORK/$NETMASK -o $TAP -m state --state RELATED,ESTABLISHED -j ACCEPT - -echo 0 | dd of=/proc/sys/net/ipv4/ip_forward > /dev/null && echo "ip_forward disabled" \ No newline at end of file diff --git a/vm-files/network-scripts/tap_ifup b/vm-files/network-scripts/tap_ifup deleted file mode 100755 index e89ac40..0000000 --- a/vm-files/network-scripts/tap_ifup +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash - -# Set to the name of your tap device -TAP=tap0 - -# Network information -NETWORK=192.168.99.0 -NETMASK=255.255.255.0 -GATEWAY=192.168.99.1 -DHCPRANGE=192.168.99.2,192.168.99.10 - -check_tap() { - if ip link show | grep $TAP > /dev/null; then - return - else - exit 1 - fi -} - -enable_ip_forward() { - echo 1 | dd of=/proc/sys/net/ipv4/ip_forward > /dev/null -} - -start_dnsmasq(){ - dnsmasq \ - --strict-order \ - --interface=$TAP \ - --listen-address=$GATEWAY \ - --bind-interfaces \ - --dhcp-range=$DHCPRANGE \ - --dhcp-no-override \ - --pid-file=/var/run/qemu-dnsmasq-$TAP.pid -} - -add_iptable_rules() { -iptables-restore -n <<EOF -*nat --A POSTROUTING -s $NETWORK/$NETMASK -j MASQUERADE -COMMIT - -*filter --A INPUT -i $TAP -s $NETWORK/$NETMASK -d $NETWORK/$NETMASK -j ACCEPT -# Allow port 67 for DHCP, port 53 for dnsmasq --A INPUT -i $TAP -p tcp -m tcp --dport 67 -j ACCEPT --A INPUT -i $TAP -p udp -m udp --dport 67 -j ACCEPT --A INPUT -i $TAP -p tcp -m tcp --dport 53 -j ACCEPT --A INPUT -i $TAP -p udp -m udp --dport 53 -j ACCEPT - -# Connect the external network --A FORWARD -i $TAP -o $TAP -j ACCEPT --A FORWARD -s $NETWORK/$NETMASK -i $TAP -j ACCEPT --A FORWARD -s $GATEWAY -i $TAP -j ACCEPT --A FORWARD -d $NETWORK/$NETMASK -o $TAP -m state --state RELATED,ESTABLISHED -j ACCEPT -COMMIT -EOF -} - -start_tap() { - enable_ip_forward - check_tap - - # Flush old config and set new config - ip addr flush dev $TAP - ip addr add $GATEWAY/$NETMASK dev $TAP - ip link set $TAP up - - start_dnsmasq - - add_iptable_rules -} - -start_tap \ No newline at end of file From 16803ac03a01090c4e0c95dde54d9a4a2f5c7cd3 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Tue, 24 Aug 2021 18:26:14 +0200 Subject: [PATCH 30/40] Add support for more package managers (untested); Add missing dependencies --- .gitignore | 1 + requirements.sh | 2 +- scripts/main/generate-live-iso.sh | 3 +- scripts/main/setup.sh | 1 + scripts/main/vm.sh | 1328 +++++++++-------- scripts/utils/common/tools/get-manager | 8 + scripts/utils/manager-specific/package/apt | 45 +- scripts/utils/manager-specific/package/emerge | 72 + scripts/utils/manager-specific/package/pacman | 65 + scripts/utils/manager-specific/package/yum | 73 + scripts/utils/manager-specific/package/zypper | 64 + 11 files changed, 1024 insertions(+), 638 deletions(-) create mode 100755 scripts/utils/manager-specific/package/emerge create mode 100755 scripts/utils/manager-specific/package/pacman create mode 100755 scripts/utils/manager-specific/package/yum create mode 100755 scripts/utils/manager-specific/package/zypper diff --git a/.gitignore b/.gitignore index 55eac3e..7f7e13b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /helper-iso-files/drivers /helper-iso-files/.checksum /live-iso-files/*.iso +/live-iso-files/scripts/chocolatey-install.ps1 /utils/nvflash_linux /tmp .*.swp diff --git a/requirements.sh b/requirements.sh index 7a821a2..abb6273 100644 --- a/requirements.sh +++ b/requirements.sh @@ -35,7 +35,7 @@ EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") # git moby-engine EXEC_DEPS_GENERATE_CONFIG=("crudini") # crudini EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") # git wget curl-minimal unzip ruby rubygems rubygem-bundler p7zip make innoextract upx FILE_DEPS_VBIOS_FINDER=("/usr/include/rub*/ruby.h") # ruby-devel -EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat" "fdisk" "dd") # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat coreutils util-linux +EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat" "fdisk" "dd" "nmap") # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat coreutils util-linux nmap FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd" "/usr/share/libvirt/networks/default.xml") # edk2-ovmf libvirt-daemon-config-network EXEC_DEPS_RDP=("remmina") # remmina EXEC_DEPS_SAMBA=("samba") # samba diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh index a6e2b81..921dea2 100755 --- a/scripts/main/generate-live-iso.sh +++ b/scripts/main/generate-live-iso.sh @@ -81,7 +81,8 @@ function build_method_1() { echo 'echo "$GET_MBPT_DESKTOP_FILE" > /usr/share/applications/mbpt.desktop' >> "${TMP_SCRIPT}" sudo chmod +x "${TMP_SCRIPT}" - sudo editliveos \ + USERNAME="T-vK" sudo editliveos \ + --builder "T-vK" \ --noshell \ --script "${TMP_SCRIPT}" \ --extra-kernel-args "$ALL_KERNEL_PARAMS" \ diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index e6f3488..a959dec 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -31,6 +31,7 @@ alias createAutoStartService="'${SERVICE_MANAGER}' create-autostart-service" alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service" mkdir -p "${THIRDPARTY_DIR}" +mkdir -p "${VM_FILES_DIR}" MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 13cac67..a977360 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -22,7 +22,7 @@ elif [ "$VM_ACTION" = "stop" ]; then if [ "$VM_START_MODE" = "virt-install" ]; then sudo virsh destroy --domain "${VM_NAME}" elif [ "$VM_START_MODE" = "qemu" ]; then - sudo killall qemu-system-x86_64 &> /dev/null + sudo killall -9 qemu-system-x86_64 &> /dev/null fi elif [ "$VM_ACTION" = "auto" ]; then if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then @@ -36,7 +36,7 @@ elif [ "$VM_ACTION" = "remove" ]; then sudo virsh destroy --domain "${VM_NAME}" sudo virsh undefine --domain "${VM_NAME}" --nvram elif [ "$VM_START_MODE" = "qemu" ]; then - sudo killall qemu-system-x86_64 &> /dev/null + sudo killall -9 qemu-system-x86_64 &> /dev/null fi if [[ ${DRIVE_IMG} == *.img ]]; then sudo rm -f "${DRIVE_IMG}" @@ -72,794 +72,888 @@ QEMU_PARAMS=() ##################################################################################### ############################## Set basic VM parameters ############################## ##################################################################################### -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-name" "${VM_NAME}") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--name" "${VM_NAME}") -fi +function setMiscParams() { + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-name" "${VM_NAME}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--name" "${VM_NAME}") + fi -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-machine" "type=q35,accel=kvm") # for virt-install that's the default WHEN "--os-variant win10" is specified -fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-machine" "type=q35,accel=kvm") # for virt-install that's the default WHEN "--os-variant win10" is specified + fi -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-global" "ICH9-LPC.disable_s3=1") # for virt-install this enabled by default - QEMU_PARAMS+=("-global" "ICH9-LPC.disable_s4=1") # for virt-install this enabled by default -fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-global" "ICH9-LPC.disable_s3=1") # for virt-install this enabled by default + QEMU_PARAMS+=("-global" "ICH9-LPC.disable_s4=1") # for virt-install this enabled by default + fi -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-enable-kvm") # for virt-install this enabled by default -fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-enable-kvm") # for virt-install this enabled by default + fi -if [ "$VM_START_MODE" = "qemu" ]; then - # Refer to https://github.com/saveriomiroddi/qemu-pinning for information on how to set your cpu affinity properly - QEMU_PARAMS+=("-cpu" "host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--cpu" "host") - VIRT_INSTALL_PARAMS+=("--feature" "kvm.hidden.state=yes") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./features/hyperv/vendor_id/@state=on" "--xml" "xpath.set=./features/hyperv/vendor_id/@value='12alphanum'") -fi + if [ "$VM_START_MODE" = "qemu" ]; then + # Refer to https://github.com/saveriomiroddi/qemu-pinning for information on how to set your cpu affinity properly + QEMU_PARAMS+=("-cpu" "host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cpu" "host") + VIRT_INSTALL_PARAMS+=("--feature" "kvm.hidden.state=yes") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./features/hyperv/vendor_id/@state=on" "--xml" "xpath.set=./features/hyperv/vendor_id/@value='12alphanum'") + fi -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-mem-prealloc") # for virt-install this enabled by default -fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-mem-prealloc") # for virt-install this enabled by default + fi -QEMU_PARAMS+=("-rtc" "clock=host,base=localtime") -QEMU_PARAMS+=("-nographic") -QEMU_PARAMS+=("-serial" "none") -QEMU_PARAMS+=("-parallel" "none") -QEMU_PARAMS+=("-boot" "menu=on") -QEMU_PARAMS+=("-boot" "once=d") -QEMU_PARAMS+=("-k" "en-us") + QEMU_PARAMS+=("-rtc" "clock=host,base=localtime") + QEMU_PARAMS+=("-nographic") + QEMU_PARAMS+=("-serial" "none") + QEMU_PARAMS+=("-parallel" "none") + QEMU_PARAMS+=("-boot" "menu=on") + QEMU_PARAMS+=("-boot" "once=d") + QEMU_PARAMS+=("-k" "en-us") -QEMU_PARAMS+=("-device" "ich9-intel-hda") -QEMU_PARAMS+=("-device" "hda-output") -QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") -# More parameters are added throughout the whole script + QEMU_PARAMS+=("-device" "ich9-intel-hda") + QEMU_PARAMS+=("-device" "hda-output") + QEMU_PARAMS+=("-device" "pci-bridge,addr=12.0,chassis_nr=2,id=head.2") + # More parameters are added throughout the whole script -VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") -VIRT_INSTALL_PARAMS+=("--os-variant" "win10") -VIRT_INSTALL_PARAMS+=("--arch=x86_64") + VIRT_INSTALL_PARAMS+=("--virt-type" "kvm") + VIRT_INSTALL_PARAMS+=("--os-variant" "win10") + VIRT_INSTALL_PARAMS+=("--arch=x86_64") +} ##################################################################################### ################################# Set up networking ################################# ##################################################################################### -if [ "$NETWORK_MODE" == "bridged" ]; then - echo "> Using network mode ${NETWORK_MODE}..." - if ! sudo virsh net-list | grep default | grep --quiet active; then - sudo virsh net-start default - fi +function setUpNetworking() { + if [ "$NETWORK_MODE" == "bridged" ]; then + echo "> Using network mode ${NETWORK_MODE}..." + if ! sudo virsh net-list | grep default | grep --quiet active; then + sudo virsh net-start default + fi - if [ "$MAC_ADDRESS" = "auto" ]; then - MAC_ADDRESS=$(printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))) - fi - echo "> Using MAC address: ${MAC_ADDRESS}..." + if [ "$MAC_ADDRESS" = "auto" ]; then + MAC_ADDRESS=$(printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))) + fi + echo "> Using MAC address: ${MAC_ADDRESS}..." - INTERFACE_NAME="$(sudo cat /var/lib/libvirt/dnsmasq/default.conf | grep "^interface=" | cut -d'=' -f2-)" - NETWORK="$(sudo ip route | grep " ${INTERFACE_NAME} " | cut -d' ' -f1)" + INTERFACE_NAME="$(sudo cat /var/lib/libvirt/dnsmasq/default.conf | grep "^interface=" | cut -d'=' -f2-)" + NETWORK="$(sudo ip route | grep " ${INTERFACE_NAME} " | cut -d' ' -f1)" - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-net" "nic,model=e1000,macaddr=${MAC_ADDRESS}" "-net" "bridge,br=virbr0") - #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") - #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") - #-net user,hostfwd=tcp::13389-:3389 -net nic - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--network" "network=default,model=e1000,mac=${MAC_ADDRESS}") - #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[type=network]/mac@address='${MAC_ADDRESS}'") - #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[0]/source@network=default") - #if ! sudo virsh net-list | grep default | grep --quiet active; then - # sudo virsh net-start default - #fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-net" "nic,model=e1000,macaddr=${MAC_ADDRESS}" "-net" "bridge,br=virbr0") + #QEMU_PARAMS+=("-netdev" "type=tap,id=net0,ifname=tap0,script=${VM_FILES_DIR}/network-scripts/tap_ifup,downscript=${VM_FILES_DIR}/network-scripts/tap_ifdown,vhost=on") + #QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0,addr=19.0,mac=${MAC_ADDRESS}") + #-net user,hostfwd=tcp::13389-:3389 -net nic + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--network" "network=default,model=e1000,mac=${MAC_ADDRESS}") + #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[type=network]/mac@address='${MAC_ADDRESS}'") + #VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/interface[0]/source@network=default") + #if ! sudo virsh net-list | grep default | grep --quiet active; then + # sudo virsh net-start default + #fi + fi + else + echo "Networking will not be enabled for this VM..." fi -else - echo "Networking will not be enabled for this VM..." -fi +} ##################################################################################### ################################### Set CPU Cores ################################### ##################################################################################### -if [ "$CPU_CORE_COUNT" = "auto" ]; then - AVAILABLE_CPU_CORE_COUNT="$(nproc)" - CPU_CORE_COUNT="$((AVAILABLE_CPU_CORE_COUNT-1))" - if [[ $CPU_CORE_COUNT -gt 16 ]]; then - CPU_CORE_COUNT=16 +function setCpuCores() { + if [ "$CPU_CORE_COUNT" = "auto" ]; then + AVAILABLE_CPU_CORE_COUNT="$(nproc)" + CPU_CORE_COUNT="$((AVAILABLE_CPU_CORE_COUNT-1))" + if [[ $CPU_CORE_COUNT -gt 16 ]]; then + CPU_CORE_COUNT=16 + fi fi -fi -echo "> Using ${CPU_CORE_COUNT} CPU cores..." -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-smp" "${CPU_CORE_COUNT}") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--vcpu" "${CPU_CORE_COUNT}") -fi + echo "> Using ${CPU_CORE_COUNT} CPU cores..." + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-smp" "${CPU_CORE_COUNT}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--vcpu" "${CPU_CORE_COUNT}") + fi +} ##################################################################################### ################################### Set RAM size #################################### ##################################################################################### -if [ "$RAM_SIZE" = "auto" ]; then - FREE_RAM="$(free -g | grep 'Mem: ' | tr -s ' ' | cut -d ' ' -f7)" - RAM_SIZE_GB="$((FREE_RAM-1))" - if [[ $RAM_SIZE_GB -gt 16 ]]; then - RAM_SIZE_GB=16 +function setRamSize() { + if [ "$RAM_SIZE" = "auto" ]; then + FREE_RAM="$(free -g | grep 'Mem: ' | tr -s ' ' | cut -d ' ' -f7)" + RAM_SIZE_GB="$((FREE_RAM-1))" + if [[ $RAM_SIZE_GB -gt 16 ]]; then + RAM_SIZE_GB=16 + fi + RAM_SIZE="${RAM_SIZE_GB}G" fi - RAM_SIZE="${RAM_SIZE_GB}G" -fi -echo "> Using ${RAM_SIZE} of RAM..." -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-m" "${RAM_SIZE}") -elif [ "$VM_START_MODE" = "virt-install" ]; then - RAM_SIZE_GB="$(numfmt --from=si "${RAM_SIZE}" --to-unit=1M)" - VIRT_INSTALL_PARAMS+=("--memory" "${RAM_SIZE_GB}") -fi + echo "> Using ${RAM_SIZE} of RAM..." + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-m" "${RAM_SIZE}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + RAM_SIZE_GB="$(numfmt --from=si "${RAM_SIZE}" --to-unit=1M)" + VIRT_INSTALL_PARAMS+=("--memory" "${RAM_SIZE_GB}") + fi +} ##################################################################################### ############################## Set install media (ISO) ############################## ##################################################################################### -if [ "$VM_ACTION" = "install" ]; then - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") +function setInstallMediaParam() { + if [ "$VM_ACTION" = "install" ]; then + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${INSTALL_IMG},index=1,media=cdrom") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--cdrom" "${INSTALL_IMG}") + fi fi -fi +} ##################################################################################### ################################## Set helper ISO ################################### ##################################################################################### -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=2,media=cdrom") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") -fi +function setHelperIsoParam() { + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${HELPER_ISO},index=2,media=cdrom") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "device=cdrom,path=${HELPER_ISO}") + fi +} ##################################################################################### ########################### Set/create OS install drive ############################# ##################################################################################### -if [[ ${DRIVE_IMG} == /dev/* ]]; then - echo "> Using a physical OS drive..." - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "file=${DRIVE_IMG},if=virtio" "-snapshot") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") - fi - #QEMU_PARAMS+=("-drive" "file=/dev/sda,if=virtio" "-drive" "file=/dev/sdb,if=virtio" "-drive" "file=/dev/sdc,if=virtio" "-drive" "file=/dev/sdd,if=virtio" "-snapshot") -elif [[ ${DRIVE_IMG} == *.img ]]; then - echo "> Using a virtual OS drive..." - if [ "$VM_ACTION" = "install" ] && [ -f "${DRIVE_IMG}" ]; then - echo "> Removing old virtual disk..." - sudo rm -rf "${DRIVE_IMG}" - fi - if [ ! -f "${DRIVE_IMG}" ]; then - echo "> Creating a virtual disk for the VM..." - qemu-img create -f raw "${DRIVE_IMG}" "${VM_DISK_SIZE}" > /dev/null - sudo chown "$(whoami):$(id -gn "$(whoami)")" "${DRIVE_IMG}" - fi - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=${DRIVE_IMG}") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") +function setUpOsDrive() { + if [[ ${DRIVE_IMG} == /dev/* ]]; then + echo "> Using a physical OS drive..." + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "file=${DRIVE_IMG},if=virtio" "-snapshot") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") + fi + #QEMU_PARAMS+=("-drive" "file=/dev/sda,if=virtio" "-drive" "file=/dev/sdb,if=virtio" "-drive" "file=/dev/sdc,if=virtio" "-drive" "file=/dev/sdd,if=virtio" "-snapshot") + elif [[ ${DRIVE_IMG} == *.img ]]; then + echo "> Using a virtual OS drive..." + if [ "$VM_ACTION" = "install" ] && [ -f "${DRIVE_IMG}" ]; then + echo "> Removing old virtual disk..." + sudo rm -rf "${DRIVE_IMG}" + fi + if [ ! -f "${DRIVE_IMG}" ]; then + echo "> Creating a virtual disk for the VM..." + qemu-img create -f raw "${DRIVE_IMG}" "${VM_DISK_SIZE}" > /dev/null + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${DRIVE_IMG}" + fi + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=${DRIVE_IMG}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--disk" "${DRIVE_IMG}") + fi + OS_DRIVE_SIZE="$(sudo ls -l --b=G "${DRIVE_IMG}" | cut -d " " -f5)" + echo "> Virtual OS drive has ${OS_DRIVE_SIZE} of storage." + else + echo "> Error: It appears that no proper OS drive (image) has been provided. Check your 'DRIVE_IMG' var: '${DRIVE_IMG}'" + exit fi - OS_DRIVE_SIZE="$(sudo ls -l --b=G "${DRIVE_IMG}" | cut -d " " -f5)" - echo "> Virtual OS drive has ${OS_DRIVE_SIZE} of storage." -else - echo "> Error: It appears that no proper OS drive (image) has been provided. Check your 'DRIVE_IMG' var: '${DRIVE_IMG}'" - exit -fi +} ##################################################################################### ################ Figure out if optirun or DRI_PRIME should be used ################## ##################################################################################### -if sudo which optirun &> /dev/null && sudo optirun echo > /dev/null ; then - OPTIRUN_PREFIX="optirun " - DRI_PRIME_PREFIX="" - echo "> Bumblebee works fine on this system. Using optirun when necessary..." -else - OPTIRUN_PREFIX="" - if [ "$SUPPORTS_DRI_PRIME" = true ]; then - DRI_PRIME_PREFIX="DRI_PRIME=1 " +function bumblebeeCheck() { + if sudo which optirun &> /dev/null && sudo optirun echo > /dev/null ; then + OPTIRUN_PREFIX="optirun " + DRI_PRIME_PREFIX="" + echo "> Bumblebee works fine on this system. Using optirun when necessary..." else - echo "> Bumblebee is not available..." + OPTIRUN_PREFIX="" + if [ "$SUPPORTS_DRI_PRIME" = true ]; then + DRI_PRIME_PREFIX="DRI_PRIME=1 " + else + echo "> Bumblebee is not available..." + fi fi -fi +} ##################################################################################### ########################## Set up samba share directory ############################# ##################################################################################### -if [ -z "$SMB_SHARE_FOLDER" ]; then - echo "> Not using SMB share..." -else - echo "> Using SMB share..." - QEMU_PARAMS+=("-net" "user,smb=${SMB_SHARE_FOLDER}") -fi +function setUpSambaShare() { + if [ -z "$SMB_SHARE_FOLDER" ]; then + echo "> Not using SMB share..." + else + echo "> Using SMB share..." + QEMU_PARAMS+=("-net" "user,smb=${SMB_SHARE_FOLDER}") + fi +} ##################################################################################### ####################### Set parameters for dGPU passthrough ######################### ##################################################################################### -if [ "$DGPU_PASSTHROUGH" != false ]; then - DGPU_PASSTHROUGH=false - availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" - if [ "$DGPU_PCI_ADDRESS" = "auto" ]; then - DGPU_PCI_ADDRESS="" - while IFS= read -r pciAddress; do - gpuInfo="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" - if [[ "$gpuInfo" != *"Intel"* ]]; then - DGPU_PCI_ADDRESS="$pciAddress" - break - fi - done <<< "$availableGpusIds" - fi - - if [ "$(echo -e "$availableGpusIds" | wc -l)" -le 1 ]; then - echo "> Not using dGPU passthrough because single GPU passthrough is not supported yet..." - elif [ "$DGPU_PCI_ADDRESS" != "" ]; then - DGPU_PASSTHROUGH=true - echo "> Using dGPU passthrough..." - - if [ "$HOST_DGPU_DRIVER" = "auto" ]; then - HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" +function setDGpuParams() { + if [ "$DGPU_PASSTHROUGH" != false ]; then + DGPU_PASSTHROUGH=false + availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" + if [ "$DGPU_PCI_ADDRESS" = "auto" ]; then + DGPU_PCI_ADDRESS="" + while IFS= read -r pciAddress; do + gpuInfo="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" + if [[ "$gpuInfo" != *"Intel"* ]]; then + DGPU_PCI_ADDRESS="$pciAddress" + break + fi + done <<< "$availableGpusIds" fi - DGPU_INFO="$(sudo lspci | grep "$DGPU_PCI_ADDRESS" | cut -d' ' -f2-)" - echo "> dGPU is: $DGPU_INFO" - echo "> dGPU dirver is $HOST_DGPU_DRIVER" - - echo "> Retrieving and parsing DGPU IDs..." - DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) - DGPU_VENDOR_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f1) - DGPU_DEVICE_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f2) - DGPU_SS_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -vnn -d "${DGPU_IDS}" | grep "Subsystem:" | grep -oP "\w+:\w+") - DGPU_SS_VENDOR_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f1) - DGPU_SS_DEVICE_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f2) - - if [ -z "$DGPU_IDS" ]; then - echo "> Error: Failed to retrieve DGPU IDs!" - echo "> DGPU_PCI_ADDRESS: ${DGPU_PCI_ADDRESS}" - echo "> DGPU_IDS: $DGPU_IDS" - echo "> DGPU_VENDOR_ID: $DGPU_VENDOR_ID" - echo "> DGPU_DEVICE_ID: $DGPU_DEVICE_ID" - echo "> DGPU_SS_IDS: $DGPU_SS_IDS" - echo "> DGPU_SS_VENDOR_ID: $DGPU_SS_VENDOR_ID" - echo "> DGPU_SS_DEVICE_ID: $DGPU_SS_DEVICE_ID" - exit 1 - fi + if [ "$(echo -e "$availableGpusIds" | wc -l)" -le 1 ]; then + echo "> Not using dGPU passthrough because single GPU passthrough is not supported yet..." + elif [ "$DGPU_PCI_ADDRESS" != "" ]; then + DGPU_PASSTHROUGH=true + echo "> Using dGPU passthrough..." - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=pci.1") # DGPU root port - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port,address.type=pci,address.bus=0x0,address.slot=0x1c,address.function=0x0,address.multifunction=on,index=1,alias.name=pci.1") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/model/@name=ioh3420") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/target/@chassis=1") - fi + if [ "$HOST_DGPU_DRIVER" = "auto" ]; then + HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" + fi - if [ "$VM_START_MODE" = "qemu" ]; then - if [ -z "$DGPU_ROM" ]; then - echo "> Not using DGPU vBIOS override..." - DGPU_ROM_PARAM=",rombar=0" - else - echo "> Using DGPU vBIOS override..." - DGPU_ROM_PARAM=",romfile=${DGPU_ROM}" + DGPU_INFO="$(sudo lspci | grep "$DGPU_PCI_ADDRESS" | cut -d' ' -f2-)" + echo "> dGPU is: $DGPU_INFO" + echo "> dGPU dirver is $HOST_DGPU_DRIVER" + + echo "> Retrieving and parsing DGPU IDs..." + DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) + DGPU_VENDOR_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f1) + DGPU_DEVICE_ID=$(echo "${DGPU_IDS}" | cut -d ":" -f2) + DGPU_SS_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -vnn -d "${DGPU_IDS}" | grep "Subsystem:" | grep -oP "\w+:\w+") + DGPU_SS_VENDOR_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f1) + DGPU_SS_DEVICE_ID=$(echo "${DGPU_SS_IDS}" | cut -d ":" -f2) + + if [ -z "$DGPU_IDS" ]; then + echo "> Error: Failed to retrieve DGPU IDs!" + echo "> DGPU_PCI_ADDRESS: ${DGPU_PCI_ADDRESS}" + echo "> DGPU_IDS: $DGPU_IDS" + echo "> DGPU_VENDOR_ID: $DGPU_VENDOR_ID" + echo "> DGPU_DEVICE_ID: $DGPU_DEVICE_ID" + echo "> DGPU_SS_IDS: $DGPU_SS_IDS" + echo "> DGPU_SS_VENDOR_ID: $DGPU_SS_VENDOR_ID" + echo "> DGPU_SS_DEVICE_ID: $DGPU_SS_DEVICE_ID" + exit 1 fi - QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=pci.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") - elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ -z "$DGPU_ROM" ]; then - echo "> Not using DGPU vBIOS override..." - DGPU_ROM_PARAM=",rom.bar=on" + + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=pci.1") # DGPU root port + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--controller" "type=pci,model=pcie-root-port,address.type=pci,address.bus=0x0,address.slot=0x1c,address.function=0x0,address.multifunction=on,index=1,alias.name=pci.1") # <controller type='pci' model='pcie-root-port'><model name='ioh3420'/></controller> + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/model/@name=ioh3420") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/controller/target/@chassis=1") fi - VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.bus=1,address.type=pci,address.multifunction=on${DGPU_ROM_PARAM}") - if [ ! -z "$DGPU_ROM" ]; then - echo "> Using DGPU vBIOS override..." - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev/rom/@file=${DGPU_ROM}") - QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-device-id=$((16#${DGPU_SS_DEVICE_ID}))") - QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-vendor-id=$((16#${DGPU_SS_VENDOR_ID}))") + + if [ "$VM_START_MODE" = "qemu" ]; then + if [ -z "$DGPU_ROM" ]; then + echo "> Not using DGPU vBIOS override..." + DGPU_ROM_PARAM=",rombar=0" + else + echo "> Using DGPU vBIOS override..." + DGPU_ROM_PARAM=",romfile=${DGPU_ROM}" + fi + QEMU_PARAMS+=("-device" "vfio-pci,host=${DGPU_PCI_ADDRESS},bus=pci.1,addr=00.0,x-pci-sub-device-id=0x${DGPU_SS_DEVICE_ID},x-pci-sub-vendor-id=0x${DGPU_SS_VENDOR_ID},multifunction=on${DGPU_ROM_PARAM}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ -z "$DGPU_ROM" ]; then + echo "> Not using DGPU vBIOS override..." + DGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "${DGPU_PCI_ADDRESS},address.bus=1,address.type=pci,address.multifunction=on${DGPU_ROM_PARAM}") + if [ ! -z "$DGPU_ROM" ]; then + echo "> Using DGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev/rom/@file=${DGPU_ROM}") + QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-device-id=$((16#${DGPU_SS_DEVICE_ID}))") + QEMU_PARAMS+=("-set" "device.hostdev0.x-pci-sub-vendor-id=$((16#${DGPU_SS_VENDOR_ID}))") + fi fi + else + echo "> Not using dGPU passthrough..." fi else echo "> Not using dGPU passthrough..." fi -else - echo "> Not using dGPU passthrough..." -fi +} ############################################################################################## ### If mediated iGPU passthrough is enabled, check if vGPU exists or if one can be created ### ############################################################################################## -DMA_BUF_AVAILABLE=false -if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = "auto" ]; then - - if [ "$IGPU_PCI_ADDRESS" = "auto" ]; then - IGPU_PCI_ADDRESS="" - availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" - - while IFS= read -r pciAddress; do - gpuInfo="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" - if [[ "$gpuInfo" == *"Intel"* ]]; then - IGPU_PCI_ADDRESS="$pciAddress" - break +function vGpuSetup() { + DMA_BUF_AVAILABLE=false + if [ "$SHARE_IGPU" = true ] || [ "$SHARE_IGPU" = "auto" ]; then + + if [ "$IGPU_PCI_ADDRESS" = "auto" ]; then + IGPU_PCI_ADDRESS="" + availableGpusIds="$(sudo ${OPTIRUN_PREFIX}lshw -C display -businfo | grep 'pci@' | cut -d'@' -f2 | cut -d' ' -f1 | cut -d':' -f2-)" + + while IFS= read -r pciAddress; do + gpuInfo="$(sudo ${OPTIRUN_PREFIX}lspci -s "$pciAddress")" + if [[ "$gpuInfo" == *"Intel"* ]]; then + IGPU_PCI_ADDRESS="$pciAddress" + break + fi + done <<< "$availableGpusIds" + fi + + if [ "$IGPU_PCI_ADDRESS" != "" ]; then + vgpu init # load required kernel modules + + # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. + # So for now we can't create a new vGPU every time the VM starts. + #vgpu remove "${IGPU_PCI_ADDRESS}" &> /dev/null # Ensure there are no vGPUs before creating a new one + VGPU_UUID="$(vgpu get "${IGPU_PCI_ADDRESS}" | head -1)" + if [ "$VGPU_UUID" == "" ]; then + echo "> Creating a vGPU for mediated iGPU passthrough..." + VGPU_UUID="$(vgpu create "${IGPU_PCI_ADDRESS}")" + if [ "$?" = "1" ]; then + echo "> [Error] Failed creating a vGPU. (You can try again. If you still get this error, you have to reboot. This seems to be a bug in Linux.)" + echo "> Continuing without mediated iGPU passthrough..." + VGPU_UUID="" + fi fi - done <<< "$availableGpusIds" - fi - - if [ "$IGPU_PCI_ADDRESS" != "" ]; then - vgpu init # load required kernel modules - # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. - # So for now we can't create a new vGPU every time the VM starts. - #vgpu remove "${IGPU_PCI_ADDRESS}" &> /dev/null # Ensure there are no vGPUs before creating a new one - VGPU_UUID="$(vgpu get "${IGPU_PCI_ADDRESS}" | head -1)" - if [ "$VGPU_UUID" == "" ]; then - echo "> Creating a vGPU for mediated iGPU passthrough..." - VGPU_UUID="$(vgpu create "${IGPU_PCI_ADDRESS}")" - if [ "$?" = "1" ]; then - echo "> [Error] Failed creating a vGPU. (You can try again. If you still get this error, you have to reboot. This seems to be a bug in Linux.)" - echo "> Continuing without mediated iGPU passthrough..." - VGPU_UUID="" + if [ "$VGPU_UUID" != "" ]; then + IGPU_INFO="$(sudo lspci | grep "$IGPU_PCI_ADDRESS" | cut -d' ' -f2-)" + echo "> iGPU is: $IGPU_INFO" + echo "> iGPU dirver is: $HOST_DGPU_DRIVER" + echo "> UUID of vGPU is: $VGPU_UUID" + DMA_BUF_AVAILABLE=true fi - fi - - if [ "$VGPU_UUID" != "" ]; then - IGPU_INFO="$(sudo lspci | grep "$IGPU_PCI_ADDRESS" | cut -d' ' -f2-)" - echo "> iGPU is: $IGPU_INFO" - echo "> iGPU dirver is: $HOST_DGPU_DRIVER" - echo "> UUID of vGPU is: $VGPU_UUID" - DMA_BUF_AVAILABLE=true + else + echo "> No iGPU found. - Not using mediated iGPU passthrough..." fi else - echo "> No iGPU found. - Not using mediated iGPU passthrough..." + echo "> Not using mediated iGPU passthrough..." fi -else - echo "> Not using mediated iGPU passthrough..." -fi +} ##################################################################################### ############################ Load display output plugin ############################# ##################################################################################### -if [ "$DISPLAY_MODE" != "" ]; then - echo "> Loading display-mode-${DISPLAY_MODE} plugin..." - source "${COMMON_UTILS_PLUGINS_DIR}/display-mode-${DISPLAY_MODE}" -else - echo "> [Error] No display mode provided..." -fi +function loadDisplayOutputPlugin() { + if [ "$DISPLAY_MODE" != "" ]; then + echo "> Loading display-mode-${DISPLAY_MODE} plugin..." + source "${COMMON_UTILS_PLUGINS_DIR}/display-mode-${DISPLAY_MODE}" + else + echo "> [Error] No display mode provided..." + fi +} ######################################################################################################### ### If there is a vGPU for mediated iGPU passthrough, set parameters for iGPU passthrough and dma-buf ### ######################################################################################################### -if [ "$VGPU_UUID" != "" ]; then - if [ "$VM_START_MODE" = "qemu" ]; then +function setIGpuParams() { + if [ "$VGPU_UUID" != "" ]; then + if [ "$VM_START_MODE" = "qemu" ]; then - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - DMA_BUF_PARAM=",display=on,x-igd-opregion=on" - else - echo "> Not using dma-buf..." - DMA_BUF_PARAM="" - fi + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + DMA_BUF_PARAM=",display=on,x-igd-opregion=on" + else + echo "> Not using dma-buf..." + DMA_BUF_PARAM="" + fi - if [ -z "$IGPU_ROM" ]; then - echo "> Not using iGPU vBIOS override..." - #IGPU_ROM_PARAM=",rom.bar=on" - else - echo "> Using iGPU vBIOS override..." - IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" - fi + if [ -z "$IGPU_ROM" ]; then + echo "> Not using iGPU vBIOS override..." + #IGPU_ROM_PARAM=",rom.bar=on" + else + echo "> Using iGPU vBIOS override..." + IGPU_ROM_PARAM=",romfile=${IGPU_ROM}" + fi - QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G - elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ "$USE_DMA_BUF" = true ]; then - echo "> Using dma-buf..." - #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display - QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") - GVTG_DISPLAY_STATE="on" - else - echo "> Not using dma-buf..." - GVTG_DISPLAY_STATE="off" - fi + QEMU_PARAMS+=("-device" "vfio-pci,bus=pcie.0,addr=05.0,sysfsdev=/sys/bus/mdev/devices/${VGPU_UUID}${IGPU_ROM_PARAM}${DMA_BUF_PARAM}") # GVT-G + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$USE_DMA_BUF" = true ]; then + echo "> Using dma-buf..." + #QEMU_PARAMS+=("-display" "egl-headless") #"-display" "gtk,gl=on" # DMA BUF Display + QEMU_PARAMS+=("-set" "device.hostdev1.x-igd-opregion=on") + GVTG_DISPLAY_STATE="on" + else + echo "> Not using dma-buf..." + GVTG_DISPLAY_STATE="off" + fi - if [ -z "$IGPU_ROM" ]; then - echo "> Not using iGPU vBIOS override..." - IGPU_ROM_PARAM=",rom.bar=on" - fi - VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") - - if [ ! -z "$IGPU_ROM" ]; then - echo "> Using iGPU vBIOS override..." - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + if [ -z "$IGPU_ROM" ]; then + echo "> Not using iGPU vBIOS override..." + IGPU_ROM_PARAM=",rom.bar=on" + fi + VIRT_INSTALL_PARAMS+=("--hostdev" "type=mdev,alias.name=hostdev1,address.domain=0000,address.bus=0,address.slot=2,address.function=0,address.type=pci,address.multifunction=on${IGPU_ROM_PARAM}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/@model=vfio-pci") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/source/address/@uuid=${VGPU_UUID}") + + if [ ! -z "$IGPU_ROM" ]; then + echo "> Using iGPU vBIOS override..." + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/hostdev[2]/rom/@file=${IGPU_ROM}") + fi fi fi -fi +} ##################################################################################### ############################### Set Spice parameters ################################ ##################################################################################### -if [ "$USE_SPICE" = true ]; then - if sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN; then - echo "[Error] Something is blocking the SPICE_PORT (${SPICE_PORT})! Change it in your config or kill whatever is blocking it." - else - echo "> Using spice on port ${SPICE_PORT}..." - #QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--channel" "spicevmc,target.address=127.0.0.1:${SPICE_PORT}") - #VIRT_INSTALL_PARAMS+=("--graphics" "spice,port=${SPICE_PORT}") +function setSpiceParams() { + if [ "$USE_SPICE" = true ]; then + if sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN; then + echo "[Error] Something is blocking the SPICE_PORT (${SPICE_PORT})! Change it in your config or kill whatever is blocking it." + else + echo "> Using spice on port ${SPICE_PORT}..." + #QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-spice" "port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing") #Spice + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--channel" "spicevmc,target.address=127.0.0.1:${SPICE_PORT}") + #VIRT_INSTALL_PARAMS+=("--graphics" "spice,port=${SPICE_PORT}") + fi fi + function waitForSpice() { + while true; do + if sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN &> /dev/null; then + break + fi + sleep 1 + done + } + else + echo "> Not using Spice..." fi - function waitForSpice() { - while true; do - if sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN &> /dev/null; then - break - fi - sleep 1 - done - } -else - echo "> Not using Spice..." -fi +} ##################################################################################### ###################### Check if spice client should be started ###################### ##################################################################################### -if [ "$USE_SPICE_CLIENT" = "auto" ] && [ "$USE_SPICE" = true ]; then - if [ "$VM_ACTION" = "install" ]; then - USE_SPICE_CLIENT=true - elif [ "$USE_LOOKING_GLASS" = true ]; then - USE_SPICE_CLIENT=true +function spiceClientCheck() { + if [ "$USE_SPICE_CLIENT" = "auto" ] && [ "$USE_SPICE" = true ]; then + if [ "$VM_ACTION" = "install" ]; then + USE_SPICE_CLIENT=true + elif [ "$USE_LOOKING_GLASS" = true ]; then + USE_SPICE_CLIENT=true + fi fi -fi +} ##################################################################################### ############ Set QXL parameters if loaded display output plugin wants it ############ ##################################################################################### -if [ "$USE_QXL" = true ]; then - echo "> Using QXL..." - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "qxl,bus=pcie.0,addr=1c.4,id=video.2") - #QEMU_PARAMS+=("-vga" "qxl") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--video" "qxl") - #-video qxl --channel spicevmc +function setQxl() { + if [ "$USE_QXL" = true ]; then + echo "> Using QXL..." + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "qxl,bus=pcie.0,addr=1c.4,id=video.2") + #QEMU_PARAMS+=("-vga" "qxl") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--video" "qxl") + #-video qxl --channel spicevmc + fi + else + echo "> Not using QXL..." fi -else - echo "> Not using QXL..." -fi +} ##################################################################################### ####### Set Looking Glass parameters if loaded display output plugin wants it ####### ##################################################################################### -if [ "$USE_LOOKING_GLASS" = true ]; then - echo "> Using Looking Glass..." - echo "> Calculating required buffer size for ${LOOKING_GLASS_MAX_SCREEN_WIDTH}x${LOOKING_GLASS_MAX_SCREEN_HEIGHT} for Looking Glass..." - UNROUNDED_BUFFER_SIZE=$((($LOOKING_GLASS_MAX_SCREEN_WIDTH * $LOOKING_GLASS_MAX_SCREEN_HEIGHT * 4 * 2)/1024/1024+10)) - BUFFER_SIZE=1 - while [[ $BUFFER_SIZE -le $UNROUNDED_BUFFER_SIZE ]]; do - BUFFER_SIZE=$(($BUFFER_SIZE*2)) - done - LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}" - echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}MB" - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") - QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}M") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/@name=looking-glass") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/model/@type=ivshmem-plain") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=${LOOKING_GLASS_BUFFER_SIZE}") - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size/@unit=M") - fi - #sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" - #sudo bash -c "echo 'f /dev/shm/looking-glass 0660 qemu kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" - #sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass - - function autoConnectLookingGlass() { - while true; do - VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" - if [ "$VM_IP" != "" ]; then - while true; do - if nc -vz "$VM_IP" 3389 &> /dev/null; then - sleep 5 - echo "> Starting the Looking Glass client to connect with the VM..." - sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]' & - break - fi - sleep 1 - done - break - fi - sleep 1 +function setUpLookingGlassParams() { + if [ "$USE_LOOKING_GLASS" = true ]; then + echo "> Using Looking Glass..." + echo "> Calculating required buffer size for ${LOOKING_GLASS_MAX_SCREEN_WIDTH}x${LOOKING_GLASS_MAX_SCREEN_HEIGHT} for Looking Glass..." + UNROUNDED_BUFFER_SIZE=$((($LOOKING_GLASS_MAX_SCREEN_WIDTH * $LOOKING_GLASS_MAX_SCREEN_HEIGHT * 4 * 2)/1024/1024+10)) + BUFFER_SIZE=1 + while [[ $BUFFER_SIZE -le $UNROUNDED_BUFFER_SIZE ]]; do + BUFFER_SIZE=$(($BUFFER_SIZE*2)) done - } -else - echo "> Not using Looking Glass..." -fi + LOOKING_GLASS_BUFFER_SIZE="${BUFFER_SIZE}" + echo "> Looking Glass buffer size set to: ${LOOKING_GLASS_BUFFER_SIZE}MB" + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-device" "ivshmem-plain,memdev=ivshmem,bus=pcie.0") + QEMU_PARAMS+=("-object" "memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=${LOOKING_GLASS_BUFFER_SIZE}M") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/@name=looking-glass") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/model/@type=ivshmem-plain") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size=${LOOKING_GLASS_BUFFER_SIZE}") + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./devices/shmem/size/@unit=M") + fi + #sudo bash -c "echo '#Type Path Mode UID GID Age Argument' > /etc/tmpfiles.d/10-looking-glass.conf" + #sudo bash -c "echo 'f /dev/shm/looking-glass 0660 qemu kvm - ' >> /etc/tmpfiles.d/10-looking-glass.conf" + #sudo systemd-tmpfiles --create --prefix=/dev/shm/looking-glass + else + echo "> Not using Looking Glass..." + fi +} +function autoConnectLookingGlass() { + while true; do + VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" + if [ "$VM_IP" != "" ]; then + while true; do + if nc -vz "$VM_IP" 3389 &> /dev/null; then + sleep 5 + echo "> [Background task] Starting the Looking Glass client to connect with the VM..." + sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]' & + break + fi + sleep 1 + done + break + fi + sleep 1 + done +} ##################################################################################### ########################## Set up fake battery if enabled ########################### ##################################################################################### -if [ "$USE_FAKE_BATTERY" = true ]; then - echo "> Using fake battery..." - if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ]; then - mv "${ACPI_TABLES_DIR}/fake-battery.aml" "${VM_FILES_DIR}/fake-battery.aml" - fi - FAKE_BATTERY_SSDT_TABLE="$(readlink -f "${VM_FILES_DIR}/fake-battery.aml")" - if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-acpitable" "file=${FAKE_BATTERY_SSDT_TABLE}") - elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./os/acpi/table/@type=slic" "--xml" "xpath.set=./os/acpi/table=${VM_FILES_DIR}/fake-battery.aml") +setUpFakeBattery() { + if [ "$USE_FAKE_BATTERY" = true ]; then + echo "> Using fake battery..." + if [ ! -f "${VM_FILES_DIR}/fake-battery.aml" ]; then + mv "${ACPI_TABLES_DIR}/fake-battery.aml" "${VM_FILES_DIR}/fake-battery.aml" + fi + FAKE_BATTERY_SSDT_TABLE="$(readlink -f "${VM_FILES_DIR}/fake-battery.aml")" + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-acpitable" "file=${FAKE_BATTERY_SSDT_TABLE}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--xml" "xpath.set=./os/acpi/table/@type=slic" "--xml" "xpath.set=./os/acpi/table=${VM_FILES_DIR}/fake-battery.aml") + fi + else + echo "> Not using fake battery..." fi -else - echo "> Not using fake battery..." -fi - +} ##################################################################################### ########### Create copy of OVMF_VARS_VM which is required for UEFI VMs ############# ##################################################################################### -if [ ! -f "${OVMF_VARS_VM}" ] || [ "$VM_ACTION" = "install" ]; then - echo "> Creating fresh OVMF_VARS copy for this VM..." - sudo rm -f "${OVMF_VARS_VM}" - sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" - sudo chown "$(whoami):$(id -gn "$(whoami)")" "${OVMF_VARS_VM}" -fi +function createOvmfVarsCopy() { + if [ ! -f "${OVMF_VARS_VM}" ] || [ "$VM_ACTION" = "install" ]; then + echo "> Creating fresh OVMF_VARS copy for this VM..." + sudo rm -f "${OVMF_VARS_VM}" + sudo cp "${OVMF_VARS}" "${OVMF_VARS_VM}" + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${OVMF_VARS_VM}" + fi +} ##################################################################################### ####################### Patch OVMF with vBIOS ROM if enabled ######################## ##################################################################################### -if [ "$PATCH_OVMF_WITH_VROM" = true ]; then - PATCHED_OVMF_FILES_DIR="${VM_FILES_DIR}/patched-ovmf-files" - if [ "$DGPU_ROM" != "" ]; then - echo "> Using patched OVMF..." - DGPU_ROM_NAME="$(basename "${DGPU_ROM}")" - if [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" ] || [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" ]; then - DGPU_ROM_DIR="$(dirname "${DGPU_ROM}")" - mkdir -p "${PATCHED_OVMF_FILES_DIR}/tmp-build" - sudo chown "$(whoami):$(id -gn "$(whoami)")" "${PATCHED_OVMF_FILES_DIR}" - echo "> Patching OVMF with your vBIOS ROM. This may take a few minutes!" - sleep 5 # Ensure the user can read this first - sudo service docker start - sudo docker run --rm -ti -v "${PATCHED_OVMF_FILES_DIR}/tmp-build:/build:z" -v "${DGPU_ROM_DIR}:/roms:z" -e "VROM=${DGPU_ROM_NAME}" ovmf-vbios-patch - sudo chown "$(whoami):$(id -gn "$(whoami)")" -R "${PATCHED_OVMF_FILES_DIR}/tmp-build" - sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_CODE.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" - sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_VARS.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" - sudo rm -rf "${PATCHED_OVMF_FILES_DIR}/tmp-build" - fi - OVMF_CODE="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" - if [ "$VM_ACTION" = "install" ]; then - echo "> Creating fresh copy of patched OVMF VARS..." - rm -f "${OVMF_VARS_VM}" - sudo cp "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" "${OVMF_VARS_VM}" +function patchOvmf() { + if [ "$PATCH_OVMF_WITH_VROM" = true ]; then + PATCHED_OVMF_FILES_DIR="${VM_FILES_DIR}/patched-ovmf-files" + if [ "$DGPU_ROM" != "" ]; then + echo "> Using patched OVMF..." + DGPU_ROM_NAME="$(basename "${DGPU_ROM}")" + if [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" ] || [ ! -f "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" ]; then + DGPU_ROM_DIR="$(dirname "${DGPU_ROM}")" + mkdir -p "${PATCHED_OVMF_FILES_DIR}/tmp-build" + sudo chown "$(whoami):$(id -gn "$(whoami)")" "${PATCHED_OVMF_FILES_DIR}" + echo "> Patching OVMF with your vBIOS ROM. This may take a few minutes!" + sleep 5 # Ensure the user can read this first + sudo service docker start + sudo docker run --rm -ti -v "${PATCHED_OVMF_FILES_DIR}/tmp-build:/build:z" -v "${DGPU_ROM_DIR}:/roms:z" -e "VROM=${DGPU_ROM_NAME}" ovmf-vbios-patch + sudo chown "$(whoami):$(id -gn "$(whoami)")" -R "${PATCHED_OVMF_FILES_DIR}/tmp-build" + sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_CODE.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" + sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_VARS.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" + sudo rm -rf "${PATCHED_OVMF_FILES_DIR}/tmp-build" + fi + OVMF_CODE="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd" + if [ "$VM_ACTION" = "install" ]; then + echo "> Creating fresh copy of patched OVMF VARS..." + rm -f "${OVMF_VARS_VM}" + sudo cp "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" "${OVMF_VARS_VM}" + fi + #OVMF_VARS_VM="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" + else + echo "> Not using patched OVMF..." fi - #OVMF_VARS_VM="${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_VARS.fd" else echo "> Not using patched OVMF..." fi -else - echo "> Not using patched OVMF..." -fi +} ##################################################################################### ############################### Set OVMF parameters ################################# ##################################################################################### -if [ "$VM_START_MODE" = "qemu" ]; then - QEMU_PARAMS+=("-drive" "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}") - QEMU_PARAMS+=("-drive" "if=pflash,format=raw,file=${OVMF_VARS_VM}") -elif [ "$VM_START_MODE" = "virt-install" ]; then - VIRT_INSTALL_PARAMS+=("--boot" "loader=${OVMF_CODE},loader.readonly=yes,loader.type=pflash,nvram.template=${OVMF_VARS_VM},loader_secure=no") -fi +function setOvmfParams() { + if [ "$VM_START_MODE" = "qemu" ]; then + QEMU_PARAMS+=("-drive" "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}") + QEMU_PARAMS+=("-drive" "if=pflash,format=raw,file=${OVMF_VARS_VM}") + elif [ "$VM_START_MODE" = "virt-install" ]; then + VIRT_INSTALL_PARAMS+=("--boot" "loader=${OVMF_CODE},loader.readonly=yes,loader.type=pflash,nvram.template=${OVMF_VARS_VM},loader_secure=no") + fi +} ##################################################################################### ########################## Set up USB device passthrough ############################ ##################################################################################### -QEMU_PARAMS+=("-usb") -if [ -z "$USB_DEVICES" ]; then - echo "> Not using USB passthrough..." - USB_DEVICE_PARAMS="" -else - echo "> Using USB passthrough..." - IFS=';' read -a USB_DEVICES_ARRAY <<< "${USB_DEVICES}" - for USB_DEVICE in "${USB_DEVICES_ARRAY[@]}"; do - QEMU_PARAMS+=("-device" "usb-host,${USB_DEVICE}") - echo "> Passing USB device '${USB_DEVICE}' through..." - done -fi +function setUpUsbPassthrough() { + QEMU_PARAMS+=("-usb") + if [ -z "$USB_DEVICES" ]; then + echo "> Not using USB passthrough..." + USB_DEVICE_PARAMS="" + else + echo "> Using USB passthrough..." + IFS=';' read -a USB_DEVICES_ARRAY <<< "${USB_DEVICES}" + for USB_DEVICE in "${USB_DEVICES_ARRAY[@]}"; do + QEMU_PARAMS+=("-device" "usb-host,${USB_DEVICE}") + echo "> Passing USB device '${USB_DEVICE}' through..." + done + fi +} ##################################################################################### ############################### Set up input method ################################# ##################################################################################### -if [ "$VIRTUAL_INPUT_TYPE" = "virtio" ]; then - echo "> Using virtual input method 'virtio' for keyboard/mouse input..." - QEMU_PARAMS+=("-device" "virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2") - QEMU_PARAMS+=("-device" "virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2") -elif [ "$VIRTUAL_INPUT_TYPE" = "usb-tablet" ]; then - echo "> Using virtual input method 'usb-tablet' for keyboard/mouse input..." - QEMU_PARAMS+=("-device" "usb-tablet") -else - echo "> Not using virtual input method for keyboard/mouse input..." -fi +function setUpInputMethod() { + if [ "$VIRTUAL_INPUT_TYPE" = "virtio" ]; then + echo "> Using virtual input method 'virtio' for keyboard/mouse input..." + QEMU_PARAMS+=("-device" "virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2") + QEMU_PARAMS+=("-device" "virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2") + elif [ "$VIRTUAL_INPUT_TYPE" = "usb-tablet" ]; then + echo "> Using virtual input method 'usb-tablet' for keyboard/mouse input..." + QEMU_PARAMS+=("-device" "usb-tablet") + else + echo "> Not using virtual input method for keyboard/mouse input..." + fi +} ##################################################################################### ################################### Set up RDP ###################################### ##################################################################################### -if [ "$USE_RDP" = true ] && [ "$NETWORK_MODE" != "none" ]; then - echo "> Using RDP..." - RDP_USER=Administrator - RDP_PASSWORD=admin - # Run it once because the first time it prints a useless message instead of actually encrypting - echo "$RDP_PASSWORD" | remmina --encrypt-password &> /dev/null - # Run it again, hoping it always works the second time - RDP_PASSWORD_ENCRYPTED="$(echo "$RDP_PASSWORD" | remmina --encrypt-password | grep 'Encrypted password: ' | cut -d':' -f2- | tr -d ' ')" - - function autoConnectRdp() { - while true; do - VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" - if [ "$VM_IP" != "" ]; then - echo "" - echo "> The IP address of the VM is: ${VM_IP}" - echo "" - echo "> Waiting for RDP to be available in the VM..." - while true; do - if nc -vz "$VM_IP" 3389 &> /dev/null; then - echo "> Opening Remmina to start an RDP connection with the VM..." - remmina -c "rdp://${RDP_USER}:${RDP_PASSWORD_ENCRYPTED}@${VM_IP}" &> /dev/null & - break - fi - sleep 1 - done - break - fi - sleep 1 - done - } -else - echo "> Not using RDP..." -fi +function setUpRdp() { + if [ "$USE_RDP" = true ] && [ "$NETWORK_MODE" != "none" ]; then + echo "> Using RDP..." + RDP_USER=Administrator + RDP_PASSWORD=admin + # Run it once because the first time it prints a useless message instead of actually encrypting + echo "$RDP_PASSWORD" | remmina --encrypt-password &> /dev/null + # Run it again, hoping it always works the second time + RDP_PASSWORD_ENCRYPTED="$(echo "$RDP_PASSWORD" | remmina --encrypt-password 2>&1 | grep 'Encrypted password: ' | cut -d':' -f2- | tr -d ' ')" + + function autoConnectRdp() { + while true; do + VM_IP="$(sudo nmap -sn -n ${NETWORK} -T5 | grep "MAC Address: ${MAC_ADDRESS}" -B 2 | head -1 | rev | cut -d' ' -f1 | rev)" + if [ "$VM_IP" != "" ]; then + echo "" + echo "> [Background task] The IP address of the VM is: ${VM_IP}" + echo "> [Background task] Waiting for RDP to be available in the VM..." + while true; do + if nc -vz "$VM_IP" 3389 &> /dev/null; then + echo "> [Background task] Opening Remmina to start an RDP connection with the VM..." + remmina -c "rdp://${RDP_USER}:${RDP_PASSWORD_ENCRYPTED}@${VM_IP}" &> /dev/null & + break + fi + sleep 1 + done + break + fi + sleep 1 + done + } + else + echo "> Not using RDP..." + fi +} ##################################################################################### ################# Load vfio-pci and bind dGPU to vfio-pci driver #################### ##################################################################################### -if [ "$DRY_RUN" = false ]; then - if [ "$DGPU_PASSTHROUGH" = true ] || [ "$SHARE_IGPU" = true ]; then - echo "> Loading vfio-pci kernel module..." - sudo modprobe vfio-pci - fi +function vfioPci() { + if [ "$DRY_RUN" = false ]; then + if [ "$DGPU_PASSTHROUGH" = true ] || [ "$SHARE_IGPU" = true ]; then + echo "> Loading vfio-pci kernel module..." + sudo modprobe vfio-pci + fi - if [ "$DGPU_PASSTHROUGH" = true ]; then - echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." - driver unbind "${DGPU_PCI_ADDRESS}" - echo "> Binding dGPU to VFIO driver..." - driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" - #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" - # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) + if [ "$DGPU_PASSTHROUGH" = true ]; then + echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." + driver unbind "${DGPU_PCI_ADDRESS}" + echo "> Binding dGPU to VFIO driver..." + driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" + #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" + # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) + fi fi -fi +} -if [ "$VM_ACTION" = "install" ]; then - echo "> Deleting VM if it already exists..." - sudo virsh destroy --domain "${VM_NAME}" &> /dev/null - sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null -fi +##################################################################################### +############ Clean up before creating a new VM when action is install ############### +##################################################################################### +function preCleanUp() { + if [ "$VM_ACTION" = "install" ]; then + echo "> Deleting VM if it already exists..." + sudo virsh destroy --domain "${VM_NAME}" &> /dev/null + sudo virsh undefine --domain "${VM_NAME}" --nvram &> /dev/null + fi +} ##################################################################################### ########################## Start a few background tasks ############################# ##################################################################################### -if [ "$VM_START_MODE" = "qemu" ]; then - if [ "$DRY_RUN" = false ]; then - if [ "$VM_ACTION" = "install" ]; then - echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." - QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") - bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & - fi +function startBackgroundTasks() { + if [ "$VM_START_MODE" = "qemu" ]; then + if [ "$DRY_RUN" = false ]; then + if [ "$VM_ACTION" = "install" ]; then + echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." + QEMU_PARAMS+=("-monitor" "unix:/tmp/${VM_NAME}-monitor,server,nowait") + bash -c "for i in {1..30}; do echo 'sendkey home' | sudo socat - 'UNIX-CONNECT:/tmp/${VM_NAME}-monitor'; sleep 1; done" &> /dev/null & + fi - if [ "$USE_SPICE_CLIENT" = true ]; then - echo "> Starting the spice client at localhost:${SPICE_PORT}..." - bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" & + if [ "$USE_SPICE_CLIENT" = true ]; then + echo "> [Background task] Starting the spice client at localhost:${SPICE_PORT}..." + bash -c "sleep 2; spicy -h localhost -p ${SPICE_PORT}" &> /dev/null & + fi fi - fi -elif [ "$VM_START_MODE" = "virt-install" ]; then - if [ "$DRY_RUN" = false ]; then - if [ "$VM_ACTION" = "install" ]; then - echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." - bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + elif [ "$VM_START_MODE" = "virt-install" ]; then + if [ "$DRY_RUN" = false ]; then + if [ "$VM_ACTION" = "install" ]; then + echo "> Repeatedly sending keystrokes to the new VM for 30 seconds to ensure the Windows ISO boots..." + bash -c "for i in {1..30}; do sudo virsh send-key ${VM_NAME} KEY_HOME; sleep 1; done" &> /dev/null & + fi fi fi -fi -if [ "$USE_RDP" = true ] && [ "$NETWORK_MODE" != "none" ]; then - echo "> Starting RDP autoconnect background task..." - autoConnectRdp & -fi -if [ "$USE_LOOKING_GLASS" = true ]; then - echo "> Starting the Looking Glass client..." - #while true; do sleep 1 && echo "lg" && sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN &> /dev/null && sleep 5 && sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]'; done & - autoConnectLookingGlass & -fi + if [ "$USE_RDP" = true ] && [ "$NETWORK_MODE" != "none" ]; then + echo "> [Background task] Starting RDP autoconnect..." + autoConnectRdp & + fi + if [ "$USE_LOOKING_GLASS" = true ]; then + echo "> [Background task] Starting the Looking Glass client..." + #while true; do sleep 1 && echo "lg" && sudo lsof -i ":${SPICE_PORT}" | grep --quiet LISTEN &> /dev/null && sleep 5 && sudo -u "$(logname)" "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" -p "${SPICE_PORT}" 2>&1 | grep '^\[E\]'; done & + autoConnectLookingGlass & + fi +} ##################################################################################### ################################## Start the VM ##################################### ##################################################################################### -if [ "$VM_START_MODE" = "qemu" ]; then - if [ "$DRY_RUN" = true ]; then - echo "> Generating qemu-system-x86_64 command (dry-run)..." - echo "" - printf "sudo qemu-system-x86_64" +function startVm() { + if [ "$VM_START_MODE" = "qemu" ]; then + if [ "$DRY_RUN" = true ]; then + echo "> Generating qemu-system-x86_64 command (dry-run)..." + echo "" + printf "sudo qemu-system-x86_64" + for param in "${QEMU_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" + else + echo "> Starting the Virtual Machine using qemu..." + sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" + fi + elif [ "$VM_START_MODE" = "virt-install" ]; then + #VIRT_INSTALL_PARAMS+=("--debug") for param in "${QEMU_PARAMS[@]}"; do - if [[ "${param}" == -* ]]; then - printf " \\\\\n ${param}" - elif [[ $param = *" "* ]]; then - printf " \"${param}\"" - else - printf " ${param}" - fi + VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") done - echo "" - echo "" - else - echo "> Starting the Virtual Machine using qemu..." - sudo qemu-system-x86_64 "${QEMU_PARAMS[@]}" - fi -elif [ "$VM_START_MODE" = "virt-install" ]; then - #VIRT_INSTALL_PARAMS+=("--debug") - for param in "${QEMU_PARAMS[@]}"; do - VIRT_INSTALL_PARAMS+=("--qemu-commandline='${param}'") - done - if [ "$DRY_RUN" = true ]; then - echo "> Generating virt-install command (dry-run)..." - echo "" - printf "sudo virt-install" - for param in "${VIRT_INSTALL_PARAMS[@]}"; do - if [[ "${param}" == -* ]]; then - printf " \\\\\n ${param}" - elif [[ $param = *" "* ]]; then - printf " \"${param}\"" - else - printf " ${param}" - fi - done - echo "" - echo "" - elif [ "$GET_XML" = true ]; then - VIRT_INSTALL_PARAMS+=("--print-xml") - sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" - elif [ "$VM_ACTION" = "install" ]; then - echo "> Starting the Virtual Machine using virt-install..." - sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" - elif [ "$VM_ACTION" = "start" ]; then - echo "> Starting the Virtual Machine using virsh..." - sudo virsh start "${VM_NAME}" + if [ "$DRY_RUN" = true ]; then + echo "> Generating virt-install command (dry-run)..." + echo "" + printf "sudo virt-install" + for param in "${VIRT_INSTALL_PARAMS[@]}"; do + if [[ "${param}" == -* ]]; then + printf " \\\\\n ${param}" + elif [[ $param = *" "* ]]; then + printf " \"${param}\"" + else + printf " ${param}" + fi + done + echo "" + echo "" + elif [ "$GET_XML" = true ]; then + VIRT_INSTALL_PARAMS+=("--print-xml") + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + elif [ "$VM_ACTION" = "install" ]; then + echo "> Starting the Virtual Machine using virt-install..." + sudo virt-install "${VIRT_INSTALL_PARAMS[@]}" + elif [ "$VM_ACTION" = "start" ]; then + echo "> Starting the Virtual Machine using virsh..." + sudo virsh start "${VM_NAME}" + fi fi -fi +} ##################################################################################### -################ Everything below gets executed when the vm exits ################### +############### The function below gets executed when the vm exits ################## ##################################################################################### -if [ "$DGPU_PASSTHROUGH" = true ]; then - echo "> Unbinding dGPU from vfio driver..." - driver unbind "${DGPU_PCI_ADDRESS}" - if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nouveau" ]; then - echo "> Turn the dGPU off using bumblebee..." - sudo bash -c "echo 'OFF' >> /proc/acpi/bbswitch" +function onExit() { + echo "Cleaning up..." + if [ "$DGPU_PASSTHROUGH" = true ]; then + echo "> Unbinding dGPU from vfio driver..." + driver unbind "${DGPU_PCI_ADDRESS}" + if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nouveau" ]; then + echo "> Turn the dGPU off using bumblebee..." + sudo bash -c "echo 'OFF' >> /proc/acpi/bbswitch" + fi + echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." + driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" fi - echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." - driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" -fi -if [ "$VGPU_UUID" != "" ]; then - echo "> Keeping Intel vGPU for next VM start..." + if [ "$VGPU_UUID" != "" ]; then + echo "> Keeping Intel vGPU for next VM start..." - # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. - # So for now we can't create a new vGPU every time the VM starts. - #echo "> Remove Intel vGPU..." - #vgpu remove "${IGPU_PCI_ADDRESS}" "${VGPU_UUID}" + # FIXME: There is a bug in Linux that prevents creating new vGPUs without rebooting after removing one. + # So for now we can't create a new vGPU every time the VM starts. + #echo "> Remove Intel vGPU..." + #vgpu remove "${IGPU_PCI_ADDRESS}" "${VGPU_UUID}" -fi + fi -if [ "$VM_ACTION" = "install" ]; then - if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then - if [ "$ORIGINAL_VM_ACTION" = "auto" ]; then - sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start + if [ "$VM_ACTION" = "install" ]; then + if sudo fdisk -lu "${DRIVE_IMG}" 2> /dev/null | grep --quiet 'Microsoft'; then + if [ "$ORIGINAL_VM_ACTION" = "auto" ]; then + sudo "${MAIN_SCRIPTS_DIR}/vm.sh" start + fi + exit 0 + else + echo "> [Error] Seems like the installation failed..." + exit 1 fi - exit 0 - else - echo "> [Error] Seems like the installation failed..." - exit 1 fi -fi \ No newline at end of file + + stty sane + kill $(jobs -p) &> /dev/null + stty sane +} + + +setMiscParams +setUpNetworking +setCpuCores +setRamSize +setInstallMediaParam +setHelperIsoParam +setUpOsDrive +bumblebeeCheck +setUpSambaShare +setDGpuParams +vGpuSetup +loadDisplayOutputPlugin +setIGpuParams +setSpiceParams +spiceClientCheck +setQxl +setUpLookingGlassParams +setUpFakeBattery +createOvmfVarsCopy +patchOvmf +setOvmfParams +setUpUsbPassthrough +setUpInputMethod +setUpRdp +trap onExit EXIT +vfioPci +preCleanUp +startBackgroundTasks +startVm diff --git a/scripts/utils/common/tools/get-manager b/scripts/utils/common/tools/get-manager index 05d960e..9e627fe 100755 --- a/scripts/utils/common/tools/get-manager +++ b/scripts/utils/common/tools/get-manager @@ -30,8 +30,16 @@ elif [ "$COMMAND" = "kernelparams" ]; then elif [ "$COMMAND" = "package" ]; then if command -v dnf &> /dev/null; then echo "dnf" + elif command -v yum &> /dev/null; then + echo "yum" elif command -v apt-get &> /dev/null; then echo "apt" + elif command -v pacman &> /dev/null; then + echo "pacman" + elif command -v zypper &> /dev/null; then + echo "zypper" + elif command -v emerge &> /dev/null; then + echo "emerge" else exit 1 fi diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index e741b71..52742a4 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -31,7 +31,7 @@ function installPackages() { if [ "$SEARCH_MODE" = "--executables" ]; then PACKAGE_TO_INSTALL="$(sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM | head -1 | cut -d':' -f1)" elif [ "$SEARCH_MODE" = "--files" ]; then - PACKAGE_TO_INSTALL="$(sudo apt-file search $CURRENT_ITEM | head -1 | cut -d':' -f1))" + PACKAGE_TO_INSTALL="$(sudo apt-file search $CURRENT_ITEM | head -1 | cut -d':' -f1)" fi if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" @@ -44,24 +44,31 @@ function installPackages() { fi } -if [ "$SEARCH_MODE" = "--executables" ]; then - MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" - installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" - MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" -elif [ "$SEARCH_MODE" = "--files" ]; then - MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" - installPackages "$SEARCH_MODE" "$MISSING_FILES" - MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" +if [ "$COMMAND" = "install" ]; then + if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 + fi + if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" + fi + if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" + fi + if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 + fi +elif [ "$COMMAND" = "update" ]; then + updatePackageInfo else - echo "ERROR: Invalid mode or no mode at all was speficied!" - exit 1 -fi -if [ "$MISSING_EXECUTABLES" != "" ]; then - echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" -fi -if [ "$MISSING_FILES" != "" ]; then - echo "ERROR: Still missing package providing the following files: $MISSING_FILES" -fi -if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Invalid command" exit 1 fi diff --git a/scripts/utils/manager-specific/package/emerge b/scripts/utils/manager-specific/package/emerge new file mode 100755 index 0000000..35c416c --- /dev/null +++ b/scripts/utils/manager-specific/package/emerge @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# +# WARNING!!!!!!!!!!!!!!!! The `e-file` calls in this file have not been properly implemented yet!!! +# WARNING!!!!!!!!!!!!!!!! The `e-file` calls in this file have not been properly implemented yet!!! +# WARNING!!!!!!!!!!!!!!!! The `e-file` calls in this file have not been properly implemented yet!!! +# +# Simple script to install the packages containing the given executable names or file names +# Usage: `./emerge --executables "curl git wget docker"` +# Usage: `./emerge --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" + +COMMAND="$1" +SEARCH_MODE="$2" +WANTED_ITEMS="$3" + +function updatePackageInfo() { + sudo emerge-webrsync -v +} + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + if ! command -v e-file &> /dev/null; then + sudo emerge app-portage/pfl + fi + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo e-file $CURRENT_ITEM ????)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo e-file $CURRENT_ITEM ????)" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo emerge $PACKAGES_TO_INSTALL + fi +} + +if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" +elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" +else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 +fi +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" +fi +if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" +fi +if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 +fi diff --git a/scripts/utils/manager-specific/package/pacman b/scripts/utils/manager-specific/package/pacman new file mode 100755 index 0000000..3635fef --- /dev/null +++ b/scripts/utils/manager-specific/package/pacman @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# Simple script to install the packages containing the given executable names or file names +# Usage: `./pacman --executables "curl git wget docker"` +# Usage: `./pacman --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" + +COMMAND="$1" +SEARCH_MODE="$2" +WANTED_ITEMS="$3" + +function updatePackageInfo() { + sudo pacman -Syy + sudo pacman -Fy +} + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo pacman -F $CURRENT_ITEM | grep -B 1 /bin/$CURRENT_ITEM | head -1 | cut -d' ' -f1)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo pacman -F $CURRENT_ITEM | head -1 | rev | cut -d' ' -f2 | rev)" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo pacman -S --noconfirm $PACKAGES_TO_INSTALL + fi +} + +if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" +elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" +else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 +fi +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" +fi +if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" +fi +if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 +fi diff --git a/scripts/utils/manager-specific/package/yum b/scripts/utils/manager-specific/package/yum new file mode 100755 index 0000000..e18456b --- /dev/null +++ b/scripts/utils/manager-specific/package/yum @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# Simple script to install the packages containing the given executable names or files +# Usage: `./yum --executables "curl git wget docker"` +# Usage: `./yum --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" + +COMMAND="$1" +SEARCH_MODE="$2" +WANTED_ITEMS="$3" + +function updatePackageInfo() { + sudo yum check-update +} + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo yum provides {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo yum provides $CURRENT_ITEM 2> /dev/null | grep ' : ' | head -1 | cut -d'.' -f1 | rev | cut -d'-' -f 2- | rev)" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo yum install -y $PACKAGES_TO_INSTALL + fi +} + +if [ "$COMMAND" = "install" ]; then + if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 + fi + if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" + fi + if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" + fi + if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 + fi +elif [ "$COMMAND" = "update" ]; then + updatePackageInfo +else + echo "ERROR: Invalid command" + exit 1 +fi + diff --git a/scripts/utils/manager-specific/package/zypper b/scripts/utils/manager-specific/package/zypper new file mode 100755 index 0000000..8bb6dfa --- /dev/null +++ b/scripts/utils/manager-specific/package/zypper @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" +loadConfig + +##################################################################################################### +# Simple script to install the packages containing the given executable names or file names +# Usage: `./zypper --executables "curl git wget docker"` +# Usage: `./zypper --files "/usr/include/{ree,ruby}/ruby.h /usr/share/virtio-win/virtio-win.iso"` +##################################################################################################### + +alias getMissingExecutables="${COMMON_UTILS_TOOLS_DIR}/get-missing-executables" +alias getMissingFiles="${COMMON_UTILS_TOOLS_DIR}/get-missing-files" + +COMMAND="$1" +SEARCH_MODE="$2" +WANTED_ITEMS="$3" + +function updatePackageInfo() { + sudo zypper refresh +} + +function installPackages() { + SEARCH_MODE="$1" + WANTED_ITEMS="$2" + PACKAGES_TO_INSTALL="" + for CURRENT_ITEM in $WANTED_ITEMS; do + if [ "$SEARCH_MODE" = "--executables" ]; then + PACKAGE_TO_INSTALL="$(sudo zypper search -f {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM | grep " | package" | head -1 | tr -d ' ' | cut -d'|' -f2)" + elif [ "$SEARCH_MODE" = "--files" ]; then + PACKAGE_TO_INSTALL="$(sudo zypper search -f $CURRENT_ITEM | grep " | package" | head -1 | tr -d ' ' | cut -d'|' -f2)" + fi + if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then + PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" + else + STILL_MISSING_ITEMS+=" $CURRENT_ITEM" + fi + done + if [ "$PACKAGES_TO_INSTALL" != "" ]; then + sudo zypper --non-interactive install $PACKAGES_TO_INSTALL + fi +} + +if [ "$SEARCH_MODE" = "--executables" ]; then + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_EXECUTABLES" + MISSING_EXECUTABLES="$(getMissingExecutables "$WANTED_ITEMS")" +elif [ "$SEARCH_MODE" = "--files" ]; then + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" + installPackages "$SEARCH_MODE" "$MISSING_FILES" + MISSING_FILES="$(getMissingFiles "$WANTED_ITEMS")" +else + echo "ERROR: Invalid mode or no mode at all was speficied!" + exit 1 +fi +if [ "$MISSING_EXECUTABLES" != "" ]; then + echo "ERROR: Still missing package providing the following executables: $MISSING_EXECUTABLES" +fi +if [ "$MISSING_FILES" != "" ]; then + echo "ERROR: Still missing package providing the following files: $MISSING_FILES" +fi +if [ "$MISSING_EXECUTABLES" != "" ] && [ "$MISSING_FILES" != "" ]; then + exit 1 +fi From 86579340814c4652e8bd402d533c44ff1ff3753d Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Wed, 25 Aug 2021 03:14:20 +0200 Subject: [PATCH 31/40] Automatically bind all devices in the dGPU IOMMU group to vfio-pci excluding bridges --- requirements.sh | 2 +- scripts/main/generate-live-iso.sh | 2 +- scripts/main/setup.sh | 2 +- scripts/main/vm.sh | 50 ++++++++++++++----- .../utils/common/setup/ovmf-vbios-patch-setup | 2 +- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/requirements.sh b/requirements.sh index abb6273..b7d0e4d 100644 --- a/requirements.sh +++ b/requirements.sh @@ -35,7 +35,7 @@ EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker") # git moby-engine EXEC_DEPS_GENERATE_CONFIG=("crudini") # crudini EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx") # git wget curl-minimal unzip ruby rubygems rubygem-bundler p7zip make innoextract upx FILE_DEPS_VBIOS_FINDER=("/usr/include/rub*/ruby.h") # ruby-devel -EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat" "fdisk" "dd" "nmap") # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat coreutils util-linux nmap +EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_64" "virsh" "virt-viewer" "virt-install" "spicy" "socat" "fdisk" "dd" "nmap" "driverctl" ) # qemu-system-x86-core libvirt-client virt-viewer virt-install spice-gtk-tools socat coreutils util-linux nmap driverctl FILE_DEPS_VIRTUALIZATION=("/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/OVMF/OVMF_VARS.fd" "/usr/share/libvirt/networks/default.xml") # edk2-ovmf libvirt-daemon-config-network EXEC_DEPS_RDP=("remmina") # remmina EXEC_DEPS_SAMBA=("samba") # samba diff --git a/scripts/main/generate-live-iso.sh b/scripts/main/generate-live-iso.sh index 921dea2..d817a6d 100755 --- a/scripts/main/generate-live-iso.sh +++ b/scripts/main/generate-live-iso.sh @@ -170,7 +170,7 @@ function flash() { sudo umount --force "$mp" done <<< "$mps" fi - yes "" | sudo livecd-iso-to-disk --format ext4 --efi --force --extra-kernel-args "$ALL_KERNEL_PARAMS" "${ISO_FILE_MODIFIED}" "$DRIVE" + yes "" | sudo livecd-iso-to-disk --format ext4 --overlay-size-mb 4095 --efi --force --extra-kernel-args "$ALL_KERNEL_PARAMS" "${ISO_FILE_MODIFIED}" "$DRIVE" } if [ "$MODE" = "flash" ]; then diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index a959dec..43dd6ee 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -168,7 +168,7 @@ else echo "> [Skipped] Windows ISO has already been downloaded." fi -if [[ "$(sudo docker images -q tavk/ovmf-vbios-patch:1.0.1-edk2-stable201905 2> /dev/null)" == "" ]]; then +if [[ "$(sudo docker images -q 'tavk/ovmf-vbios-patch:1.0.1-edk2-stable201905' 2> /dev/null)" == "" ]]; then echo "> Installing 'ovmf-vbios-patch' Docker Image..." ovmfVbiosPatchSetup else diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index a977360..d08c177 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -62,9 +62,14 @@ if [ "$VM_ACTION" = "install" ] || [ "$VM_ACTION" = "start" ]; then fi fi +# Remove domain from PCI addressed if provided +DGPU_PCI_ADDRESS="$(echo "$DGPU_PCI_ADDRESS" | sed 's/0000://g')" +IGPU_PCI_ADDRESS="$(echo "$IGPU_PCI_ADDRESS" | sed 's/0000://g')" + #source "$COMMON_UTILS_LIBS_DIR/gpu-check" alias driver="sudo '$COMMON_UTILS_TOOLS_DIR/driver-util'" alias vgpu="sudo '$COMMON_UTILS_TOOLS_DIR/vgpu-util'" +alias lsiommu="sudo '$COMMON_UTILS_TOOLS_DIR/lsiommu'" VIRT_INSTALL_PARAMS=() QEMU_PARAMS=() @@ -319,7 +324,7 @@ function setDGpuParams() { DGPU_INFO="$(sudo lspci | grep "$DGPU_PCI_ADDRESS" | cut -d' ' -f2-)" echo "> dGPU is: $DGPU_INFO" - echo "> dGPU dirver is $HOST_DGPU_DRIVER" + echo "> dGPU driver is $HOST_DGPU_DRIVER" echo "> Retrieving and parsing DGPU IDs..." DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) @@ -769,10 +774,23 @@ function vfioPci() { fi if [ "$DGPU_PASSTHROUGH" = true ]; then - echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." - driver unbind "${DGPU_PCI_ADDRESS}" - echo "> Binding dGPU to VFIO driver..." - driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" + #echo "> Unbinding dGPU from ${HOST_DGPU_DRIVER} driver..." + #driver unbind + #echo "> Binding dGPU to VFIO driver..." + #driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" + + LSPCI_OUTPUT="$(sudo lspci)" + LSIOMMU_OUTPUT="$(lsiommu)" + IOMMU_GROUP="$(echo "$LSIOMMU_OUTPUT" | grep "${DGPU_PCI_ADDRESS}" | cut -d' ' -f3)" + DGPU_IOMMU_GROUP_DEVICES=$(echo "$LSIOMMU_OUTPUT" | grep "IOMMU Group ${IOMMU_GROUP} " | grep -v "PCI bridge" | grep -v "ISA bridge") + echo "> IOMMU group for passthrough is ${IOMMU_GROUP}" + while IFS= read -r deviceInfo; do + deviceName="$(echo "$deviceInfo" | cut -d ' ' -f4-)" + deviceAddress="$(echo "$deviceInfo" | cut -d ' ' -f4)" + echo "> Unbinding device '${deviceName} from its driver, then bind it to the vfio-pci driver..." + sudo driverctl --nosave set-override "0000:${deviceAddress}" vfio-pci + done <<< "$DGPU_IOMMU_GROUP_DEVICES" + #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) fi @@ -890,14 +908,20 @@ function startVm() { function onExit() { echo "Cleaning up..." if [ "$DGPU_PASSTHROUGH" = true ]; then - echo "> Unbinding dGPU from vfio driver..." - driver unbind "${DGPU_PCI_ADDRESS}" - if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nouveau" ]; then - echo "> Turn the dGPU off using bumblebee..." - sudo bash -c "echo 'OFF' >> /proc/acpi/bbswitch" - fi - echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." - driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" + #echo "> Unbinding dGPU from vfio driver..." + #driver unbind "${DGPU_PCI_ADDRESS}" + #if [ "$HOST_DGPU_DRIVER" = "nvidia" ] || [ "$HOST_DGPU_DRIVER" = "nouveau" ]; then + # echo "> Turn the dGPU off using bumblebee..." + # sudo bash -c "echo 'OFF' >> /proc/acpi/bbswitch" + #fi + #echo "> Binding dGPU back to ${HOST_DGPU_DRIVER} driver..." + #driver bind "${DGPU_PCI_ADDRESS}" "${HOST_DGPU_DRIVER}" + while IFS= read -r deviceInfo; do + deviceName="$(echo "$deviceInfo" | cut -d ' ' -f4-)" + deviceAddress="$(echo "$deviceInfo" | cut -d ' ' -f4)" + echo "> Unbinding device '${deviceName} from the vfio-pci driver, then bind it back to its original driver..." + sudo driverctl --nosave unset-override "0000:${deviceAddress}" + done <<< "$DGPU_IOMMU_GROUP_DEVICES" fi if [ "$VGPU_UUID" != "" ]; then diff --git a/scripts/utils/common/setup/ovmf-vbios-patch-setup b/scripts/utils/common/setup/ovmf-vbios-patch-setup index 3dc8fff..9888f92 100755 --- a/scripts/utils/common/setup/ovmf-vbios-patch-setup +++ b/scripts/utils/common/setup/ovmf-vbios-patch-setup @@ -15,5 +15,5 @@ sudo service docker start #git clone https://github.com/T-vK/ovmf-with-vbios-patch.git #cd ovmf-with-vbios-patch #sudo docker build -t ovmf-vbios-patch . -sudo docker pull tavk/ovmf-vbios-patch:1.0.1-edk2-stable201905 # Pull instead of build because the root partition of the Live version is too small. +sudo docker pull 'tavk/ovmf-vbios-patch:1.0.1-edk2-stable201905' # Pull instead of build because the root partition of the Live version is too small. # TODO: Get rid of Docker and build this thing natively \ No newline at end of file From 086e7f209f66875528533fe43e1b151968b38925 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Wed, 25 Aug 2021 12:09:28 +0200 Subject: [PATCH 32/40] Improve bumblebee support; Clean up config generator and defualt.conf --- default.conf | 79 ++++++++----------- scripts/main/generate-vm-config.sh | 49 ++++++++---- scripts/main/vm.sh | 12 +-- scripts/utils/manager-specific/package/emerge | 4 +- 4 files changed, 69 insertions(+), 75 deletions(-) diff --git a/default.conf b/default.conf index 9e91df8..1bfdf85 100644 --- a/default.conf +++ b/default.conf @@ -1,57 +1,50 @@ -VM_NAME="MBPT_WindowsVM" # Required +# Predefined variables: PROJECT_DIR (contains the path to the MobilePassthrough project) -CPU_CORE_COUNT=auto # Required (e.g. 8, 12 or auto) -RAM_SIZE=auto # Required (e.g. 8G, 10G or auto) -VM_DISK_SIZE=40G # Required once, Changing this after the drive image has been created has no effect +# Variables that require a reinstall when changed (./mbpt.sh install) +VM_NAME="MBPT_WindowsVM" # Can't be empty; no spaces allowed +VM_FILES_DIR="${PROJECT_DIR}/vm-files" # The folder into which all files for your VM will be saved (Can't be an empty string) +DRIVE_IMG="${VM_FILES_DIR}/${VM_NAME}.img" # The location of your VM disk (Can't be an empty string) +VM_DISK_SIZE="40G" # Required once; changing this after the drive image has been created has no effect, unless you reinstall (E.g. "40G", "250G", ...); At least "40G" is highly recommended; "30G" will probably work, but Windows will break if you use it all +INSTALL_IMG="${VM_FILES_DIR}/windows10.iso" # Path of Windows 10 ISO used during installation (Will be downloaded to that location if it doesn't exist; Can't be an empty string) -VM_FILES_DIR="${PROJECT_DIR}/vm-files" # Required ; The folder into which all files for your VM will be saved +# Variables that can be changed between VM starts (./mbpt.sh start) +CPU_CORE_COUNT="auto" # "auto" is recommended (e.g. "8", "12" or "auto"); "auto" uses all, but one core, but no more than 16 +RAM_SIZE="auto" # "auto" is recommended (e.g. "8G", "10G" or "auto"); "auto" uses [all free RAM]-1GB, but no more than 16GB -DRIVE_IMG="${VM_FILES_DIR}/${VM_NAME}.img" # Required ; The location of your VM disk +DGPU_PCI_ADDRESS="auto" # E.g. "01:00:0" or "auto", "auto" will use the fist dGPU it finds (if more than one, you will be asked which one to use; after 10 seconds it will timeout and use the fist one); see output of lspci +IGPU_PCI_ADDRESS="auto" # Only Intel iGPUs supported atm; recommended to leave on "auto"; Use "" to disable or "auto" to automatically detect it (recommended); required for mediated iGPU passthrough. you can check your iGPU PCI address using lspci +DGPU_PASSTHROUGH="auto" # "auto", "true" or "false" ("auto" Recommended) "auto" will enable it if the system has more than one GPU +SHARE_IGPU="auto" # "auto", "true", or "false"; only works for Intel iGPUs atm; "auto" will enable it automatically if an Intel iGPU is detected; Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) -INSTALL_IMG="${VM_FILES_DIR}/windows10.iso" # Required for Windows installation +DGPU_ROM="" # Optional (Can help getting rid of error 43); Use "" to not load a vBIOS ROM or specify a path to one (e.g. "${VM_FILES_DIR}/vbios-roms/vbios.rom") +IGPU_ROM="" # Optional (Can help getting rid of error 43); Use "" to not load a vBIOS ROM or specify a path to one (e.g. "${VM_FILES_DIR}/vbios-roms/igpu-vbios.rom") +PATCH_OVMF_WITH_VROM="true" # "true" or "false"; Recommended to avoid Error 43; (Doesn't do anything, unless you specify a DGPU_ROM or IGPU_ROM) -DGPU_ROM="" # Optional; for example "${VM_FILES_DIR}/vbios-roms/vbios.rom" -IGPU_ROM="" # Optional; for example "${VM_FILES_DIR}/vbios-roms/igpu-vbios.rom" - -SMB_SHARE_FOLDER="" # Optional; for example "${VM_FILES_DIR}/vmshare" - -OVMF_CODE="/usr/share/OVMF/OVMF_CODE.fd" # Required -OVMF_VARS="/usr/share/OVMF/OVMF_VARS.fd" # Required -OVMF_VARS_VM="${VM_FILES_DIR}/OVMF_VARS_VM.fd" # Required - -HELPER_ISO="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated driver installation, looking glass setup, IP setup, remote desktop setup etc inseide of the VM - -DGPU_PCI_ADDRESS=auto # Required; If you don't use Bumblebee, you have to set this to the correct PCI address of your dGPU (see output of lspci) -# This project has only been tested with Bumblebee enabled. -IGPU_PCI_ADDRESS=auto # Recommended; required for mediated iGPU passthrough. you can cehck your iGPU PCI address using lspci - -DGPU_PASSTHROUGH=auto # Recommended - -SHARE_IGPU=auto # Recommended to save battery life (this is mediated iGPU passthrough using GVT-g) - -HOST_DGPU_DRIVER=auto # Only tested with "nvidia" and "amdgpu", not tested with "nouveau" +MAC_ADDRESS="auto" # Required (E.g. 00:11:22:33:44:55 or auto to generate a new one with every VM start) +NETWORK_MODE="bridged" # Supports bridged or none +SMB_SHARE_FOLDER="" # Optional; for example "${VM_FILES_DIR}/vmshare" or "" to not use it VIRTUAL_INPUT_TYPE="virtio" # "usb-tablet", "virtio" or "". If keyboard input doesn't work properly for you, you may want to use "virtio" instead of "usb-tablet" -MAC_ADDRESS="" # Required -NETWORK_MODE="bridged" # Supports bridged or none +OVMF_CODE="/usr/share/OVMF/OVMF_CODE.fd" # Path to the unmodified OVMF_CODE image +OVMF_VARS="/usr/share/OVMF/OVMF_VARS.fd" # Path to the unmodified OVMF_VARS image +OVMF_VARS_VM="${VM_FILES_DIR}/OVMF_VARS_VM.fd" # Path to where a copy of the unmodified OVMF_VARS image will be created automatically -LOOKING_GLASS_MAX_SCREEN_WIDTH=1920 # 1920 Recommended (bigger resolutions will result in a bigger buffer with worse performance) -LOOKING_GLASS_MAX_SCREEN_HEIGHT=1080 # 1080 Recommended (bigger resolutions will result in a bigger buffer with worse performance) -LOOKING_GLASS_VERSION=B4 # B4 Recommended +HELPER_ISO="${VM_FILES_DIR}/mobile-passthrough-helper.iso" # Required for automated driver installation, looking glass setup, IP setup, remote desktop setup etc. inside of the VM -USE_SPICE=true # Required for Windows installation and recommended for Looking Glass -SPICE_PORT=5904 # 5900 is the normal port, but it may already be used by something else on your system like VNC +LOOKING_GLASS_MAX_SCREEN_WIDTH="1920" # 1920 Recommended (bigger resolutions will result in a bigger buffer with worse performance) +LOOKING_GLASS_MAX_SCREEN_HEIGHT="1080" # 1080 Recommended (bigger resolutions will result in a bigger buffer with worse performance) +LOOKING_GLASS_VERSION="B4" # B4 Recommended -USE_SPICE_CLIENT="true" # Required for installation +DISPLAY_MODE="4" # ("4" is the only working one atm) Display mode to use (e.g. 1 or 2 ... see scripts/utils/common/plugins) -DISPLAY_MODE=4 # See scripts/utils/common/plugins ; Mode 4 is the only working one atm ; Looking Glass doesn't play nicely yet +USE_SPICE="true" # Recommended for Windows installation and required for Looking Glass and QXL +SPICE_PORT="5904" # 5900 is the normal port, but it may already be used by something else on your system like VNC +USE_SPICE_CLIENT="true" # Recommended for installation USE_FAKE_BATTERY="true" # Recommended to avoid Error 43 -PATCH_OVMF_WITH_VROM="true" # Recommended to avoid Error 43 - -VM_START_MODE="qemu" # Required (qemu or virt-install) +VM_START_MODE="qemu" # "qemu" is recommended ("qemu" or "virt-install") # USB devices to pass through automatically while the VM is running. Separated by semicolons! # (See output of lsusb for vendorid/productid or hostbus/hostaddr) @@ -59,11 +52,3 @@ USB_DEVICES="" # example1: USB_DEVICES="hostbus=3,hostaddr=9" # example2: USB_DEVICES="vendorid=0x0b95,productid=0x1790" # example3: USB_DEVICES="vendorid=0x0b12,productid=0x9348;vendorid=0x0b95,productid=0x1790;hostbus=3,hostaddr=9" - -####### This part of the config get's burned into the helper iso that you can generate by running './mbpt.sh iso' ###### -# Not implemented yet; Please change the helper-iso-files/start.bat file manually, if you need to change the IPs -#V_NETWORK_GATEWAY_IP=192.168.99.1 # Recommended (Leave this as is unless you know what you're doing) -#V_NETWORK_DNS_IP=192.168.99.1 # Recommended (Leave this as is unless you know what you're doing) -#V_NETWORK_IP=192.168.99.2 # Recommended (Leave this as is unless you know what you're doing) -# TODO: add DHCP -########################################################################################################################## diff --git a/scripts/main/generate-vm-config.sh b/scripts/main/generate-vm-config.sh index f484c4b..06883ab 100755 --- a/scripts/main/generate-vm-config.sh +++ b/scripts/main/generate-vm-config.sh @@ -51,35 +51,50 @@ mkdir -p "$(dirname "${USER_CONFIG_FILE}")" cp "${PROJECT_DIR}/default.conf" "${USER_CONFIG_FILE}" echo "> Config will be created at ${USER_CONFIG_FILE}'" +# Variables that require a reinstall when changed (./mbpt.sh install) interactiveCfg "What should the name of the VM be?" VM_NAME -interactiveCfg "Where to save the VM drive image? (At least 40G is highly recommended; Can't be changed wihtout a reinstall)" DRIVE_IMG -interactiveCfg "How big should the VM drive image be?" VM_DISK_SIZE -interactiveCfg "How many CPU cores should the VM get? (e.g. 8 or auto; auto=AVAILABLE_CORES-1G)" CPU_CORE_COUNT -interactiveCfg "How much RAM should the VM get? (e.g. 16G or auto; auto=FREE_RAM-1G)" RAM_SIZE +interactiveCfg "Where to save the VM drive image?" DRIVE_IMG +interactiveCfg "How big should the VM drive image be? (At least 40G is highly recommended; Can't be changed wihtout a reinstall)" VM_DISK_SIZE interactiveCfg "Path to your Windows installation iso. (If it doesn't exist it will be downloaded to that location automatically.)" INSTALL_IMG -interactiveCfg "Path to a dGPU ROM. (Optional)" DGPU_ROM -interactiveCfg "Path to a iGPU ROM. (Optional)" IGPU_ROM -interactiveCfg "Path to a folder to share with the VM via SMB. (Optional)" SMB_SHARE_FOLDER -interactiveCfg "Location of OVMF_VARS.fd." OVMF_VARS -interactiveCfg "Where to create Creating a copy of OVMF_VARS.fd (containing the executable firmware code and but the non-volatile variable store) for the VM?" OVMF_VARS_VM -interactiveCfg "Location of OVMF_CODE.fd." OVMF_CODE -interactiveCfg "Location of helper iso or where to create it." HELPER_ISO -interactiveCfg "Pass the dGPU through to the VM. (true, false or auto to enable if more than one GPU is in this system)" DGPU_PASSTHROUGH -interactiveCfg "Share the iGPU with the VM to allow using Optimus within the VM to save battery life (true, false or auto to share it only if available)" SHARE_IGPU -interactiveCfg "dGPU driver used by the Linux host (E.g. nvidia, nouveau, amdgpu, radeon or auto to detect it automatically)" HOST_DGPU_DRIVER + +# Variables that can be changed between VM starts (./mbpt.sh start) +interactiveCfg "How many CPU cores should the VM get? (e.g. 8 or auto; auto equals [AVAILABLE CORES]-1 but uses 16 cores max)" CPU_CORE_COUNT +interactiveCfg "How much RAM should the VM get? (e.g. 16G or auto; auto equals [FREE RAM]-1G but uses 16G max)" RAM_SIZE + interactiveCfg "The PCI address of your dGPU as obtained by 'lspci' or 'optimus lspci'. (E.g. 01:00.0 or auto to detect it automatically)" DGPU_PCI_ADDRESS interactiveCfg "The PCI address of your iGPU as obtained by 'lspci'. (E.g. 00:02.0 or auto to detect it automatically)" IGPU_PCI_ADDRESS -interactiveCfg "Virtual input device mode for keyboard and mouse. (if usb-tablet doesn't work properly, you may want to switch to virtio)" VIRTUAL_INPUT_TYPE +interactiveCfg "Pass the dGPU through to the VM. (true, false or auto to enable if more than one GPU is in this system)" DGPU_PASSTHROUGH +interactiveCfg "Share the iGPU (only supports Intel atm) with the VM to allow using Optimus within the VM to save battery life (true, false or auto to share it only if available)" SHARE_IGPU + +interactiveCfg "Path to a dGPU ROM. (Optional; Can help avoid error 43)" DGPU_ROM +interactiveCfg "Path to a iGPU ROM. (Optional; Can help avoid error 43)" IGPU_ROM +interactiveCfg "Patch OVMF with your dGPU ROM if you supply one. (Highly recommended to avoid Error 43)" PATCH_OVMF_WITH_VROM + interactiveCfg "MAC address to use (e.g. 11:22:33:44:55:66 or auto to generate it automatically)" MAC_ADDRESS interactiveCfg "Network mode to use? Only supports bridge at the moment." NETWORK_MODE +interactiveCfg "Path to a folder to share with the VM via SMB. (Optional)" SMB_SHARE_FOLDER + +interactiveCfg "Virtual input device mode for keyboard and mouse. (if usb-tablet doesn't work properly, you may want to switch to virtio)" VIRTUAL_INPUT_TYPE + +interactiveCfg "Location of the unmodified OVMF_VARS.fd." OVMF_VARS +interactiveCfg "Location of the unmodified OVMF_CODE.fd." OVMF_CODE +interactiveCfg "Where to create Creating a copy of OVMF_VARS.fd (containing the executable firmware code and but the non-volatile variable store) for the VM?" OVMF_VARS_VM + +interactiveCfg "Location of helper iso or where to create it." HELPER_ISO + interactiveCfg "Max screen width with Looking Glass." LOOKING_GLASS_MAX_SCREEN_WIDTH interactiveCfg "Max screen height with Looking Glass." LOOKING_GLASS_MAX_SCREEN_HEIGHT interactiveCfg "Version of Looking Glass to use (B4 is highly recommended)" LOOKING_GLASS_VERSION + +interactiveCfg "Display mode to use (e.g. 1 or 2 ... see scripts/utils/common/plugins)" DISPLAY_MODE + interactiveCfg "Enable spice. (Leave this on unless you know what you're doing!)" USE_SPICE interactiveCfg "Port to use for spice." SPICE_PORT -interactiveCfg "Display mode to use (e.g. 1 or 2 ... see scripts/utils/common/plugins)" DISPLAY_MODE +interactiveCfg "Automatically start a Spice client when the VM starts." USE_SPICE_CLIENT + interactiveCfg "Provide the VM with a fake battery (Highly recommended to avoid Error 43)" USE_FAKE_BATTERY -interactiveCfg "Patch OVMF with your dGPU ROM if you supply one. (Highly recommended to avoid Error 43)" PATCH_OVMF_WITH_VROM + interactiveCfg "Tool to use to start/install the VM. (qemu or virt-install)" VM_START_MODE + interactiveCfg "List of USB devices to pass through. (Semicolon separated, e.g. vendorid=0x0b12,productid=0x9348;vendorid=0x0b95,productid=0x1790)" USB_DEVICES # TODO: Make selecting USB devices easier \ No newline at end of file diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index d08c177..5d4d4d5 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -318,13 +318,8 @@ function setDGpuParams() { DGPU_PASSTHROUGH=true echo "> Using dGPU passthrough..." - if [ "$HOST_DGPU_DRIVER" = "auto" ]; then - HOST_DGPU_DRIVER="$(sudo ${OPTIRUN_PREFIX}lspci -s "$DGPU_PCI_ADDRESS" -vv | grep driver | cut -d':' -f2 | cut -d' ' -f2-)" - fi - - DGPU_INFO="$(sudo lspci | grep "$DGPU_PCI_ADDRESS" | cut -d' ' -f2-)" + DGPU_INFO="$(sudo ${OPTIRUN_PREFIX}lspci | grep "$DGPU_PCI_ADDRESS" | cut -d' ' -f2-)" echo "> dGPU is: $DGPU_INFO" - echo "> dGPU driver is $HOST_DGPU_DRIVER" echo "> Retrieving and parsing DGPU IDs..." DGPU_IDS=$(export DRI_PRIME=1 && sudo ${OPTIRUN_PREFIX}lspci -n -s "${DGPU_PCI_ADDRESS}" | grep -oP "\w+:\w+" | tail -1) @@ -422,9 +417,8 @@ function vGpuSetup() { fi if [ "$VGPU_UUID" != "" ]; then - IGPU_INFO="$(sudo lspci | grep "$IGPU_PCI_ADDRESS" | cut -d' ' -f2-)" + IGPU_INFO="$(sudo ${OPTIRUN_PREFIX}lspci | grep "$IGPU_PCI_ADDRESS" | cut -d' ' -f2-)" echo "> iGPU is: $IGPU_INFO" - echo "> iGPU dirver is: $HOST_DGPU_DRIVER" echo "> UUID of vGPU is: $VGPU_UUID" DMA_BUF_AVAILABLE=true fi @@ -779,7 +773,7 @@ function vfioPci() { #echo "> Binding dGPU to VFIO driver..." #driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" - LSPCI_OUTPUT="$(sudo lspci)" + LSPCI_OUTPUT="$(sudo ${OPTIRUN_PREFIX}lspci)" LSIOMMU_OUTPUT="$(lsiommu)" IOMMU_GROUP="$(echo "$LSIOMMU_OUTPUT" | grep "${DGPU_PCI_ADDRESS}" | cut -d' ' -f3)" DGPU_IOMMU_GROUP_DEVICES=$(echo "$LSIOMMU_OUTPUT" | grep "IOMMU Group ${IOMMU_GROUP} " | grep -v "PCI bridge" | grep -v "ISA bridge") diff --git a/scripts/utils/manager-specific/package/emerge b/scripts/utils/manager-specific/package/emerge index 35c416c..e254ecc 100755 --- a/scripts/utils/manager-specific/package/emerge +++ b/scripts/utils/manager-specific/package/emerge @@ -34,9 +34,9 @@ function installPackages() { PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do if [ "$SEARCH_MODE" = "--executables" ]; then - PACKAGE_TO_INSTALL="$(sudo e-file $CURRENT_ITEM ????)" + PACKAGE_TO_INSTALL="$(sudo e-file $CURRENT_ITEM ????)" # TODO: FIXME elif [ "$SEARCH_MODE" = "--files" ]; then - PACKAGE_TO_INSTALL="$(sudo e-file $CURRENT_ITEM ????)" + PACKAGE_TO_INSTALL="$(sudo e-file $CURRENT_ITEM ????)" # TODO: FIXME fi if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" From d359b93de29f904caf4ddd167d875aff80b67fc1 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Wed, 25 Aug 2021 18:33:28 +0200 Subject: [PATCH 33/40] Remove remaining distribution-specific code --- requirements.sh | 2 +- .../distro-specific/Fedora/34/bumblebee-setup | 24 ------------------- .../distro-specific/Fedora/34/nvidia-setup | 18 -------------- .../Ubuntu/21.04/bumblebee-setup | 21 ---------------- .../distro-specific/Ubuntu/21.04/nvidia-setup | 9 ------- scripts/utils/manager-specific/package/apt | 5 ++++ 6 files changed, 6 insertions(+), 73 deletions(-) delete mode 100755 scripts/utils/distro-specific/Fedora/34/bumblebee-setup delete mode 100755 scripts/utils/distro-specific/Fedora/34/nvidia-setup delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup delete mode 100755 scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup diff --git a/requirements.sh b/requirements.sh index b7d0e4d..97925c9 100644 --- a/requirements.sh +++ b/requirements.sh @@ -2,7 +2,7 @@ # This file is supposed to be `source`d by the `scripts/main/setup.sh` bash script. # It specifies which executables and files and kernel parameters which part of this project depends on # WARNING: File dependencies can't contain spaces at the moment -# Usage: `source ./requirements.txt` +# Usage: `source ./requirements.sh` ##################################################################################################### # TODO: #sudo dnf install -y msr-tools tunctl # TODO: check if these are still needed and if so what for diff --git a/scripts/utils/distro-specific/Fedora/34/bumblebee-setup b/scripts/utils/distro-specific/Fedora/34/bumblebee-setup deleted file mode 100755 index 120f19e..0000000 --- a/scripts/utils/distro-specific/Fedora/34/bumblebee-setup +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - -echo "Install third party repositories" -sudo dnf install fedora-workstation-repositories -y - -echo "Enable the Bumblebee repository" -sudo dnf copr enable chenxiaolong/bumblebee -y - -echo "Install Bumblebee" -sudo dnf install akmod-bbswitch bumblebee primus -y - -echo "Make Bumblebee avialable to the current user" -sudo gpasswd -a $(who -m | awk '{print $1;}') bumblebee - -echo "Enable Bumblebee autostart" -sudo systemctl enable bumblebeed - -echo "Block nvidia-fallback service" -sudo systemctl mask nvidia-fallback - -echo "Start Bumblebee" -sudo systemctl start bumblebeed \ No newline at end of file diff --git a/scripts/utils/distro-specific/Fedora/34/nvidia-setup b/scripts/utils/distro-specific/Fedora/34/nvidia-setup deleted file mode 100755 index 4a3f62f..0000000 --- a/scripts/utils/distro-specific/Fedora/34/nvidia-setup +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - -#echo "Disable Nouveau drivers" -#addKernelParam "nouveau.modeset=0" -#sudo grep -qxsF 'blacklist nouveau' "/etc/modprobe.d/blacklist.conf" || echo "blacklist nouveau" | sudo tee -a "/etc/modprobe.d/blacklist.conf" > /dev/null -#sudo grep -qxsF 'exclude=xorg-x11*' "/etc/dnf/dnf.conf" || echo "exclude=xorg-x11*" | sudo tee -a "/etc/dnf/dnf.conf" > /dev/null -#sudo dnf remove xorg-x11-drv-nouveau -y - -echo "Install third party repositories" -sudo dnf install fedora-workstation-repositories -y - -echo "Install third party repositories" -sudo dnf config-manager rpmfusion-nonfree-nvidia-driver --set-enabled -y - -echo "Enable the NVIDIA driver repository" -sudo dnf install akmod-nvidia acpi -y \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup b/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup deleted file mode 100755 index b39b500..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/bumblebee-setup +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - -echo "Install third party repositories" -sudo add-apt-repository ppa:bumblebee/testing -y - -echo "Install Bumblebee" -sudo apt install bumblebee bumblebee-nvidia -y - -echo "Make Bumblebee available to the current user" -sudo gpasswd -a $(whoami) bumblebee - -echo "Enable Bumblebee autostart" -sudo systemctl enable bumblebeed - -echo "Block nvidia-fallback service" -sudo systemctl mask nvidia-fallback - -echo "Start Bumblebee" -sudo systemctl start bumblebeed diff --git a/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup b/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup deleted file mode 100755 index 0781e84..0000000 --- a/scripts/utils/distro-specific/Ubuntu/21.04/nvidia-setup +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -source "$PROJECT_DIR/scripts/utils/common/libs/helpers" - -echo "Install third party repositories" -sudo add-apt-repository ppa:graphics-drivers/ppa -y - -echo "Auto-install NVIDIA Drivers with ubuntu-drivers" -sudo ubuntu-drivers install -y \ No newline at end of file diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index 52742a4..f8262b6 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -18,6 +18,10 @@ WANTED_ITEMS="$3" function updatePackageInfo() { sudo apt-get update + if ! command -v apt-file &> /dev/null; then + sudo apt-get install -y apt-file + fi + sudo apt-file update } function installPackages() { @@ -25,6 +29,7 @@ function installPackages() { WANTED_ITEMS="$2" if ! command -v apt-file &> /dev/null; then sudo apt-get install -y apt-file + sudo apt-file update fi PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do From a74e2797a411b809ff7b4c0acedf754983a44453 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Thu, 26 Aug 2021 00:23:19 +0200 Subject: [PATCH 34/40] Add HDMI Audio support --- scripts/main/vm.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index d08c177..51ad5b5 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -770,7 +770,9 @@ function vfioPci() { if [ "$DRY_RUN" = false ]; then if [ "$DGPU_PASSTHROUGH" = true ] || [ "$SHARE_IGPU" = true ]; then echo "> Loading vfio-pci kernel module..." - sudo modprobe vfio-pci + sudo modprobe vfio + sudo modprobe vfio_pci + sudo modprobe vfio_iommu_type1 fi if [ "$DGPU_PASSTHROUGH" = true ]; then @@ -779,17 +781,28 @@ function vfioPci() { #echo "> Binding dGPU to VFIO driver..." #driver bind "${DGPU_PCI_ADDRESS}" "vfio-pci" + IOMMU_GROUP="$(echo "$LSIOMMU_OUTPUT" | grep "${DGPU_PCI_ADDRESS}" | cut -d' ' -f3)" + echo "> IOMMU group for passthrough is ${IOMMU_GROUP}" + LSPCI_OUTPUT="$(sudo lspci)" LSIOMMU_OUTPUT="$(lsiommu)" IOMMU_GROUP="$(echo "$LSIOMMU_OUTPUT" | grep "${DGPU_PCI_ADDRESS}" | cut -d' ' -f3)" DGPU_IOMMU_GROUP_DEVICES=$(echo "$LSIOMMU_OUTPUT" | grep "IOMMU Group ${IOMMU_GROUP} " | grep -v "PCI bridge" | grep -v "ISA bridge") - echo "> IOMMU group for passthrough is ${IOMMU_GROUP}" + DGPU_FUNCTION_DEVICES=$(echo "$LSIOMMU_OUTPUT" | grep " ${DGPU_PCI_ADDRESS::-1}" | grep -v "PCI bridge" | grep -v "ISA bridge" | grep -v "${DGPU_PCI_ADDRESS}" | grep -v ^$) + DEVICES_TO_REBIND="$(echo -e "${DGPU_IOMMU_GROUP_DEVICES}\n${DGPU_FUNCTION_DEVICES}" | sort | uniq | grep -v ^$)" while IFS= read -r deviceInfo; do deviceName="$(echo "$deviceInfo" | cut -d ' ' -f4-)" deviceAddress="$(echo "$deviceInfo" | cut -d ' ' -f4)" - echo "> Unbinding device '${deviceName} from its driver, then bind it to the vfio-pci driver..." + echo "> Unbinding device '${deviceName}' from its driver, then bind it to the vfio-pci driver..." sudo driverctl --nosave set-override "0000:${deviceAddress}" vfio-pci - done <<< "$DGPU_IOMMU_GROUP_DEVICES" + done <<< "$DEVICES_TO_REBIND" + + while IFS= read -r deviceInfo; do + if [ "${deviceInfo}" != "" ]; then + deviceAddress="$(echo "$deviceInfo" | cut -d ' ' -f4)" + QEMU_PARAMS+=("-device" "vfio-pci,host=${deviceAddress}") + fi + done <<< "$DGPU_FUNCTION_DEVICES" #sudo bash -c "echo 'options vfio-pci ids=${DGPU_VENDOR_ID}:${DGPU_DEVICE_ID}' > '/etc/modprobe.d/vfio.conf'" # TODO: Make sure to also do the rebind for the other devices that are in the same iommu group (exclude stuff like PCI Bridge root ports that don't have vfio drivers) From 6223e0f57d0832e4f80ab6704d026e56b5e9ac23 Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Thu, 26 Aug 2021 01:05:35 +0200 Subject: [PATCH 35/40] Fix HDMI audio rebinding --- scripts/main/vm.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/main/vm.sh b/scripts/main/vm.sh index 784d5a4..b6e8be8 100755 --- a/scripts/main/vm.sh +++ b/scripts/main/vm.sh @@ -793,6 +793,7 @@ function vfioPci() { while IFS= read -r deviceInfo; do if [ "${deviceInfo}" != "" ]; then + echo "> Passing through $deviceInfo" deviceAddress="$(echo "$deviceInfo" | cut -d ' ' -f4)" QEMU_PARAMS+=("-device" "vfio-pci,host=${deviceAddress}") fi @@ -928,7 +929,8 @@ function onExit() { deviceAddress="$(echo "$deviceInfo" | cut -d ' ' -f4)" echo "> Unbinding device '${deviceName} from the vfio-pci driver, then bind it back to its original driver..." sudo driverctl --nosave unset-override "0000:${deviceAddress}" - done <<< "$DGPU_IOMMU_GROUP_DEVICES" + done <<< "$DEVICES_TO_REBIND" + fi if [ "$VGPU_UUID" != "" ]; then From 1aeb0ea132d8b2cff657363528d96b9029a29aa5 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Mon, 30 Aug 2021 17:39:34 +0200 Subject: [PATCH 36/40] fix apt plugin --- scripts/main/setup.sh | 4 ++++ scripts/utils/distro-specific/ubuntu/21.04/add-repos | 4 ++++ scripts/utils/manager-specific/package/apt | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100755 scripts/utils/distro-specific/ubuntu/21.04/add-repos diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index 43dd6ee..e015d3a 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -33,6 +33,10 @@ alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service" mkdir -p "${THIRDPARTY_DIR}" mkdir -p "${VM_FILES_DIR}" +if [ -f "${DISTRO_UTILS_DIR}/add-repos" ]; then + "${DISTRO_UTILS_DIR}/add-repos" +fi + MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" MISSING_FILES="$(getMissingFiles "$ALL_FILE_DEPS")" diff --git a/scripts/utils/distro-specific/ubuntu/21.04/add-repos b/scripts/utils/distro-specific/ubuntu/21.04/add-repos new file mode 100755 index 0000000..bd61545 --- /dev/null +++ b/scripts/utils/distro-specific/ubuntu/21.04/add-repos @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done + +sudo add-apt-repository -y universe diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index f8262b6..4f973ce 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -34,9 +34,9 @@ function installPackages() { PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do if [ "$SEARCH_MODE" = "--executables" ]; then - PACKAGE_TO_INSTALL="$(sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM | head -1 | cut -d':' -f1)" + PACKAGE_TO_INSTALL="$(sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM | grep "${CURRENT_ITEM}$" | head -1 | cut -d':' -f1)" elif [ "$SEARCH_MODE" = "--files" ]; then - PACKAGE_TO_INSTALL="$(sudo apt-file search $CURRENT_ITEM | head -1 | cut -d':' -f1)" + PACKAGE_TO_INSTALL="$(sudo apt-file search $CURRENT_ITEM | grep "${CURRENT_ITEM}$" | head -1 | cut -d':' -f1)" fi if [ "$?" = "0" ] && [ "$PACKAGE_TO_INSTALL" != "" ]; then PACKAGES_TO_INSTALL+=" $PACKAGE_TO_INSTALL" From 30aaa28b8c169bd404bc4e56afda119c5bad5945 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Mon, 30 Aug 2021 17:49:43 +0200 Subject: [PATCH 37/40] fix apt plugin interactivity issue --- scripts/utils/manager-specific/package/apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index 4f973ce..3c8890e 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -45,7 +45,7 @@ function installPackages() { fi done if [ "$PACKAGES_TO_INSTALL" != "" ]; then - sudo apt-get install -y $PACKAGES_TO_INSTALL + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y $PACKAGES_TO_INSTALL fi } From c66e36f19f54ec67829d949eb8e80221e14a3951 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:56:53 +0200 Subject: [PATCH 38/40] Improve apt support --- scripts/utils/manager-specific/package/apt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/utils/manager-specific/package/apt b/scripts/utils/manager-specific/package/apt index 3c8890e..bce9810 100755 --- a/scripts/utils/manager-specific/package/apt +++ b/scripts/utils/manager-specific/package/apt @@ -34,7 +34,7 @@ function installPackages() { PACKAGES_TO_INSTALL="" for CURRENT_ITEM in $WANTED_ITEMS; do if [ "$SEARCH_MODE" = "--executables" ]; then - PACKAGE_TO_INSTALL="$(sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/$CURRENT_ITEM | grep "${CURRENT_ITEM}$" | head -1 | cut -d':' -f1)" + PACKAGE_TO_INSTALL="$(sudo apt-file search -l -x "^/(bin|sbin|usr/bin|usr/sbin)/${CURRENT_ITEM}$" | head -1)" elif [ "$SEARCH_MODE" = "--files" ]; then PACKAGE_TO_INSTALL="$(sudo apt-file search $CURRENT_ITEM | grep "${CURRENT_ITEM}$" | head -1 | cut -d':' -f1)" fi @@ -45,7 +45,7 @@ function installPackages() { fi done if [ "$PACKAGES_TO_INSTALL" != "" ]; then - DEBIAN_FRONTEND=noninteractive sudo apt-get install -y $PACKAGES_TO_INSTALL + sudo bash -c "DEBIAN_FRONTEND=noninteractive apt-get install -yq $PACKAGES_TO_INSTALL" fi } From 4a1627a69b7e1c50aeda7a49823adf5376eca437 Mon Sep 17 00:00:00 2001 From: T-vK <t-vk@users.noreply.github.com> Date: Mon, 13 Sep 2021 17:41:20 +0200 Subject: [PATCH 39/40] Some fixes for Ubuntu --- README.md | 3 +-- scripts/main/setup.sh | 14 +++++----- scripts/utils/common/libs/helpers | 3 ++- scripts/utils/common/tools/distro-info | 6 ++++- scripts/utils/common/tools/get-manager | 10 ++++--- .../pre-package-info-update} | 2 +- .../Ubuntu/pre-package-install | 12 +++++++++ .../utils/manager-specific/kernelparams/grub | 26 +++++++++++++------ .../utils/manager-specific/service/initctl | 20 ++++++++++++++ .../utils/manager-specific/service/service | 21 +++++++++++++++ .../utils/manager-specific/service/systemd | 8 +++++- 11 files changed, 102 insertions(+), 23 deletions(-) rename scripts/utils/distro-specific/{ubuntu/21.04/add-repos => Ubuntu/pre-package-info-update} (79%) create mode 100755 scripts/utils/distro-specific/Ubuntu/pre-package-install create mode 100755 scripts/utils/manager-specific/service/initctl create mode 100755 scripts/utils/manager-specific/service/service diff --git a/README.md b/README.md index 9556672..f092f12 100644 --- a/README.md +++ b/README.md @@ -221,8 +221,7 @@ Credits to [Cole Robinson](https://blog.wikichoon.com/) for giving me a lot of i ## TODO ### High prio -- Create a bootable live version of this project -- Test on Ubuntu +- Fix for Ubuntu (Fix file dependency installation) - Document all the new features - Create a first Beta release - Test with an Nvidia notebook diff --git a/scripts/main/setup.sh b/scripts/main/setup.sh index e015d3a..afe5fa7 100755 --- a/scripts/main/setup.sh +++ b/scripts/main/setup.sh @@ -24,8 +24,6 @@ alias buildFakeBatterySsdt="sudo '$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssd alias vbiosFinderSetup="sudo '$COMMON_UTILS_SETUP_DIR/vbios-finder-setup'" alias lookingGlassSetup="sudo '$COMMON_UTILS_SETUP_DIR/looking-glass-setup'" alias generateHelperIso="sudo '${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh'" -alias nvidiaSetup="sudo '$DISTRO_UTILS_DIR/nvidia-setup'" -alias bumblebeeSetup="sudo '$DISTRO_UTILS_DIR/bumblebee-setup'" alias downloadWindowsIso="$COMMON_UTILS_TOOLS_DIR/download-windows-iso" alias createAutoStartService="'${SERVICE_MANAGER}' create-autostart-service" alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service" @@ -33,8 +31,8 @@ alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service" mkdir -p "${THIRDPARTY_DIR}" mkdir -p "${VM_FILES_DIR}" -if [ -f "${DISTRO_UTILS_DIR}/add-repos" ]; then - "${DISTRO_UTILS_DIR}/add-repos" +if [ -f "${DISTRO_UTILS_DIR}/pre-package-info-update" ]; then + "${DISTRO_UTILS_DIR}/pre-package-info-update" fi MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")" @@ -45,6 +43,10 @@ if [ "$MISSING_EXECUTABLES" != "" ] || [ "$MISSING_FILES" != "" ]; then updatePkgInfo fi +if [ -f "${DISTRO_UTILS_DIR}/pre-package-install" ]; then + "${DISTRO_UTILS_DIR}/pre-package-install" +fi + if [ "$MISSING_EXECUTABLES" != "" ]; then echo "> Finding and installing packages containing executables that we need..." getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need @@ -182,11 +184,11 @@ fi if [ "$1" = "auto" ]; then if [ "$REBOOT_REQUIRED" = true ]; then echo "> Creating a temporary service that will run on next reboot and continue the installation..." - createAutoStartService "${PROJECT_DIR}/mbpt.sh auto" + createAutoStartService "${PROJECT_DIR}/mbpt.sh auto" "MobilePassthroughInitSetup" echo "> Rebooting in 30 seconds... Press Ctrl+C to cancel." sleep 30 && sudo shutdown -r 0 else - removeAutoStartService &> /dev/null + removeAutoStartService "MobilePassthroughInitSetup" &> /dev/null echo "> No reboot required." fi else diff --git a/scripts/utils/common/libs/helpers b/scripts/utils/common/libs/helpers index 747ad33..d02c5fb 100644 --- a/scripts/utils/common/libs/helpers +++ b/scripts/utils/common/libs/helpers @@ -14,7 +14,8 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts" COMMON_UTILS_PLUGINS_DIR="${COMMON_UTILS_DIR}/plugins" COMMON_UTILS_SETUP_DIR="${COMMON_UTILS_DIR}/setup" COMMON_UTILS_TOOLS_DIR="${COMMON_UTILS_DIR}/tools" - DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")" + DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info" --exclude-version)" + DISTRO_VERSION_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")" MANAGER_UTILS_DIR="${UTILS_DIR}/manager-specific" INITRAMFS_MANAGER="${MANAGER_UTILS_DIR}/initramfs/$(sudo "${COMMON_UTILS_TOOLS_DIR}/get-manager" initramfs)" SERVICE_MANAGER="${MANAGER_UTILS_DIR}/service/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" service)" diff --git a/scripts/utils/common/tools/distro-info b/scripts/utils/common/tools/distro-info index 40ccee1..f29322f 100755 --- a/scripts/utils/common/tools/distro-info +++ b/scripts/utils/common/tools/distro-info @@ -37,4 +37,8 @@ else VER=$(uname -r) fi -echo "${OS}/${VER}" +if [ "$1" = "--exclude-version" ]; then + echo "${OS}" +else + echo "${OS}/${VER}" +fi diff --git a/scripts/utils/common/tools/get-manager b/scripts/utils/common/tools/get-manager index 9e627fe..2dc3d08 100755 --- a/scripts/utils/common/tools/get-manager +++ b/scripts/utils/common/tools/get-manager @@ -10,8 +10,12 @@ COMMAND="$1" if [ "$COMMAND" = "service" ]; then if command -v "systemctl" &> /dev/null; then echo "systemd" - elif [ -d "/etc/init.d/" ] && command -v "service" &> /dev/null; then - echo "sysvinit" + elif command -v "service" &> /dev/null; then + echo "service" + elif command -v "initctl" &> /dev/null; then + echo "initctl" + #elif [ -d "/etc/init.d/" ] && command -v "service" &> /dev/null; then + # echo "sysvinit" else exit 1 fi @@ -22,7 +26,7 @@ elif [ "$COMMAND" = "initramfs" ]; then exit 1 fi elif [ "$COMMAND" = "kernelparams" ]; then - if [ -f "/etc/default/grub" ] && [ -f "/etc/grub2-efi.cfg" ]; then + if [ -f "/etc/default/grub" ]; then echo "grub" else exit 1 diff --git a/scripts/utils/distro-specific/ubuntu/21.04/add-repos b/scripts/utils/distro-specific/Ubuntu/pre-package-info-update similarity index 79% rename from scripts/utils/distro-specific/ubuntu/21.04/add-repos rename to scripts/utils/distro-specific/Ubuntu/pre-package-info-update index bd61545..cb648db 100755 --- a/scripts/utils/distro-specific/ubuntu/21.04/add-repos +++ b/scripts/utils/distro-specific/Ubuntu/pre-package-info-update @@ -1,4 +1,4 @@ #!/usr/bin/env bash while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done -sudo add-apt-repository -y universe +sudo add-apt-repository -y universe \ No newline at end of file diff --git a/scripts/utils/distro-specific/Ubuntu/pre-package-install b/scripts/utils/distro-specific/Ubuntu/pre-package-install new file mode 100755 index 0000000..07600a5 --- /dev/null +++ b/scripts/utils/distro-specific/Ubuntu/pre-package-install @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done + +alias commandAvailable="${COMMON_UTILS_TOOLS_DIR}/commands-available" + +if ! commandAvailable "x86_64-w64-mingw32-g++"; then + sudo apt-get install -y g++-mingw-w64-x86-64-win32 +fi + +if ! commandAvailable "upx"; then + sudo apt-get install -y upx-ucl +fi \ No newline at end of file diff --git a/scripts/utils/manager-specific/kernelparams/grub b/scripts/utils/manager-specific/kernelparams/grub index 81c8dc6..47053ab 100755 --- a/scripts/utils/manager-specific/kernelparams/grub +++ b/scripts/utils/manager-specific/kernelparams/grub @@ -5,12 +5,18 @@ GRUB_CFG_PATH=/etc/default/grub COMMAND="$1" # Supported commands: add, remove, apply PARAM="$2" +if sudo cat "$GRUB_CFG_PATH" | grep --quiet "GRUB_CMDLINE_LINUX_DEFAULT="; then + GRUB_CMDLINE_VAR="GRUB_CMDLINE_LINUX_DEFAULT" +else + GRUB_CMDLINE_VAR="GRUB_CMDLINE_LINUX" +fi + function addKernelParam() { - if ! sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then - sudo sed -i "s/^GRUB_CMDLINE_LINUX=\"/&$1 /" "$GRUB_CFG_PATH" - echo "addKernelParam: Added \"$1\" to GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" + if ! sudo cat "$GRUB_CFG_PATH" | grep "$GRUB_CMDLINE_VAR=" | grep --quiet "$1"; then + sudo sed -i "s/^$GRUB_CMDLINE_VAR=\"/&$1 /" "$GRUB_CFG_PATH" + echo "addKernelParam: Added \"$1\" to $GRUB_CMDLINE_VAR in $GRUB_CFG_PATH" else - echo "addKernelParam: No action required. \"$1\" already exists in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" + echo "addKernelParam: No action required. \"$1\" already exists in $GRUB_CMDLINE_VAR of $GRUB_CFG_PATH" fi } function addKernelParams() { @@ -19,11 +25,11 @@ function addKernelParams() { done } function removeKernelParam() { - if sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then + if sudo cat "$GRUB_CFG_PATH" | grep "$GRUB_CMDLINE_VAR=" | grep --quiet "$1"; then sudo sed -i "s/$1 //" "$GRUB_CFG_PATH" - echo "removeKernelParam: Removed \"$1\" from GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH" + echo "removeKernelParam: Removed \"$1\" from $GRUB_CMDLINE_VAR in $GRUB_CFG_PATH" else - echo "removeKernelParam: No action required. \"$1\" is not set in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH" + echo "removeKernelParam: No action required. \"$1\" is not set in $GRUB_CMDLINE_VAR of $GRUB_CFG_PATH" fi } function removeKernelParams() { @@ -33,7 +39,11 @@ function removeKernelParams() { } function applyKernelParamChanges() { - sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg' + if command -v update-grub &> /dev/null; then + sudo update-grub + elif [ -f "/etc/grub2-efi.cfg" ]; then + sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg' + fi } if [ "$COMMAND" = "add" ]; then diff --git a/scripts/utils/manager-specific/service/initctl b/scripts/utils/manager-specific/service/initctl new file mode 100755 index 0000000..54b5ad0 --- /dev/null +++ b/scripts/utils/manager-specific/service/initctl @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" +SERVICE_NAME="$2" + +if [ "$COMMAND" = "create-autostart-service" ]; then + echo "Not implemented" + exit 1 +elif [ "$COMMAND" = "remove-autostart-service" ]; then + echo "Not implemented" + exit 1 +elif [ "$COMMAND" = "start" ]; then + sudo service start ${SERVICE_NAME} &> /dev/null +elif [ "$COMMAND" = "stop" ]; then + sudo service stop ${SERVICE_NAME} &> /dev/null +elif [ "$COMMAND" = "restart" ]; then + sudo initctl restart ${SERVICE_NAME} &> /dev/null +fi diff --git a/scripts/utils/manager-specific/service/service b/scripts/utils/manager-specific/service/service new file mode 100755 index 0000000..dbe4a93 --- /dev/null +++ b/scripts/utils/manager-specific/service/service @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done +source "$PROJECT_DIR/scripts/utils/common/libs/helpers" + +COMMAND="$1" +SERVICE_NAME="$2" + +if [ "$COMMAND" = "create-autostart-service" ]; then + echo "Not implemented" + exit 1 +elif [ "$COMMAND" = "remove-autostart-service" ]; then + echo "Not implemented" + exit 1 +elif [ "$COMMAND" = "start" ]; then + sudo service ${SERVICE_NAME} start &> /dev/null +elif [ "$COMMAND" = "stop" ]; then + sudo service ${SERVICE_NAME} stop &> /dev/null +elif [ "$COMMAND" = "restart" ]; then + sudo service ${SERVICE_NAME} stop &> /dev/null + sudo service ${SERVICE_NAME} start &> /dev/null +fi diff --git a/scripts/utils/manager-specific/service/systemd b/scripts/utils/manager-specific/service/systemd index 7ef51d5..91c6e40 100755 --- a/scripts/utils/manager-specific/service/systemd +++ b/scripts/utils/manager-specific/service/systemd @@ -4,7 +4,7 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers" COMMAND="$1" -SERVICE_NAME="MobilePassthroughInitSetup" +SERVICE_NAME="$2" if [ "$COMMAND" = "create-autostart-service" ]; then COMMAND_TO_RUN="$2" EXEC_START="'$GUI_TERMINAL' run-with-command '$COMMAND_TO_RUN'" @@ -29,4 +29,10 @@ WantedBy=multi-user.target" > /etc/systemd/system/${SERVICE_NAME}.service sudo systemctl enable ${SERVICE_NAME}.service elif [ "$COMMAND" = "remove-autostart-service" ]; then sudo systemctl disable ${SERVICE_NAME}.service &> /dev/null +elif [ "$COMMAND" = "start" ]; then + sudo systemctl start ${SERVICE_NAME}.service &> /dev/null +elif [ "$COMMAND" = "stop" ]; then + sudo systemctl stop ${SERVICE_NAME}.service &> /dev/null +elif [ "$COMMAND" = "restart" ]; then + sudo systemctl restart ${SERVICE_NAME}.service &> /dev/null fi From 8c3c2750f59a79d08bcf8d091d2f900ed0a8066d Mon Sep 17 00:00:00 2001 From: T-vK <T-vK@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:03:37 +0100 Subject: [PATCH 40/40] Add note that Ubuntu support is currently broken --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f092f12..b449b8b 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,11 @@ And there is also a lot of advanced stuff that I managed to fully automate, like ## Currently supported distributions - Fedora 34 - - Ubuntu 21.04 (not tested in a while) + - Ubuntu 21.04 (Currently not working. Some dependencies won't be installed automatically.) ## Limitations -- The project is currently only really being tested on Fedora and Ubuntu. But it has been written in a somewhat distribution-agnostic way, meaning it might just work on other distributions and if not, you might just have to add a new script to `scripts/utils/manager-specific/`. (For example the project currently supports the package managers `dnf` and `apt`, if your distro uses `pacman`, you have to add a pacman script that can be called the same way as the [apt script](scripts/utils/manager-specific/package/apt).) +- The project is currently only really being tested on Fedora and Ubuntu (currently broken). But it has been written in a somewhat distribution-agnostic way, meaning it might just work on other distributions and if not, you might just have to add a new script to `scripts/utils/manager-specific/`. (For example the project currently supports the package managers `dnf` and `apt`, if your distro uses `pacman`, you have to add a pacman script that can be called the same way as the [apt script](scripts/utils/manager-specific/package/apt).) - This project currently only supports Windows 10 x64 VMs and hopefully Windows 11 x64 VMs at some point. (For older Windows versions you have to figure out the driver installation etc. on your own.) - Only tested for Intel+Nvidia and Intel+AMD systems. (Although the compatibility-check (./mbpt.sh check) should actually work on any hardware.) - Expect bugs. I have only tested this on a handful of devices and I have constantly changed the scripts without testing everything every time. @@ -246,4 +246,4 @@ Credits to [Cole Robinson](https://blog.wikichoon.com/) for giving me a lot of i - Check if required dependencies are installed for each script - Add support for multiple VMs - Add support for Linux guests -- Add support for Desktop PCs \ No newline at end of file +- Add support for Desktop PCs