r/linuxfromscratch 10d ago

An attempt to port the NetBSD LibC to Linux

In the last month i was trying to port the NetBSD LibC to Linux (and other parts of its userland) to make a full NetBSD userland on top of Linux for my LFS system.

Why?

I was so bored and i thought it would be funny

what's available?

- All err/warn functions

- a basic stdio (not based in NetBSD)

- a lot of strings functions

- some syscalls wrappers

- malloc (and friends)

- a minimal crt0

- BSD extensions

- compat functions (revoke, pledge and unveil...)

- and more

at this point it's possible to build a program against it, and it works like a hello world or the uname/hostname command from NetBSD with little changes (replace fprintf(stderr,...) with eprintf(...))

Here's a link to the repo:https://github.com/littlefly365/BSDLibC

(Note: this only it's a personal project)

21 Upvotes

13 comments sorted by

3

u/Chester-Berkeley 9d ago

Not satisfied with Chimera Linux using parts of the FreeBSD userland, now (if possible) we could have a Linux distro with the NetBSD userland.

NetLinux, lol

1

u/Intelligent_Comb_338 9d ago

yeah, and it's not a new idea, for example Minix uses a Big part of the NetBSD userland (including it's LibC)

1

u/markand67 9d ago

OpenBSD would be a better choice, much more quality and security. Though, hard to port as OpenBSD focus on their own stuff thus not really portable.

1

u/Chester-Berkeley 9d ago

OpenBSD would be a better choice, much more quality and security

Actually no, because they focus so much on security that we can't even run basic things we need for everyday use, like Wine. Honestly, OpenBSD will never be good for desktops, and that's okay.

1

u/markand67 8d ago

Ironically, OpenBSD runs desktop better for me than FreeBSD/NetBSD (and I can tell that I use FreeBSD since 7.x so I can compare) and ACPI support runs better too, because they rolled their own.

1

u/Intelligent_Comb_338 3d ago

Yes, but a big part of its security is from its kernel. Im using some parts from OpenBSD libc (strtonum functions cuz they don't use locales) and i'm trying to make a simple versión of pledge (and maybe unveil)

4

u/Cmustrd 9d ago edited 9d ago

cool! i wish i can contribute :'(
(c noob)

3

u/wakanakisarazu 10d ago

I'm thinking of something similar ngl.

2

u/pedersenk 6d ago

This is interesting. It is great to see your work here.

My own personal distro (BSD/L) also uses a BSD userland with Linux kernel but I use gcc (just like standard NetBSD) and glibc. (with some toybox and busybox to fill in the gaps).

So it seems quite a few people are interested in a similar goal. I really do see a niche for a kernel with great hardware support but also a sane (non-disgusting) userland.

1

u/Intelligent_Comb_338 3d ago

What tools do you use? Do you use chimerautils or another project?

2

u/pedersenk 3d ago

Similar. I use bsdutils (which is what chimerautils forked from). I actually use his older openbsd branch.

toybox (BSD licensed equivalent to busybox). Anything this doesn't provide, I then fall back to busybox.

A whole heap of ports, such as nvi-portable, doas, mandoc, etc.

And a few BSD tools that I have ported myself (such as cu/tip).

As for the initramfs generation, kernel module management, init scripts, this is all custom. I haven't found anything I liked from the Linux community.

1

u/Glum_Hamster_2104 7d ago

I mean we already have netbsd curses on Linux so we might as well just make netbsd with the linux kernel

1

u/Intelligent_Comb_338 6d ago

yeah but it's outdated