What Is xv6? How to Run MIT’s Free Operating System in QEMU

xv6 is a free Unix-like operating system that MIT uses to teach how computers run programs. You can build its RISC-V edition on your PC, boot it in QEMU and try its shell. If you searched for “CS-XV6-Free” because you remember a Counter-Strike mod with zombie and ghost modes, the title you’re looking for is Counter-Strike Xtreme V6. Its creator lists the V6 release on ModDB.

Illustrated xv6 shell in QEMU showing init: starting sh and the command echo hello

What can you do in xv6?

Try listing a directory. You can see the names on screen, then open the source for ls and follow how it reads the directory and prints each entry. If you’ve ever wondered what happens between pressing Enter and seeing a result, this is a small enough example to follow. MIT publishes both the source for ls and the complete operating system.

How to run xv6 in QEMU

You’ll need Git, Make, a RISC-V compiler toolchain and a version of QEMU that can emulate RISC-V. On Windows, MIT’s course documents a route using Ubuntu under WSL 2. In Windows Terminal, wsl -l -v shows which version your Linux distribution uses. Once the tools are installed, open your Linux terminal for the build commands below. MIT’s setup instructions for Windows and Linux.

git clone https://github.com/mit-pdos/xv6-riscv.git
cd xv6-riscv
make qemu

The first command downloads the source. The second puts you in the directory containing the Makefile. The third builds xv6 and starts the emulator. Watch for init: starting sh followed by a $ prompt. That prompt is where you can enter xv6 commands.

Two commands to try on your first boot

  1. Type echo hello and press Enter. You should see hello on the next line. Leave out the $ shown in examples. It’s the shell prompt.

  2. Type ls. The files listed here belong to the emulated xv6 disk. Your Windows Downloads folder or Linux home directory has its own files on the host.

To leave QEMU in this terminal configuration, press Ctrl+A, release both keys, then press X. You should be back in the terminal where you ran make qemu.

What to check if xv6 won’t start

  • Make cannot find a Makefile. In your host terminal, run pwd and ls. You should be inside xv6-riscv and see a file named Makefile.
  • The error mentions a missing RISC-V compiler or QEMU. Use MIT’s tool list for your host system. On Windows with WSL 2, install the Linux build tools inside the Ubuntu environment where you run Make.
  • You expected a game menu. A shell prompt means the operating system booted. To identify the gaming project, look for the full name Counter-Strike Xtreme V6 and the October 2012 release entry on its project file list.

Post a Comment