Maestro – Introduction
![](https://blinkingrobots.com/wp-content/uploads/2024/01/Maestro-Introduction.png)
2024-01-02T15:00:00+00:00
Maestro is a Unix-like kernel and working system written from scratch in Rust
Due to the web, I can learn the way most issues I’m excited about work. Nonetheless, one thing stayed a thriller to me for a very long time: computer systems.
Computer systems are amongst essentially the most advanced instruments that humanity has ever constructed. They’re a marvel of engineering that we take with no consideration as a result of we use them in our on a regular basis lives.
I wish to dig into complexity, and I wish to study by doing.
On high of that, I spend loads of time on the pc. Wouldn’t it’s cool if I had a system that I’d know from A to Z and that I may customise as a lot as I needed to suit my expectations?
Because of this I made a decision to construct Maestro. A Unix-like working system that’s meant to be light-weight and compatible-enough with Linux to be usable in on a regular basis life.
A little bit of historical past
The primary commit of the kernel dates again to December twenty second, 2018, at 3:18 within the morning (the perfect time to jot down code, in fact). It began as a faculty undertaking.
It was initially applied utilizing the C language and continued to be for roughly a yr and a half, till the codebase grew to become too exhausting to maintain clear.
At that second, I made a decision to change to Rust (my first undertaking on this language), which represented a number of benefits:
- Restart the undertaking from the start, utilizing classes discovered from earlier errors
- Be a bit extra modern than simply writing a Linux-like kernel in C. In any case, simply use Linux at that time
- Use the protection of the Rust language to leverage some issue of kernel programming. Utilizing Rust’s typing system permits to shift some duty over reminiscence security from the programmer to the compiler
In kernel improvement, debugging may be very exhausting for a number of causes:
- Documentation is usually exhausting to seek out, and BIOS implementations could also be flawed (extra usually than you’d assume)
- On boot, the kernel has full entry to the reminiscence and is allowed to jot down the place it mustn’t (its personal code, for instance)
- Troubleshooting reminiscence leaks is just not straightforward. Instruments akin to valgrind can’t be used
- gdb can be utilized with QEMU and VMWare, however the kernel might have a unique behaviour when working on a unique emulator or digital machine. Additionally, these emulators might not assist gdb (instance VirtualBox)
- Some options within the assist for gdb in QEMU or VMWare are lacking (akin to Document and Replay) and gdb would possibly even crash generally
All these points are causes for utilizing a memory-safe language, to keep away from them as a lot as attainable.
General, the usage of Rust within the kernel allowed for the implementation of loads of safeguards. And I consider that it’s, to today, the perfect resolution I’ve made for this undertaking.
Timelapse
Created utilizing Gource. Music: Many Moons of Saturn, Mike Cole
The present state of the undertaking
Maestro is a monolithic kernel, supporting solely the x86 (in 32 bits) structure for now.
On the time of writing, 135 out of 437 Linux system calls (roughly 31%) are roughly applied.
The undertaking has 48 800 strains of code throughout 615 information (all repositories mixed, counted utilizing the cloc
command).
The OS at the moment has the next parts, except for the kernel:
- Solfège: a boot system and daemon supervisor (sort of much like systemd, however lighter)
- maestro-utils: system utility instructions
- blimp: a bundle supervisor
- And extra parts which might be out there on my github
To date, the next third-party software program has been examined and is engaged on the OS:
- musl (C normal library)
- bash
- Some GNU coreutils instructions akin to
ls
,cat
,mkdir
,rm
,rmdir
,uname
,whoami
, and so forth… - neofetch (a patched model, because the authentic neofetch doesn’t find out about my OS)
Take a look at it your self!
Disclaimer: It is very important observe that the OS continues to be in a really early stage of improvement and is extremely unstable. I discourage attempting to put in it on a machine with essential information on it.
To date, it has been examined totally on QEMU, VMWare and VirtualBox.
There are two methods you’ll be able to set up the OS:
The ISO supplies an installer for the OS. You should utilize it on QEMU, VMWare or VirtualBox for instance.
It’s best to run the ISO with ample RAM (1GB must be greater than sufficient).
Such an quantity of reminiscence is required as a result of packages to be put in are saved in RAM (on the initramsfs) as an alternative of the disk. That is at the moment the perfect technique because the OS is not but in a position to learn on a USB stick or CD-ROM by itself, so it depends on the bootloader for this.
What this weblog is about
The purpose of this weblog is not to jot down tutorials about learn how to create an OS. That is already effectively coated by different web sites/blogs. I like to recommend particularly:
The purpose is to discover extra superior topics (since most individuals/blogs are inclined to cease on the fundamentals), to push the themes so far as I’m able to, to jot down articles about issues I encounter and the way I resolve them, to find how computer systems work beneath, but additionally working methods, the web, and far more… Loads of issues to speak about!
What’s coming subsequent?
Cleansing of the codebase and efficiency optimisations are so as. Because the OS began as a faculty undertaking, I needed to minimize corners with a view to end it on time. However now’s the time to pay again the technical debt I gathered.
Some reminiscence leaks are additionally mendacity round and should be mounted. Efficiency optimisations will most likely be a topic for weblog articles.
The subsequent leap ahead can be to have the bundle supervisor absolutely engaged on the OS. To take action, some options are required:
- Community assist, which is at the moment below improvement. And can most likely be the topic of quite a few articles
- Shared library assist. This at the moment doesn’t work as a result of it requires mapping information immediately into reminiscence, which isn’t at the moment supported by the implementation of the
mmap
system name on the kernel
After that, I can set up (with out ache) and check programmes akin to compilers (gcc/g++, clang, rustc), make, Git, Vim, and so forth… After which develop the kernel whereas utilizing it!
The event of the kernel largely follows a easy process:
- 1: Run a programme on the kernel and see if it really works appropriately
- 2: If it doesn’t work, then:
- 3: Run the programme whereas printing system calls and seek for the primary system name that’s inflicting troubles (not applied or buggy)
- 4: Implement or repair the system name in query
- 5: Go to step 1
- 6: Else: Yay!
The extra programmes working appropriately on the kernel, the extra steady and full it turns into!
How you can assist
You possibly can depart a star ⭐ on the Github repository of the kernel ❤️
And keep in contact by:
Don’t hesitate to hitch Discord! When you have suggestions to make, recommendation to provide, or inquiries to ask, I can be glad to reply!