Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Sorry if this is an extremely stupid question, but I'm brand new to Linux and I'd like to try to figure out how to modify my own system. From what little I know so far about Linux, I would imagine that what I'm actually looking for is the kernel's source code. I know that there are some resources out there that would allow me to download a copy of the kernel (like kernel.org), but presumably that is just a copy, and I would have to switch from my current kernel to that new one after modifying it in order to see the changes that I make take effect. Is there a way to avoid doing that, and just modify the kernel that I already have? And if not, how do I tell Ubuntu to use the new Kernel that I've downloaded rather than the original one? And how do I know whether or not my changes will screw up the system? Thanks in advance for your help!

share|improve this question
3  
"I'm brand new to Linux" and "modifying the kernel" are two things which are like... like "I never played chess, how do I win the World Championship?" Can you program? Do you have intimate knowledge of how computer works? I'm pretty sure there are other ways to solve your problem, please explain what exactly you're trying to achieve. –  Sergey Dec 11 '12 at 1:11
    
Fair enough. I can program a bit, well enough that I think that if I had some time to look at the source code I could figure out how the kernel works and start to make small tweaks. So I guess what I'm asking is, what would be the best way for me to access the kernel's source code, and implement the changes on my own computer? –  BPD Dec 11 '12 at 1:16
    
+1 for the attitude! :) –  Sergey Dec 11 '12 at 1:26
add comment

3 Answers

There are a few different ways to do so, but it's good to know as much as you can about your computer (hardware wise). I used the instructions here :http://www.howtogeek.com/howto/ubuntu/how-to-customize-your-ubuntu-kernel/. I had to do some things different because the website had an older kernel version than the one i have.

share|improve this answer
    
This looks like the kind of thing I'm looking for, thanks! –  BPD Dec 11 '12 at 1:21
add comment

Ubuntu Wiki has an article on that: Kernel/Compile

The article is a bit dated, but the important difference with other methods is that they explain how to get the source from kernel's Git repository, which is important if you ever plan to update your working tree to a new version.

share|improve this answer
    
This looks great, thank you so much! –  BPD Dec 11 '12 at 2:12
add comment

Your question can be broken down into two parts, as you can tweak some kernel parameters during runtime and also bytepatching but as a beginner i would strongly not suggest you to try bytepatching.

In your case, to getting started would i strongly suggest to do modifications to the source code recompile it, and install and test it. It do also exist ways to test your kernel in emulators eg. without the need to reboot your system eg. QEMU is one...

It exist a lot of ways to do kernel development, here is way that should be simple if you have some expirence with using ubuntu.

Quick and dirty (you need to complete some arguments\paths):

sudo apt-get install libncurses5-dev binutils-dev linux-source 
sudo apt-get install fakeroot build-essential crash kernel-wedge kernel-package  

mkdir ~/src
cd ~/src
apt-get source linux-image-$(uname -r)
cd linux-3._LINUX_SRC_FOLDER_

Just enter the menu tweak around if you wanna or just exit and save.

make menuconfig

The level of parallelism when compiling it. (number of processor-cores +1)

export CONCURRENCY_LEVEL=5

Pick the targeted system, google it or leave it out. Two examples

export CHOST="x86_64-pc-Linux-gnu"
export CHOST="i686-pc-linux-gnu"

If you want the compiler to optimize eg.

export CFLAGS="-march=native -O2 -pipe"
export CXXFLAGS="$CFLAGS"

Do your tweaks, eg.

vim ~/src/LINUX_SRC_FOLDER/include/linux/hid.h 
cd  ~/src/LINUX_SRC_FOLDER

Compile the kernel and make deb packages, and report time used.

time fakeroot make-kpkg --initrd --append-to-version=-tweak-CUSTOM-NAME kernel-image kernel-headers

Install your compiled kernel and the headers.

sudo dpkg -i ../linux-image-3._YOUR_DEB_FILE_
sudo dpkg -i ../linux-headers-3._YOUR_DEB_FILE_

Your kernel should be installed and show in your grub-boot-menu. Reboot.

sudo reboot

Enable the grub boot menu or tap shift a few times during startup.

Select your desired kernel to boot.

If you use this guide, feel free to improve it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.