Skip to content

Instantly share code, notes, and snippets.

@aaronedev
Last active June 5, 2025 13:52
Show Gist options
  • Save aaronedev/37d2789ccbf44d9949cf14f541fd6a70 to your computer and use it in GitHub Desktop.
Save aaronedev/37d2789ccbf44d9949cf14f541fd6a70 to your computer and use it in GitHub Desktop.
QEMU Windows 10 VM with USB Audio Passthrough (Komplete Audio 6 & AKAI LPK25)
#!/usr/bin/env bash
# _ _ _ _ _ _ _ _ _ _ _ _ _
# .-"-._,-'_`-._,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,_,-'_`-,.
# ( ,-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-<.>-'_,-~-} ;.
# \ \.'_>-._`-<_>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._>-._`-._~--. \ .
# /\ \/ ,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._`./ \ \ .
# (`/ / `/ /.) ) .
# \ \ / \ / / \ / .
# \ \') ) ▌ ▗ ▌ ▗ ▌ ▌ ▗▀▖ ▌ ▜ ( (,\ \ .
# / \ / / ▞▀▘▝▀▖▞▀▌ ▌ ▌▄ ▛▀▖▞▀▌▞▀▖▌ ▌▞▀▘ ▄ ▞▀▘ ▛▀▖▞▀▖▞▀▖▞▀▌▞▀▖▞▀▌ ▐ ▞▀▖▙▀▖ ▝▀▖▛▀▖▐ ▞▀▖ \ / \ \ .
# ( (`/ / ▝▀▖▞▀▌▌ ▌ ▐▐▐ ▐ ▌ ▌▌ ▌▌ ▌▐▐▐ ▝▀▖ ▐ ▝▀▖ ▌ ▌▛▀ ▛▀ ▌ ▌▛▀ ▌ ▌ ▜▀ ▌ ▌▌ ▞▀▌▌ ▌▐ ▛▀ / /.) ) .
# \ \ / \ ▀▀ ▝▀▘▝▀▘ ▘▘ ▀▘▘ ▘▝▀▘▝▀ ▘▘ ▀▀ ▀▘▀▀ ▘ ▘▝▀▘▝▀▘▝▀▘▝▀▘▝▀▘ ▐ ▝▀ ▘ ▝▀▘▀▀ ▘▝▀▘ / / \ / .
# \ \') ) ▐ ( (,\ \ .
# / \ / / ▜▀ ▞▀▖▛▀▖ \ / \ \ .
# ( (`/ / ▐ ▖▌ ▌▌ ▌ / /.) ) .
# \ \ / \ ▀ ▝▀ ▘ ▘ / / \ / .
# \ \') ) ( (,\ \ .
# / \ / / \ / \ \ .
# ( (`/ / / /.) ) .
# \ \ / \ _ _ _ _ _ _ _ _ _ _ _ / / \ /.
# \ `.\ `-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_`-._,-'_/,\ \ .
# ( `. `,~-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-<,>-._`-=,' ,\ \ .
# `. `'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,-<_>-'_,"-' ; .
# `-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-._,-' `-.-' .
# QEMU/KVM Windows 10 VM with USB Audio Passthrough for Music Production
#
# Description: Production-ready script for running Windows 10 in QEMU/KVM with
# USB passthrough for audio interfaces and MIDI controllers. Optimized for
# music production on Linux with Native Instruments Komplete Audio 6 and AKAI LPK25.
#
# Author: aaronedev (https://github.com/aaronedev)
# Version: 1.0
# License: MIT
#
# Features:
# - Automatic USB device detection and passthrough
# - SPICE display with automatic viewer launch
# - PipeWire audio backend for low latency
# - SMB network folder sharing
# - Hyper-V enlightenments for Windows optimization
# - 24GB RAM, 10 CPU cores configuration
#
# Requirements:
# - QEMU 8.x+ with KVM support
# - User must be in 'kvm' group: sudo usermod -a -G kvm $USER
# - SPICE viewer: sudo pacman -S virt-viewer (Arch) / apt install virt-viewer (Debian)
# - PipeWire audio system
# - Windows 10 ISO and VirtIO drivers ISO
#
# USB Devices Supported:
# - Native Instruments Komplete Audio 6 (17cc:1001)
# - AKAI LPK25 MIDI Controller (09e8:0076)
# - Easy to add more devices by copying the detection pattern
#
# Usage:
# 1. Update paths to ISOs and disk image
# 2. Run: ./qemu-windows10-usb-audio-passthrough.sh
# 3. SPICE viewer will auto-launch
# 4. Access shared folder in Windows: \\10.0.2.4\qemu
#
# Troubleshooting:
# - If USB devices cause disconnects, disable autosuspend:
# echo -1 | sudo tee /sys/module/usbcore/parameters/autosuspend
# - For permission issues: ls -la /dev/bus/usb/*/*
# - Check logs: journalctl -f | grep qemu
#
# Tags: qemu, kvm, windows-10, windows-vm, usb-passthrough, audio-interface,
# music-production, native-instruments, komplete-audio, midi-controller,
# akai-lpk25, linux-audio, pipewire, spice, virtualization, vm-script,
# bash-script, fachinformatiker, system-integration, arch-linux
set -euo pipefail
### VM parameters ###
VM_NAME="Windows10"
CPU_CORES=10
RAM_SIZE="24G"
DISK_IMAGE="/var/lib/libvirt/images/win10.qcow2"
### ISOs ###
WIN10_ISO="/var/lib/libvirt/images/Win10_22H2_English_x64v1.iso"
VIRTIO_ISO="$HOME/repos/qemu/virtio-win-0.1.271.iso"
### Networking ###
RDP_PORT=3389
SHARED_FOLDER="$HOME/shared"
SPICE_PORT=5900
mkdir -p "$SHARED_FOLDER"
### Display ###
VGAMEM_MB=128
### CPU features ###
CPU_MODEL="host"
HV_FEATURES="hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,hv_vpindex,hv_synic,hv_stimer,hv_ipi"
### USB passthrough ###
# Komplete Audio 6 (VID:PID=17cc:1001)
if lsusb -d 17cc:1001 >/dev/null 2>&1; then
read -r audio_bus audio_addr < <(
lsusb -d 17cc:1001 |
awk '{print $2, $4}' |
sed 's/://'
)
audio_bus=${audio_bus#0}
audio_addr=${audio_addr#0}
USB_AUDIO="-device usb-host,bus=xhci.0,hostbus=${audio_bus},hostaddr=${audio_addr}"
else
echo "Warning: Komplete Audio 6 not found"
USB_AUDIO=""
fi
# AKAI LPK25 (VID:PID=09e8:0076)
if lsusb -d 09e8:0076 >/dev/null 2>&1; then
read -r midi_bus midi_addr < <(
lsusb -d 09e8:0076 |
awk '{print $2, $4}' |
sed 's/://'
)
midi_bus=${midi_bus#0}
midi_addr=${midi_addr#0}
USB_MIDI="-device usb-host,bus=xhci.0,hostbus=${midi_bus},hostaddr=${midi_addr}"
else
echo "Warning: AKAI LPK25 not found"
USB_MIDI=""
fi
### Run QEMU in background ###
echo "Starting Windows 10 VM..."
qemu-system-x86_64 \
-name "$VM_NAME" \
-machine q35,accel=kvm \
-smp "${CPU_CORES}",sockets=1,cores="${CPU_CORES}",threads=1 \
-m "$RAM_SIZE" \
-cpu "$CPU_MODEL","$HV_FEATURES" \
-netdev user,id=net0,hostfwd=tcp::${RDP_PORT}-:${RDP_PORT},smb="$SHARED_FOLDER" \
-device virtio-net-pci,netdev=net0 \
-device qxl-vga,vgamem_mb="${VGAMEM_MB}" \
-spice port=${SPICE_PORT},disable-ticketing=on \
-display none \
-device virtio-serial-pci \
-chardev spicevmc,id=spicechannel0,name=vdagent \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
-audiodev pipewire,id=snd0 \
-device ich9-intel-hda \
-device hda-output,audiodev=snd0 \
-device qemu-xhci,id=xhci \
$USB_AUDIO \
$USB_MIDI \
-drive file="$WIN10_ISO",media=cdrom,index=2 \
-drive file="$VIRTIO_ISO",media=cdrom,index=3 \
-drive file="$DISK_IMAGE",if=ide \
-boot menu=on \
-enable-kvm \
-daemonize
# Wait for SPICE to be ready
echo "Waiting for SPICE server..."
for i in {1..10}; do
if nc -z 127.0.0.1 $SPICE_PORT 2>/dev/null; then
echo "SPICE server ready!"
break
fi
sleep 1
done
# Connect with SPICE client
echo "Launching SPICE viewer..."
remote-viewer spice://127.0.0.1:${SPICE_PORT} &
echo "VM started successfully!"
echo "SPICE: spice://127.0.0.1:${SPICE_PORT}"
echo "RDP: 127.0.0.1:${RDP_PORT} (when Windows boots)"
echo "Shared folder: \\\\10.0.2.4\\qemu"
@aaronedev
Copy link
Author

@Ableton any ideas how i could improve this setup?

@aaronedev
Copy link
Author

@libvirt yo guys what u think can i improve this setup?

@aaronedev
Copy link
Author

@NativeInstruments any ideas how i could improve my vm setup for music production?

@aaronedev
Copy link
Author

@alsa-project guys what u think any ideas how i can improve this?

@aaronedev
Copy link
Author

@PipeWire thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment