# Configuring a VM for driver development

The easiest way to build and test drivers is via a hypervisor that supports kernel debugging. I use my physical Windows host to write and build the driver, and another Windows host running virtually in Hyper-V to load and test it. Hyper-V allows the physical host to attach a debugger to the virtual host via a COM port to inspect memory etc, and crashing a VM is far less hassle than crashing your host.

Before being able to write a driver, head to the [Windows Driver Kit](https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk) (WDK) page and follow the steps outlined on your host/dev machine: first set up Visual Studio 2022 and install the following packages from "Individual Components":

* MSVC v143 - VS 2022 C++ ARM64/ARM64EC Spectre-mitigated libs (Latest)
* MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (Latest)
* C++ ATL for latest v143 build tools with Spectre Mitigations (ARM64/ARM64EC)
* C++ ATL for latest v143 build tools with Spectre Mitigations (x86 & x64)
* C++ MFC for latest v143 build tools with Spectre Mitigations (ARM64/ARM64EC)
* C++ MFC for latest v143 build tools with Spectre Mitigations (x86 & x64)

Then install the Windows 11 SDK (Windows SDK 10.0.26100.1) from the C++ Desktop Development options; now install [Windows WDK](https://go.microsoft.com/fwlink/?linkid=2272234) making sure to tick "Install Windows Driver Kit Visual Studio extension".

Now from a elevated CMD session run the following

```cmd
bcdedit /debug on
bcdedit /dbgsettings serial debugport:1 baudrate:115200
bcdedit /set testsigning on
```

`BCDEDIT` is the Boot Configuration Data Store Editor which can modify the boot configuration for Windows: the first command enables kernel debugging and the second command configures the debug parameters. The `debugport` number should correspond to the COM port number we configured with the named pipe. he third command permits Windows to load test-signed drivers (which is disabled by default).

Next, open regedit (also in an elevated context) and navigate to `HKLM\SYSTEM\CurrentControlSet\Control\Session Manager`. Create a new Key called **Debug Print Filter** and within that, a new DWORD Value. Give it the name **DEFAULT** and a value of **8**. This will allow Windows to generate kernel debug messages, which are disabled by default.

**Now reboot the VM**.

Another useful post is [this one](https://github.com/xalicex/kernel-debug-lab-for-virtual-box).
