Skip to content

Instantly share code, notes, and snippets.

@vroad
vroad / README.md
Last active May 16, 2022 08:05
Single partition passthrough with mdadm hack

WARNING!! You may lose all of your data stored in the partition if you don't follow these steps correctly. Backup important data and use at your own risk. I strongly recommend you to start with an empty partition, or a loopback device backed by an empty image file.

This script will allow you to pass existing NTFS partition to windows running on KVM, which is also readable by bare-metal windows. You can't simply pass existing NTFS partition to the VM since guest OS see the partion as a whole disk device with a partiton table. The trick used here is sandwiching the partition with 2 loopback devices using software RAID (MD) device built with mdadm --build --level=linear. First device stores main partition table in the beginning of disk, and second one stores backup table in the end of disk. This idea is originally posted by a redditor ws-ilazki, I just converted it to the script: https://www.reddit.com/r/VFIO/comments/j443ad/pass_through_a_partition/g7hn38z/

Trim from guest OS seems to be not possible. I

@vroad
vroad / Readme.md
Last active December 28, 2021 07:38 — forked from WhittlesJr/Readme.md
NixOS: PCI Passthrough

Things I changed in this fork

Modified WhittlesJr's forked version to prevent some devices from loading its drivers. In my case, NVIDIA's USB Host controller is in the same IOMMU group, and specifying vfio-pci option didn't prevent the device from loading xhci_usb driver.

IOMMU Group 1   00:01.0 PCI bridge [0604]: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x16) [8086:1901] (rev 07)
IOMMU Group 1   01:00.0 VGA compatible controller [0300]: NVIDIA Corporation TU106M [GeForce RTX 2060 Mobile] [10de:1f11] (rev a1)
IOMMU Group 1   01:00.1 Audio device [0403]: NVIDIA Corporation TU106 High Definition Audio Controller [10de:10f9] (rev a1)
IOMMU Group 1 01:00.2 USB controller [0c03]: NVIDIA Corporation TU106 USB 3.1 Host Controller [10de:1ada] (rev a1)
#include <node.h>
#include <stdio.h>
using namespace v8;
void Exit(void* arg) {
printf("node::AtExit called\n");
}
void Initialize(Handle<Object> exports) {