Show HN: Banan-OS, an Unix-like operating system written from scratch
333 points
21 days ago
| 16 comments
| github.com
| HN
This is my operating system that I've been working for the past 2 years. All of the code is written exclusively by me except from ported software. banan-os has a monolithic kernel targeting x86 (i686) and x86_64 architectures. The project consists of bootloader, kernel and userspace libraries (libc, libGUI, libFont, ...). It also uses my custom C++ standard library partly based on stdc++.

Currently I have basic TTY and GUI environment with some of the basic UNIX utilities like cp, ls and stat. I have basic support for USB (keyboard/mouse/storage), disks (NVMe, AHCI), custom networking stack with TCP and UDP support, and a UNIX-like filesystem with /dev /tmp /proc filesystems.

The whole project is written in C++ except for my BIOS bootloader that is written in 16-bit real mode assembly. I have been testing the OS mainly on virtual machines but also frequently on real hardware.

DigiEggz
21 days ago
[-]
This is really cool! I like the name, too. Of all the things you've implemented for this, what has been the most difficult part? And have you hit any serious roadblocks along the way?
reply
Bananymous
20 days ago
[-]
There hasn't been any overly difficult parts. I'd say the most difficult one has to be either AML interpreter because the ACPI specs are very badly written or the USB stack just because the size of the specifications is so large with a lot of cross referencing.

There hasn't been any major roadblocks. Sometimes I give up on a feature and come back to it maybe month or two later though.

reply
ksp-atlas
20 days ago
[-]
Good work using a custom AML interpreter instead of a premade one!
reply
Bananymous
20 days ago
[-]
My current one is really bad. It does work on maybe 50% of the hardware I have tested. I am in the middle on writing a new proper one, it is already way better but still missing some necessary parts before I can integrate it.
reply
Findecanor
20 days ago
[-]
I would anticipate that you only have support for boot-mode keyboard and mouse now, considering the complexity of the full USB-HID spec. Otherwise I'd be very impressed.
reply
Bananymous
20 days ago
[-]
I do actually support USB keyboard and mouse with USB-HID. There are some parts I don't support, like mouse specifying its movement with physical units (I haven't encountered any of those yet). Also I only have support for xHCI USB controller so PC's with older UHCI, EHCI or AHCI controllers are not yet supported.
reply
bsimpson
20 days ago
[-]
I read it thinking "banyan tree" until I saw the ASCII art and realized it's a banana reference.
reply
sedatk
20 days ago
[-]
This is so cool! I especially applaud you for managing to implement USB drivers from scratch! By the way, I broke it by typing "cat doom1.wad" :)
reply
Bananymous
20 days ago
[-]
Thank you! Yeah there isn't really any data serialization done to data written into the TTY, so can break if you feed it arbitrary binary data :D
reply
dvh
21 days ago
[-]
There is a certain customary sentence to be put in new os kernels announcements and your announcement lacks this sentence.
reply
bityard
20 days ago
[-]
You surely mean that it's a hobby project and probably won't be big and professional like GNU?
reply
ASalazarMX
20 days ago
[-]
I can't see anyone seriously suggesting to management that they run Banan-OS. Probably the same self-inflicted handicap of CockroachDB.
reply
coldpie
20 days ago
[-]
Agreed. We run a respectable Freax shop around here.
reply
GTP
20 days ago
[-]
It's because we learnt the lesson and know that management wouldn't run it anyway. Otherwise they would go bananas.
reply
38
20 days ago
[-]
oh fun, a guessing game :|
reply
xandrius
20 days ago
[-]
The other poster already answered...
reply
readyplayernull
20 days ago
[-]
...that the word iiis...
reply
drivers99
20 days ago
[-]
"just a hobby, won't be big and professional like gnu" which is a quote from Linus's Linux announcement on Usenet in 1991.[1] He didn't know it was going to be big at the time, making it an ironic statement after the fact, and that could also be the case for any new OS from scratch such as this one.

[1] https://www.cs.cmu.edu/~awb/linux.history.html

reply
caspper69
20 days ago
[-]
There was a need for linux, and that's why it took off. The Unix wars, the provenance of the 4.3 BSD code, the cred of running a Unix (or Unix-alike).

Not to trash this guy's project, but there's no similar perfect storm going on right now.

reply
Imustaskforhelp
20 days ago
[-]
I don't think it was a perfect storm going on , but rather since today Linux is popular & strong , you are retracing it to it having a perfect storm and nothing can come close to it .

That being said , I still think that this wouldn't reach mass adoption "just for being an alternative to linux" and that this has to have a specific purpose

For example serenity os has a really cool old - ui and some people think its a fun os in general , out of which came the ladybird project.

Redox os is trying to write it in rust , something which can have some practical meaning in my opinion

reply
caspper69
20 days ago
[-]
Not really. I don't see how Linux being popular & strong today had any bearing on people's willingness to contribute 33 years ago.

Writing an operating system is challenging. Not as challenging as a compiler, but certainly more work (so much hardware, so many specifications ugh).

In 91-92, people were clamoring for a free, unencumbered 386 Unix. Enter Linux.

Every successful (non-commercial) OS undertaking needs and has a hook.

Redox? Rust (enough said).

Serenity? Live coding and mental health (no knock there).

And on the flip side, look at ReactOS. Languishing. Painfully slow 15+ years in development, and people would still rather pay Microsoft or roll the dice running applications under Wine. It's hook just isn't strong enough.

Again, not to knock this guy, because just the fact that he wrote his own AML interpreter is super impressive to me (I've floundered around in those same ACPI specs for far, far (far, far) too many sleepless nights), and never put out 1 line of AML code. So mad props.

But there's just no hook. C++? Passe. No microkernel / hypervisor / <insert_feature_here>? No capability model?

It'll be tough. But I know that OS'ing is a labor of love, even if not a single other person cares. Cheers.

reply
spiffyk
20 days ago
[-]
Very cool! How much time do you dedicate to this, in terms of hours per week? Looks like a lot of work has gone into it!

You say you're a student on your profile - does that mean university? If so, have you also worked on the OS directly as part of your studies?

reply
Bananymous
20 days ago
[-]
Yeah I am a student at an university. I have managed to "skip" some courses like operating systems and concurrency just by showing my project to the professor. Otherwise my project is not integrated to my studies in any way. I also got a part time job in my university's embedded side because of my project.

How much time I put to this really depends on what else is happening in my life at the moment. There has been months where I've put total of 5 hours into this and some weeks alone I may reach close to 40 hours.

reply
breakfastduck
20 days ago
[-]
No doubt you've learned a hell of a lot from this.

I would imagine this will set you up incredibly well for a career in the industry, arguably moreso than your actual degree. Any reasonable prospective potential hirer is gonna be super impressed by it I think.

reply
Bananymous
20 days ago
[-]
> I would imagine this will set you up incredibly well for a career in the industry, arguably moreso than your actual degree.

That's what I hope at least. This is something I would want to do for my career in the future. Good portfolio never hurts :)

reply
rossant
20 days ago
[-]
>×I have managed to "skip" some courses like operating systems and concurrency just by showing my project to the professor.

Love this! Well done. Best way to skip classes ever!

reply
spiffyk
20 days ago
[-]
Awesome, thanks!

One more set of questions: was there something you would call an "it's alive!" moment in the beginning of the project? A part where it would start to get _really_ fun for you? If so, what was it and how long did it take you to get there?

reply
Bananymous
20 days ago
[-]
There has been multiple really great moments during the development. Its always cool to see some completely new features working on real hardware, like first time getting keyboard input, USB mouse input, running DOOM, reading from disks, networking, and getting a compiler working!

I think it became actually fun after I got all the basic requirements done and could start deviating from more or less standard OS code. When I could actually decide what I want to work on. Maybe after couple of months it was in that state. It was also fun at the beginning. it was just way harder as I didn't have any prior knowledge and I was trying to wrap my head around some basic concepts :D

reply
ryandrake
20 days ago
[-]
> first time getting keyboard input, USB mouse input, running DOOM, reading from disks, networking, and getting a compiler working

One of these is really a lot more impressive (and indicates a far more mature and finished product) than the rest. I love how it's just listed in there next to the basics. Nice job.

reply
zimmund
19 days ago
[-]
Joining these courses may be enriching for everyone though. You may learn something new or a different approach to a problem you've solved. Other students will appreciate your actual experience with the subject. And the professor may learn a thing or two (and appreciate your contributions) if you can add to the subject. That said, I'm not good managing my time and I don't have the guts to code an OS from scratch, so what do I know?
reply
mrbungie
20 days ago
[-]
Cool project!, alternative name for a fork: PlatanOS
reply
p0w3n3d
20 days ago
[-]
PlátanOS with stressed first a
reply
whartung
21 days ago
[-]
Very nice. Lot of work.

What stand out challenges have you encountered?

reply
Bananymous
20 days ago
[-]
I think biggest challenges have to be with reading large specifications. I've never really done that before so it took some time to get used to.
reply
eismeer
20 days ago
[-]
Could you link a random specification you were working against? I'm curious how there are written
reply
Bananymous
20 days ago
[-]
reply
convolvatron
20 days ago
[-]
good for you. it gets easier. and being able to actually get down the meat of things is a real superpower. totally agree with you about ACPI though.
reply
savgore
20 days ago
[-]
This is awesome! Can I ask what development looks like? Do you run this in a VM or on bare metal? When you sit down and work on this, what does it look like?

I bet you learned a lot with this - how do you keep notes and track your development? Or is the OS your live journal. Thanks

reply
Bananymous
20 days ago
[-]
I do maybe 95% of testing on a VM. It is way faster and much more convenient. I do test on real hardware regularly though. It's always cool to see stuff actually running on bare metal and bare metal is not as forgiving as VMs can be.

Generally I decide a feature I want to add. Then I do a general overview of the corresponding specifications and sometimes look at how already existing OSs handle that. I try to make some kind of mental model about the system and what it needs. Then I basically just write what ever I come up on the spot.

I have a really bad habit of not writing docs or taking notes. Basically I just hold everything in my head (and forget about it when I would need that information again). For some more complex stuff I do draw diagrams and write notes but I pretty much only keep those locally for myself.

reply
johnisgood
20 days ago
[-]
> I have a really bad habit of not writing docs or taking notes. Basically I just hold everything in my head (and forget about it when I would need that information again).

This was me for a very long time. I started making notes now, knowing that I will most likely forget (some of it). I still have all sorts of files scattered around though with my notes, i.e. the notes are disorganized (to some extent). I thought of using Obsidian for them and I have tried it but I do not use it consistently, I just go for my XTerm window with emacs or vim.

reply
kortex
20 days ago
[-]
How does one even begin to write drivers for nvme, ata, rtl nics, etc? I know mice and keyboards use HID which is a standard, but are there similar standard protocols for all other devices?

Is this how linux manages to avoid needing to "install drivers" in the vast majority of cases? And if there are standard device APIs, why does windows have to go through that whole install driver routine every time I plug something in?

reply
Bananymous
20 days ago
[-]
Yeah basically every commonly used device has its protocol standardized. Although there exist some devices where the manufacturer has to provide the drivers. All of the devices I have written drivers have had their specifications publicly available for free (e.g. NVMe at https://nvmexpress.org/specifications).

I'm not really familiar with how Linux nor Windows handle drivers. While compiling the Linux kernel you specify which drivers you want to build into the kernel and which ones you want as modules. Usually most common ones compiled along side the kernel so there isn't really need to install them later, just load the driver modules. There are also devices that work with just a generic driver but would have more features with a specific one (e.g. led settings on a gaming mouse). I think Windows is maybe installing these optional drivers.

reply
caspper69
20 days ago
[-]
So here's the kicker.

Microsoft, having the resources it does, was able to design and implement a stable driver ABI. In fact, they also have a stable userspace ABI. Both have evolved, but that's not the point.

Linux conversely (whether by design or by limitation) does not have stable ABIs (although userspace compatibility isn't terrible). Even though you can build kernel drivers as modules (and then load/unload), those modules are unique to each specific kernel build.

Remember those guys didn't write the compiler & linker toolchains they were using like Microsoft was able to do.

I will be honest, I understand why Linus & Co. have decided to keep it this way, because it encourages hardware manufacturers to submit either their drivers or their specifications to the upstream kernel, which promotes software freedom. It is a noble goal and has served them well.

BUT - thieir decision has caused me no small amount of consternation over the years as a system administrator. Once you use Linux for something that is not "server software" (be it auth, file sharing, web, etc.), you are generally using it to drive some piece of hardware (CNCs, industrial tools, cough phone systems cough). Vendors, especially those that deal in low-volume / high-margin products, do not want to release their source code. They're allergic to the idea even. So I have gotten stuck in outdated kernel hell on several occasions because the kernel devs have decided to change internal interfaces in a point-point release that my driver software relied upon.

I so wish that Linux would move to a stable driver ABI. It would make administration & upgrades so much easier, especially on the embedded side.

But I also know that it'll never happen.

FWIW, the "no stable kernel ABI" is unique to Linux, although no one really does this like Microsoft (i.e. the BSDs can break between releases, but I do believe NetBSD is superior to FreeBSD in this respect).

reply
notawolf
20 days ago
[-]
This a very cool side project, congratulations! Any tips for anyone that also would like to attempt something similar ? Like where to start or or sources etc
reply
Bananymous
20 days ago
[-]
Pretty much what others said. You should read through https://wiki.osdev.org/Getting_Started and note that it will take a lot time if you decide to go for developing an OS.
reply
torlok
20 days ago
[-]
OSDev Wiki for practical knowledge, operating system design and computer architecture books for the theory.
reply
udev4096
20 days ago
[-]
There's https://os.phil-opp.com/ for rust, https://github.com/tuhdo/os01 for general OS development and make sure to read Operating Systems: Three Easy Pieces
reply
VagabundoP
20 days ago
[-]
Awesome. I was not expecting something with that feature set.

Do you plan on porting more software?

reply
Bananymous
20 days ago
[-]
I do plan to port more! I want to keep the base OS free of 3rd party code, but ports are really nice way to get things running that I have not yet written.

I have some ports locally that are not yet working. I have git, binutils, gcc, make all compiling but they are giving some weird errors. Probably a bug in my libc or syscalls.

reply
VagabundoP
18 days ago
[-]
Not enough OS's built from scratch nowadays. Fair play.
reply
stevekemp
20 days ago
[-]
A minor bug-report, if you run "cd /proc/3" you cannot "cd .." afterwards.

It looks like ".." entries don't exist beneath /proc.

reply
Bananymous
19 days ago
[-]
Thank you!
reply
MomsAVoxell
19 days ago
[-]
I think it’s going to be quite important to address portability and general flexibility when it comes to architectures.

What do you think it will take to target RISC-V?

reply
Bananymous
18 days ago
[-]
I've tried to abstract everything architecture dependent but there is still a lot of x86 specific code outside of archutecure specific directories. I've been planning on adding support for new platforms, but I've not yet had the motivation to start doing it.

I'm not familiar with other architectures than x86 so I can't really say what it will take. At least a lot of work :D

reply
nunobrito
20 days ago
[-]
Really enjoyed that you just run and fun from the browser.

Doom wasn't loading for me (Brave browser on Ubuntu without javascript disablers).

Very good work. It was fun without doubt.

reply
Bananymous
20 days ago
[-]
Oh yeah, sorry. I'm missing documentation on how to access the GUI environment. You have to enter the GUI environment using `start-gui` command. After that doom should start by running `doom` in the GUI terminal. Performance in the web emulator is really bad though, so don't expect much :D
reply
ajxs
20 days ago
[-]
Really impressive achievement! I love the name too!
reply
jart
20 days ago
[-]
Rename the project UHHNIX or OOHNIX. Great work!
reply
PTOB
20 days ago
[-]
Are you trying to start a flame war?? :-D
reply
jart
20 days ago
[-]
Just paying my respect for what Oskari pulled off. I tried building my own hobby OS and didn't get nearly this far. I just thought that, like Linux, this UNIX-like OS deserved a name that's closer to the source. For example, Linus originally wanted to name Linux "phreax" but Linux is what stuck after his friend changed the folder name when hosting it for him on an FTP server.
reply
keyvank
19 days ago
[-]
can you compile and run smth like gcc in your OS?
reply
Bananymous
18 days ago
[-]
I've managed to compile the GNU toolchain (binutils + gcc). gcc seems to work fine, it can properly compile source code into assembly. There are some problems with binutils that make it not able to create object files or link. I'm haven't dug deeper to see where the problem actually is.
reply
keyvank
18 days ago
[-]
wow, i envy you! :) i have been working on a really simple self-compiling C compiler for some time, was wondering if you are interested in adding it to your OS haha. but if GCC works fine, then i don't see a reason :d
reply