Getting started: Booting xv6 and its shell

Easy

Development setup

xv6 is specifically designed for RISC-V processors, an emerging open standard instruction set architecture. RISC-V is especially well-suited for educational purposes because of its simplicity and flexibility, making it an ideal choice for learning about operating systems. Since we do not have access to physical RISC-V hardware, we will utilize emulator software, specifically, the powerful QEMU tool, to accurately simulate a RISC-V processor that runs the xv6 operating system.

Before you begin, ensure that you have a fully functional development environment with all the necessary RISC-V and QEMU tools installed. The most convenient way to get started is by using the web-based Visual Studio Code (VSCode) IDE. This platform comes with all required tools pre-installed within an Ubuntu GNU/Linux container, allowing you to dive right in. You can access it at https://code.os.edu.distrinet-research.be/ (for additional information, see here).

:bulb: The VSCode web IDE at https://code.os.edu.distrinet-research.be/ will also be the official environment for the coding exams.

Cloning the xv6 repository

To clone the base xv6 git repository we will use, open a terminal in the VSCode environment and type the following:

[vscode-terminal]$ git clone https://gitlab.kuleuven.be/distrinet/education/operating-systems/kul-xv6.git xv6

This will clone the repository into a new directory called xv6.

Building and running xv6

To build xv6 and automatically boot it in the QEMU emulator, open a terminal in the VSCode environment and type the following in the directory where you cloned the xv6 repository.

[vscode-terminal]$ make qemu

If compilation was successful, you will now enter a simple shell environment within xv6.

Exploring the xv6 shell interface

  • Execute the ls command in the xv6 shell:

      [xv6-shell]$ ls
    

    The output of the ls command will display the root directory of the xv6 file system. In the root directory, you will find all user-space programs that you can execute from the xv6 shell, along with a README file.

  • Read the README file using the cat command:

      [xv6-shell]$ cat README
    
  • Create a folder named testfolder and change into that directory:

    [xv6-shell]$ mkdir testfolder
    [xv6-shell]$ cd testfolder
    
  • Verify that you are in the empty folder by using ls:

      [xv6-shell]$ ls
    

You will see the message exec ls failed because the xv6 shell is quite simple and only searches for executable programs in the current directory. Unlike typical shells that use a $PATH variable to locate commands across multiple directories, the xv6 shell (the sh program) does not have this feature. However, you can still run ls by specifying a relative or absolute path.

  • Run ls using a relative path:

      [xv6-shell]$ ../ls
    
  • Run ls using an absolute path:

      [xv6-shell]$ /ls
    

To exit the shell, use the keyboard shortcut CTRL+A x (or type halt).

:bulb: Note that CTRL+A x is not the same as CTRL+A+x. First, press CTRL+A, release it, and then press x.


This site uses Just the Docs, a documentation theme for Jekyll.