You are expected to understand this. CS 111 Operating Systems Principles, Spring 2007
You are here: CS111: [[2007spring:qemu]]

Using QEMU to compile and run labs

May 5, 2007: Please note that we have changed DebOSP.tar.gz and the run-qemu script to support Mac OS X and Cygwin machines. If you would like to run the labs from your Mac or Windows (with Cygwin) machine in the same way that you do from the linux lab, by simply calling "./run-qemu", Download the updated lab 2 run-qemu script and the updated DebOSP.tar.gz.

Current DebOSP.qvm/datestamp.txt: Wed May 16 13:20:11 PDT 2007

Rather than installing linux on your machine, you may choose to do the labs on an emulated computer that runs linux. An emulator (at least one kind of emulator) is a piece of software that exposes an interface that looks like a hardware interface, in this case the software behaves like an x86 machine. That way you can be running an emulated "guest" machine on top of your physical "host" machine.

One freely available emulator is called QEMU. It runs on Windows, Mac OS X, and Unix/Linux host platforms. The emulated guest machine needs a disk to boot from. We have created a disk image (a file that contains the bytes that a raw disk would have) that will boot a minimalist version of the Debian distribution of linux. In particular, it does not have XWindows which provides a graphical interface on most linux machines. This allows the image to be much smaller. However, it does have everything you need to compile and run the labs.

Installing on Windows

  1. Download QEMU 0.9.0 using this link.
  2. Unzip the file. Hooray! QEMU is installed.
  3. Download this file: DebOSP.tar.gz. It's big (around 200 MB).
  4. Extract the file (winzip should be able to handle it or any number of free programs, of if you have Cygwin installed, you should be able to do tar xvzf DebOSP.tar.gz to extract it)

If you have Cygwin installed, you may now use the ./run-qemu scripts supplied with Lab 2 and higher. (No need to follow the directions below.)

If you do not have Cygwin,

  1. You will need an SSH program. SEASnet has a list of windows ssh clients here.
  2. Within the DebOSP.qvm directory (extracted above), edit the ospqemu.bat file to set QDIR to the full path to your qemu installation and IMGDIR to the DebOSP.qvm directory.
  3. Now you should be able to run the ospqemu.bat file and see a window with a linux prompt!
  4. Follow the instructions under Manually Copying Files to QEMU section below.

Installing on Mac OS X

  1. Download the latest unstable version of Q (a nice GUI on top of QEMU) from this link. (The latest "stable" version is 0.8.1 and our disk image uses features from 0.9.0, the unstable build seems to work quite well).
  2. Install the application by opening the downloaded .dmg file and draging Q into your applications.
  3. Download this file: DebOSP.tar.gz. It's big (around 200 MB).
  4. Extract the file into the QEMU directory under your user documents. (I think this QEMU directory gets created the first time you run Q, so you may need to run it once and exit). The following command from the terminal should extract the file in the right place:
mv DebOSP.tar.gz ~/Documents/QEMU/ && cd ~/Documents/QEMU && tar xvzf DebOSP.tar.gz

You may now use the ./run-qemu scripts supplied with Lab 2 and higher. (No need to follow the directions below.)

Installing on Linux

  1. Download and install version 0.9.0 of QEMU using this link. Install it into /usr/local. (The binary version installs correctly into /usr/local already.)
  2. Download this file: DebOSP.tar.gz. It's big (around 200 MB).
  3. Extract this file and move the DebOSP.qvm/debosp.qcow2 file into the /usr/local/share/qemu directory.
  4. You may now use the ./run-qemu scripts supplied with Lab 2 and higher. (No need to follow the directions below.)

Manually Copying Files to QEMU

The provided disk image and configuration / batch files are set up so that you don't have to wait for the entire boot process of the guest OS, which could take 2-3 minutes. Instead, it jumps right to a saved state that QEMU calls a virtual machine snapshot. The VM was saved right after the machine booted up and user root logged on -- so you don't have to wait! When using a stored VM snapshot, QEMU's networking does not immediately work. So before copying files, you need to execute the following command in the guest OS:

  osp:~# ./netprep

There are two users set up in the DebOSP operating system:

  • osp (password: osp)
  • root (password: osp)

The batch and configuration files that we have provided for launching qemu automatically redirect port 2222 of your local host machine to port 22 (the ssh/scp port) of the guest DebOSP machine. So if using command line interface:

scp -r -P2222 lab2/ root@localhost:

will copy your lab2 directory onto the guest machine.

If using a GUI interface to ssh/scp, then you'll need to set the host to localhost and the port to be the non-default port 2222. The user should be root.

So it's pretty cool that QEMU actually emulates a NIC so your guest OS can access the network, right! It actually uses your host OS's name resolution setup as well, so you can type something like


at the shell prompt in the guest OS and it will download and save the index.html page from yahoo. So if you want to install some additional packages to the very minimal debian installation, you can do so by using the apt-get utility and it will download them from the debian package mirrors. But I digress...

Once your lab files are over on the guest machine, you can compile and run them from the guest OS. (e.g. cd lab1 && make && ./cmdline).

If you exit QEMU without saving a new VM snapshot, you will lose any changes that you made on the guest OS. So, for example, when you run QEMU again, your lab directory won't be there in the guest OS. This is probably fine. That way you always start with a clean machine and use scp to move your files over, then compile and run them. If you would prefer your state to be saved, you can create a new VM snapshot with your changes. Ctl+Alt+2 will change QEMU to its monitor interface with a (qemu) prompt. Here you can type:

(qemu) savevm my-lab1-vm

If you want to get back to the linux shell, type Ctl+Alt+1. Now next time you run qemu, you can switch to the qemu monitor and type

(qemu) loadvm my-lab1-vm

to get back where you were.

That's all folks! Send email with any questions.

2007spring/qemu.txt · Last modified: 2007/09/28 00:27 (external edit)
Recent changes RSS feed Driven by DokuWiki