diff --git a/dotfiles_github/.virtualization/dump_rom.sh b/dotfiles_github/.virtualization/dump_rom.sh new file mode 100644 index 00000000..8a93142d --- /dev/null +++ b/dotfiles_github/.virtualization/dump_rom.sh @@ -0,0 +1,29 @@ +systemctl stop gdm.service + +sleep 3 + +modprobe -r nvidia_drm +modprobe -r nvidia_modeset +modprobe -r drm_kms_helper +modprobe -r nvidia +modprobe -r i2c_nvidia_gpu +modprobe -r drm +modprobe -r nvidia_uvm + +sleep 3 + +./nvflash --save vbios.rom + +sleep 3 + +modprobe nvidia_drm +modprobe nvidia_modeset +modprobe drm_kms_helper +modprobe nvidia +modprobe i2c_nvidia_gpu +modprobe drm +modprobe nvidia_uvm + +sleep 3 + +systemctl start gdm.service \ No newline at end of file diff --git a/dotfiles_github/.virtualization/nvflash b/dotfiles_github/.virtualization/nvflash new file mode 100755 index 00000000..46e4bfe9 Binary files /dev/null and b/dotfiles_github/.virtualization/nvflash differ diff --git a/dotfiles_github/README.md b/dotfiles_github/README.md index da6dd9f6..c4b3a672 100644 --- a/dotfiles_github/README.md +++ b/dotfiles_github/README.md @@ -22,12 +22,17 @@ Using GNOME, disable all extensions. Install [Tiling Assistant](https://extensio Set Windows and Screen Edges gaps to 12px. ## Virtualization -Install `libvirt`. -`nano /etc/default/grub` and add `amd_iommu=on iommu=pt` to the `GRUB_CMDLINE_LINUX_DEFAULT` variable. -`sudo grub-mkconfig -o /boot/grub/grub.cfg` to update the bootloader. -Install QEMU, KVM, libvirt, virtmanager. `sudo pacman -S virt-manager qemu vde2 ebtables dnsmasq bridge-utils openbsd-netcat ovmf` -Configure `libvirtd` +1. Install necessary packages. +`sudo pacman -S virt-manager qemu vde2 ebtables dnsmasq bridge-utils openbsd-netcat ovmf` + +2. Prepare the bootloader (GRUB) +```bash +sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor udev.log_priority=3"/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor amd_iommu=on iommu=pt udev.log_priority=3"/' /etc/default/grub && \ +sudo grub-mkconfig -o /boot/grub/grub.cfg +``` + +3. Configure `libvirtd` ```bash sudo sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf && \ @@ -42,33 +47,14 @@ sudo sed -i 's/#group = "root"/group = "joey"/' /etc/libvirt/qemu.conf && \ sudo systemctl restart libvirtd ``` -Reboot. +4. Dump the GPU vbios. +Run the script to dump the vbios. -Set up the VM, following the [RisingPrism wiki](https://gitlab.com/risingprismtv/single-gpu-passthrough/-/wikis). +5. Patch the GPU vbios with Bless Hex Editor. +Follow [Mutahar's guide](https://youtu.be/BUSrdUoedTo?t=874) (timestamped) for this bit. +Save the patched version as `vbios_patched.rom`. Restrict its permissions with `chmod 660 vbios_patched.rom && sudo chown joey:joey vbios_patched.rom` then copy it to the share folder with `sudo mkdir /usr/share/vbios && sudo cp vbios_patched.rom /usr/share/vbios/vbios.rom` -Open Nvidia X Server Settings, go to GPU 0 and check the VBIOS version. -Browse to https://www.techpowerup.com/vgabios/ and download the correct VBIOS file. -Rename the file to `vbios.rom`. - -Actually, dump and patch your own ROM with techpowerup's nvflash and the Bless hex editor. -This will require unloading all of the nvidia kernel modules, so connect via SSH from another host. - -Stop the display manager, then unload the nvidia kernel modules -`sudo systemctl stop gdm.service && sudo modprobe -r i2c_nvidia_gpu nvidia_uvm nvidia nvidia_drm` -Then dump the rom. -`sudo ./nvflash --save vbios.rom` - -Reload the kernel modules and restart the display manager -`sudo modprobe i2c_nvidia_gpu nvidia_uvm nvidia nvidia_drm && sudo systemctl start gdm.service` - -Open the new vbios file in Bless hex editor, search for 'VIDEO' in text mode. Delete all lines up to the `U` character on that line (exclusive). Save the patched version as `vbios_patched.rom`. Restrict its permissions with `chmod 660 vbios_patched.rom` then copy it to the share folder with `sudo cp vbios_patched.rom /usr/share/vbios/vbios.rom` - -Place the VBIOS file. -```bash -sudo mkdir /usr/share/vbios && \ -sudo cp ~/Downloads/vbios.rom /usr/share/vbios/vbios.rom && \ -cd /usr/share/vbios && \ -sudo chmod -R 660 vbios.rom && \ -sudo chown joey:joey vbios.rom -``` +6. Set up the VM. +Follow page 5 of the [RisingPrism wiki](https://gitlab.com/risingprismtv/single-gpu-passthrough/-/wikis/) for details on configuring the VM. +7. Reboot to effect the changes we made to the bootloader. \ No newline at end of file diff --git a/dotfiles_github/install_virtualization.sh b/dotfiles_github/install_virtualization.sh new file mode 100644 index 00000000..696c4d33 --- /dev/null +++ b/dotfiles_github/install_virtualization.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +sudo pacman -S virt-manager qemu vde2 ebtables dnsmasq bridge-utils openbsd-netcat ovmf + +sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor udev.log_priority=3"/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor amd_iommu=on iommu=pt udev.log_priority=3"/' /etc/default/grub && \ +sudo grub-mkconfig -o /boot/grub/grub.cfg + +sudo sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf && \ +sudo sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf && \ +sudo bash -c 'echo "log_filters=\"1:qemu\"" >> /etc/libvirt/libvirtd.conf' && \ +sudo bash -c 'echo "log_outputs=\"1:file:/var/log/libvirt/libvirtd.log\"" >> /etc/libvirt/libvirtd.conf' && \ +sudo usermod -aG libvirt $USER && \ +sudo systemctl enable libvirtd && \ +sudo systemctl start libvirtd && \ +sudo sed -i 's/#user = "root"/user = "joey"/' /etc/libvirt/qemu.conf && \ +sudo sed -i 's/#group = "root"/group = "joey"/' /etc/libvirt/qemu.conf && \ +sudo systemctl restart libvirtd + +source ./.virtualization/dump_rom.sh \ No newline at end of file diff --git a/dotfiles_github/start.sh b/dotfiles_github/start.sh deleted file mode 100755 index 8b3bb1b5..00000000 --- a/dotfiles_github/start.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# debuggings -set -x - -# stop display manager -systemctl stop display-manager.service -killall gdm-x-session - -# unbind VTconsoles -echo 0 > /sys/class/vtconsole/vtcon0/bind -echo 0 > /sys/class/vtconsole/vtcon1/bind - -# unbind EFI-framebuffer -echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind - -# avoid race condition -sleep 10 - -# unload nvidia -modprobe -r nvidia_drm -modprobe -r nvidia_modeset -modprobe -r drm_kms_helper -modprobe -r nvidia -modprobe -r i2c_nvidia_gpu -modprobe -r drm -modprobe -r nvidia_uvm - -# unbind gpu -virsh nodedev-detach pci_0000_09_00_0 -virsh nodedev-detach pci_0000_09_00_1 -virsh nodedev-detach pci_0000_09_00_2 -virsh nodedev-detach pci_0000_09_00_3 - -# load vfio -modprobe vfio -modprobe vfio_pci -modprobe vfio_iommu_type1 - diff --git a/dotfiles_github/stop.sh b/dotfiles_github/stop.sh deleted file mode 100755 index 10389190..00000000 --- a/dotfiles_github/stop.sh +++ /dev/null @@ -1,35 +0,0 @@ -# debug -set -x - -# unload vfio-pci -modprobe -r vfio_pci -modprobe -r vfio_iommu_type1 -modprobe -r vfio - -# rebind gpu -virsh nodedev-reattach pci_0000_09_00_0 -virsh nodedev-reattach pci_0000_09_00_1 -virsh nodedev-reattach pci_0000_09_00_2 -virsh nodedev-reattach pci_0000_09_00_3 - -# rebind VTconsoles -echo 1 > /sys/class/vtconsole/vtcon0/bind -echo 0 > /sys/class/vtconsole/vtcon1/bind - -# read nvidia x config -nvidia-xconfig --query-gpu-info > /dev/null 2>&1 - -# bind EFI-framebuffer -echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind - -# load nvidia -modprobe nvidia_drm -modprobe nvidia_modeset -modprobe drm_kms_helper -modprobe nvidia -modprobe drm -modprobe nvidia_uvm - -# restart display manager -systemctl start gdm.service -