Running virtual linux using qemu on windows
I am trying to use Qemu 1.3 for windows to run lubuntu on a USB stick with Windows 7. After downloading and unpacking Qemu on my usb stick, if I click on qemu.io.exe, I get
qemu-io.exe>
How do I start my downloaded linux .iso file? It sounds basic but its not clear to me from the Qemu website.
The Qemu manual would be a good place to start. It'll help you work out what you're supposed to do next, which is to tell qemu what to do, and exactly how to do that.
Here is how I run a minimal version of CentOS 7 on a Windows 7 Enterprise, 64 bits, without being a member of the administrator group (non-admin).
The basic idea is:
- Download qemu for windows and unzip it anywhere
- Download an ISO image of the Linux distribution you want to run
- Create a file that will be your virtual machine hard disk
- Run qemu, booting from the CD image
- Install the OS
- Reboot the virtual machine, this time without the CD image
Networking and fancy graphics are hard to get right. Still struggling, actually...
1. Download QEMU
Use a precompiled binary found on QEMU links page. I used version 2.8.0 for this.
To "install" this version as a non-admin, open a command prompt, issue the command set __COMPAT_LAYER=RunAsInvoker
and run qemu-w64-setup-20170131.exe
from that prompt. Install in a folder where you have write permissions, like "My Documents" or something.
2. Download an ISO image of Linux
Again, help yourself. I used the Minimal distribution of CentOS 7, the file is called CentOS-7-x86_64-Minimal-1611.iso
.
3. Create a virtual hard disk
I used a batch file for this. Copy the following to a file named createvm.bat
and adjust the variables to suit your environment:
@echo off
rem ==================================
rem Replace with your values
rem ==================================
set "QEMUDIR=%USERPROFILE%\Documents\Warez\qemu-2.8.0-win64"
rem ==================================
rem Safety net
rem ==================================
if not exist hda.img (
rem CREATE a virtual hard disk
"%QEMUDIR%\qemu-img.exe" create hda.img 40G
) else (
echo file hda.img already exist. Delete or move and try again.
goto:eof
)
4. Run QEMU, booting from the virtual CD
Use a batch for this one, as you might use it often. Copy the follwing into installvm.bat
:
@echo off
rem ==================================
rem Replace with your values
rem ==================================
set "QEMUDIR=%USERPROFILE%\Documents\Warez\qemu-2.8.0-win64"
set "ISOFILE=CentOS-7-x86_64-Minimal-1611.iso"
rem ==================================
rem You can add a w suffix to this if
rem you don't want a console
rem ==================================
set "QEMUBIN=qemu-system-x86_64.exe"
rem ==================================
rem Run the virtual machine
rem ==================================
start "QEMU" "%QEMUDIR%\%QEMUBIN%" -drive file=hda.img,index=0,media=disk,format=raw -cdrom %ISOFILE% -m 2G -L Bios -usbdevice mouse -usbdevice keyboard -boot menu=on -rtc base=localtime,clock=host -parallel none -serial none -name centos -no-acpi -no-hpet -no-reboot
5. Install the OS
I had trouble with the GUI installer. When prompted to install CentOS, hit the TAB key and replace the word quiet
at the end of that line with the word text
.
Follow the installation instructions on screen. When the installation is finished, the virtual machine will exit. It can take quite a while, especially when running as a non-admin user.
6. Run your Linux image in QEMU
This step is what you will do over and over again to run the VM each time you need it. Copy the follwing into runvm.bat
:
@echo off
rem ==================================
rem Replace with your values
rem ==================================
set "QEMUDIR=%USERPROFILE%\Documents\Warez\qemu-2.8.0-win64"
rem ==================================
rem You can add a w suffix to this if
rem you don't want a console
rem ==================================
set "QEMUBIN=qemu-system-x86_64.exe"
rem ==================================
rem Run the virtual machine
rem ==================================
start "QEMU" "%QEMUDIR%\%QEMUBIN%" -drive file=hda.img,index=0,media=disk,format=raw -m 2G -L Bios -usbdevice mouse -usbdevice keyboard -boot menu=on -rtc base=localtime,clock=host -parallel none -serial none -name centos -no-acpi -no-hpet -no-reboot -device e1000,netdev=user.0 -netdev user,id=user.0,hostfwd=tcp::2222-:22
I added a local portforward : if you ssh/putty to localhost:2222, you will reach the SSH daemon of your VM. Beware that firewalld
or iptables
might block traffic, depending on the way you installed Linux.