tags:

views:

331

answers:

9

I want to modify the source code for Linux. I don't know from where to start.

I want to study the code and then modify it and see the changes by runnng it. Where do I start? I am a college passout and I know C and C++ but never edited the source code of Linux. I want a small light-weight Linux that has small source code files so that I can study it and modiy. To create my own one. Which Linux will be best for me and how do I get started with editing the soucre code? Will just installing Linux also give me its source code?

+3  A: 

Install Ubuntu

Learn how to download, compile and install your own kernel

Read and edit the code

Recompile and install your edited kernel

DisplacedAussie
+3  A: 

Here's a nice tutorial on compiling the Linux kernel.

A word of advice: use a virtual machine like VirtualBox for running the modified kernel - this way you can easily experiment without harming any real hardware.

Eli Bendersky
+9  A: 

The term "Linux" can mean a couple of different things.

The Linux Kernel

This is the real Linux, and is available from http://kernel.org/.

You won't find a small or light weight version of this. The kernel is the kernel. (That said, you can turn features off during compile time, which is useful if you are targeting low powered hardware such as for an embedded device).

Linux distributions

This is a Linux kernel, bundled with a big stack of other software needed to make it useful. The source code for the various pieces of software are available separately.

A netinstall of Debian gives you the core of the system in a small download. It has a package management system that makes it easy to get the source code of the various programs available for it.

David Dorward
+8  A: 

What exactly do you want to edit from a Linux distribution?

Linux itself is just a kernel, but the term is also used to refer to operating systems using the kernel. If you want to tinker with GUI programs, you can install a Linux distribution then download the source of those programs separately. If you want to tinker with the kernel itself, the source can be obtained from kernel.org. Each Linux distribution has it's own set of programs and features you can change around to your liking, but I doubt you want to edit everything that comes in a standard distribution like Ubuntu, as recompiling everything each time to see changes will take a while.

Linux is a lot to dive into for a first timer in the OS field. There is a great smaller Unix-like operating system for learning called MINIX. The source download is around 2.2M I believe and it is used as a teaching aid in many operating system development courses worldwide. Personally I'd sink my teeth into that a bit before taking on Linux, but the choice is yours, so have fun with it! Build it, break it, and try to rebuild it again! It's a great learning experience.

John T
A: 

The linux kernel is a monster of a source tree (at least in the sense of not being small). Old kernels are smaller, so it may make sense to look at those if you're after a small linux kernel to look at and play around with.

However, if all you're looking for is some unix-like kernel to play around with, Minix 3 may be another possible choice.

For the specifics, install any linux distribution, then install the kernel source package (Gentoo will probably install this by default; the specifci name of the kernel source package depends on your distribution).

Vatine
+1  A: 

If you just want to learn about operating systems in general, Minix might be a good place to start: http://www.minix3.org. Minix uses a fairly small (<5000) line microkernel so it is fairly easy to get familiar with its basic operation. Running it virtually (e.g. under vmware) is the easiest way to get started.

Richard Pennington
+3  A: 

If you want to modify the Linux Kernel or one of the "core" applications that usually form a distribution, and if you don't have much experience with Linux or modifying it, I recommend looking at Linux From Scratch. It will guide you to the process of installing a Linux system purely from it's core components and allows you to really understand a) what is actually part of Linux and b) what every part does.

Once you've done that, you should know where the sources are, how to compile them and how to deploy the changes. The next step is then just firing up your favorite editor and modifying it.

Michael Stum
A: 

Installing a Linux distribution is of course a reasonable prerequisite - Linux is self-hosting, in that it can (probably) only be compiled under a GNU/Linux system (with gcc and the gnu C library - although the C library is only used in tools during compilation - it isn't linked into the kernel). Numerous other tools are also required to compile Linux, which are documented.

Getting the source code is easy enough, but the difficult bit is configuring the kernel correctly for your machine - therefore you probably want to use your distribution's kernel source instead (which may have patches but they will be insignificant for your purposes).

The easiest way to "try out" kernel programming is to write a kernel module - these can be dynamically loaded (which means you can test your code without a reboot - provided it doesn't crash the system)

There are loads of examples of kernel modules around, however almost all of them are obsolete due to the fast-changing internal APIs in the kernel itself (even the build system changes relatively rapidly).

Kernel modules can do almost anything that doesn't involve directly changing a core part of the kernel - there are a lot of "hook" functions (mostly register_something to register a device, hook, protocol, etc) which can be used to extend the kernel's userspace API or modify its behaviour in some way.

MarkR
A: 

You might consider the BSD distributions, they are a lot easier to compile from source

I know you said Linux but distributions like NetBSD are also a flavor of Unix and they are much more approachable from a compiler-everything-from-source perspective.

  • Generally a much smaller default or minimal install
  • The base system is built as a single system with make. Linux is a collection of utilities and packages from a lot of different places that are individually built, while the BSD distributions have a specific source tree that can be built from the top of /usr/src with a single command.
  • A lot easier to cross-compile, should you need to do that.

With the BSD distributions a single source tree contains the base system, and a clear dividing line is drawn between internal and external elements. The projects distribute their entire systems in ready-to-compile form.

DigitalRoss