Page 1 of 48 12311 ... LastLast
Results 1 to 10 of 478

Thread: HOWTO: Kernel Compilation for Newbies

  1. #1
    Join Date
    May 2005
    Location
    Lecce, Italy
    Beans
    6,168
    Distro
    Ubuntu

    HOWTO: Kernel Compilation for Newbies

    DAPPER USERS, please follow this guide:
    http://doc.gwos.org/index.php/Kernel_Compilation_Dapper


    THIS GUIDE IS FOR BREEZY

    This guide is aimed at the newbies who are willing to learn something about kernel compilation or just who need a new kernel for incompatibility issues (e.g. DMA issues). This is a STEP-BY-STEP guide, so don't be afraid of compiling your first kernel, it's a piece of cake. Moreover if you need to compile any kernel module (nvidia modules, ndiswrapper, etc.) I will also explain how to do it.

    It takes a while (even an hour) to complete the process described below, so make sure you have enough time to spend.

    Make sure you have all the repositories enabled

    BEFORE YOU START

    If you have an Nvidia or ATI graphic card and you are using a proprietary driver (i.e. if you have installed the graphic driver before) please do this, otherwise get straight to step 1:

    Open Terminal or Konsole and type these commands:

    (if you are using GNOME, the graphic interface that comes with Ubuntu)
    sudo gedit /etc/X11/xorg.conf

    Otherwise

    (if you are using KDE, the graphic interface that comes with Kubuntu)
    sudo kate /etc/X11/xorg.conf

    Scroll down the text until you find this section (this is my configuration):

    Section "Device"
    Identifier "ATI Technologies, Inc. Radeon 330M/340M/350M (RS200 IGP)"
    Driver "ati"
    BusID "PCI:1:5:0"

    Substitute the word in red with “vesa” or “nv” (NVIDIA's opensource driver) or “ati” (ATI's opensource driver), make it look like this:
    Section "Device"
    Identifier "ATI Technologies, Inc. Radeon 330M/340M/350M (RS200 IGP)"
    Driver "vesa"
    BusID "PCI:1:5:0"

    Save and exit. Restart the computer and go to the next step.

    When you have the new kernel working you might want to reinstall the proprietary drivers for your graphic card. Have a look at my guide for the NVIDIA drivers: use method 2 if you want to install them manually OR compile the module with your kernel (as described below) and follow method 1 in my guide.

    1) Open Terminal or Konsole and type these commands

    uname -r (so as to see what kernel you are using)

    NOTE: if you want to compile a vanilla kernel from kernel.org have a look at the end of the guide.Otherwise proceed with step 2.

    2)
    IF YOU USE UBUNTU BREEZY or HOARY:
    sudo apt-get install linux-tree (this will download Ubuntu kernel sources and patches for kernel 2.6.12)

    IF YOU USE DAPPER
    :

    sudo apt-get install linux-tree

    3) Open Terminal or Konsole (if it's not open yet) and type these commands:

    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install kernel-package
    sudo apt-get install gcc (this will install gcc-4.0 for kernel 2.6.13 or superior)
    sudo apt-get install gcc-3.4
    sudo apt-get install libncurses5
    sudo apt-get install libncurses5-dev
    sudo apt-get install libqt3-mt-dev
    sudo apt-get install bin86
    sudo passwd root
    (and set the root password which you will need later)

    cd /usr/src
    sudo tar --bzip2 -xvf linux-source-2.6.12.tar.bz2
    sudo ln -s /usr/src/linux-source-2.6.12 /usr/src/linux
    cd /usr/src/linux

    NOTE: if the computer says "file exists" when you try type this command "sudo ln -s /usr/src/linux-source-2.6.12 /usr/src/linux", you have to type "sudo rm /usr/src/linux" (this will remove the old link). Now you wont' have this error and the command "sudo ln -s /usr/src/linux-source-2.6.12 /usr/src/linux" will work.


    sudo make oldconfig (so as not to compile the entire kernel from scratch)

    If it makes you any questions just press Enter (so as to select the recommended answer)

    sudo make menuconfig

    4) Now you have to use the keyboard to move the cursor over the function or submenu you want and press Enter to select it.

    Select the 4th option: Processor type and features

    If you have a multiprocessor system you might want to enable "Symmetric multi-processing support" (SMP): select it with your keyboard and press the spacebar to enable it (a "*" will appear beside it). If you don't have it don't enable it.

    Select Processor Family and choose the right one (i386 in my case) depending on the output of the command “uname -r” you have used before

    Press the right arrow and select exit

    If you have more than 900MB RAM then you'll definitely need this, otherwise (or if you are using Ubuntu 64 bit) skip this step:
    Scroll down the text until you find “High Memory Support”.
    Select it.
    You'll have three possible choices:
    Off
    4GB (if you have no more than 4GB RAM)
    64GB (if you have more than 4GB RAM)
    Select one of these functions and press enter.
    Press the right arrow and select exit

    The following operation is required if you want to enable DMA directly in your kernel. You might want to try this if none of the methods found in this forum works for you, Otherwise skip it and go to Step 5.
    NOTE: if you have old hardware which doesn't support DMA you won't be able to access this hardware with your new kernel. If this happens go straight to Step 8.

    Select Device drivers

    then

    Select ATA/ATAPI/MFM/RLL support

    Scroll down the text until you find (and highlight with the keyboard) “Enable DMA only for disks” and disable it by pressing N (now the “*” beside it should disappear, this means it is not selected any more)

    Press the right arrow and select exit

    5) Keep on selecting Exit until it asks you whether you want to save your new configuration or not. Answer yes.

    Now you are back to the command line, type:

    6) su
    CC=gcc-3.4
    export CC
    exit
    CC=gcc-3.4
    export CC


    7) DO THIS ONLY IF YOU NEED SOME RESTRICTED MODULE otherwise go to Point 8

    There will be no restricted modules for the kernel you are going to compile. However if you need them you can pick the modules you need and compile them together with your kernel.

    Get the source package/s (from Ubuntu's repositories or from the web) and extract it under /usr/src

    For example if you need ndiswrapper and or the nvidia drivers:

    sudo apt-get install ndiswrapper-utils

    sudo apt-get install ndiswrapper-source

    sudo apt-get install nvidia-kernel-source
    OR
    sudo apt-get install nvidia-legacy-kernel-source (if you have a old card which belongs to the list in the “Nvidia Legacy Cards” section at the end of the guide)

    [If you have got the package from the web (and not from the repositories) extract the file wherever you want and then type: sudo mv /path_to_the_folder_of_the_extracted_file /usr/src ]


    cd /usr/src/

    sudo tar --bzip2 -xvf ndiswrapper-source.tar.bz2

    sudo tar -xvf nvidia-kernel-source.tar.gz
    OR
    sudo tar -xvf nvidia-legacy-kernel-source.tar.gz(if you have a old card which belongs to the list in the “Notes section” at the end of the guide)

    Repeat the commands you've just typed for any other module you want to add (you can add as many modules as you need)

    When you have finished to extract any other additional module you have to type the following command in order to compile your kernel image, headers and modules.

    cd /usr/src/linux

    sudo make-kpkg clean

    sudo make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers modules_image

    NOTE: you can put whatever you want instead of “custom”

    8 ) If you have followed point 7, skip this step and proceed to step 9
    cd /usr/src/linux

    sudo make-kpkg clean

    sudo make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

    NOTE: you can put whatever you want instead of “custom”

    e.g. sudo make-kpkg --initrd –-append-to-version=-alberto kernel_image kernel_headers


    The system will ask you this question:

    “By default, I assume you know what you are doing, and I
    apologize for being so annoying. Should I abort[Ny]?”

    Answer no by either typing N and then pressing Enter, or just by pressing Enter (as N is the recommended answer)

    Well now you'll have to wait at least 45min. The process will use 100% of your CPU so try to leave your computer alone, go have a tea or something else just to keep you away from your computer for a while.

    9) After the (long) process type this in the command line (Terminal or Konsole)

    cd /usr/src

    ls

    You'll see a list of the names of the files in the folder as well as the names of your new kernel image , kernel headers (and modules if you have followed Point 7); they should look (approximately)like these ones:

    kernel-image-2.6.12-custom_10.00.Custom_i386.deb
    kernel-headers-2.6.12-custom_10.00.Custom_i386.deb

    (you will also see the modules like the ones below if you have followed Point 7)
    ndiswrapper-modules-2.6.12-custom_1.1-4ubuntu2+10.00.Custom_i386.deb
    nvidia-kernel-2.6.12-custom_1.0.7667-0ubuntu3+10.00.Custom_i386.deb

    Now install them by typing these commands (change the name of the files according to the ones you have seen after the output of the command “ls”):

    sudo dpkg -i kernel-image-2.6.12-custom_10.00.Custom_i386.deb

    sudo dpkg -i kernel-headers-2.6.12-custom_10.00.Custom_i386.deb

    sudo dpkg -i name_of_the_module (only if you have followed point 7) (there might be several modules so you have to use this command for every module you have compiled)
    e.g.
    sudo dpkg -i ndiswrapper-modules-2.6.12-custom_1.1-4ubuntu2+10.00.Custom_i386.deb
    sudo dpkg -i nvidia-kernel-2.6.12-custom_1.0.7667-0ubuntu3+10.00.Custom_i386.deb

    REMEMBER NOT TO UNINSTALL your previous kernel (just in case anything goes wrong) (i.e. don't do anything else apart from following the instructions)

    10) Ok, now it's time to see if they work.

    Restart your computer.

    Then if you want to see if DMA is active (if you have enabled it in the kernel as described before) type (in Terminal or Konsole):

    sudo hdparm -d /dev/hda (to check if your harddisk has DMA enabled)
    sudo hdparm -d /dev/cdrom (to check if your cd-reader has DMA enabled)

    Don't you worry if it gives you an error as output but the performance of your harddisk and cdreader have improved (try to transfer a file from a CD to your harddisk and see if it the system slows down).

    If everything is ok, then Congratulations you have compiled your first kernel successfully!

    11 ) If anything went wrong (I don't know a reason for which it would) you could switch back to your previous kernel: while your computer is booting press "ESC" repeatedly while your computer is booting until GRUB menu appears and you can choose kernel 2.6.12 again (using your keyboard arrows). Once you enter Ubuntu type these commands in order to uninstall the new kernel (remember to put the name of the kernel you have created)

    follow this example and put the name of the kernel you have created instead of “custom”

    sudo dpkg -r kernel-image-2.6.12-custom

    sudo dpkg -r kernel-headers-2.6.12-custom

    (in my case, sudo dpkg -r kernel-image-2.6.12-alberto)

    NOTE you DON'T have to type the full name of the file .deb which you created

    e.g. put “kernel-image-2.6.12-custom” instead of “kernel-image-2.6.12-custom_10.00.Custom_i386.deb”

    And restart your computer.

    Enjoy!

    Alberto

    --------------------------------------------------------------------------

    NOTE: HOWTO compile from a vanilla kernel from kernel.org

    If you want to compile from a vanilla kernel from kernel.org something need to be changed in my guide:

    Skip Point 2
    You have to download it from www.kernel.org (try the latest stable kernel source)

    When you get to Point 3 of the guide and you get to the following lines you have to modify them in this way:

    cd /home/your_username_folder/directory_where_you_put_the_downloaded_kernel (instead of cd /usr/src) (e.g. "cd /home/alberto/download" in my case)
    sudo tar --bzip2 -xvf linux-source-2.6.12.tar.bz2 /usr/src (use the name of the file you downloaded)
    sudo ln -s /usr/src/linux-source-2.6.12 /usr/src/linux (use the name of the file you downloaded)
    cd /usr/src/linux

    OPTIONAL PATCH (if you don't need it you can continue with the instructions of Point 3)

    At this point if you want to patch your vanilla kernel you have to:

    1)Download the patch (I recommend you Kolivas' patches: go to http://ck.kolivas.org/patches/2.6/ and choose the folder with the name which matches your kernel version (e.g. if you are going to compile "kernel 2.6.14" get to http://ck.kolivas.org/patches/2.6/2.6.14/). You will see other folders with different versions of the patch: I suggest you to select the latest version (2.6.14-ck3 in this case). Then you have to choose the file "patch-2.6.14-ck3.bz2" if you have a desktop computer (or laptop) or "patch-2.6.14-cks3.bz2" if you have a server.

    NOTE about KOLIVAS patch: if you want to use Kolivas patches you have to download the 1st stable version of a series of kernels and apply the latest patch to it. I'd better explain it with an example: if you are interested in 2.6.14.x series you have to download the source of 2.6.14 (NOT of 2.6.14.4 or 2.6.14.3, etc.) and to apply the latest Kolivas patch (as it will include the patches which make the difference between e.g. version 2.6.14 and 2.6.14.4)

    2)cd /usr/src/linux

    3)sudo bzcat /home/your_user_name/folder_in_which_you_downloaded_the_file/patch-2.6.14-ck3.bz2 | patch -p1
    (put the name of the file you have downloaded instead of the word I have put in red)

    And in Point 4 (this is the 1st thing to do at the beginning of point 4):

    Get to "File Systems".

    Select your filesystem (ext3, reiserfs, etc.) with the cursor.( ext3 is the filesystem used by Ubuntu by default, so if you chose automatic partitioning when you installed Ubuntu Hoary then "ext3" is definitely your filesystem)

    Then press the spacebar on the desired filesystem (a "*" will appear beside it). (Make sure there's a "*" beside it instead of a "M". In this way the support for you filesystem will be built directly in the kernel instead of being built as a module and you will not get a "kernel panic")

    For example:
    select "ext3 journalling filesystem support" and press the spacebar (a "*" will appear beside it).

    Press the right arrow and select exit.

    Then you can go on with the instructions of Point 4.

    If you want to compile a kernel 2.6.13 or higher you have to skip Point 6.

    The rest of the HOWTO is ok.

    --------------------------------------------------------------------------

    NVIDIA LEGACY CARDS

    Below are the legacy GPUs that are no longer supported in the unified driver.
    These GPUs will continue to be maintained through the special legacy NVIDIA
    GPU driver releases.

    NVIDIA chip name Device PCI ID
    ------------------------------- -------------------------------
    RIVA TNT 0x0020
    RIVA TNT2/TNT2 Pro 0x0028
    RIVA TNT2 Ultra 0x0029
    Vanta/Vanta LT 0x002C
    RIVA TNT2 Model 64/Model 64 Pro 0x002D
    Aladdin TNT2 0x00A0
    GeForce 256 0x0100
    GeForce DDR 0x0101
    Quadro 0x0103
    GeForce2 GTS/GeForce2 Pro 0x0150
    GeForce2 Ti 0x0151
    GeForce2 Ultra 0x0152
    Quadro2 Pro 0x0153
    Last edited by tseliot; July 15th, 2006 at 09:12 PM.

  2. #2
    Join Date
    Oct 2005
    Beans
    34

    Question Re: HOWTO: Kernel Compilation for Newbies

    I tell you, this is horrible. It either locks the system, or says "no screen"...

    Why is it so damn hard to get a nvidia 7800 to work in ubuntu... (Dell 9100, dual core 2.8ghz, 1920x1200 native lcd resolution)... I dont even need acceleration, just native resolution, but vesa wont support that.

    (nv driver locks system too)

    Any ideas?

  3. #3
    Join Date
    May 2005
    Location
    Lecce, Italy
    Beans
    6,168
    Distro
    Ubuntu

    Re: HOWTO: Kernel Compilation for Newbies

    Quote Originally Posted by IronWolve
    I tell you, this is horrible. It either locks the system, or says "no screen"...

    Why is it so damn hard to get a nvidia 7800 to work in ubuntu... (Dell 9100, dual core 2.8ghz, 1920x1200 native lcd resolution)... I dont even need acceleration, just native resolution, but vesa wont support that.

    (nv driver locks system too)

    Any ideas?
    You should use nvidia driver 7676, I think the problem is the "nv" (the open source driver) in xorg, which perhaps doesn't support your graphic card yet. The nv driver was buggy for one of my cards (GeForce 6200 TC PCI-E).

    If you have compiled the modules using this guide you are trying to use driver 7667. It probably won't work for you.

    1) Set the driver to vesa (it doesn't matter if it doesn't support the resolution you need, it's only a way to use the graphical interface)

    2) Try my guide (HOWTO: Latest NVIDIA drivers) (use method2) and use drivers 7676 (FOLLOW EVERY STEP)

    3) Post any kind of problems you have in this other thread of mine: http://www.ubuntuforums.org/showthread.php?t=75074

  4. #4
    Join Date
    Aug 2005
    Location
    Georgia,USA
    Beans
    91
    Distro
    Ubuntu Breezy 5.10

    Re: HOWTO: Kernel Compilation for Newbies

    Um...I'm trying to install a 2.6.14 from kernel.org.
    Everything works until I get to step #7. When I type "sudo make-kpkg clean",

    I get

    sudo: make-kpkg: command not found
    This is probably a simple problem:That's why it's so annoying that I don't know how to fix it.
    I installed all the packages that this guide listed, and followed it closely.
    I probably shouldn't even be doing kernel compilation if I can't solve this problem myself.

    Oh, well, I don't care. This is interesting. I'm gonna do it. Asking people for help and experimenting is the
    only way to learn.

    Help would be appreciated.
    Last edited by phanboy_iv; November 7th, 2005 at 05:39 PM.
    GUNZIP!! BUNZIP TOO!!!

    "I may not understand what I'm installing, but that's not my job. I just need to click Next, Next, Finish here so I can walk to the next system and repeat the process"
    -- Anonymous NT Admin

  5. #5
    Join Date
    May 2005
    Location
    Rochester, NY
    Beans
    29
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Kernel Compilation for Newbies

    Quote Originally Posted by phanboy_iv
    Um...I'm trying to install a 2.6.14 from kernel.org.
    Everything works until I get to step #7. When I type "sudo make-kpkg clean",
    make kpkg is part of "kernel-package" installed in the early steps. you may want to make sure you have that installed properly (do another apt-get install kernel-package) and you should be set.

  6. #6
    Join Date
    Aug 2005
    Location
    Georgia,USA
    Beans
    91
    Distro
    Ubuntu Breezy 5.10

    Re: HOWTO: Kernel Compilation for Newbies

    Quote Originally Posted by slimb
    make kpkg is part of "kernel-package" installed in the early steps. you may want to make sure you have that installed properly (do another apt-get install kernel-package) and you should be set.
    I KNEW it was something simple I shoulda known.
    Thanks much.
    Now, let's try this again......
    GUNZIP!! BUNZIP TOO!!!

    "I may not understand what I'm installing, but that's not my job. I just need to click Next, Next, Finish here so I can walk to the next system and repeat the process"
    -- Anonymous NT Admin

  7. #7
    Join Date
    Nov 2004
    Location
    Milan, italiy
    Beans
    41

    Re: HOWTO: Kernel Compilation for Newbies

    Quote Originally Posted by tseliot
    Now you are back to the command line, type:

    6) su
    CC=gcc-3.4
    export CC
    exit
    CC=gcc-3.4
    export CC
    what is this?
    i never did it, and i wonder what it does...

    and what about Kolivas' patches? on the url you gave there no info...

    eraclito

  8. #8
    Join Date
    May 2005
    Location
    Lecce, Italy
    Beans
    6,168
    Distro
    Ubuntu

    Re: HOWTO: Kernel Compilation for Newbies

    Quote Originally Posted by eraclito
    what is this?
    i never did it, and i wonder what it does...

    and what about Kolivas' patches? on the url you gave there no info...

    eraclito
    Sometimes exporting the compiler you want to use (gcc-3.4 or 4.0) doesn't work if you do it with the "sudo" command. For this reasons you will use "su" according to the steps described above (it won't damage or modify your system in any way).

    About Kolivas' patches: get to the folder with a name which matches your kernel version (e.g. if you are going to compile "kernel 2.6.14" get to http://ck.kolivas.org/patches/2.6/2.6.14/). You will see other folders with different versions of the patch: I suggest you to select the latest version (2.6.14-ck3 in this case). Then you have to choose the file "patch-2.6.14-ck3.bz2" if you have a desktop computer (or laptop) or "patch-2.6.14-cks3.bz2" if you have a server.

    Ok, I will add this to the guide, thanks for the feedback.
    Last edited by tseliot; November 7th, 2005 at 11:07 PM.

  9. #9
    Join Date
    Nov 2004
    Location
    Milan, italiy
    Beans
    41

    Re: HOWTO: Kernel Compilation for Newbies

    Quote Originally Posted by tseliot
    About Kolivas' patches: get to the folder with a name which matches your kernel version (e.g. if you are going to compile "kernel 2.6.14" get to http://ck.kolivas.org/patches/2.6/2.6.14/). You will see other folders with different versions of the patch: I suggest you to select the latest version (2.6.14-ck3 in this case). Then you have to choose the file "patch-2.6.14-ck3.bz2" if you have a desktop computer (or laptop) or "patch-2.6.14-cks3.bz2" if you have a server.
    thanks, but i was asking what the patches can do, why i have to use them (sorry but i want undertend what i do, to improve my linux knowledge...)

    eraclito

  10. #10
    Join Date
    Oct 2005
    Beans
    333

    Re: HOWTO: Kernel Compilation for Newbies

    tseliot, when I get to step 8 and type: sudo make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers modules_image
    I get these errors:kernel/sched.c:1231: error: redefinition of ‘cache_delay’
    kernel/sched.c:1211: error: previous definition of ‘cache_delay’ was here
    kernel/sched.c:1238: error: redefinition of ‘preempt’
    kernel/sched.c:1218: error: previous definition of ‘preempt’ was here
    {standard input}: Assembler messages:
    {standard input}:524: Error: symbol `cache_delay' is already defined
    make[2]: *** [kernel/sched.o] Error 1
    make[1]: *** [kernel] Error 2
    make[1]: Leaving directory `/usr/src/linux-2.6.14cK1'
    make: *** [stamp-build] Error 2

    what am I doing wrong I can never get past this step.

Page 1 of 48 12311 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •