# Virtual machine creation

While any other VM software could be used, we're using VirtualBox because it allows us to do port forwarding through its NAT network, but for this to work automatically, we need VirtualBox's Guest Additions installed. It's also pretty fast, and easy to use. In theory, the same concept could work with QEMU, or VMWare, if you're brave enough.

# Preparation

You need to set these apps to run as administrator. They're usually located in C:\Program Files\Oracle\VirtualBox

  • VirtualBoxVM.exe
  • VirtualBox.exe
  • VBoxSVC.exe

To do this, just follow these steps on each file:

  1. Right click
  2. Properties
  3. Compatibility (tab)
  4. Run this program as administrator
  5. OK

# Creating the VM

Open VirtualBox and attempt to create a new VM. When prompted, follow these instructions:

Name Value Description
VM Name WSL2 You can type anything, just make note of it, we'll be using it later.
OS Type Ubuntu (64-bit) Could be different depending on the distro you want to use.
Memory 8 GB Any size is good, depending on your distro's requirements and your host OS resources.
HDD Format VDI Anything works. VDI is preferred as it allows for dynamic HDD types.
VDI type Dynamic The file size will grow with the VM's HDD contents, just like WSL2's VHDX.
HDD space allocation 40 GB Preferably, you would put here your total HDD space. It doesn't matter if you don't have it all free, that's just the maximum value it'll grow to. Just like WSL2, it'll use all the available space in your HDD.

Once it's done, you can look for the .vbox file created by Virtual Box (usually in %USERPROFILE\VirtualBox VMs) and move the .vdi and the .vbox files to another location if you so desire. Make sure to re-add the VDI in the VM's Storage section in case it throws errors. As of VirtualBox 6.1, I didn't have to do anything extra when doing this.

# Configuring the VM (before first boot)

Tab Name Value Description
Basic Boot order 1st CD/DVD, 2nd HDD. Disable all others.
Basic Boot Enable EFI
Advanced Shared Clipboard Drag & Drop: Bidirectional
Motherboard Max cores Max Set to the max recommended value for your CPU (use the green bar as guide)
Motherboard Enable PAE/NX Yes
Motherboard Enable Nested VT-x / AMD-v Yes
Acceleration Paravirtualization KVM
Acceleration Enable Nested Paging Yes
Screen Max video memory Max
Screen Enable 3D Acceleration Yes
Storage CD/DVD Your distro ISO file
Storage Controllers VirtIO-SCSI To do this, remove the default SATA controller, and add a new VirtIO-SCSI one. This way there's no I/O emulation for your HDD files. Once done, add your VDI file there. Also, mark as Solid State Drive (if possible).
Audio Enabled Yes/No Depends on what you need
Network NIC 1 virtio-net Click on Advanced and then set the paravirtualization adapter as virtio-net, for max speed.
USB Emulation USB 3.0 xHCI