apt-get source
命令下载Ubuntu内核的版本。apt-get source linux-image-$(uname -r)
sudo apt-get install kernel-package
sudo apt-get build-dep linux-image-$(uname -r)
sudo apt-get install libncurses5 libncurses5-dev
sudo apt-get install qt3-dev-tools libqt3-mt-dev
然后运行:
(文本)
make menuconfig
make xconfig
fakeroot make-kpkg -j N --initrd --append-to-version=my-very-own-kernel kernel-image kernel-headers
其中N
是并行运行的作业数量(通常是您拥有的CPU数量),而my-very-own-kernel
是用于标识此构建的自定义字符串。
完成后,内核映像和头文件将准备好作为debs文件在父目录中;您可以使用sudo dpkg -i
安装它们,这也会处理添加GRUB条目等操作。
linux-3.2.0
目录并运行patch -p1 <../patch.diff
是吗? - user827992apt-get source ...
已经为您做了这个! - ish/usr/src/linux-headers-3.2.0
吗? - Sopalajo de Arrierezmake nconfig
。 - Rayfakeroot
调用make-kpkg
。在“安装”deb时出现错误。正在编辑答案... - tudor -Reinstate Monica-fakeroot debian/rules editconfigs
, fakeroot debian/rules clean
, fakeroot debian/rules binary
是正确、无问题的方法。 - Aleksandr Dubinskyapt-get source linux-source
,然后按照克隆git仓库的说明进行操作。 - rustyx您可以在kernel.org获取上游内核源代码。在撰写本文时,使用的是版本3.16.1(最新稳定内核)。因此,如果您使用不同版本,可能需要修改这些命令。
内核源代码目前以 .tar.xz 归档文件形式提供,因此请点击您所需版本的 "tar.xz" 链接:
cd
命令切换到该目录,然后可以使用tar
命令解压缩它。tar xf linux-3.16.1.tar.xz
为了获取Ubuntu的工具链(gcc
,make
等),请安装build-essential 元包:
sudo apt-get update
sudo apt-get install build-essential
有两种相对用户友好的方法可以配置内核,它们是通过make
目标xconfig
和menuconfig
提供的。
xconfig
运行一个图形化配置工具,而menuconfig
是基于文本的(即其界面完全出现在终端中)。每个都需要一些额外的软件,这些软件不是由build-essential 提供。
要进行图形化配置,请安装libqt4-dev 和pkg-config
,然后运行
make xconfig
:
sudo apt-get install libqt4-dev pkg-config
make xconfig
sudo apt-get install libncurses5-dev
make menuconfig
首先运行以下命令编译内核并创建vmlinuz
:
make
vmlinuz
是指“内核”。具体而言,它是将由GRUB或你所使用的任何其他引导加载器解压缩和载入到内存中的内核映像。
然后构建可加载内核模块:
make modules
假设那些make
命令成功完成,现在是时候安装新内核了。首先安装模块:
sudo make modules_install
sudo make install
这将把vmlinuz-3.16.1
(vmlinuz
的副本)、config-3.16.1
(存储内核配置参数的文本文件)和System.map-3.16.1
(内核符号查找表)放在/boot
中。有关更多详细信息,请参见Hadron在comp.os.linux.misc上发布的帖子和man installkernel
。
本节部分基于Kernel/Compile中的信息。
现在内核已经到达需要的位置,它需要:
一个启动加载程序的配置项,这样你就可以选择并从中引导。
一个初始RAM文件系统,它是内核加载驱动程序和挂载/
文件系统的环境。
(如果你正在安装旧的内核或者已经配置了内核使用devfs代替较新的udev, 你可能需要设置一个初始ramdisk。如果你确定需要使用它,请参阅man initrd
。)
mkinitramfs
生成您的initramfs:cd /boot
sudo mkinitramfs -ko initrd.img-3.16.1 3.16.1
sudo update-grub
现在你可以重新启动来测试你的新内核。在启动过程中,你可能需要按住Shift键或者按下Esc键,以便看到GRUB引导菜单,你可以在其中选择安装的不同内核。
要将你的内核(或其他内核)设置为默认内核,请参阅如何更改GRUB引导顺序?
make menuconfig
需要先执行apt get install libncurses5-dev
命令。 - Hannu# Get source code
apt-get source linux-image-$(uname -r)
# Install dependencies
sudo apt-get build-dep linux-image-$(uname -r)
# Compile
cd linux-4.4.0
fakeroot debian/rules clean
fakeroot debian/rules binary
# Install (obviously the versions will be different)
cd ..
sudo dpkg -i linux-image-4.4.0-38-generic_4.4.0-38.57_amd64.deb linux-headers-4.4.0-38_4.4.0-38.57_all.deb linux-headers-4.4.0-38-generic_4.4.0-38.57_amd64.deb
Ubuntu git内核仓库
根据https://help.ubuntu.com/community/Kernel/Compile的想法,并更清楚地解释为什么我认为配置看起来正确,可以在Where can I get the 11.04 kernel .config file?找到更多信息:
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git linux
cd linux
git checkout Ubuntu-4.15.0-36.39
fakeroot debian/rules clean
debian/rules updateconfigs
fakeroot debian/rules build-generic
cp debian/build/build-generic/.config .
make -j `nproc`
fakeroot debian/rules ...
命令。请参阅@Pilot6在链接问题中的回答。或者我漏掉了什么吗? - minghua