XV6 OS Tutorial

Shivam Marathe
3 min readApr 9, 2020

--

#First Blog

#xv6 operating system is really tough to understand when you are beginner. I spent 8–9 days on xv6 OS and learned a little about it. Especially when you are a beginner, you need help to utilize your valuable time on xv6. So let’s get started.

xv6 OS repository can be cloned from the github website. Once you cloned the repository, first thing you need to do is run make command. Thereby it creates the xv6 image file in current folder. Once you are done with that, check if you have qemu emulator downloaded within your system.

QEMU runs the file in the emulator. It is also useful to work with many assembly level programs too. Next command that you have to run is

$ make qemu-nox

If you don’t include nox then you will see two screens where image file runs. To not get interrupted it is better to go with nox. Welcome to the world of XV6 operating system. To close the qemu emulator type ctrl+A and leave. Later type C, you will get qemu command shell. There you can type q+ENTER and you are back in your terminal.

qemu screen shows you various commands that you can run from shell. And there is catch too. If you check sh.c file, there you can see that only cd command can run anywhere as it gets called through shell itself, whereas others are forked in the shell. After changing the directory, fork happens from current directory of sh.c which is your cloned directory.

So making sure that exec fails while trying to bring the new program into the memory which is not there in the current directory, you must oil your mind how and which changes you can bring in the xv6. Once you are fixed with the your tasks it’s always easy on xv6 to execute them too.

To create new Directories you can always use following command from the root..

$ mkdir new

..it creates new directories for you. Moreover you can go recursive with the command..

$mkdir new/new1

..it will create new1 folder inside new folder. Now to create file there is a hack which I used.

a. Create a new file FILE.c

b. Use normal open system call and open a file. Using the write system call write into the file.

c. Add _fl/ under the list of apps(UPROGS) and FILE.c in EXTRA variable of Makefile.

d. run the make and make qemu-nox again

e. Type command fl and you can see new file created in root folder.

For the use of a particular call, one must check or track the execution of that system call. For this type of checking it is important that you are familiar with grep command line utility in linux-unix systems. I use this tool a lot to detect the presence of any function in xv6.

For eg. when you use ls system call here you need to mention folder name to track the files inside it. As mentioned above exec fails if you change directory and execute ls command there. Thus way of learning is the key to understand xv6.

There are many topics in operating systems where you can change the functionalities in XV6 using those concepts. There is a lot of material which is available on github regarding scheduling policies, system calls. Sometimes following such sources can also help you to learn new concepts and functions.

Ok then if you are new to xv6 and want to learn it , Yes this is the first tutorial that you should follow.

For any queries write a mail or comment will be helpful too.

Process is more important than the end result — MS

--

--

Shivam Marathe

B .Tech IT Student at COEP, Mathematics, Cricket lover.