如何自定义您的Ubuntu内核

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命令

$ uname -r

$ uname -r

2.6.17-10-generic

2.6.17-10-通用

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.

现在,我们需要为您的内核安装linux源,请注意我正在运行2.6.17-10内核,因此安装程序行将对此进行反映。 出于本文的目的,您可以用内核号替代正在运行的任何内容。 我们还需要安装curses库和其他一些工具来帮助我们进行编译。

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

须藤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:

如果您好奇Linux源代码的安装位置,则可以使用dpkg命令告诉您软件包中的文件。 这是我系统上的输出:

$ 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)

$ 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(已整理)

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

我们可以看到源文件已经以压缩文件的形式安装到/ usr / src目录中。

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打开新的shell进入root模式。 还有其他方法可以做到这一点,但我更喜欢这种方式。

sudo /bin/bash

须藤/ 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)

现在将目录更改为源位置,以便我们可以安装。 请注意,如果未安装bunzip实用程序,则可能需要安装它。 (在我的)

cd /usr/src

光盘/ usr / src

bunzip2 linux-source-2.6.17.tar.bz2

bunzip2 linux-source-2.6.17.tar.bz2

tar xvf linux-source-2.6.17.tar

tar xvf linux-source-2.6.17.tar

ln -s linux-source-2.6.17 linux

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

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

光盘/ usr / src / linux

make menuconfig

制作menuconfig

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

首先,向下以加载备用配置文件,然后加载.config文件。 (只需按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.

现在我们进入了实用程序,我们可以为自定义内核设置选项。 导航非常简单,如果您迷路了,顶部会有一个图例。 我决定选择“网络连接”,然后按Enter键进入该类别。

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.

好吧,我将立即禁用它。 为什么到底在我的内核中安装了那个? 我按Esc退出帮助屏幕,然后按N将其从内核中排除。

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

使kpkg干净

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

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.

此过程将在/ usr / src中创建两个包含内核的.deb文件。 linux-image ****文件是实际的内核映像,另一个文件包含dpkg都可以安装。 文件名在您的系统上可能会有所不同。

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. 

请注意,当您运行以下命令时,这会将新内核设置为新的默认内核。 这可能会破坏事情! 如果您的计算机无法启动,则可以在GRUB加载菜单上单击Esc,然后选择旧内核。 然后,您可以在/boot/grub/menu.lst中禁用内核,或尝试再次编译。

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

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

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进行检查。 请注意,确切的数字在您的计算机上将有所不同。

uname -r

匿名-r

2.6.17.14-ubuntu1-custom

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.

我计划写一系列有关内核定制的文章,因此订阅RSS feed进行更新。

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”.

另外, 出于全面披露的目的,我从HowtoForge的文章中了解了如何进行此操作, HowtoForge是一个很好的网站,提供有关Linux的一些非常高级的教程。 您会注意到,尽管我试图使本文更加“ Ubuntu”,但本文中的许多步骤都是相似的。

翻译自: https://www.howtogeek.com/howto/ubuntu/how-to-customize-your-ubuntu-kernel/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值