Ubuntu 编译kernel 的几种方法

Method 1:

1. Use apt-get source to download the Ubuntu version of the kernel

apt-get source linux-image-$(uname -r)
gives a folder that contains, for example:

linux-3.2.0                linux_3.2.0-26.41.dsc
linux_3.2.0-26.41.diff.gz  linux_3.2.0.orig.tar.gz

The bolded diff includes all the Ubuntu/Debian customizations.

2. To build a stock kernel with your own .config, use the "old-fashioned" Debian make-kpkg method

sudo apt-get install kernel-package
If you are compiling a kernel for the first time:
sudo apt-get build-dep linux-image-$(uname -r)
Then cd into the source directory (here, linux-3.2.0), and either run make oldconfig to create .config file with your running kernel's configuration, or copy a third-part .config to this directory.

Depending on whether you want a text or graphical config, install:

(Text)

sudo apt-get install libncurses5 libncurses5-dev
(Graphical)

sudo apt-get install qt3-dev-tools libqt3-mt-dev

And then run:

(Text)

make menuconfig

(Graphical)

make xconfig

When done, just run

make-kpkg

make-kpkg -j N --initrd --append-to-version=my-very-own-kernel kernel-image kernel-headers

where N is how many jobs to run in parallel (usually the number of CPUs you have), and my-very-own-kernel is a custom string to identify this build.

When done, the kernel image and header files will be ready as debs in the parent directory; you can simply install them with sudo dpkg -i, which will also take care of adding GRUB entries, etc.


method 2:

1. download kernel code(linux.3.16.1.tar.xz),  untar the file, then  run 

make; make modules; 

2. install the modules by running:

sudo make modules_install
Install the kernel itself by:

sudo make install
That puts vmlinuz-3.16.1 (a copy of vmlinuz), config-3.16.1 (a text file storing kernel configuration parameters), and System.map-3.16.1 (the kernel symbol lookup table) in /boot. For more details, see this comp.os.linux.misc post by Hadron and man installkernel.

Final setup, so the kernel can be started and boot the system:

This section is partly based on information in Kernel/Compile.

With the kernel now where it needs to be, it needs:

Generate your initramfs with mkinitramfs:

cd /boot
sudo mkinitramfs -ko initrd.img-3.16.1 3.16.1

or:

sudo update-initramfs -u -k 3.16.1
or:

sudo update-initramfs -c -k 3.0.0

When you update the configuration of the GRUB2 boot loader--which has been the default in Ubuntu since 9.10--should automatically detect the new kernel and add an option to boot from it.

sudo update-grub

It could be possible that the create initrd.img is very large (over 100MB), and the boot partiiton maybe don't have enough free space.  In this case, apply the strip parameter when installing modules:

make INSTALL_MOD_STRIP=1 modules_install

Similarly, for building the deb packages:

make INSTALL_MOD_STRIP=1 deb-pkg




  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译Ubuntu内核的步骤如下: 1. 下载内核源代码: 在终端中执行以下命令来下载最新版本的内核源代码: ``` $ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-<RELEASE-CODE-NAME>.git ``` 其中 `<RELEASE-CODE-NAME>` 是你要编译Ubuntu版本的代号,比如 "focal" 代表 Ubuntu 20.04 LTS。 2. 安装编译所需的依赖: 在终端中执行以下命令来安装编译所需的依赖: ``` $ sudo apt-get build-dep linux-image-$(uname -r) $ sudo apt-get install libncurses-dev flex bison openssl libssl-dev ``` 3. 配置内核: 进入内核源代码目录,执行以下命令来配置内核: ``` $ cd ubuntu-<RELEASE-CODE-NAME> $ cp /boot/config-$(uname -r) .config $ make menuconfig ``` 这会打开一个菜单界面,你可以根据需要进行内核配置的修改。 4. 编译内核: 执行以下命令来编译内核: ``` $ make -j$(nproc) ``` `-j$(nproc)` 表示使用与你的系统内核数量相同的线程数进行编译,可以加快编译速度。 5. 安装编译好的内核: 执行以下命令来安装编译好的内核: ``` $ sudo make modules_install $ sudo make install ``` 6. 更新引导: 执行以下命令来更新引导: ``` $ sudo update-initramfs -c -k <KERNEL-VERSION> $ sudo update-grub ``` `<KERNEL-VERSION>` 是你编译好的内核版本号。 7. 重启系统: 编译和安装完成后,你可以通过以下命令来重启系统: ``` $ sudo reboot ``` 请注意,编译内核需要一定的时间和计算资源,并且对系统有一定的风险。在进行这个过程之前,请确保你了解相关知识并备份重要数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值