Page 1 of 1

Bare Bones Linux Kernel Tutorial

Posted: Sun Oct 07, 2012 12:59 am
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.

Re: Bare Bones Linux Kernel Tutorial

Posted: Sun Oct 07, 2012 1:14 am
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

Re: Bare Bones Linux Kernel Tutorial

Posted: Sun Oct 07, 2012 11:24 pm
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?

Re: Bare Bones Linux Kernel Tutorial

Posted: Mon Oct 08, 2012 12:06 am
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.

Re: Bare Bones Linux Kernel Tutorial

Posted: Mon Oct 08, 2012 12:37 am
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.

Re: Bare Bones Linux Kernel Tutorial

Posted: Thu Oct 11, 2012 7:17 am
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.

Re: Bare Bones Linux Kernel Tutorial

Posted: Thu Oct 11, 2012 7:21 am
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.

Re: Bare Bones Linux Kernel Tutorial

Posted: Fri Oct 12, 2012 2:32 am
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.