Introduction: Make a Simple Operating System

Ever wanted to make an Operating System? Ever waned to know how command line operating systems work? Everything's here!

So we'll make a basic Operating System in C#, don't worry, if you even know some basics of c++ or java, you'll understand the code :D

By end of this tutorial, you'll be able to make your cool operating system!

So lets begin with some ind

Step 1: The Concept

So, how actually a OS works? I'll explain from the level of a electric circuit.

Most of you know logic gates in electric circuits. when many logic gates are connected, i.e. billions of transistors are connected together inside a chip, they can store 0s and 1s. Each gate could store either 0 or 1.

Then the connected transistor forms a Micro-Controller or a Micro-Processor. Here we are going to program on the micro-processor which is in your computer.

Did you know that your computer can also run with a operating system!? Wonder how! Every chip in your computer can run individually without a microprocessor but then without OS, it can't do multi tasking or run multiple threads together like in simple words, play a video in which one time music can play and one time graphics can play. But both can't run together.

Because of an operating system, today you can listen to music while browsing the internet.

The OS works based on its kernel. The kernel stores all the library files and whenever we run a program, the program's code calls header files from the kernel. In windows, kernel is 'Win32'

Step 2: Materials and Prerequisite Knowledge

What will you need-

1) Microsoft Visual Studio 2012/2013/2010 (Any Edition)

Link: https://www.visualstudio.com/

2) COSMOS User Development Kit Milestone 4 (C# Open Source Managed Operating System)

Link: https://cosmos.codeplex.com/downloads/get/90082

3) Any Virtulization Software to run the OS. I'm using VMware Player.

Perquisite Knowledge-

Basics of C++, Java, .net would work

I just request to just browse some 5-10 basic online tutorials of c# so you can get a better understanding

Step 3: Introduction to COSMOS

Cosmos (C# Open Source Managed Operating System) is an operating system development kit which uses Visual Studio as its development environment. Despite C# in the name, any .NET based language can be used including VB.NET, Fortran, Delphi Prism, IronPython, F# and more. Cosmos itself and the kernel routines are primarily written in C#, and thus the Cosmos name. Besides that, NOSMOS (.NET Open Source Managed Operating System) sounds stupid.

Cosmos is not an operating system in the traditional sense, but instead it is an "Operating System Kit", or as I like to say "Operating System Legos". Cosmos lets you create operating systems just as Visual Studio and C# normally let you create applications. Most users can write and boot their own operating system in just a few minutes, all using Visual Studio. Milestone 5 includes new features such as an integrated project type in Visual Studio, and an integrated debugger. You can debug your operating system directly from Visual Studio using breakpoints. Cosmos is available in two distributions, the developer kit (dev kit), and the user kit. The dev kit is designed for users who want to work on Cosmos itself. The user kit is designed for those who are interested in building their own operating system and doing some Cosmos work. The dev kit might be thought of as the Cosmos SDK. Most users should start off with the user kit as it is not so overwhelming like the dev kit. This article focuses on the user kit.

Step 4: Writing Your First Operating System

So, first lets write a OS which can simply print some text on screen!

So first of all, install all of the software required that is mentioned in the previous step.

1) Open visual studio and navigate to File>New Project

2) In the new project dialog box, select COSMOS and then COSMOS Project in the templates box. Name the project and click OK!

3) Now you'll see a file "program.cs" in the solution explorer. Click and load it.

4) You'll see a whole lot of code in it, don't be scared, we just need to edit code under "public static void Init()" block only :D

5) Now click on start button you see on visual studio toolbar or from Debug menu, click "start debugging"

6) You'll see a COSMOS Builder window appear, without any modification, just boot click build

7) WOW! So that QEMU window appear? QEMU is actually a operating system emulator so you are seeing the code being executed. Now lets make some modifications and personalize the OS.

Step 5: Personalizing the OS

Now just make some simple changes in code,

under public static void Init(),

Change Console.WriteLine("Welcome! You just booted C# code. Please edit Program.cs to fit your needs"); to Console.WriteLine("Hello World! This is my first operating system");


So, you've changed Welcome! You just booted C# code. Please edit Program.cs to fit your needs to Hello World! This is my first operating system.

We've just edited the text. Now lets compile the code and see the output. Perform the steps in previous step to compile the code.

Saw that! Text has changed! you can even put your name here. Congrats! you've won half the battle by understanding the basics. But how about a operating system that takes input from user and gives user a output? Just like command line operating systems or Linux terminal.

Step 6: Making a Command Line OS

So here we'll make a command line operating system. As we saw the previous code, the code just writes some text on screen via Console.WriteLine() function. Now we will write a OS where the user gives the input and the computer processes it.

So, lets make a code which prints Hello User! Thanks for using this operating system! when we give hello as input to the computer.

In programming, there are different kinds of loops which most of you know like If loop which does the action if the conditions are met. So here will will use if loop and if the input of a user is hello, then it will print the line we mentioned above.

CODE:

string input;

input = Console.ReadLine();

if (input == "hello")

{ Console.WriteLine("Hello User! Thanks for using this operating system!");

}

Here in this code, we made a string named input in which we read some data. The If loop checks that if the input matches the word hello, then it should print Hello User! Thanks for using this operating system!

Now lets go and execute this code!

You can now type into the operating system now! type hello

Excited? Saw the output? :D

You made your own command line OS. but how about adding many more features in this? Like if you type about, it tells you the info about the OS and if you type help it shows the list of commands? Lets do it in the next step.

Step 7: Adding More Features to Our OS

So, lets add more features like about which displays COSMOS OS 1.0 and help which displays

hello - Simple OS command

about - Know about OS

Similarly like the previous step, make 2 more if loops.

CODE:

string input;
input = Console.ReadLine();

if (input == "hello")

{ Console.WriteLine("Hello User! Thanks for using this operating system!"); }

if (input == "about")

{ Console.WriteLine("COSMOS OS 1.0 ");

}


if (input == "help")

{

Console.WriteLine("hello - Simple OS command");

Console.WriteLine("about - Know about OS ");

}

In this code as you see we've made 2 more if loops. Now execute the code and type about. Saw that, it displays COSMOS OS 1.0 and then close the window and re-execute the code and then type help. Saw that? This means everything is going good.

Now every OS has a option of shut down or power off. So lets add features like shutdown and restart.

Step 8: Adding Shutdown and Restart Features

Adding shutdown and restart feature is also extremely easy. In cosmos the code to shutdown is Cosmos.Sys.Deboot.ShutDown(); and to restart is Cosmos.Sys.Deboot.Reboot();

Now make IF loops which have input as shutdown and restart.

CODE:

string input;
input = Console.ReadLine();

if (input == "hello") { Console.WriteLine("Hello User! Thanks for using this operating system!"); }

if (input == "about") { Console.WriteLine("COSMOS OS 1.0 ");

}

if (input == "help") { Console.WriteLine("hello - Simple OS command"); Console.WriteLine("about - Know about OS "); }

if (input == "shutdown") { Cosmos.Sys.Deboot.ShutDown(); }

if (input == "restart") { Cosmos.Sys.Deboot.Reboot(); }


Now execute the code and type restart. Saw it xD! It restarted! Now type shutdown. Saw it, the window closed which means the OS shut down.

This may be the most exciting part when you made a OS which can shutdown and restart itself!

Now lets improve this OS by giving it final touches.

Step 9: Final Touches

In the final touches, we will use the switch case because it is much more simpler and better then IF statement. We will also make a command that when the user types a keyword which is not in list of our commands, it should show No such command

Just see the code once.

CODE:

while (true)
{

string command = Console.ReadLine();

switch (command) {

case "shutdown": { Cosmos.Sys.Deboot.ShutDown();

break;

}

case "help":

{

Console.WriteLine("hello - Simple OS command");

Console.WriteLine("about - Know about OS ");

break;

}

case "about":

{

Console.WriteLine("COSMOS OS 1.0 ");

break;

}

case "reboot": {

Cosmos.Sys.Deboot.Reboot();

break;

}

case "hello": {

Console.WriteLine("Hello User! Thanks for using this operating system!");

break;

}

default: { Console.WriteLine("No such command");

command = null; break; } }

}

Ok, just copy the code into visual studio and execute the code. Note that we added the break;. This is used in switch case. Now have the fun with your OS!

Now try to type a wrong command like help me. this command was not defined so it shows No command found. This means now our OS won't accept wrong commands. And try all commands. You may have noted that now you can type another command after previous as we are taking input in a constant loop.

Step 10: Running & Testing the OS

So i'm now going to test the OS we made. I'll be using a Virtualization software to run the OS. I'll be using VMware player which is free to download!

Ok, so create a virtual machine and open C:\Users\ {Your Username} \AppData\Roaming\Cosmos User Kit

Here you will find cosmos.iso file after you select build ISO in visual studio. Just boot this file in VMware and enjoy your operating system! (make it full screen)

Step 11: Thanks & About Me

I'm a 16 year old embedded developer, working with MIT Media Labs India Initiative. I work in various technologies like ARM, AVR, Arduino and Raspberry Pi.

You can find about me here: http://www.sarthaksethi.net/

Facebook: https://www.facebook.com/pages/Sarthak-Sethi/25272...

Youtube: https://www.youtube.com/channel/UCv7OszKtRFkJ_e0Af...

Comments

author
bradatan13 (author)2015-04-06

Cool.

author
ssarthak598 (author)bradatan132015-04-07

Thanks :)

author

: - ))

author
Tinker Bench (author)2017-06-02

Great Sarthak. I was unable to find your website or channel but i appreciate your work. Well done. When I read through the first parts, I didn't even dream that it would be an instructable by an Indian. Great work

author
jeffbowman (author)2016-12-06

Much of this text is blatantly plagiarized from the original documentation at Cosmos' GitHub source code repository.

SSARTHAK598, you're 12 years old... this isn't a good way for you to start out. Be honorable. It'll get you further.

author
cuban.guy.94 (author)2015-04-09

Nice. Some corrections:

1. This is not an OS. All the
functions of the OS kernel plus the .NET runtime and libraries are
provided by COSMOS. You're just writing a very basic .NET application.

2. The processor on a PC can do multitasking without an OS. You just have to program it for it.

3.
The Windows kernel is not Win32. Win32 is just a subsystem (more like C
libraries). You can run even run the kernel without win32 with some
hacking and you can run other subsystems (such as INTERIX) side-by-side.

author

Are you stupid or what? That is an operating system that has a kernel. I've made an operating system in Cosmos before. It can boot on computer hardware using a cd or dvd.

author

you can contact me on sviquarahmed@gmail.com

author
hueyp (author)cuban.guy.942015-05-19

With the kernel point, wouldn't that mean that Ubuntu isn't an operating System and instead a Linux application set on top of the Linux kernel?

author
WernerM1 (author)cuban.guy.942015-04-10

Actually, had you read his initial considerations, you would have caught the following, which I am bringing up here for you:

"Cosmos is not an operating system in the traditional sense, but instead
it is an 'Operating System Kit', or as I like to say 'Operating System
Legos'"

No one with some basic commercial programming knowledge would expect this framework to ever become a full blown OS after looking at it, as it is clearly not intended to. This is merely a tool for learning and playing around.

author
dhall-1 (author)2015-04-09

This seems more like a UI than an OS.

At the very most a line input interpreter.

author
WernerM1 (author)dhall-12015-04-10

If you judge it merely by the examples provided by the author, then yes. Nothing differs much from writing a console application that parses command line arguments, such as:

void main(char[] argc, int argv){

if (argv > 0){

switch argc{

case "help": {
Console.WriteLine("hello - Simple OS command");
Console.WriteLine("about - Know about OS ");
break;
}
case "about": {
Console.WriteLine("COSMOS OS 1.0 ");
break;
}
case "hello": {
Console.WriteLine("Hello User! Thanks for using this operating system!");
break;
}

}
else {
Console.WriteLine("No such command");
break;
}

But since this article only demonstrated some simple commands that are available under the whole COSMOS framework (which has an extensive library), I think it is always a good idea to do some more exploration before issuing comments way too soon.

author
sviquarahmed (author)WernerM12016-10-02

my emial is :- sviquarahmed@gmail.com ,you contact on that

author
dhall-1 (author)WernerM12015-04-11

So I was correct in my original statement.

This is NOT an operating system. COSMOS is the operating system and this is just a way to interface with it.

I spent 6 months in college writing an operating system for a vax/vms mainframe. And even it was just extension of the emulator our professor had written on top of the VAX's OS.

Did the author write COSMOS or the library files? without COSMOS would the examples execute? Then no, the author did NOT make a OS, he made a way to interface with the OS. It is still a great project just the title is misleading.

author
Connor Willett (author)dhall-12015-08-23

Good for you buddy. 6 months in college. I'm 12 years old and I made an operating system with this Cosmos thing.

author
WernerM1 (author)dhall-12015-04-11

Your comments clearly demonstrate your lack of attention to the text and excess criticism. And that's enough said.

author
WernerM1 (author)dhall-12015-04-11

Had you read the authors initial considerations it would have saved you from issuing a redundant comment.
If you're so cool, why are you here looking at something that useless to you in the first place?
Go write your own kickass OS and then come back to show it to us.

author
sviquarahmed (author)2016-10-02

I NEE S PEOPLE FOR MAKING OPREATING SYSTEM , E MAIL:- sviquarahmed@gmail.co m

author
AzeemF (author)2016-09-11

Amazing. Thanks so much

author
Syed Muhd Ilham Arif (author)2016-09-04

Can you do this in MonoDevelop?

author
SameerA18 (author)2015-11-04

Hello Friends!My name's Sameer Ali. I am looking for some people to work with me in S.A.P.G(Sameer Ali Programming Group) There are There are currently 3 members.
If you want to join,email me:sali77419@gmail.com

author
Sayyed ViquarA (author)SameerA182016-06-12

Hi what is your location

author
RyanY2 (author)2015-09-19

it works thanks

author
Kelvin Ikome (author)2015-08-05

Hello!
My name is Michael, I am currently making an operating system and I am looking for others who are interested in joining me. Here is my email address miketony.ma@gmail.com

author
Ayush 007 (author)2015-07-07

Hey help me please I want to make is I am 13 year boy I know c vb java languges please help me

author

I would not use this for creating a OS because no programs to go along with it unless you write them yourself (or if you write and emulator that runs linux/windows/mac programs which is not the best for performance). You are better off looking at http://www.linuxfromscratch.org/ if you wanna write a proper OS. Cosmos is really just for educational purposes. Linuxfromscratch (lfs) already had the linux kernal support so you have way more programs you can use. You can also use something like Novo builder or straight up code to build off of what communities have been doing for decades.

author
Troop5 (author)2015-07-06

Good. I wonder if I can get my VB Operating Systems to run in VirtualBox.

author
awent0428 (author)2015-04-25

Wow! Thanks for sharing this! I never knew an Operating System in C#.

author
GraydonT (author)2015-04-19

Any chance you could out the iso up for download?

author
duncan.tallon.9 (author)2015-04-16

Hey, when I try to start project I can not find Cosmos. What could I have done wrong?

author
WernerM1 (author)duncan.tallon.92015-04-17

OK, but first give us some more details.

Which version of VS are you using?

Which version of COSMOS did you download?

author
duncan.tallon.9 (author)WernerM12015-04-18

2013 and the one in the link

author
WernerM1 (author)duncan.tallon.92015-04-19

Ya gotta do some digging. Read through the COSMOS project page. Lots of info to aid troubleshooting your setup.

author
ZeshanM (author)2015-04-15

Cosmos isn't appearing in the new project dialogue box, help? :l

author
WernerM1 (author)ZeshanM2015-04-17

OK, but first give us some more details.

Which version of VS are you using?

Which version of COSMOS did you download?

author
ZeshanM (author)WernerM12015-04-17

im using the 2015 one and the COSMOS version is the one in the link that was given to download it.

author
WernerM1 (author)ZeshanM2015-04-17

Well if you're really talking about the newly-released Visual Studio 2015 then there may be problems, as COSMOS' latest release is intended for 2013. Nobody can tell if it will install properly with 2015.

Suggest you downgrade to 2013 and give it another try.

author
ZeshanM (author)WernerM12015-04-17

i've got the 2013 version and it still doesn't work.

author
WernerM1 (author)ZeshanM2015-04-18

You're a developer, right??

Just checking.

Guess if you read through their website, you'll find some useful information for getting COSMOS to work on your setup. Including alternate download links to prior versions.

FYI, I got COSMOS installed for both my VS2010 and VS2012 and working fine. Maybe you need to do some more digging.

author
ZeshanM (author)WernerM12015-04-17

is there some specific place i have to download COSMOS?

author
duncan.tallon.9 (author)2015-04-16

Cool! Can this run on a RPi?

author
TriA2 (author)2015-04-15

cool how about Uc OS or Uprocessor OS....

author
Raphango (author)2015-04-09

Awesome project man! =D

Congratulations!!!

author
Raphango (author)Raphango2015-04-09

Is it technically possible to install it on a common PC?

author
ssarthak598 (author)Raphango2015-04-14

Yea it is :) Thanks :)

author
WernerM1 (author)Raphango2015-04-10

Even without having tried it myself, it all indicates that yes, it is. It looks like the COSMOS framework can compile your code and pack it into an ISO image, so you could in theory load it into a virtual (or physical) machine as the author demonstrates.

author
Raphango (author)WernerM12015-04-10

Thanks! =D

author
sxdavey (author)2015-04-09

Folks need to spend less time being grammar police, and more time appreciating the sentiment. This is an international site, and it's shortsighted to believe that everyone in the world should have a stellar command of the English language. Before you start casting grammatical stones, ask yourself how many languages you speak fluently ... and then act appropriately.

author
Istarian (author)sxdavey2015-04-11

Or the lot of you could quit compulsively complaining about people who mention a few grammatical issues in a tiny part of their post. Especially when it isn't the only thing they have to say. The number of languages one speaks fluently isn't relevant. Anyone posting to an site in English when that isn't their native language (and probably when it is, too) has an obligation to make their best attempt at correct grammar and take corrections in stride. They frequently aren't the ones complaining about receiving grammatical corrections, just the people like you who can't help but gripe anytime someone says anything about grammar at all. Quit being the anti-grammar police already. --- Also, proper grammar is important to making clear, precise statements that are easy to understand.

author
WernerM1 (author)Istarian2015-04-11

...and all of that mumbo-jumbo is meant to..? What?
Maybe only to try and justify your incompetence to venture outside your native language? Or the incompetence to demonstrate real insights on a subject matter you haven't actually done anything practical about?
Who made YOU the english grammar master champion of the entire world in the first place? Either shut up or go write an Instructable about how to speak and write plain english correctly. Maybe someone will read it.

About This Instructable

129,864views

1,029favorites

License:

More by ssarthak598:DIY Smart Home Monitoring BottleArduino Video Game (The DIY Gift)Is My Fridge Door Open?!
Add instructable to: