← Introduction | Documentation Index | Next: Architecture →
This document explains what you need installed, how to set up a Linux host, and the exact steps to turn OpenKernel into a bootable image of your own operating system.
| Tool | Why it is needed |
|---|---|
i686-elf-gcc |
Cross compiler for 32-bit freestanding x86. Produces the kernel objects. |
i686-elf-ld |
Linker that applies link.ld. Usually installed with the cross compiler. |
nasm |
Assembles your boot code into elf32 objects. |
make |
Drives the build. |
qemu-system-i386 |
Emulator used by make run. |
grub-mkrescue |
Builds the bootable ISO. |
xorriso |
Used by grub-mkrescue under the hood. |
grub-pc-bin (Debian) / grub2-pc-modules (Fedora) / grub (Arch) |
Provides the 32-bit GRUB modules for grub-mkrescue. |
| Tool | Why |
|---|---|
git |
Version control and the release changelog. |
| PulseAudio client library | The make run command attaches a Sound Blaster 16 device through -audiodev pa. Without a working audio backend QEMU may warn or fail on that device. |
install_pkg.sh supports Linux only (apt, dnf, pacman). On Windows or macOS you must install the tools manually.
chmod +x install_pkg.sh
sudo ./install_pkg.shThe script does the following:
- Detects the package manager (
apt,dnf, orpacman). - Refreshes the package lists. On Arch Linux a full upgrade always runs, because partial upgrades are unsupported there; on apt and dnf a full system upgrade only runs when you pass
--upgrade. - Installs everything the
Makefileneeds:nasm,make,xorriso,grub-mkrescuetogether with the 32-bit GRUB modules,qemu-system-i386,qemu-img,gitand the PulseAudio client library used by QEMU's-audiodev pa. - Builds the
i686-elfcross compiler (i686-elf-gcc+i686-elf-ld) from GNU sources when it is not already installed. This step downloads binutils and GCC and compiles them into/usr/local; it is by far the slowest part, roughly 15-40 minutes on the first run, and later runs skip it. The defaults are GCC 14.2.0 and binutils 2.43, the versions the project is tested with; override them withOPENKERNEL_GCC_VERSIONandOPENKERNEL_BINUTILS_VERSIONif needed. The build needs about 4 GB of free disk space in/var/tmp(override the location withOPENKERNEL_CROSS_BUILD_DIR). - Verifies every tool and prints a checklist. The script exits with a non-zero status if a required tool is still missing, so you know
makewill work before you even try it.
Options:
| Option | Effect |
|---|---|
--skip-update |
Do not refresh the package lists before installing |
--upgrade |
Also perform a full system upgrade before installing |
--skip-cross |
Skip the cross compiler build (make fails without it) |
--verify-only |
Only print the checklist; installs nothing and does not need root |
To re-check the tools at any time without installing anything:
./install_pkg.sh --verify-onlyThis is the single most confusing part of the project, so read it carefully.
OpenKernel/ <- repository root, Makefile lives here
├── Makefile
├── link.ld
├── notes.txt
├── install_pkg.sh
├── version.txt
├── Kernel/
├── Drivers/
├── SystemLib/
├── ...
Inside this layout, every path in the C_SRC variable of the Makefile starts with OpenKernel/, for example OpenKernel/Drivers/Vga/vga.c. Since the Makefile is already inside the OpenKernel folder, that path does not resolve. Running make here fails with:
make # produces build/os.binThis layout builds end to end. The only remaining link warning is cannot find entry symbol _start, because the repository ships no boot code.
project/ <- you would run make here
├── Makefile
├── link.ld
├── notes.txt
├── install_pkg.sh
└── OpenKernel/ <- the kernel source tree
├── Kernel/
├── Drivers/
├── SystemLib/
└── ...
.github/workflows/release.yml still produces exactly this ZIP: it copies the Makefile next to an OpenKernel/ folder, which was the layout the prefixed C_SRC paths and -I . used to assume.
The current Makefile no longer matches this layout. Two things break:
C_SRCpaths carry noOpenKernel/prefix, soOpenKernel/Drivers/Vga/vga.cdoes not exist relative toproject/.- The include path is
-I ., which points outsideproject/instead of atproject/itself.
To build the release package, run make from inside project/OpenKernel/, or restore the prefixed paths and -I .. Supporting both layouts at once would need the Makefile to detect which one it is in (for example VPATH := OpenKernel plus a conditional include directory); that has not been done.
How to get Layout B: download a release ZIP from the GitHub Releases page, or build it yourself the way .github/workflows/release.yml does:
mkdir -p package/OpenKernel
rsync -av --exclude='.git' --exclude='.github' --exclude='version.txt' \
--exclude='package' --exclude='install_pkg.sh' --exclude='link.ld' \
--exclude='Makefile' --exclude='notes.txt' \
./ package/OpenKernel/
cp Makefile link.ld notes.txt install_pkg.sh package/Then run make from package/.
Even in Layout B the build does not fully succeed today. Two
C_SRCpaths are wrong regardless of layout, and 11 of 31 C files have compile errors. See 09 - Project Status.
notes.txt describes the intended workflow. The essential idea: OpenKernel provides no boot code; you write it.
Two options:
- Write a raw bootloader in assembly, following the
ENTRY(_start)symbol declared inlink.ld. - Write a GRUB multiboot header so GRUB loads the kernel directly.
A minimal multiboot entry point looks like this (this is a pattern, not code taken from this repository - the repository contains no assembly):
; boot.asm
MBALIGN equ 1 << 0
MEMINFO equ 1 << 1
FLAGS equ MBALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
section .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
section .bss
align 16
stack_bottom: resb 16384
stack_top:
section .text
global _start
extern kernel_main
_start:
mov esp, stack_top
call kernel_main
cli
.hang:
hlt
jmp .hangAdd your file to the ASM_SRC variable in the Makefile:
ASM_SRC = Boot/boot.asmThe Makefile assembles it with nasm -f elf32 into build/Boot/boot.o.
Implement kernel_main() in C. This is where you initialise subsystems, because nothing inside OpenKernel initialises itself:
#include <OpenKernel/Drivers/Vga/vga.h>
#include <OpenKernel/SystemLib/Memory/mem.h>
#include <OpenKernel/Drivers/Keyboard/keyboard.h>
#include <OpenKernel/VFS/vfs.h>
#include <OpenKernel/OFS/ofs.h>
void kernel_main(void)
{
vga_init(); /* required before any print */
heap_init(0x100000, 1024 * 1024); /* 1 MiB heap */
kbd_init();
vfs_init(OFS);
ofs_init();
vga_set_color_scheme(0x00, 0x0A);
vga_print_scr_nw("My OS booted on OpenKernel 5.0");
}Calling order matters. For example, every VGA print function returns immediately if vga_init() has not been called, and kmalloc() returns NULL for every request if heap_init() has not been called (it does not hand out invalid addresses - it refuses to allocate).
Append your .c files to C_SRC in the Makefile. Keep OpenKernel's own entries as they are.
notes.txt asks you not to modify the OpenKernel folder, so that you can drop in a newer release without merging conflicts.
The iso target copies Boot/grub/grub.cfg into the ISO. That file is not in the repository, so you must create it:
set timeout=0
set default=0
menuentry "My OS" {
multiboot /boot/os.bin
boot
}
make # compile and link -> build/os.bin
make iso # build ISO -> your_os.iso, create disk.img if missing
make run # boot it in QEMUmake run executes:
qemu-system-i386 \
-m 512M \
-smp 4 \
-cdrom your_os.iso \
-drive file=disk.img,format=raw,if=ide \
-audiodev pa,id=snd0 \
-device sb16,audiodev=snd0 \
-boot d \
-serial stdioWhat each flag gives you:
| Flag | Effect |
|---|---|
-m 512M |
512 MiB of RAM. |
-smp 4 |
4 virtual CPUs. OpenKernel has no SMP support, so this only affects timing-sensitive busy loops. |
-cdrom your_os.iso |
Boots your ISO. |
-drive file=disk.img,...,if=ide |
Attaches a 25 MiB raw IDE disk. ATA and OFS operate on this. |
-audiodev pa / -device sb16 |
Sound Blaster 16 on port 0x220. |
-boot d |
Boot from CD first. |
-serial stdio |
Routes COM1 output to your terminal. Useful once the serial driver compiles. |
make cleanRemoves build/, iso/, your_os.iso, and leaves disk.img alone.
make iso creates disk.img (25 MiB) if it does not exist. To inspect or populate it from the host:
# list partitions
fdisk -l disk.img
# read the first 64 sectors
xxd -l 32768 disk.imgThere is no FAT formatter in this project. If you want to test the FAT readers you must create a FAT filesystem on the image with host tools such as mkfs.fat and mount it with mtools or a loop device.