Introduction: Make a Simple Operating System

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

bradatan13 (author)2015-04-06

Cool.

ssarthak598 (author)bradatan132015-04-07

Thanks :)

: - ))

Inebriated Scientist (author)2017-10-04

Not sure what the problem is, that
people dislike this system.

In a traditional sense, yes, this is
not an OS that you make from scratch.

However, you would be foolish to
neglect this wonderful software and its brilliants.

I took a look at this, and
I must admit, this a brilliant software design that was made by
brilliant people. Think of it as this...these people made LEGO with
instructions. You can build with LEGO, throw them at someone, step
on them, or feed them to your cat. You can do whatever the hell you
want. You can even design your own house out of LEGO, if that is
what you want. However, you never made the “LEGO” In the
traditional sense. It was already made for you. You are just
following instructions even if the seems a bit arbitrary.

Let me
Give you and Example: Let us say
I wanted a special OS to run my 3 hydroponics systems. Instead of
going from point A to point B then to point C then back to point A,
So I could check how the system is doing. I deiced to use this
software and attache it to my makeshift old PC through floppy drive
(Lol). I then wrote a software for this OS to connect to my hydroponics
system so I can check the progress, and any problems that
my systems might have.

Whatever you want to do, is up to you.
Don't neglect this opportunity to learn a lot just because of
“traditions”. Yes, traditionally, it takes a lot more brainpower to make an “Official” OS. However, I never would had the
time, had I had to write the damned OS from scratch, or use it by the
time I finished making it.

I needed the thing running like “NOW”
so I used this. Why should I be ashamed to call this “My OS”.

The point is, if you really want to use
it, in any way you want. You will figure out how to make use of this,
besides just “Playground” purposes.

You can sit here and do some nit
picking as well as continue arguing about the semantics....

Or you can attempt this tutorial,
“Making your OS” and learn something at the end of the day.

The choice is yours.

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

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.

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.

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.

you can contact me on sviquarahmed@gmail.com

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?

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.

dhall-1 (author)2015-04-09

This seems more like a UI than an OS.

At the very most a line input interpreter.

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.

sviquarahmed (author)WernerM12016-10-02

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

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.

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.

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.

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.

sviquarahmed (author)2016-10-02

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

AzeemF (author)2016-09-11

Amazing. Thanks so much

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

Can you do this in MonoDevelop?

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

Sayyed ViquarA (author)SameerA182016-06-12

Hi what is your location

RyanY2 (author)2015-09-19

it works thanks

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

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

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.

Troop5 (author)2015-07-06

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

awent0428 (author)2015-04-25

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

GraydonT (author)2015-04-19

Any chance you could out the iso up for download?

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?

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?

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

2013 and the one in the link

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.

ZeshanM (author)2015-04-15

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

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?

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.

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.

ZeshanM (author)WernerM12015-04-17

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

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.

ZeshanM (author)WernerM12015-04-17

is there some specific place i have to download COSMOS?

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

Cool! Can this run on a RPi?

TriA2 (author)2015-04-15

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

Raphango (author)2015-04-09

Awesome project man! =D

Congratulations!!!

Raphango (author)Raphango2015-04-09

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

ssarthak598 (author)Raphango2015-04-14

Yea it is :) Thanks :)

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.

Raphango (author)WernerM12015-04-10

Thanks! =D

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.

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.

About This Instructable

132,144views

1,032favorites

License:

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