LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 05-05-2005, 08:36 PM   #1
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Rep: Reputation: 30
Post Guide to running Windows under the qemu emulator


This guide will discuss how to properly install qemu, set up windows under qemu emulation, and transfer data onto and off of the windows hard disk image -- all in a completely secure way. We don't want to open up the security vulnerablities of allowing windows unfettered access to the internet. Note that commands that begin with "su" are asking you to enter the root password for your system.

First we want to install qemu including the kqemu kernel module. The kqemu module allows you to run windows with only a marginal 1X to 2X slowdown vs. native. To install kqemu, we need to install from source. Don't be scared of this, it isn't too difficult. Note that kqemu is not released under a free (as in speech) software license. If the morality of this bothers you, do not install kqemu. It is however available at no cost.

Open up a shell/terminal and let's download the source code (about 2 MB)

Code:
$ mkdir source
$ cd source
$ wget -N http://fabrice.bellard.free.fr/qemu/qemu-0.8.0.tar.gz
$ wget -N http://fabrice.bellard.free.fr/qemu/kqemu-0.7.2.tar.gz
$ tar zxvf qemu-0.8.0.tar.gz
$ cd qemu-0.8.0
$ tar zxvf ../kqemu-0.7.2.tar.gz
Certain libraries are necessary to compile qemu. If you are using Debian or a Debian-based GNU/Linux distribution, execute the following command (typed exactly as below on a single line)

Code:
$ su -c "apt-get install libsdl1.2debian libsdl1.2-dev libx11-dev
   zlib1g zlib1g-dev texi2html sharutils libgpmg1-dev
   kernel-headers-$(uname -r)"
Note that if you are using the debian etch (testing) or sid (unstable) distributions, the word kernel should be replaced with the word linux in the above command. This will be about a 40 MB download (if none of the above packages are yet installed). If you do not have a Debian-based distribution, download and install the above-listed packages for your distribution or install an apt-get package and issue the command above.

Note that debian etch and sid are built using gcc 4.0, which is not yet supported by qemu (as of October 2005). So, if you have etch or sid, you need to download the older 3.4 version of gcc.

Code:
$ su -c "apt-get install gcc-3.4"
Now, we'll configure the source

Code:
$ ./configure --enable-adlib
Again, if you are using etch or sid, this is slightly different

Code:
$ ./configure --enable-adlib --cc=gcc-3.4 --host-cc=gcc-3.4
Make sure "SDL support" and "KQEMU Support" say "yes". Now, compile the code

Code:
$ make
Go grab a cold beer as this will take 10-15 minutes. When compilation completes, we will install the qemu binaries to proper locations. Log in as root and install the qemu binaries with

Code:
$ su
# make install
Remain as root because the following commands require root priviledges. We want to set up a mount point for the windows hard disk image

Code:
# mkdir /mnt/windows
We also want to set up the file system table to automate mounting. Execute

Code:
# gedit /etc/fstab
and add the following two lines at the bottom

Code:
/home/<user name>/images/win2k.img  /mnt/windows  vfat  rw,user,loop,noauto,offset=32256  0  0
tmpfs  /dev/shm tmpfs  user,size=528M  0  0
where <user name> should be replaced by the name of the user that you generally use on your system. Close and save the file. Note that if you want to give windows access to more ram, you should increase the 528M (it should be 16M more than the amount of ram given to windows). You need to have more than 528M of physical ram to use this setting, otherwise you will need to use a smaller value. We now want to insert the pertinent modules into the Linux kernel (again, the kqemu kernel module is non-free and "taints" the kernel, so if you have moral objections, stop now)

Code:
# modprobe kqemu
# modprobe loop
We also want these modules loaded at every boot, so execute

Code:
# gedit /etc/modules
and add the following lines at the bottom

Code:
loop
kqemu
Close and save the file. The /dev/kqemu device is not correctly created at boot (a bug?), so we need to add this operation to a boot script

Code:
# gedit /etc/init.d/bootmisc.sh
and add the following two lines before the last line that says ": exit 0"

Code:
mknod /dev/kqemu c 250 0
chmod 666 /dev/kqemu
Note that If /etc/init.d/bootmisc.sh does not exist, you can edit /etc/rc.d/rc.local instead. Now, we can stop being root.

Code:
# exit
Remount the temporary file system so that the full amount of ram is available to qemu

Code:
umount /dev/shm
mount /dev/shm
Let's make a directory to store the qemu disk images

Code:
$ mkdir ~/images
Ok, so now we want to install windows onto a disk image file. From my experience, windows 2000 runs quite well under qemu (winxp is usable also, but there is no easy way to deal with the product activation). Now, insert your windows installation cd into your cdrom drive and type

Code:
$ qemu-img create -f raw ~/images/win2k.img 8G
$ qemu -dummy-net -m 512 -enable-audio -localtime -cdrom /dev/cdrom -boot d ~/images/win2k.img
If you want to be able to read and write the data, you have to format your qemu windows install with the FAT file system. Make sure to select FAT as the file system format during installation. NTFS has read-only support under GNU/Linux.

The "-dummy-net" option blocks windows' access to the network. "/dev/cdrom" should be the file enumeration of your hardware cdrom, and "-m 512" gives the qemu guest OS 512M of ram. Your best bet for the install to complete without hanging is to turn off your screensaver and leave the mouse cursor in the qemu window at all times. Don't use CTRL-ALT to get the X cursor back -- asume that your system is going to be tied up. Go out for a walk, play with the kids, write a poem, write this article, etc. Wait like 4 hours for windows to install checking back periodically for dialogs to answer.

We should now be able to mount, view, manipulate, and unmount the windows disk image.

Code:
$ mount /mnt/windows
$ ls /mnt/windows
$ umount /mnt/windows
Never attempt to mount the windows hard disk image while qemu is running as this may cause unanticipated data corruption.

You can run windows using

Code:
$ qemu -dummy-net -m 512 -enable-audio -localtime ~/images/win2k.img
Note that if you upgrade the Linux kernel, you will need to recompile qemu (make sure to do a "make clean" first).

Well, I hope this gets you started running windows under qemu. Good luck.

-zero

Last edited by zero79; 12-26-2005 at 10:22 AM.
 
Old 05-06-2005, 03:30 AM   #2
Nobber
Member
 
Registered: Jun 2002
Location: Nova Scotia
Distribution: Debian (home), Kubuntu 7.04 (work)
Posts: 265

Rep: Reputation: 30
See below...

Last edited by Nobber; 05-06-2005 at 03:33 AM.
 
Old 05-06-2005, 03:32 AM   #3
Nobber
Member
 
Registered: Jun 2002
Location: Nova Scotia
Distribution: Debian (home), Kubuntu 7.04 (work)
Posts: 265

Rep: Reputation: 30
Nice guide!

Two comments:

1. FAT filesystems can be larger than 2GB, but individual files on them can't (or is the limit 4GB?).

2. The following (alternative) line in /etc/fstab would circumvent the need to use losetup:

Code:
/path/to/win2k.img /mnt/win2k vfat rw,user,noauto,umask=0666,loop,offset=32256 0 0
 
Old 05-12-2005, 03:14 PM   #4
raid517
Member
 
Registered: Feb 2002
Posts: 393

Rep: Reputation: 30
Hi, when I try to compile qemu, this is the output I get.

Code:
/My_Downloads/Linux_Stuff/qemu-0.7.0/qemu-0.7.0$ ./configure --prefix=/opt/qemu
Install prefix    /opt/qemu
BIOS directory    /opt/qemu/share/qemu
binary directory  /opt/qemu/bin
Manual directory  /opt/qemu/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /My_Downloads/Linux_Stuff/qemu-0.7.0/qemu-0.7.0
C compiler        gcc
make              make
host CPU          i386
host big endian   no
target list       i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu
gprof enabled     no
static build      no
SDL support       yes
SDL static link   yes
mingw32 support   no
Adlib support     no
FMOD support      no
kqemu support     no
This doesn't seem right to me. I think I heard somewhere that kqemu support is definately desirable. Which of these other options are desirable - and how do I change that no into a 'yes'?

GJ
 
Old 05-12-2005, 03:28 PM   #5
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
make sure you extract the kqemu tar.gz package into the qemu source directory and that there is a kqemu subdirectory with the kqemu kernel module source and object files (kqemu-mod-i386.o, kqemu.h, kmod.c).

$ ls qemu-0.7.0/kqemu/
kmod.c kqemu-mod-i386.o kqemu.h ...

other than that, i would say the configuration looks good to go.

Last edited by zero79; 05-12-2005 at 03:33 PM.
 
Old 05-12-2005, 07:36 PM   #6
raid517
Member
 
Registered: Feb 2002
Posts: 393

Rep: Reputation: 30
Yeah that worked great thanks. The only thing is, what is the point of mounting the image of a loopback device? If I start qemu I do it by invoking $qemu myimage.image. Is there some speed advantage to mounting it as a loopback device? If so how can I run it from the loop device directory? (Also how can I increase the momory size? XP runs ok on 128MB, but it swaps like crazy). Also FMOD support sounds interesting, as sound on emulators has generally always sucked - so hopefully this might fix it. How would I enable this? I tried a similar trick to the one that was listed previously, but this didn't work. Sorry for the questions, I had never heard of Qemu until I read this thread.

GJ

Last edited by raid517; 05-12-2005 at 08:06 PM.
 
Old 05-13-2005, 09:20 AM   #7
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
the part about mounting the hard disk image via the loopback device is to show you how to get data off of the drive. you don't need to do that part. you can even allow windows to access the internet if you don't use the "-dummy-net" option. increase memory with for example "-m 512" which will give windows 512 MB RAM. i haven't tried to get sound working, so i'm not sure how to do this. you can find more help on qemu here http://m2.dad-answers.com/qemu-forum/
 
Old 05-14-2005, 05:49 AM   #8
raid517
Member
 
Registered: Feb 2002
Posts: 393

Rep: Reputation: 30
Man it sure is slow though. I think this is down to CPU usage. Even on my Athlon 3800+ system cpu usage averages about 70 or 80% - with frequent peaks of 100% - even with the accelearator module installed. (This is compared to VMware which sits around the 20% CPU usage mark).

Still it's good work I guess - and it's free - and hopefully things will eventually get better. As far as I read some big companies have thrown their hand in with this (IBM for one). so there may be hope of better things to come.

Still cool to play with for now though.

GJ

Last edited by raid517; 05-14-2005 at 05:50 AM.
 
Old 05-14-2005, 12:26 PM   #9
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
it's best to turn of winxp's fancy elements like shadows and the visual theme. it's probably also useful to disable the swap file. also, win2k runs significantly better, but there's a bug that prevents it from running 16-bit executables...i don't think winxp suffers from this. win98 seems to run ok too, but i haven't been able to get decent screen resolutions.
 
Old 05-15-2005, 04:37 AM   #10
darkleaf
Senior Member
 
Registered: Jun 2004
Location: the Netherlands
Distribution: debian SID
Posts: 2,170

Rep: Reputation: 45
Does anyone have tested kqemu with winme? I had winme installed with the debian apt qemu but I deleted that and installed like this which worked fine. Though I always got a bsod when windows loaded (just before the splash screen) and when I installed again I had some broken system files. So I decided to start over on a new image and the installation goes well till it has to reboot and I get the bsod again. So I removed the kqemu module from the kernel and suddenly it works (really slow though so I'd like to get it back)

In case this is important this is my ./configure:
Quote:
Install prefix /usr/local
BIOS directory /usr/local/share/qemu
binary directory /usr/local/bin
Manual directory /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path /usr/src/qemu-0.7.0
C compiler gcc
make make
host CPU i386
host big endian no
target list i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu
gprof enabled no
static build no
SDL support yes
SDL static link yes
mingw32 support no
Adlib support no
FMOD support no
kqemu support yes

KQEMU Linux module configuration:
kernel sources /lib/modules/2.6.8.1/build
kbuild type 2.6
 
Old 05-15-2005, 05:49 AM   #11
darkleaf
Senior Member
 
Registered: Jun 2004
Location: the Netherlands
Distribution: debian SID
Posts: 2,170

Rep: Reputation: 45
nm. It's a known error that to run kqemu you'll need at least win2k. Below you'll get a BSOD. There's supposed to be another kernel module which does the same called qvm86 but I haven't tried it yet though I plan to do it soon.
 
Old 05-16-2005, 06:40 PM   #12
alpha_foobar
LQ Newbie
 
Registered: May 2005
Location: New Zealand
Distribution: OpenSuse
Posts: 13

Rep: Reputation: 0
There are a few typoes in this guide; i.e. qemu -dummy-net -cdrom /dev/cdrom -boot d wink2.img

I am running debian with a blackbox windows manager, and I am unable to get a window with qemu.. though it still burns cpu cycles.

UML works in it.. but thats not what I'm after. I've all but given up on Qemu... sticking with Bochs... which I have done some work trying to optimise via its configuration... so it's not too bad to run now.
 
Old 05-16-2005, 09:19 PM   #13
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
to get graphical rendering compiled, you need to make sure that "SDL support" says "yes" when you do ./configure. i ran into this initially. you need to install the libsdl1.2-dev package or equivilent for your distribution.

Last edited by zero79; 05-16-2005 at 09:21 PM.
 
Old 05-19-2005, 08:57 PM   #14
alpha_foobar
LQ Newbie
 
Registered: May 2005
Location: New Zealand
Distribution: OpenSuse
Posts: 13

Rep: Reputation: 0
cheers zero79!

will be stoked if this provides a solution! am looking forward to the claimed speed benefits of Qemu!
 
Old 05-20-2005, 06:27 PM   #15
alpha_foobar
LQ Newbie
 
Registered: May 2005
Location: New Zealand
Distribution: OpenSuse
Posts: 13

Rep: Reputation: 0
Unfortunately, it was the case. Here is my configure output:

Install prefix /usr/local
BIOS directory /usr/local/share/qemu
binary directory /usr/local/bin
Manual directory /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path /home/james/working/qemu-0.7.0
C compiler gcc
make make
host CPU i386
host big endian no
target list i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu
gprof enabled no
static build no
SDL support yes
SDL static link yes
mingw32 support no
Adlib support no
FMOD support no
kqemu support yes

KQEMU Linux module configuration:
kernel sources /lib/modules/2.4.27-2-686/build
kbuild type 2.4
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
qemu running linux under windows linuxmandrake Linux - Software 1 10-18-2005 10:34 AM
anyone got winme running via qemu darkleaf Linux - Software 3 04-15-2005 03:36 AM
How can I use Qemu in Windows? dustin_wielenga Linux - General 3 03-28-2005 12:21 AM
qemu: qemu stopped right after command exec bitpicker Linux - Software 1 03-04-2005 11:25 PM
Emulating Windows using Qemu greek Linux - Software 3 08-16-2004 11:41 AM


All times are GMT -5. The time now is 03:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration