现在的位置: 首页 > 综合 > 正文

自定义你自己的xubuntu

2013年10月02日 ⁄ 综合 ⁄ 共 8312字 ⁄ 字号 评论关闭
文章目录

最近想学习linux driver programming,  买了第三版,作者说,最好自己编译一个linux出来,我就打算这么做了。

下面这个网址的内容帮助我良多

http://www.howtogeek.com/howto/ubuntu/how-to-customize-your-ubuntu-kernel/

////// 以下是原文

How to Customize Your Ubuntu Kernel

Kernel customization is not for everyone. Please note before you try any of this that it can break your system.

There’s a bunch of reasons that you’d want to customize your kernel. You may want to trim down your kernel to only the necessary services, especially if you are running a server or dedicated device that only requires the essentials. You also may need to patch your kernel to support hardware that isn’t currently supported with the kernel you are running on.

This article will not explain how to patch your kernel, just how to customize your current one. I’ll have another followup article that explains how to patch your kernel, and some practical reasons why you’d want to do so.

To start, we need to figure out what version of the kernel we are currently running. We’ll use the uname command for that

$ uname -r

2.6.17-10-generic

Now we need to Install the linux source for your kernel, note that I’m running the 2.6.17-10 kernel, so the installer line reflects that. For the purposes of this article, you can substitute the kernel number for whatever you are running. We also need to install the curses library and some other tools to help us compile.

sudo apt-get install linux-source-2.6.17 kernel-package libncurses5-dev fakeroot

If you are curious where the linux source gets installed to, you can use the dpkg command to tell you the files within a package. Here’s the output on my system:

$ dpkg -L linux-source-2.6.17
/.
/usr
/usr/src
/usr/src/linux-source-2.6.17.tar.bz2
/usr/share
/usr/share/doc
/usr/share/doc/linux-source-2.6.17
(trimmed)

We can see that the source has been installed to the /usr/src directory in a zipped file.

To make things easier, we’ll put ourselves in root mode by using sudo to open a new shell. There’s other ways to do this, but I prefer this way.

sudo /bin/bash

Now change directory into the source location so that we can install. Note that you may need to install the bunzip utility if it’s not installed. (it was on mine)

cd /usr/src

bunzip2 linux-source-2.6.17.tar.bz2

tar xvf linux-source-2.6.17.tar

ln -s linux-source-2.6.17 linux

Make a copy of your existing kernel configuration to use for the custom compile process. Note that the ` character is the one below the tilde ~

cp /boot/config-`uname -r` /usr/src/linux/.config

Now we will launch the utility that will let us customize the kernel:

cd /usr/src/linux

make menuconfig

First, go down to Load an Alternate Configuration File, and load the .config file. (just hit enter)

///  外站图片,略

Now that we are inside the utility, we can set the options for our custom kernel. Navigation is pretty simple, there’s a legend at the top if you get lost. I decided to select Networking and hit the Enter key to go down into that category.

///  外站图片,略

Amateur Radio Support?  What in the hell is that installed for? You’ll note by the * that it’s built-in to the kernel.

///  外站图片,略

By pressing the ? key, we can see the help for that particular item. Here’s the explanation:

///  外站图片,略

Well, I’m going to disable that immediately. Why on earth is that installed in my kernel anyway? I hit Esc to exit the help screen, and then hit N to exclude that from my kernel.

When you are finished making whatever choices you want, hit Exit and save the configuration when prompted.

Now we have a configuration ready for compile. First we’ll do a make clean, just to make sure everything is ready for the compile.

make-kpkg clean

Next we’ll actually compile the kernel. This will take a LONG FREAKING TIME, so go find something interesting to do.

fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers

This process will create two .deb files in /usr/src that contain the kernel. The linux-image****  file is the actual kernel image, and the other file contains the You can install both with dpkg. The filenames will probably be different on your system.

Please note that when you run these next commands, this will set the new kernel as the new default kernel. This could break things! If your machine doesn’t boot, you can hit Esc at the GRUB loading menu, and select your old kernel. You can then disable the kernel in /boot/grub/menu.lst or try and compile again. 

dpkg -i linux-image-2.6.17.14-ubuntu1-custom_2.6.17.14-ubuntu1-custom-10.00.Custom_i386.deb

dpkg -i linux-headers-2.6.17.14-ubuntu1-custom_2.6.17.14-ubuntu1-custom-10.00.Custom_i386.deb

Now reboot your machine. If everything works, you should be running your new custom kernel. You can check this by using uname. Note that the exact number will be different on your machine.

uname -r

2.6.17.14-ubuntu1-custom

 

I plan to write a series of articles on kernel customization, so subscribe to the RSS feed for updates.

Also, In the interests of full disclosure, I learned how to do this from the article at HowtoForge, which is a great website for some very advanced tutorials on linux. You’ll note that many of the steps in this article are similar, although I tried to make this article more “Ubuntu”.

////////////////  原文结束

刚开始的过程都是按照上面说的做的。

后来发现一个问题,经过下面2条命令,

dpkg -i linux-image-2.6.17.14-ubuntu1-custom_2.6.17.14-ubuntu1-custom-10.00.Custom_i386.deb

dpkg -i linux-headers-2.6.17.14-ubuntu1-custom_2.6.17.14-ubuntu1-custom-10.00.Custom_i386.deb

grub.cfg 并不会更新,新编译的verion的linux 并不能加入到启动列表中。

后来,google 发现了如下网址:

http://okomestudio.net/biboroku/?p=754#comment-891

帮我解决了grub.cfg更新的问题

///////////// 原文

Customizing & Installing Linux Kernel on Debian Squeeze

Here is a quickie for customizing and install Linux kernel 2.6.x on Squeeze.

Install some packages and kernel source:

$ sudo aptitude update
$ sudo aptitude install kernel-package bzip2 g++ libqt3-mt-dev libncurses5-dev sudo fakeroot

If you do not belong to group “src”, add yourself to the group as we work under /usr/src:

$ sudo adduser username src

You need to logout and login for this change to take effect. You also need to be able to use sudo or su to install the new kernel in the end.

The kernel packaged for Squeeze is at version 2.6.32. Alternatively a newer kernel could be obtained from kernel.org and saved to /usr/src. The customization procedure should be similar. Here I just follow the Debian way:

$ sudo aptitude install linux-source-2.6.32

Extract the source tree:

$ sudo chgrp -R src /usr/src
$ sudo chmod -R g+w /usr/src
$ cd /usr/src
$ rm linux
$ tar -jxf linux-source-2.6.32.tar.bz2
$ ln -s linux-source-2.6.32 linux
$ cd linux

Edit the EXTRAVERSION entry in Makefile, as in:

EXTRAVERSION = .20100321.1

for example to add .20100321.1 to the kernel version number. This is convenient for keeping the existing, working kernels around when you need to recompile with different options.

Use xconfig or menuconfig to customize the kernel options. Before the make-kpkg lines, setting concurrency (most likely to the number of cores of my processor) is optinal but having a higher number typically reduces the compilation time.

$ make mrproper
$ make xconfig    # or make menuconfig
$ export CONCURRENCY_LEVEL=4    # this is optional
$ fakeroot make-kpkg clean
$ fakeroot make-kpkg --initrd kernel_image
$ cd ..
$ sudo dpkg -i linux-image-2.6.32.20100321.1_2.6.32.20100321.1-10.00.Custom_amd64.deb

Upon reboot in the GRUB menu you will find the newly installed kernel:

$ sudo reboot

Purging Old Kernel Image from System

For example, if the kernel to be uninstalled is of version 2.6.26 and the extra version that I used was 20091112.1, do:

$ sudo dpkg -P linux-image-2.6.26.20091112.1

That’s it. However it is often a good idea to keep at least one kernel image that I know for sure to work so that when a custom kernel fails, I have something to fall back on.  On the other hand, it is also a good idea to purge very old kernel images to save space in /boot.

Giving Kernel Boot Options with Grub (Version 2)

The new Grub has a slightly different way of specifying boot options (/boot/grub/menu.lst no longer exists for version 2!).

$ sudo chmod +w /boot/grub/grub.cfg
... open and edit /boot/grub/grub.cfg ...
$ sudo chmod -w /boot/grub/grub.cfg

If I need to provide a kernel with boot options, find the “menuentry” for the kernel, and change from

linux /vmlinuz-2.6.36.1.3 root=UUID=somehash ro quiet

to

linux /vmlinuz-2.6.36.1.3 root=UUID=somehash ro quiet usbcore.autosuspend=1

in order to set the usbcore.autosuspend option, for example.

Playing with CONCURRENCY_LEVEL

With Core i5 (2 cores but virtually 4 cores with hyperthreading), I get:

$ fakeroot make-kpkg clean
$ export CONCURRENCY_LEVEL=4
$ time fakeroot make-kpkg --initrd kernel_image
...
real    6m50.028s
user    21m45.186s
sys     2m42.246s

$ fakeroot make-kpkg clean
$ export CONCURRENCY_LEVEL=1
$ time fakeroot make-kpkg --initrd kernel_image
...
real    13m55.216s
user    13m23.638s
sys     1m50.359s

I say significant speed up!

What if Kernel Panics after Reboot?

(NOTE: This was true back when I was playing around when Squeeze was still far from stable. I don’t think this section is relevant as of November 2010, since Squeeze is very close to stable now. Just leaving the note in case for its archival value.)

Well, it turns out make-kpkg --initrd does not automatically create a /boot/inird.img-* file for my current configuration. I wondered for a while why my new custom kernel keeps panicking upon reboot but finally realized that was the cause.

Fortunately, I can create the image myself easily:

$ sudo update-initramfs -c -k 2.6.32.20100321.1
$ sudo update-grub

This should work.

//////////////原文结束

其中的

Fortunately, I can create the image myself easily:

$ sudo update-initramfs -c -k 2.6.32.20100321.1
$ sudo update-grub

This should work.

帮我解决了问题。

现在,我已经运行我自己编译的xubuntu 了。

抱歉!评论已关闭.