I've been messing with qemu an open source processor emulator. I installed an image of windows xp using linux as the host os. Here are few notes after getting windows up and running as a guest os using linux as the host os.
Qemu install and setup
Download the binary version of Qemu http://www.qemu.org/download.html. I used 9.0 in the example.
Download kqemu the kernel accelerator module source from the same website. I tested 1.3.0pre11.
Copy the binary version to your root dir. Then untar qemu binary version in the root (/) dir. Qemu binaries will be in /usr/local/bin after untaring
cp qemu-0.9.0-i386.tar.gz /
tar xvzf qemu-0.9.0-i386.tar.gz
Go back (cd) to the dir you downloaded the kernel accelerator module source to. We are now going to untar it, compile it, and install it. You need your kernel source code to compile this module. If you don't want to use it you don't need to. It does make Qemu faster if you do.
tar xvzf kqemu-1.3.0pre11.tar.gz
./configure && make && make install
Change to a directory you want to put your disk image for Qemu. Now we will create a 7Gig disk image for the install.
qemu-img create -f qcow c.img 7G
Put your os cd in the cdrom drive (you have to find which /dev/hd? or /dev/sd? is your cdrom. Below's example is using /dev/hdc) and it's time to boot it. You can not do a windows OS install using kqemu. So if that is the os your going to use don't load it just yet. -m is memory amount -hda is the disk image you created above.
qemu -cdrom /dev/hdc -hda c.img -m 256 -boot d
Go through the OS install then after the install finishes shut down the OS.
Now let's load the kernel module we built. If you did not build it just skip this.
You can boot your new disk image with the command below. If you want cdrom access boot with "-cdrom /dev/hd?".
-smb turns on samba file sharing.
-m is the system memory used by the qemu OS.
-kernel-kqemu means use the kqemu kernel module. Don't foget to load it! If your not going to use it just remove the -kernel-kqemu.
qemu -hda c.img -m 256 -localtime -smb /tmp -kernel-kqemu &
If the guest os is win xp and the host os linux you can use samba to share files between them. The Qemu start command above has the line "-smb /tmp". This is so you can use samba on the host os to share files with the win xp guest. On the host os you need to install samba. The "force user" and "force group" settings are to be the users login name on linux. So when they put files on the share it will create them as the users correct group and username. Then they can overwrite their own files without doing all of the chmod'ing bid'ness.
Then put the lines below in the samba config in /etc/samba/smb.conf.
[global] netbios name = qemu security = share interfaces = 127.0.0.0/8 lo bind interfaces only = true socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536 strict sync = no sync always = no #workgroup = WORKGROUP [qemu] comment = Samba Share path = /tmp force user = test force group = test #force create mode = 775 #force directory mode = 775 read only = No guest only = Yes writeable = yes #browseable = Yes
Save the config. Then start samba. It will listen on localhost only. Note the "path=" above and the start up command. They are the same. You can switch them to what you want but they have to match. Make sure your LMHOSTS file on the windows host has the line "10.0.2.4 smbserver" in it. LMHOSTS is in %SystemRoot%\system32\drivers\etc in winxp and 2000.
All this info and more can be found on the qemu.org faq so check that out for more info.
To see the share start windows explorer and in the url bar at the top type "\\smbserver\qemu". You should see your files in your shared dir. They will be written as the user you forced in the smb.conf. I picked /tmp because it was easy. You might want to map to your home dir. If you don't see your share try to access the share as \\10.0.2.4 in windows explorer. 10.0.2.4 is the ip that is mapped to the host os's localhost. That is where samba is running.
If your going to run linux as the guest os and linux as the host os then you can still run samba on the linux host os. On the linux guest os you can mount the samba share on the linux host os by putting the following line in /etc/fstab.
//10.0.2.2/disk01 /disk01 cifs guest 0 0
Save fstab then issue the the following command. This will test the mount in fstab. Check that it mounted with df command.
If it mounted now then it will mount on boot.
All this info and more can be found on the qemu.org faq so check that out for more info.
To access the printers on the host linux os you just need to be running cups. Setup the printers by contacting the cups server through your linux hosts web browser with the url http://localhost:631. Use your root user name and pass if it asks for auth info. After you setup the printers you have to allow access (on u/k/x buntu distro at least) to them by a user name. Access the cups in the webrowser and click the "Administration" tab then the "Manage Printers" button. Then click the "Set allowed users" button. In there you have to list the username you used to login to the windows host os. Mine was "Administrator" so I put in "Administrator,root,anotheruser". If you don't have this button then your cups does not have this and you should be ok. The other 2 entries are for the local users on the linux machine to have access to the printer. Do this for all the printers you want users to have access to. After setting up the printers using cups go onto the windows xp host and go to Start-> Settings-> Printers and Faxes-> Add Printer. At the first screen choose "Next" then "Network Printer" then "Connect to a printer on the internet ...". Type in the url to your local cups printer http://10.0.2.4:631/printers/[cupsprintername] . The "[cupsprintername]" is the name you called the printer in cups when you set it up. Then you need to pick a driver for the printer your printing to. I have all printers that can use postscript so it makes it much eaiser. I just needed to pick a printer that does postscript like an "Apple LaserWriter" or an "HP Laserjet 5". I did find that when using a color laser printer and printing with postscript that the printer "Apple Color LW 12/660 PS" works great. I tried using the actual PS windows drivers that came with the color laser in windows xp and it completly broke the printing system.
After that just finish up with the next button and it will copy over the drivers needed. You may need to put the line "Allow From 10.*" in your cups.conf file (then restart cups) if printing does not work. I'll put an example below.
<Location /> Order allow,deny Allow localhost Allow @LOCAL Allow From 10.* </Location>
You can make a copy of the image file at any time and it will be a snapshot of the system the last time you booted. Or you could try overlay images. Check further down on this.
Ctrl-Alt-f - Toggle full screen
Ctrl-Alt - Toggle mouse and keyboard grab.
It seems that Qemu maps all network traffic from 10.0.2.4 to localhost on the host os. So if you have a ssh server running on the host os you can contact it with the guest os (windows) with putty or winscp by just ssh'ing to 10.0.2.4. It's even eaiser to do this than setup samba. Scp is you best bet with winscp.
If you need to setup your qemu networking manually here are the network settings. This example worked in a qemu windows guest image. IP: 10.0.2.15, Subnet mask: 255.255.255.0, Default Gateway: 10.0.2.2, and DNS: 10.0.2.3
Mounting A Virtual Drive
You can also mount the Qemu virtual disk just like any other drive (if the drive was created in qcow format you'll need to convert it first, see below).
Make sure you are NOT running Qemu when you do this.
To mount the drive, create a directory '/media/qemu'. Then run the following.
sudo mount -o loop,offset=32256 windows.img /media/qemu
You can quickly save and restore the state of your Windows System using Qemu's 'overlay images'. Once you have done your initial install, you can create an overlay image and run QEMU off this. The overlay image is very much smaller that the original image and will only contain changes made since the original install. If you trash your XP installation, you can simply delete the overlay image and create a new one from the original image.
To create an overlay image, use the qemu-image program. To create an image windows.ovl from windows.img, issue the following command.
qemu-img create -b windows.img -f qcow windows.ovl
To run Windows, you would now use:
qemu windows.ovl -enable-audio -user-net -localtime -smb qemu_share
If the winxp.ovl installation is ruined, you can delete it, and start Qemu using the winxp.img file. But you will lose changes made since the original install.
Qemu also accepts commands from the shell while it is running. To do this, though, you need to press CTRL+ALT+2 with the Qemu window active. This brings up the QEmu Monitor. From here, you can swap CDs, send keypresses to the emulator, suspend to disk and so on. See the [WWW] official documentation for full details. To exit the QEmu monitor press CTRL+ALT+1.
Converting a raw drive to qcow format
To convert your raw 'windows.img' file to a qcow formatted 'windows.qcow', run:
qemu-img convert windows.img -O qcow windows.qcow
Running 2 or more qemu sessions and getting them to talk over the network
Example is 2 images of OpenBSD running on a Linux host.
First image loads with mac address and opens a port on the Linux host's localhost.
qemu -hda obsd1.img -m 64 -localtime -net nic,macaddr=52:54:00:12:34:56 -net socket,listen=:1234 &
Second image loads with a different mac address and image name then connects to the socket on localhost.
qemu -hda obsd2.img -m 64 -localtime -net nic,macaddr=52:54:00:12:34:57 -net socket,connect=127.0.0.1:1234 &
You can use the second line (with "connect=127.0.0.1:1234" in it) to keep opening as many qemu sessions as you want over the network. Just boot a different image for each one (hint: cp image1.img image2.img). Don't forget to change the ip address and mac address of each new image you boot.
Changing cdrom or floppy image
To change a floppy and a CD-ROM image, use Qemu Monitor. Like when installing a multiple cd iso set for an os. To see the Monitor, press Ctrl-Alt-2 keys together. To go back to the guest OS, press Ctrl-Alt-1 keys.
Please use slash instead of back slash in a Qemu Monitor.
change fda filename.img
change fda d:/tmp/yourfile.img
change cdrom filename.iso
change cdrom d:/tmp/yourcdrom.iso
You can see a status of block device.
Getting things running on boot up if using the kqemu module
Put the lines below in your /etc/rc.local or another file that executes on boot. Make a group called "qemu" in /etc/group. Add the user that will use qemu to the qemu group. This loads the kqemu module and fixes perms.
modprobe kqemu sleep 1 chgrp qemu /dev/kqemu chmod g+rw /dev/kqemu echo 1024 > /proc/sys/dev/rtc/max-user-freq