当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 2 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [转]How to compile a Ubuntu Lucid kernel
帖子发表于 : 2010-06-27 13:28 

注册: 2009-10-30 22:54
帖子: 98
送出感谢: 0 次
接收感谢: 0 次
http://blog.avirtualhome.com/2010/05/05/how-to-compile-a-ubuntu-lucid-kernel/
How to compile a Ubuntu Lucid kernel
May 5, 2010 6:51 pm UTC | 29 Comments

Ubuntu Lucid was released in April and I have been writing articles on “How to compile a kernel for Ubuntu …” for a few releases and there is no exception for Ubuntu Lucid.
The Ubuntu kernel developers have decided to change things up yet again for the Ubuntu Lucid kernel. The steps in this article will be significantly different from previous Ubuntu releases.

But enough with the small talk, let’s start compiling our own Ubuntu Lucid kernel.

Introduction
git
I’ll be using git to get the latest kernel version. This is my favorite way to get the sources and it is in my opinion the fastest way to make changes later on when you want to update your own kernel to the latest version.
I suggest adding my Launchpad repository to your system. The repository holds the latest version of git and is usually updated within a day of a new release of git, follow the instructions on the page Git Packages for Ubuntu to add my repository. There is a version available for Lucid as well.

Arch
I am compiling the i386 version, if you want to compile for amd64 you need replace i386 for amd64 throughout this article.

Flavor
I choose the name core2 as the flavor name as for my personal use I’ll build a kernel for a Core2 processor. Besides the change of processor type in the configuration I also select support for 64GB as my laptop has 4GB, which is the main reason I started compiling my own kernels. I have some other changes but that’s beyond this article.

Preparations
Let’s get started by preparing our machine for compiling the Ubuntu Lucid kernel.
Open a terminal.

sudo su -
apt-get install fakeroot build-essential
apt-get install crash kexec-tools makedumpfile kernel-wedge
apt-get build-dep linux
apt-get install git-core libncurses5 libncurses5-dev
apt-get install libelf-dev asciidoc binutils-dev
Create a directory where you would like to build your kernel, this directory will hold the kernel source in a sub directory and all the deb files will end up in this folder. I choose /d1/development/kernel/lucid

Getting the source
cd /d1/development/kernel/lucid
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-lucid.git source
The source code is installed in the directory source.

We will create a branch in which we will be doing our modifications. That way the master branch will stay in tact which will make it a whole lot easier when we want to update our own Ubuntu Lucid kernel to a newer version.
To see the latest version:

cd source
less debian.master/changelog
Press q to get back to the prompt.
This results in something like this:

linux (2.6.32-21.31) lucid; urgency=low
Sometimes you will see the first section as UNRELEASED in that case the latest version is the first version after the UNRELEASED section.
In our case the latest version is 2.6.32-21.31.
You could select any version you see in the changelog but for the sake of this article we’ll use the latest version.

The Ubuntu kernel developers tag each version as Ubuntu- and therefor we can checkout the version we want as

git checkout Ubuntu-2.6.32-31.31 -b core2
This will create a branch called core2.

Creating a new config
I’ll be using the method of creating a new flavor, this adds a bit more work but you can always compile the original kernels.

We’ll use the generic flavor as the base for our own flavor being core2.

cp debian.master/config/i386/config.flavour.generic debian.master/config/i386/config.flavour.core2
fakeroot debian/rules clean
debian/rules updateconfigs
To make changes to the configuration file we need to edit the configuration file. The kernel developers have created a script to edit kernel configurations which has to be called through the debian/rules makefile, unfortunately you will have to go through all the flavors for this script to work properly.

debian/rules editconfigs
The script will show you which configuration is next to be edited. You should not make changes to any of the configurations until you see the core2 configuration

* Run menuconfig on i386/config.flavour.core2... Press a key.
Make your changes, save the configuration and then keep going until the script ends. You could save the other configurations but you don’t have to. I will write up what changes I made for my configuration in a separate article to be published soon.

When you’re done, make a backup of the config flavor file.

cp debian.master/config/i386/config.flavour.core2 ../.
Now we need to clean up the git tree in order to get ready for compilation.

git reset --hard
git clean -xdf
Getting ready for compilation
Because we are going to be creating a new flavor based on a existing flavor (generic in my case) we need to create some extra files. During compilation the process checks the previous release for some settings, as we’re creating a local flavor it doesn’t exist in the source, so we’re creating it. The previous release in this case is 2.6.32-20.30

ls debian.master/abi
cp debian.master/abi/2.6.32-20.30/i386/generic debian.master/abi/2.6.32-20.30/i386/core2
cp debian.master/abi/2.6.32-20.30/i386/generic.modules debian.master/abi/2.6.32-20.30/i386/core2.modules
Copy our flavored configuration file back.

cp ../config.flavour.core2 debian.master/config/i386/
We need to edit some files:

File: debian.master/etc/getabis
Search for the line:

getall i386 generic generic-pae 386
Change it in:

getall i386 generic generic-pae 386 core2
File: debian.master/rules.d/i386.mk
Search for the line:

flavours = generic generic-pae 386
Change it in:

flavours = generic generic-pae 386 core2
We need to make the compilation process aware of our own flavor we want to compile.

cp debian.master/control.d/vars.generic debian.master/control.d/vars.core2
You can edit the file and make it your own.

arch="i386 amd64"
supported="Core2"
target="Geared toward Core2 desktop systems."
desc="x86/x86_64"
bootloader="grub-pc | grub | lilo (>= 19.1)"
provides="kvm-api-4, redhat-cluster-modules, ivtv-modules, ndiswrapper-modules-1.9"
We need to commit our changes in the git repository.

git add .
git commit -a -m "Core2 modifications"
The text after -m is the message you add to your commit.

Compilation
It’s finally time for compiling but before we can start the compilation process there is one more step to do. I didn’t put this in the Preparations section as you need to the following step whether you make changes to the configuration or not

fakeroot debian/rules clean
All the packages will be created in the directory /d1/development/kernel/lucid
Create independent packages:

skipabi=true skipmodule=true fakeroot debian/rules binary-indep
The above statement will create the following deb files:

linux-source-2.6.32_2.6.32-21.31_all.deb'.
linux-doc_2.6.32-21.31_all.deb
linux-tools-common_2.6.32-21.31_all.deb
linux-headers-2.6.32-21_2.6.32-21.31_all.deb
Create the tools packages:

skipabi=true skipmodule=true fakeroot debian/rules binary-perarch
The above statement will create the following deb files:

linux-source-2.6.32_2.6.32-21.31_all.deb'.
linux-tools-2.6.32-21_2.6.32-21.31_i386.deb
Create the flavour depended files:

skipabi=true skipmodule=true fakeroot debian/rules binary-core2
The above statement will create the following deb files:

linux-headers-2.6.32-21-core2_2.6.32-21.31_i386.deb
linux-image-2.6.32-21-core2_2.6.32-21.31_i386.deb
Installation
After the compilation is finished we’ll have the above packages in the parent directory.

To install the files

cd ..
sudo dpkg -i linux-headers-2.6.32-21-core2_2.6.32-21.31_i386.deb linux-headers-2.6.32-21_2.6.32-21.31_all.deb linux-image-2.6.32-21-core2_2.6.32-21.31_i386.deb
Check your bootloader if the newly installed kernel is the default one, for grub check the file /boot/grub/menu.lst or if you run grub2 check /boot/grub/grub.cfg

Reboot and enjoy your newly installed kernel.

------------------------------------------------------------------------------
太重要了,备份下


页首
 用户资料  
 
2 楼 
 文章标题 : Re: [转]How to compile a Ubuntu Lucid kernel
帖子发表于 : 2010-06-27 13:37 
头像

注册: 2009-12-02 12:41
帖子: 748
送出感谢: 0 次
接收感谢: 0 次
:em20 :em20


_________________
who am I? I wander ...


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 2 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译