Bare Bones Linux Kernel Tutorial

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
carsonalfonzo
Posts: 4
Joined: Sun Oct 07, 2012 12:34 am

Bare Bones Linux Kernel Tutorial

Post by carsonalfonzo »

Hello everyone. I did some searches and could not find anything that answered my question. I would like some advice or a post (not using linux from scratch) on how to start building an OS using the linux or freebsd kernel as a starting point. They are well developed and documented from an api standpoint. A post, link or bare bones tutorial would be great.

Thanks.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Bare Bones Linux Kernel Tutorial

Post by Brendan »

Hi,
carsonalfonzo wrote:Hello everyone. I did some searches and could not find anything that answered my question. I would like some advice or a post (not using linux from scratch) on how to start building an OS using the linux or freebsd kernel as a starting point. They are well developed and documented from an api standpoint. A post, link or bare bones tutorial would be great.
For a Linux based OS there's 2 types of software - the kernel (and its modules if any), and a large collection of software that make up the "user space" (script interpreters, init scripts, utilities, etc).

I'd start with a minimal Linux distribution with a working "user space", then replace pieces with your own pieces until the entire "user space" is your own; and then when you've got your own minimal Linux based OS you'd build more on top of it.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
carsonalfonzo
Posts: 4
Joined: Sun Oct 07, 2012 12:34 am

Re: Bare Bones Linux Kernel Tutorial

Post by carsonalfonzo »

Can you please correct my assumptions. Grub loads the kernel at a memory address. Then after the kernel is loaded applications are loaded under that and some of them interact with the kernel using system calls.

I actually want to write my own shell. And the only other software that is going to run on this is going to be my user software. So in my mind all I need is the kernel, a C runtime library and my software. So how do I load the kernel (like they do on the barebones tutorial)?

I'm going to look into the LFS route but what I really want is an Android like OS that uses the linux kernel and everything else is my own implementation. Any other ideas or corrections to my assumptions?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bare Bones Linux Kernel Tutorial

Post by Combuster »

Having Grub load the linux kernel takes pretty much the same commands:

Code: Select all

kernel (hdx,y)/path/to/kernel argument1 argument2 argument3...
boot
That said, many existing kernels don't want to work out of the box that way because in modern days, because it needs the userspace tools to set up things like device nodes, or it even needs ramdisks to contain the drivers because they aren't an integral part of the kernel anymore. Last time I got dropped in a recovery shell, I had to switch to a PS/2 keyboard because USB wasn't working yet.

Have you ever tried installing Gentoo on a machine? It goes to show much of the things you need to know in a much more friendly environment than truly doing LFS.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
carsonalfonzo
Posts: 4
Joined: Sun Oct 07, 2012 12:34 am

Re: Bare Bones Linux Kernel Tutorial

Post by carsonalfonzo »

No never! Guess that would be a good exercise to do. Part of the reason I wanted to use the linux or freebsd kernel is it is already well developed and I thought it saved me from alot of the headaches of writing my own kernel. I could just write a shell and load my business framework. I was trying to bypass alot of assembly language programming until I got really comfortable with it.

In short this is what I'm doing. I have a CRM implemenation that I wrote on Linux. I wanted to make this into a virtual appliance (along with my other software) and users could load it and run into Hyper-V, VMWare or VirtualBox. I don't want all of the fluff of windows or linux installations just my software and a hardware abstraction. I could use LFS but I have seen other OS's do this (Android comes to mind) where they use the kernel and write the rest of the os over it.

I'm looking into building the kernel in C. Since this is not a true OS and all of the software (user applications) are going to be developed and deployed with the OS can I just use gcc without having to write a RTL? There will be no outside individuals writing software for this in this case do I have to port or write a C RTL? If I compile my app to a flat binary and write the boot loader (or use grub) will this work?

I'm envisioning in this instance all I would have to do is write the httpd and command console.

Thoughts? Thanks for all of your responses so far.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: Bare Bones Linux Kernel Tutorial

Post by TylerH »

You don't have to port an RTL, but newlib is so easy (if you have the supporting functions implemented) that I don't see why you wouldn't. Newlib is a C library meant for minimal/embedded devices and can be ported by implementing less than 20 basic functions that it uses to communicate with the kernel/drivers. All of them are trivial if you already have the underlying driver.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Bare Bones Linux Kernel Tutorial

Post by bluemoon »

carsonalfonzo wrote:No never! Guess that would be a good exercise to do. Part of the reason I wanted to use the linux or freebsd kernel is it is already well developed and I thought it saved me from alot of the headaches of writing my own kernel. I could just write a shell and load my business framework.
So, you need to think again what is your goal, a kernel, an OS, or a window manager, or even a menu application.
carsonalfonzo
Posts: 4
Joined: Sun Oct 07, 2012 12:34 am

Re: Bare Bones Linux Kernel Tutorial

Post by carsonalfonzo »

bluemoon - I don't want to write a kernel which is why I created this thread.

All - I'm looking into linux from scratch I think that would get me what I need for now. Thank you for all of your insight unless anyone else has a suggestion or sample code to load the kernel I need to go this way.
Post Reply