How to Run Linux on Windows Using QEMU Running Linux on Windows is a common requirement for developers, sysadmins, and enthusiasts. While WSL2 (Windows Subsystem for Linux) is popular, QEMU (Quick Emulator) offers a robust, flexible, and powerful alternative for full-system virtualization.
QEMU allows you to emulate a complete computer system, including processors and peripherals, enabling you to run almost any Linux distribution on top of Windows. Why Choose QEMU on Windows?
Complete Isolation: Unlike WSL, QEMU runs as a totally separate machine.
Architecture Flexibility: You can emulate different CPU architectures (x86, ARM, RISC-V).
Hardware Control: Fine-tuned control over virtual hardware, networking, and storage. Prerequisites Before starting, download the following:
QEMU for Windows: Download the latest 64-bit setup from the official QEMU website.
Linux ISO: Download your preferred Linux distribution (e.g., Ubuntu, Debian, Alpine).
Haxm/WHPX: For better performance, ensure Windows Hypervisor Platform (WHPX) is enabled in “Turn Windows features on or off”. Step 1: Install QEMU Run the QEMU installer (qemu-w64-setup-xxxx.exe).
Follow the prompts. Ensure it is installed in a path without spaces (e.g., C:\qemu) to avoid command-line issues.
Add the QEMU installation path (C:\qemu) to your Windows System PATH environment variable. Step 2: Create a Virtual Disk
You need to create a virtual hard drive image where the Linux OS will be installed. Open PowerShell or Command Prompt and use the qemu-img command: powershell qemu-img create -f qcow2 linux_disk.qcow2 20G Use code with caution. This creates a 20GB disk image named linux_disk.qcow2. Step 3: Run the Virtual Machine (Installation)
Now, tell QEMU to use your downloaded Linux ISO to install the OS onto the virtual disk. Replace ubuntu.iso with your actual file name. powershell
qemu-system-x86_64.exe -m 4G -cpu host -enable-kvm -drive file=linux_disk.qcow2,format=qcow2 -cdrom ubuntu.iso -boot d Use code with caution. Breakdown of Commands: -m 4G: Allocates 4GB of RAM. -cpu host: Uses the host CPU for better performance. -enable-kvm: Uses WHPX/KVM for hardware acceleration. -cdrom: Mounts the installation ISO. -boot d: Boots from the CD-ROM first. Step 4: Run Linux After Installation
Once the installation is complete, close the VM and run it again without the -cdrom option to boot from your new virtual hard drive: powershell
qemu-system-x86_64.exe -m 4G -cpu host -enable-kvm -drive file=linux_disk.qcow2,format=qcow2 -net nic -net user -display sdl,gl=on,show-cursor=on Use code with caution.
\ -display sdl,gl=on,show-cursor=on: This helps optimize the graphics for a smoother experience. Performance Tips
Use Accelerator: Always use -enable-kvm (WHPX) to ensure your VM doesn’t run at an agonizingly slow speed.
VGA Setting: Use -vga virtio for improved graphical performance, especially for modern Linux desktop environments.
WSL Alternative: If you find QEMU direct setup difficult, installing QEMU inside WSL2 can sometimes offer easier hardware acceleration configuration. Key Shortcuts
Exit QEMU: Ctrl+Alt+G releases the mouse/keyboard from the VM. Full Screen: Ctrl+Alt+F. If you’d like to dive deeper, Configuring network bridging for server setups. How to emulate ARM64 on an x86 Windows machine.
QEMU on Windows Is PAINFUL — But This WSL2 Trick Unlocks Full Speed!
Leave a Reply