Skip to main content

r/Operatingsystems



Luis Suárez just signed the newest contract of his career. And it’s going to be quite the party. ​
media poster


Windows and Linux and their thousands of distributions are garbage
Windows and Linux and their thousands of distributions are garbage
r/Operatingsystems - Windows and Linux and their thousands of distributions are garbage

make a os
make a os
make a os

Creating an operating system (OS) from scratch involves writing a bootloader and a kernel. You will need strong skills in C, x86 Assembly, and a solid understanding of computer architecture. Most developers test their OS inside a virtual machine (e.g., QEMU or VirtualBox). [1, 2, 3, 4]

Building a simple "Hello World" OS involves the following phases:

  1. Set Up Your Tools

Before you code, you need an environment to compile and test your OS.

  • Compiler: You will need GCC (GNU Compiler Collection) or Clang.

  • Assembler: NASM (Netwide Assembler) to translate assembly code into machine code.

  • Bootloader: GRUB is standard for loading your kernel and saves you from writing complex 16-bit assembly from scratch.

  • Emulator: QEMU or Bochs lets you test your OS without risking your physical computer's hard drive. [1, 2, 3, 4, 5]

  1. Write the Bootloader

When you turn on a computer, it runs the BIOS (or UEFI), which searches for a boot device. It looks for a bootloader. [1, 2, 3, 4]

  • You can write a tiny bootloader in Assembly that prints a character to the screen and waits.

  • Alternatively, use GRUB to load your kernel. You will create a custom ISO file and configure the GRUB boot menu to point to your compiled kernel. [1, 2]

  1. Build the Kernel

The kernel is the core of the OS. You can write this in C once you transition the CPU from 16-bit "real mode" to 32-bit (or 64-bit) "protected mode". [1, 2]

  • Write a C function (e.g., kmain()) that writes directly to the video memory (usually starting at address 0xb8000) to display text on the screen.

  1. Compile and Run

You will link your bootloader and kernel code together, then package them into an .iso file. [1]

  • Use a tool called Make to automate the build, compile, and run commands.

  • Boot your new .iso inside your emulator (e.g., qemu-system-i386 -cdrom my_os.iso). [1]

Next Steps to Level Up

Once your basic OS can display text, you will need to implement more complex features:

  • Memory Management: Write functions to allocate and free RAM.

  • Interrupt Handling: Set up the Interrupt Descriptor Table (IDT) so your OS can respond to keyboard or mouse inputs.

  • File Systems: Develop a way to read and write files to a disk using data structures like FAT or ext2. [1, 2, 3, 4]

Useful Resources

To dive deeper into OS development:

  • Tutorials: The GitHub OS Tutorial provides a step-by-step approach to writing a kernel.

  • Community: The OSDev Wiki is the largest community-driven encyclopedia for amateur OS developers.

  • Concepts: Read the textbook Operating Systems: Three Easy Pieces for theoretical principles on how schedulers and memory managers work. [1, 2, 3, 4]

For a visual breakdown of how a CPU boots and why you need assembly to initialize the hardware: