I'm interested in how operating systems work. I've been reading some articles about Linux and seem to understand how it all generally comes together, but I feel like there's a chicken and egg dilemma when it comes to constructing an operating system.

Since Linux is written in C (and Assembly), which needs a compiler to be compiled, how does one actually compile an operating system for the first time? Do you first write a boot loader out of your existing OS? Or do you do something else? Do you have to dual-boot for the first time? Or you need two machines? What did Linus first end up with when he started his project? What did his very first result look like?

What's the very first thing you need to design and write when you're programming an Operating System?

  • 3
    You might be interested in reading this: en.wikipedia.org/wiki/Bootstrapping_(compilers)
    – Cam
    Commented Mar 18, 2013 at 2:47
  • 3
    Also potentially interesting: en.wikipedia.org/wiki/Machine_code. This is how real programmers coded before assembly =)
    – beatgammit
    Commented Mar 18, 2013 at 2:49
  • 3
    The OSDev Wiki has quite a bit of information on how operating systems are built.
    – Jon Purdy
    Commented Mar 18, 2013 at 2:49
  • 3
    You might be interested in the Linux From Scratch (linuxfromscratch.org/lfs) project. It is basically a step-by-step process to go about building and setting up your own Linux OS. You start with an existing OS, using the tools on the OS, you build a new set of tools. With the new set of tools, you then build a new set of tools again (this is called cross-compiling, building tools that are independent of the host OS).
    – Alex
    Commented Mar 18, 2013 at 2:53
  • 1
    I have to say, maybe there just isn't an answer to a basic operating system saying "Hello, World!". I've browsed through some of the duplicates and have considered all of the recommendations (mostly books, obviously). Maybe the answer is that it takes years and years of experience and knowledge to even get to what I'm asking about. Sorry if I was a bit naive. Just wanted an "in a nutshell" explanation in English of how it might be done, just to get my brain around the subject. But, as I said, I've learned more than enough from the answers provided to get me started, so thank you!
    – Leo
    Commented Mar 18, 2013 at 3:31

1 Answer 1


This happens all the time in embedded systems. Generally you compile on an existing OS targetting whatever processor it is you are doing the OS for. This code then needs to be put in a form that the processor can load, either in a EPROM, or you make a "Bootloader" which has the job of being the first thing the processor will execute then it will work out how to load the OS off a medium such as a harddrive.

On the PC architecture there is a "BIOS" which provides basic access to various hardware like screen and harddrives, etc. It doest the "Bootloading" for you. So most PC based OS's like linux and windows use this to get themselves going using a "Boot Sector" on something that provides a file system.

The simplest OS is often just a task scheduler (multi threading), and a simple hardware abstraction layer. For the task schedule you will generally have a timer source that triggers a interrupt

void MyTaskSchedulerInterruptHandler()
   SaveStateOfCurrentTask(); // save all the CPU registers
   FindNextTaskToExecute();  // using tables of tasks currently being run, 
                             //find one to run next
   ExecuteTask();  // load all the CPU registers for this task
   // return from interrupt will then make the CPU start on the loaded task

   //never gets here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.